cudaMallocArray returns null pointer?

Here’s the code I’m trying to run:

       // Create a 3 channel format description

        cudaChannelFormatDesc channelDesc= cudaCreateChannelDesc(32, 32, 32, 0, cudaChannelFormatKindFloat);


        // Allocate array

        cudaMallocArray(&posBuff, &channelDesc, m_imgWidth, m_imgHeight);


        // Now we upload host memory to GPU

        cudaMemcpyToArray(posBuff, 0, 0, tempBuff, m_imgWidth*m_imgHeight*3*sizeof(float), cudaMemcpyHostToDevice);

posBuff is a cudaArray*

The problem is cudaMallocArray isn’t setting posBuff to anything, it comes back out as a null pointer, so the cudaMemcpyToArray call seg faults. m_imgWidth and m_imgHeight are both 512, so there should be plenty of memory to hold the array.

The channel format is invalid. Like all previous NVIDIA GPUs, internal texture layout is either 1,2 or 4 channels.


Really? I wrote this code using the openGL API and have a 3 element texture. Does it just internalize it to four elements and then drop the last one?

Yep, you’ve been wasting GPU memory. See the internal texture format spec.