Hi,
I have a 3d pointer data(int ***source
) on which i want to perform the operation in device.
One way is to flatten this data by copying the 3d to 1d pointer and then use cudaMemcpy
to copy the data from host to device.
But is there any way we can directly 3d pointer data to device memory. I tried in below way but its not working
int kernel(){
int N = 10, M = 10, W = 10;
int*** a; // host array
a = new int** [N];
for (int i = 0; i < N; i++) {
a[i] = new int* [M];
for (int j = 0; j < M; j++) {
a[i][j] = new int[W];
for (int w = 0; w < W; w++)
{
a[i][j][w] = w + (j * W) + (i * M * W);
}
}
}
int* b; //device pointer array
cudaError_t cudaStatus = cudaMalloc((void**)&b, (N * M * W * sizeof(int)));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMalloc failed!");
return 1;
}
cudaStatus = cudaMemcpy(b, a, (N * M * W * sizeof(int)), cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed!");
return 1;
}
}
Is there any proper way to do this.
Regards,
Bhargav