how to allocate a 2d array in cudamalloc?

In addition to the pointer that points to the start of the 2D array, you will need data (variables or constants) describing the dimensions of the 2D array. You can then map 2D-storage to 1D-storage using either row-major or column-major storage schemes, as described in this Wikipedia article:

http://en.wikipedia.org/wiki/Column-major#Column-major_order

If the 2D array is delivered by some other code outside your control, you would probably want to adopt whatever storage scheme is used in that code. For example, Fortran and Matlab programs use column- major storage.

One way in which programmers hide the address computation for multi-dimensional arrays is by using macros, e.g.

#define A(row,col)  A[row * NUM_COLUMNS + col]  // row-major storage