c++ - How to allocate Array of Pointers and preserve them for multiple kernel calls in cuda -
i trying implement algorithm in cuda , need allocate array of pointers point array of structs. struct is, lets say:
typedef struct { float x, y; } point;
i know if want preserve arrays multiple kernel calls have control them host, right? initialization of pointers must done within kernel. more specific, array of struct p
contain random order of cartesian points while dev_s_x
sorted version x coordinate of points in p
.
i have tried with:
__global__ void test( point *dev_p, point **dev_s_x) { unsigned int tid = threadidx.x + blockidx.x * blockdim.x; dev_p[tid].x = 3.141516; dev_p[tid].y = 3.141516; dev_s_x[tid] = &dev_p[tid]; ... }
and:
int main( void ) { point *p, *dev_p, **s_x, *dev_s_x; p = (point*) malloc (n * sizeof (point) ); s_x = (point**) malloc (n * sizeof (point*)); // allocate memory on gpu cudamalloc( (void**) &dev_p, n * sizeof(point) ); cudamalloc( (void***) &dev_s_x, n * sizeof(point*)); // copy array p gpu cudamemcpy( dev_p, p, n * sizeof(point), cudamemcpyhosttodevice); cudamemcpy( dev_s_x,s_x,n * sizeof(point*), cudamemcpyhosttodevice); test <<<1, 1 >>>( dev_p, &dev_s_x); ... return 0; }
which leads many
first-chance exception @ 0x000007fefcc89e5d (kernelbase.dll) in test_project_cuda.exe: microsoft c++ exception: cudaerror_enum @ memory location 0x0020f920.. critical error detected c0000374
am doing wrong in cudamalloc of array of pointers or else? usage of (void***)
correct? use example dev_s_x[tid]->x
or dev_s_x[tid]->y
within kernels pointing device memory addresses. feasible? in advance
dev_s_x should declared point **
, should passed kernel value (i.e. test <<<1, 1 >>>(dev_p, dev_s_x);
).
putting 1 side, describe sounds natural fit thrust, give simpler memory management strategy , access fast sort routines.
Comments
Post a Comment