Hi,
I am just new to CUDA and trying to learn. I tried to print thread id’s in x and y direction using the following code:
using CUDA
function test_kernel()
@cuprintln("idx: %d, idy: %d",threadIdx().x, threadIdx().y)
return nothing
end
@cuda threads=(4,4) blocks=1 test_kernel()
I am getting like following:
idx: 1, idy: 0117592186044417
idx: 2, idy: 0117592186044417
idx: 3, idy: 0117592186044417
idx: 4, idy: 0117592186044417
idx: 1, idy: 0217592186044418
idx: 2, idy: 0217592186044418
idx: 3, idy: 0217592186044418
idx: 4, idy: 0217592186044418
idx: 1, idy: 0317592186044419
idx: 2, idy: 0317592186044419
idx: 3, idy: 0317592186044419
idx: 4, idy: 0317592186044419
idx: 1, idy: 0417592186044420
idx: 2, idy: 0417592186044420
idx: 3, idy: 0417592186044420
idx: 4, idy: 0417592186044420
I got some weird value for thread id in y direction. I tried same with normal CUDA programming in visual studio, like below:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void test_kernel() {
printf("Idx: %d Idy: %d\n", threadIdx.x, threadIdx.y);
}
int main() {
dim3 block(4,4);
dim3 grid(1);
test_kernel<< < grid, block >> > ();
cudaDeviceSynchronize();
cudaDeviceReset();
return 0;
}
and I got like below:
Idx: 0 Idy: 0
Idx: 1 Idy: 0
Idx: 2 Idy: 0
Idx: 3 Idy: 0
Idx: 0 Idy: 1
Idx: 1 Idy: 1
Idx: 2 Idy: 1
Idx: 3 Idy: 1
Idx: 0 Idy: 2
Idx: 1 Idy: 2
Idx: 2 Idy: 2
Idx: 3 Idy: 2
Idx: 0 Idy: 3
Idx: 1 Idy: 3
Idx: 2 Idy: 3
Idx: 3 Idy: 3
Here I am getting the proper results.
What I did wrong?
Can anyone help me to solve this?
Thanks and Regards,
Manu