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?