Issue with cudaMemcpy2DToArray with Pytorch

I have a tensor of size {height, width, 3 channels} with uin8_t format. I used the interoperability with OpenGL to link a cuda array to a GL_TEXTURE_2D. I init the texture with :


I show by OpenCv the tensor to show that is correct and does not have an issue (see the picture called “show_byte” below).
So I use to put it in the OpenGL Texture this method :

cudaMemcpy2DToArray( cudaArray pointer, 0, 0, tensor.data_ptr<uint8_t>(), (spitch) Width x 3, Width x 3, Height, cudaMemcpyDeviceToDevice);

spitch = Width*3 because it’s a RGB image with data of 1 byte.

But, unfortunately I have the all image data in the Texture but with an issue with the width (see the picture called “Texture output 4”) :

If someone could give me ideas to solve my issue. Thanks.

Hi @PaulErMartin
This forum branch is dedicated to CUDA-GDB tool support. Your question might be better suited for
CUDA Programming and Performance - NVIDIA Developer Forums or GPU-Accelerated Libraries - NVIDIA Developer Forums

I have moved your topic to CUDA Programming and Performance - NVIDIA Developer Forums

I’ve encountered exactly the same problem. After hours of frustrating trial and error, I eventually found that you have to use 4 channels (GL_RGBA) instead of 3 in order to get this OpenGL texture interoperability to work properly.