[codebox]
///// simpleClass.cu//////////////
class simpleClass {
public:
int *array;
};
device simpleClass *test;
//////////////////////////////////////
/////////Kernel.cu /////////////
#include “simpleClass.cu”
host_function()
{
simpleClass *temp;
int *temp_array;
cudaMalloc(&temp,(size_t)(sizeof(simpleClass)*100));
cudaMemcpyToSymbol(test,&temp,sizeof(simpleClass*),0,cudaMemcpyHostToDevice);
cudaMalloc(&temp_array, (size_t)(sizeof(int)*100));
cudaMemcpy(&(temp->array), &temp_array, sizeof(temp->array), cudaMemcpyHostToDevice);
}
[/codebox]
or, for a statically allocated class
[codebox]
/////////Kernel.cu /////////////
#include “simpleClass.cu”
device simpleClass stat;
host_function()
{
int *temp_array;
cudaMalloc(&temp_array, (size_t)(sizeof(int)*100));
cudaMemcpyToSymbol(stat, &temp_array, sizeof(stat.array), offsetof(simpleClass, array), cudaMemcpyHostToDevice);
}
[/codebox]