When creating a device array in Fortran-order (column-major) using the F option as in DeviceArray("float", 7, 13, 'F'), the data is laid out in C-order (row-major) as with the C option or without specification of an order option.
Reproducer:
const n = 4
const CU = Polyglot.eval('grcuda', 'CU')
const matrixA = CU.DeviceArray('float', n, n, 'F')
for (let i = 0; i < n; i += 1) {
for (let j = 0; j < n; j += 1) {
matrixA[i][j] = i + n * j
}
}
const code = `
__global__ void kernel(const float *arr) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
while (idx < ${n} * ${n}) {
printf("%d %f\\n", idx, arr[idx]);
idx += blockDim.x * gridDim.x;
}
}
`
const kernel = CU.buildkernel(code, 'kernel', 'pointer')
kernel(1, 32)(matrixA)
When creating a device array in Fortran-order (column-major) using the
F
option as inDeviceArray("float", 7, 13, 'F')
, the data is laid out in C-order (row-major) as with theC
option or without specification of an order option.Reproducer:
Outputs
But should output: