how to allocate a 2d array in cudamalloc?

what I am confused with is that I am working with a Mat image. This image will be passed in the kernel as an unsigned char ptrin

so I am so confused…is a Mat image already a 2d array?
if not, how can I convert a mat image to array?
is it possible?
And last, how can I create data that describe the dimensions of the 2d array…the combination of the 2d array and Mat image confuses me a lot!
do you want me to copy and paste the whole code to get a better idea of what I mean?
:(