2

I have a struct which contains a double-pointer like this:

struct image
{
    int width, height;
    uchar** imageData;
}

and then

Image* h_imageList = (Image*)malloc(20 * sizeof(Image));
//fill h_imageList...

Image* d_imageList;
cudaMalloc(&d_imageList, 20 * sizeof(Image));
cudaMemcpy(d_imageList, h_imageList, 20 * sizeof(Image), cudaMemcpyHostToDevice);

when i pass d_imageList to a kernel as a parameter, it seems that imageData was not successfully copied. It is not accessible. But width and height is accessible. So what's wrong with my code? How to copy this double-pointer?

CIsForCookies
  • 10,156
  • 5
  • 36
  • 74
jianhuyy
  • 21
  • 2
  • 3
    What are you expecting to be copied? The imageData pointer, or the data the imageData pointer points to? It's kind of crucial to get that sorted out. Also how do you knw the copy has not happened? 'it seems that the imageData was not successfully copied' isn't very convincing. Explain why you think the data was not copied. – john Jan 30 '18 at 07:28
  • Please read everything at the marked duplicate – talonmies Jan 30 '18 at 07:46
  • I have tried the method given by the duplicate. When the struct contains a pointer element, it really works; when it comes to a pointer-to-pointer element, it seems to a little troublesome. Now i am trying to convert the 2D array to 1D array. THANKS A LOT! – jianhuyy Jan 31 '18 at 07:16

0 Answers0