cudaMallocPitch trouble

Hello,

When I am doing :

[codebox]

float** tab;

size_t pitch;

int width, height;

cudaMallocPitch((void**)tab, &pitch, width*sizeof(float),height);

[/codebox]

I’ve got a segmentation fault.

but when I do :

[codebox]

float* tab;

size_t pitch;

int width, height;

cudaMallocPitch((void**)&tab, &pitch, width*sizeof(float),height);

[/codebox]

The segfault disappear.

The matter is that I’d like to use a 2D tab to get the result of tex2D. Do you know what’s wrong in the first case and how I can keep the float** ?

Thanks.

cudaMallocPitch is expecting the address of a pointer, which it uses to write the value of the pointer to the newly allocated device memory. In the first case you’re passing “tab”, which has not been initialized.

I would recommend reading this:
http://www.amazon.co.uk/C-Programming-Lang…d/dp/0131103628

Ok , I missread the cuda Programming Guide 2.1 pp. 34 & 35 . And I didn’t use my brain, i “recopy” it stupidly.
Sorry to bother you.
Thanks.