Basic question for 2D array allocation (works for emu mode only) dynamic 2d using cudaMalloc

hi,

I have a need to pass a 2D array to a function. The function accepts a float **.

Now, I tried something like:

[codebox]float *U[9], float *V[9], float W[128];

for (int i0 = 0; i0 < 9; i0++)

{

	CUDA_SAFE_CALL(cudaMalloc((void **)&U[i0], 9*sizeof(float)));

	CUDA_SAFE_CALL(cudaMalloc((void **)&V[i0], 9*sizeof(float)));

}[/codebox]

This works for emu mode, but crashes for debug mode. I then tried this:

   [codebox] float **U, **V, *W; 

CUDA_SAFE_CALL(cudaMalloc((void **)&U, 9*sizeof(float *)));

CUDA_SAFE_CALL(cudaMalloc((void **)&V, 9*sizeof(float *)));

CUDA_SAFE_CALL(cudaMalloc((void **)&W, 128*sizeof(float)));

for (int i0 = 0; i0 < 9; i0++)

{

	CUDA_SAFE_CALL(cudaMalloc((void **)&U[i0], 9*sizeof(float))); <==== crashes here.

	CUDA_SAFE_CALL(cudaMalloc((void **)&V[i0], 9*sizeof(float)));

}

[/codebox]

this crashes at the statement CUDA_SAFE_CALL(cudaMalloc((void **)&U[i0], 9*sizeof(float)));

I know its a very naive question, but I seem to be messing it up…

Any help will be appreciated.

TIA,

aj

as already said in the other 2d-array thread: its best to avoid this situation by simply using 1d arrays and accessing them like U[x+y*width].

btw, @arjunjain: mpi-eva ;-)

lol. yeah.

Thanks, yes, i know, but i had to change a lot of code because of that (i was not too confident about the regex replacement) :). btw, yes, done that now…