# L-21 MCS 572 Mon 14 Oct 2024 : organization.jl # Illustrates the launching of a kernel # with a three dimensional grid of three dimensional blocks. using CUDA """ function matFill!(A) fills the array using the blockIdx and threadIdx. """ function matFill!(A) bx = blockIdx().x - 1 by = blockIdx().y - 1 tx = threadIdx().x - 1 ty = threadIdx().y - 1 row = by*blockDim().y + ty col = bx*blockDim().x + tx dim = gridDim().x*blockDim().x idx = 1 + row*dim + col A[idx] = idx return nothing end xb = 2 # gridDim.x yb = 2 # gridDim.y zb = 1 # gridDim.z xt = 2 # blockDim.x yt = 2 # blockDim.y zt = 1 # blockDim.z dim = xb*yb*zb*xt*yt*zt A_h = zeros(dim) A_d = CuArray(A_h) @cuda threads=(xt, yt, zt) blocks=(xb, yb, zb) matFill!(A_d) A_h = Array(A_d) println(A_d) println(A_h)