I have a user defined class. In my global function, I create instances of this class and call some of the member functions. I found that, I have to make all the member functions inline. Otherwise the compilation fails, and no useful information is provided.
I simplified my code to better illustrate the problem.
my header file (header.h):
#include <device_launch_parameters.h>
class ATM
{
public:
host device ATM() {}
host device double rand();
};
my cpp file (source.cpp)
#include <device_launch_parameters.h>
#include “Header.h”
host device double ATM::rand()
{
return 0.5;
}
My cu file:
#include “Header.h”
#include<device_launch_parameters.h>
#include <cuda_runtime.h>
global void test()
{
ATM* atm = new ATM();
double d = atm->rand();
}
int main(void)
{
int threadsPerBlock = 512;
int blocksPerGrid = 100;
test <<<blocksPerGrid, threadsPerBlock >>>();
return 0;
}
However, it works if I get rid of the cpp file, and modified the header file:
header.h
#include <device_launch_parameters.h>
class ATM
{
public:
host device ATM() {}
host device double rand()
{
return 0.5;
}
};
Could someone help explain? Thank you very much.