I am compiling a library using a makefile and the structure of the code is as below. I have a cuda header file “cuda_functions.cuh” and its cuda file “cuda_functions.cu” and a main file “main.cu”. When I am trying to compile the code while including “cuda_functions.cuh” I get no error, also the object file (i.e. cuda_functions.o) is created, but when I am trying to call a function of it i.e. call_from_main(), I get this error:
error: identifier “call_from_main” is undefined
any advice would be highly appreciated.
cuda_functions.cuh
const int n=4;
typedef float data;
#define MAX_DATA INT_MAX
#define MIN_DATA INT_MIN
__device__ int array[n];
__device__ int device_fun();
inline __device__ inline_fun(void);
__global__ void global_fun(float*, int);
void call_from_main(float*, int);
cuda_functions.cu
#include<cuda_functions.cuh>
__device__
int device_fun()
{
....
}
inline __device__
inline_fun(void)
{
....
}
__global__
void global_fun(float*, int)
{
device_fun();
....
inline_fun();
....
}
void call_from_main(float* a, int b)
{
global_fun<<<1,1>>>(a, b);
}
main.cu
#include<cuda_functions.cuh>
int main(int argc, char* args[])
{
float* a=(float*) malloc(sizeof(float)*5);
call_from_main(a,5);
}
makefile
CUDAMain: main.cu
nvcc -rdc=true --generate-code arch=compute_35,code=compute_35 main.cu \-std=c++11 -o result -I.