Hello,
i am doing my first steps with CUDA. My goal is to use CUDA in my project to use the CPU and GPU for the calculation. The first kernel was successfully compiled and runs perfect. I ‘improved’ that kernel by using a simple class. So, the problem begins because only inline methods can be called from the kernel. I used the following code:
[codebox]#include <stdio.h>
#include <cuda.h>
#include “math/TestClass.h”
global void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N)
{
math::TestClass test(39.0f);
a[idx] = test.doSomething();
}
}[/codebox]
[codebox]#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <cuda.h>
#ifdef GPU_COMPILATION
#ifndef GPU_DEVICE
#define GPU_DEVICE __device__ __host__
#endif
#ifndef GPU_DEVICE
#define GPU_DEVICE
#endif
namespace math
{
class TestClass
{
private:
float myVar;
public:
TestClass(float var)
: myVar(var)
{
}
GPU_DEVICE float doSomething();
GPU_DEVICE float doSomethingInline()
{
return myVar;
}
};
}
#endif[/codebox]
[codebox]#include “TestClass.h”
namespace math
{
float TestClass::doSomething()
{
return myVar;
}
}[/codebox]
I can use doSomethingInline() without any problems, but doSomething() produces the following error:
[codebox]warning: function “math::TestClass::doSomething” was referenced but not defined
Error: External calls are not supported (found non-inlined call to _ZN4math9TestClass11doSomethingEv)[/codebox]
Of course, I can only write inline-methods. But there are already a lot of complete classes in my project, splitted in *.cpp and .h.
Can anyone tell me how i can use classes (without inheritance, …) in the CUDA-kernel? :-)