cudaMallocPitch + cudaMemcpy2D results in 0 ! I use mallocpitch and memcpy2D to copy a matrix to


This is my code, initializing a matrix d_ref and copying it to device. I’m not sure if I’m using cudaMallocPitch and cudaMemcpy2D correctly but I tried to use cudaMemcpy2D.

[b]The problem I had is solved.


and is it the best way of doing this job?

Thanks in advance.



	float *d_ref;


	float **h_ref = new float* [width];

	for (int i=0;i<width;i++)

		h_ref[i]= new float [height];

	for (int i=0;i<width;i++){

 		for (int j=0;j<height;j++){

 			h_ref[i][j]=ref_list[j][i]; //transpose




	size_t ref_pitch;


	cudaMallocPitch(&d_ref, &ref_pitch, width * sizeof(float), height);


 	cudaMemcpy2D(d_ref, ref_pitch, *h_ref, n_com*sizeof(float),n_com*sizeof(float), refLength, cudaMemcpyHostToDevice); 	


 	lowerBound<<<grid, block>>>(d_ref, ...





 	__global__ void lowerBound (float* d_ref, ....



 		float* ref = (float*)((char*)d_ref + blockIdx.x * ref_pitch);


	   	cuPrintf(" %f \n",ref[threadIdx.x]);