0
votes

io.cuh:

#ifndef IO_CUH
#define IO_CUH

#include <cuda.h>

typedef struct{
    unsigned width;
    unsigned height;
    unsigned char *image; //RGBA
}rgb_image;

__global__ void transformToGrayKernel(rgb_image *img);
void decodeTwoSteps(const char* filename, rgb_image *img);
void encodeOneStep(const char* filename, rgb_image *img);
void processImage(const char *filename, rgb_image *img);

#endif // IO_CUH

I'm trying to compile simple program using the following makefile:

lodepng.o: lodepng.h
        cc -c lodepng.c -o lodepng.o
io.o: io.cuh lodepng.o
        nvcc -c io.cu -o io.o
main: io.o
        nvcc main.c io.o -o main

'main.c' uses one function from io.cu, which is dependent on lodepng.c.

After some minor warnings that reference to the code, I got the following error:

nvcc main.c io.o -o main nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release. In file included from main.c:1:0: io.cuh:12:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’ global void transformToGrayKernel(rgb_image *img); ^ makefile:6: recipe for target 'main' failed make: *** [main] Error 1

1
Aren't C functions global by default? - Weather Vane
@WeatherVane In CUDA, 'global' attribute is label for functions that runs on GPU and are called from host, so I don't think it's redundant. - 0x6B6F77616C74
Don't include the CUDA containing header into your main.c. the C compiler doesn't understand it. - talonmies
@talonmies I know it. There is no 'cuda.h' inside main.c file. - 0x6B6F77616C74

1 Answers

2
votes

The error is caused by the key word __global__, not your kernel's prototype.

That's because the compiler nvcc will interpret its input file, and choose the corresponding rule to compile it. Although you use the nvcc to compile the "main.c", but it will be treated as a C source file, not a CUDA source code. So the compiler can not recognize the CUDA key word __global__ when it compile the file "main.c".

You can change the file type from "main.c" to "main.cu", and it will be treated as a CUDA source code. Then the compiler can recognize the key word __global__.