cudaArray access data


I work with CUDA 2.0 with an GeForce 9800 GT.

My problem is pretty simple :

I load datas from a raw file into an 1D array.

After I copy this array into a 3D cudaArray.

And I bind thios cudaArray with a texture 3D.

The problem is that my texture does not contain datas (texture 's values are always 0 ). So I think the texture is not correctly loaded.

I put a part of my code here :

I use a function to load a raw file (323232) and who store datas in an 1D array.

I copy data from my 1D array into a 3D cuda array like this:

cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned char>();	

 CUDA_SAFE_CALL( cudaMalloc3DArray(&d_volumeArray, &channelDesc, volumeSize) );

	// The sample does not work with pageable memory

	// This is a known issue for beta that will be fixed for the public release



	// copy to page-locked mem

	cudaPitchedPtr pagelockedPtr;

	pagelockedPtr.pitch = volumeSize.width*sizeof(unsigned char);

	pagelockedPtr.xsize = volumeSize.width;

	pagelockedPtr.ysize = volumeSize.height;

	size_t size = volumeSize.width*volumeSize.height*volumeSize.depth*sizeof(unsigned char);

	CUDA_SAFE_CALL( cudaMallocHost(&(pagelockedPtr.ptr), size) );

	memcpy(pagelockedPtr.ptr, h_volume, size);


	cudaMemcpy3DParms copyParams = {0};


	copyParams.srcPtr   = pagelockedPtr;


	copyParams.srcPtr   = make_cudaPitchedPtr((void*)h_volume, volumeSize.width*sizeof(uchar), volumeSize.width, volumeSize.height);


	copyParams.dstArray = d_volumeArray;

	copyParams.extent   = volumeSize;

	copyParams.kind     = cudaMemcpyHostToDevice;

	CUDA_SAFE_CALL( cudaMemcpy3D(&copyParams) );


texture<unsigned char, 3, cudaReadModeNormalizedFloat> tex;         // 3D texture

Binding texture to CudaArray

// set texture parameters

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

	tex.filterMode = cudaFilterModeLinear;      // linear interpolation

	tex.addressMode[0] = cudaAddressModeClamp;  // wrap texture coordinates

	tex.addressMode[1] = cudaAddressModeClamp;

	// bind array to 3D texture

	CUDA_SAFE_CALL(cudaBindTextureToArray(tex, d_volumeArray, channelDesc));

Please could you tell me where is the problem and what is wrong?

tex.filterMode = cudaFilterModeLinear; // linear interpolation

Linear mode isn’t allowed for char. use cudaFilterModePoint

This is another problem.

You have to used cudaMemcpy insteed memcpy

memcpy(pagelockedPtr.ptr, h_volume, size) doesn’t work because you want to copy data into the GPU.

cudaMemcpy(pagelockedPtr.ptr, h_volume, size, cudaMemcpyHostToDevice) will work

Concerning the cudaFilterModeLinear you can used it only for retuned values of floating point type :

You can bind a texture to an array of unsigned char (for exemple) and the texture have to return float to use cudaFilterModeLinear .