Hi everybody,
If we take a simple class as follows:
class ClassTest
{
int size;
int *tab;
};
With Cuda, I have not found another way to allocate an object of type ClassTest like this:
// consider an object in the host memory contains data
ClassTest *h_object;
// temporary pointer on ClassTest object
ClassTest *tmp_test = new ClassTest();
tmp_test->size = h_object->size;
cudaMalloc((void **)&tmp_test->tab, sizeof(int) * tmp_test->size);
cudaMemcpy(tmp_test->tab, h_object->tab, sizeof(int) * tmp_test->size , cudaMemcpyHostToDevice);
// Pointer on real object cuda
ClassTest *d_test;
cudaMalloc((void **)&d_test, sizeof(ClassTest));
cudaMemcpy(d_test, tmp_test, sizeof(ClassTest), cudaMemcpyHostToDevice);
And this code for deallocate device object :
cudaFree(tmp_test->tab);
delete tmp_test;
cudaFree(d_test);
So, I wondered if there was a better way to do this?
Thanks