i'm trying implement on cuda involves classes have pointers classes inside. found out need copy memory of pointers separately , here's approach
__host__ production * production::allocatetodevice() { production * productionondevice; size_t productionsize = sizeof(production); cudamalloc((void **) &productionondevice, productionsize); cudamemcpy(productionondevice, this, productionsize, cudamemcpyhosttodevice); vertex * boundrootondevice; cudamalloc((void **) &boundrootondevice, boundroot->getmemsize()); cudamemcpy(boundrootondevice, boundroot, boundroot->getmemsize(), cudamemcpyhosttodevice); size_t boundrootpointersize = sizeof(vertex *); cudamemcpy(&(productionondevice->boundroot), boundrootondevice, boundrootpointersize, cudamemcpyhosttodevice); return productionondevice; }
where
class production { vertex * boundroot; public: production(vertex * root); __host__ production * allocatetodevice(); __host__ __device__ vertex * getboundnode(); __host__ __device__ void execute(); __host__ __device__ size_t getsize(); };
as can see first copy production object itself, it's member vector , @ end i'm copying pointer. yet i'm getting access violation @ penultimate line. doing wrong?
this:
cudamemcpy(&(productionondevice->boundroot), boundrootondevice, boundrootpointersize, cudamemcpyhosttodevice);
is illegal because have passed boundrootondevice
(a device pointer) source pointer in host-to-device transfer. result in host attempting perform pointer indirection on device address, resulting in segfault.
presumably want perform device device copy in case.
Comments
Post a Comment