Unable to copy color image to texture

I have an image with 24bits per pixel stored in an array char* imageData(retrieved from openCV). I want to copy this to the device by doing:

texture<uchar3, 2, cudaReadModeElementType> tex_channels;

struct cudaChannelFormatDesc my_channelDesc = cudaCreateChannelDesc(8,8,8,0,cudaChannelFormatKindUnsigned);

cudaArray* cu_channel_array;

cudaMallocArray( &cu_channel_array, &my_channelDesc, width, height );

printf("malloc worked\n");

cudaMemcpyToArray(cu_channel_array, 0, 0,imageData, width*height*3,cudaMemcpyHostToDevice);

printf("memcopy worked\n");

cudaBindTexture( tex_channels, cu_channel_array);

When I run this code, it prints “malloc worked”, but it doesn’t reach the next printf() statement.

As discussed in some other thread, the 5th argument of cudaMemcpyToArray() is the number of bytes, not the number of elements.

Surprisingly, if I change the channel description to {32,0,0,0}, it doesn’t give any error.

I have also verified that the size of the data in imageData is equal to widthheight3.

Am I missing something?

CUDA arrays only support 1, 2, or 4 components.


Check the manual. 3 channel textures are not supported. (only 1,2 or 4)


I have ever used this code to draw text on a local picture with Visual Basic .NET programming language. The VB.NET sample code will take you to load and open an image in your local directory first (“1.jpg” in disk C), then add your customized text (setting the regular font properties), and finally output the edited image to your local file with user defined file name.

Imports System.IO
Imports System.Drawing.Printing
Imports RasterEdge.Imaging
Imports RasterEdge.Imaging.Processing
Imports RasterEdge.Imaging.Drawing

Dim Image As New RasterEdgeImaging()

Public Sub TextDrawing()
If True Then
Dim LoadImage As New Bitmap(“C:\1.jpg”)
Dim Text As Graphic = Graphics.FromImage(LoadImage)
Dim DrawFont As New Font(“Arial”, 16, FontStyle.Regular)
Dim DrawBrush As New SolidBrush(Color.Red)
Dim DrawPoint As New PointF(10F, 30F)
End If
End Sub
Text.TextDrawing = (“RasterEdge.com”, DrawFont, DrawBrush, DrawPoint)