How to allocate class?

Hello guys.

I am wondering about the allocation of class.

I want to use the class on the GPU memory.

I allocate space of class on CPU.
And then, I also allocate space of class on GPU.
Finally, copy the class’s data on CPU to GPU.

but there is no class data on GPU… Space of class on GPU is valid.
but after copying from CPU class to GPU class, data is garbage value.

How to use class (CUDA C++) on GPU memory?

You have to do a deep copy which involves fixing up the pointer(s) in the class to the class data.

https://stackoverflow.com/questions/50315253/troubles-allocating-objects-in-cuda

Thank you Mr. Robert!

I read your comment that is on the stackoverflow’s board.

I used that style code but there is an error…

this part.

err = cudaMemcpy(&(dev_object->attribute_ptr), &attribute_values, sizeof(char *), cudaMemcpyHostToDevice);


./attribute_handler.hpp(603): error: member "gpu_attribute_handler::attribute_ptr"
./GPU_attribute_handler.cuh(12): here is inaccessible

./attribute_handler.hpp(603) is “err = cudaMemcpy(&(dev_object->attribute_ptr), &attribute_values, sizeof(char *), cudaMemcpyHostToDevice);”

./GPU_attribute_handler.cuh(12) is “dev_object->attribute_ptr”

type is the same, I don’t know the reason…

I found the reason of error.

your comment’s code is using public variable.

but my code is using private variable…

Thank you!