Due to some restructuring in my cuda code I get the following error " Unresolved extern function" when I try to call a device function from a kernal.
test.cuh looks like this:
#include "cuda_runtime.h"
class TestKernel
{
public:
int number;
TestKernel(int number);
__device__ __host__
void run();
};
The test.cu looks like this.
#include"testkernel.cuh"
#include "stdio.h"
TestKernel::TestKernel(int number)
{
this->number = number;
}
void TestKernel::run()
{
printf("%d", this->number);
}
My main file looks like this.
#include "device_launch_parameters.h"
#include "testkernel.cuh"
__global__ void kernel(TestKernel * testKernel)
{
testKernel[blockIdx.x * blockDim.x + threadIdx.x].run();
}
int main()
{
TestKernel * testKernel;
cudaMallocManaged(&testKernel, 10 * sizeof(*testKernel));
for (int i = 0; i < 10; i++)
{
testKernel[i] = TestKernel(i);
}
kernel << <1, 10 >> > (testKernel);
return 0;
}
I have found suggestions that this could be solved by adding -dc during the building, however when I do that I get several other errors:
"Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol __cudaRegisterLinkedBinary_45_tmpxft_00007118_00000000_7_TestKernel_cpp1_ii_aa56518f referenced in function "void __cdecl __nv_cudaEntityRegisterCallback(void * *)" (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z "
I am trying to build it with Visual Studio 2017, and with CUDA 10.1.