So I have a problem with building a CUDA project.
I’m trying to parallelize a physics engine without having to massively rewrite my code, so I want to add in directives to define my factions as define CUDA_CALLABLE_MEMBER host device in order to reduce the amount of code duplication.
Basically I want my .cu files to call methods from my .h headers.
For example:
test.h
#include <iostream>
#ifdef __CUDACC__
#define CUDA_CALLABLE_MEMBER __host__ __device__
#else
#define CUDA_CALLABLE_MEMBER
#endif
class helloWorld
{
public:
CUDA_CALLABLE_MEMBER helloWorld() {};
CUDA_CALLABLE_MEMBER void boo();
//__host__ __device__ helloWorld() {};
//__host__ __device__ void boo();
};
test.cpp
#include "test.h"
CUDA_CALLABLE_MEMBER void helloWorld::boo()
{
}
test.cuh
#pragma once
#include <cuda.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
class test
{
private:
int SIZE;
public:
test();
};
test.cu
#include "test.h"
#include "test.cuh"
__global__ void myAddKernel(helloWorld* hw, int *c, const int *a, const int *b, int n)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < n)
{
//hw->boo();
c[i] = a[i] + b[i];
}
}
test::test()
{
SIZE = 1024;
helloWorld* hello = new helloWorld();
}
The line hw->boo(); produces the following error:
Googling shows my problem seems to be different from all others. If I comment out that line it compiles fine. If I rewrite it to not bother with .h/.cpp and just use .cuh/.cu then it also compiles and works.
But I would very much like to use regular C++ h/cpp files for time saving reasons.
Additionally, I found the error goes away when:
If Boo() is defined inline in my .h file as
CUDA_CALLABLE_MEMBER void boo() { };
Then it compiles.
But defining it ‘properly’
CUDA_CALLABLE_MEMBER void helloWorld::boo()
{
}
And I get the same error?
Any help would be appreciated. :)