Problem: Invalid Argument at cudaMemcpy2DtoArray

I have a problem with the cudaMemcpy2DtoArray Function that throws a Invalid Argument exception (or Error)

Basically,

i get a pointer to an “unsigned char” array. The size is widthheight3. This array should be mapped into a texture of size widthheight. I.e. this means every texel consists of uchar3, but this isn’t allowed. Due to this fact, i want to map the first 2 chars into a texture and the last one into another texture of size widthheight.

My solution was to create two 2D-CUDA-Arrays, one of type uchar2 and one of type uchar1. This wasn’t a problem, but then i have to memcopy. I have to cut out the the first two chars; for this issue i used the cudaMemcpy2DToArray function. Compiling isn’t a problem, but at the execution I get an invalid argument exception.

Here is the code for the first two chars

int width=1920,height=1080;

unsigned char* inbuffer;

texture<uchar2, 2, cudaReadModeNormalizedFloat> tex;

cudaArray *d_2DArray;

	// Define ChannelDescriptions

    cudaChannelFormatDesc channelDesc =  cudaCreateChannelDesc<uchar2>();

	//Setting Texture Parameters

    tex.addressMode[0] = cudaAddressModeClamp;

    tex.addressMode[1] = cudaAddressModeClamp;

    tex.filterMode = cudaFilterModeLinear;

    tex.normalized = false;    // access with normalized texture coordinates

	// allocate array and copy image data

	CUDA_SAFE_CALL( cudaMallocArray( &d_2DArray, &channelDesc, width, height )); 

	CUDA_SAFE_CALL( cudaMemcpy2DToArray( d_2DArray, 0, 0, inbuffer,3*sizeof(unsigned char),2*sizeof(unsigned char),width*height, cudaMemcpyHostToDevice));

I think, I tried almost all I could imagine. (cudaMalloc3DArray, only the first line, etc.) I might be possible that the memcpy2d function wasn’t aimed for this issue. Maybe anyone has a solution for this problem.

Best regards

Patrick

Hello,

I think, i know the problem. The minimum data fetch size for an instruction is 32bit. This means four bytes. But I wan’t to cut out exactly one and two bytes and this is to small. No chance for memcpy. Do you think that this is the problem?

Well, let’s find a solution for this problem. Is there anybody who has an idea? I will try something and let you know about my progress.

Best regards