Linear Layout of threads in Fortran

These are dummy questions, yet I want to confirm.
In CUDA C, the threads are linearly organized in a way that threadIdx.x increase fastest, then threadIdx.y, and finally threadIdx.z.
Is this the same in CUDA Fortran?

Another question is using cudaMalloc(),the data is guaranteed to be aligned; is this the same with using allocate() ?

Then, using such runtime APIs in Fortran, the data is organized in column-based or row-based like in CUDA C ?

Thanks,
Tuan

Hi Tuan,

In CUDA C, the threads are linearly organized in a way that threadIdx.x increase fastest, then threadIdx.y, and finally threadIdx.z.
Is this the same in CUDA Fortran?

CUDA Fortran matches CUDA C’s behavior.

Another question is using cudaMalloc(),the data is guaranteed to be aligned; is this the same with using allocate() ?

Ultimately, allocate calls cudaMalloc, so it should be the same.

Then, using such runtime APIs in Fortran, the data is organized in column-based or row-based like in CUDA C ?

You’ll need to clarify this one. Which API calls are you do you want to use? The only ones that seem applicable are the 2D and 3D calls. There, the ‘ptich’ will be the number of columns in the array, the width be the number of columns, and the height is the number or rows.

  • Mat

I believe that a call to allocate(data(M,N)) in Fortran with ‘data’ on host memory will set up data in column-major.

However, as you made clear that allocate(d_data(M,N)) with d_data on device memory will ultimately call cudaMalloc(). cudaMalloc() in CUDA C uses row-major, yet I’m not sure with CUDA Fortran. So, in this case will d_data be organized on device memory as column-major or row-major?

Thanks Mat.

Tuan

Hi Tuan,

Your thinking too hard on this one. cudaMalloc (and malloc on the host) just returns a block of contiguous memory. It doesn’t organize the memory. How the memory is accessed is just a conceptional artifact of each language.

  • Mat