flummoxed ... losing the pointer ...

Hi all …

I’ve been looking at similar problems but still can’t seem to get this to work properly. I’m attempting to allocate pitchedMemory and copy an image down to the GPU in one function and pass the pointer to that pitched memory to another CUDA function, but can’t seem to get the pointer to the memory properly passed out so I only do one memory copy to the GPU (vice multiple times which works fine)…

Any help is much appreciated!

The function call …

copyPinnedImageToPitchMemory(imageWidth, imageHeight, 
		            &d_pitchMem, &d_pitchBytes, 
			    dev_images[imageIndex], imageIsGray);

where d_pitchMem is a pointer private to the class declared as…

uchar4 *d_pitchMem;

The copyPinnedImageToPitchMemory function defined elsewhere in a .cu file:

uchar4 **d_pitchMem = NULL;

extern "C" void 
copyPinnedImageToPitchMemory(int width, int height, 
                             uchar4 **h_pitchMem, 
			  size_t *d_pitchBytes, 
			  unsigned char *dev_images, 
			  bool isGray)
    FILE *fp;
    fp = fopen ("debug.txt","a");
    fprintf(fp, "===> CUDA : setupTexture() called %d times\n",iter);

    size_t h_pitchBytes = sizeof(uchar4)*width;

    if(d_pitchMem) {
    fp = fopen ("debug.txt","a");
    fprintf(fp, "===> CUDA : setupTexture() freeing d_pitchMem.\n");

    checkCudaErrors(cudaMallocPitch((void **) &d_pitchMem, d_pitchBytes, sizeof(uchar4)*width, height));

    checkCudaErrors(cudaMemcpy2D(d_pitchMem, *d_pitchBytes, dev_images, h_pitchBytes, h_pitchBytes, height, cudaMemcpyDeviceToDevice));

    cudaMemcpyToSymbol("d_pitchMem", &h_pitchMem, sizeof(d_pitchMem), 0, cudaMemcpyHostToDevice);

Any ideas what stupid mistake am I making here?

Thanks in advance!!!

Update … I may have fixed this. Just need to make some modifications elsewhere in my code to confirm. I’ll post the fixed function after I confirm the fix works.