Allocate memory for object in cuda

Dear All

I defined class like:

class element
int* A;

Then I defined pointers in
element e, dev_e;
cudaMalloc( (void
)&(dev_e->A), ne * sizeof( int ) );

BUT I recievd from compiler:
“Warning: Cannot tell what pointer points to, assuming global memory space”

and also has memory segmentation fault in run time.

Please help me how I can allocate memory for an object containing a dynamic array…

Thank alot,

If dev_e is a device variable, the pointer itself exists device memory, so you can’t dereference it in the host code. You have to allocate the member(s) in device memory, and have their handles as host pointers (still pointing to device memory, but the pointer is in host memory), and allocate the class/struct itself the same way.

Not sure what the best method is for copying all this to your device pointer afterwards, one way that definitely works is passing the pointers as parameters to a <<<1, 1>>> setter kernel that can work with the device variables. Or it might be simpler to pass it as a parameter to your kernel calls, and not use device variables at all.