Hello together, i try to write a metal kernel that do some operations on 3D arrays like:
function vadd!(
nz::Int64,ny::Int64,nx::Int64,
a::MtlDeviceArray{Float32, 3, 1},
b::MtlDeviceArray{Float32, 3, 1},
c::MtlDeviceArray{Float32, 3, 1})
(z,y,x) = thread_position_in_grid_3d()
if z > 1
c[z,y,x] = a[z,y,x] + b[z,y,x]
end
return nothing
end
which should do the same as:
function vadd!(
nz::Int64,ny::Int64,nx::Int64,
a::Array{Float32, 3},
b::Array{Float32, 3},
c::Array{Float32, 3})
for z in 2:nz
for y in 1:ny
for x in 1:nx
c[z,y,x] = a[z,y,x] + b[z,y,x]
end
end
end
end;
Later i need to vary with the range of the loops. However, when i try to skip a “z” like above, the kernel function doesnt work properly anymore.
So my question is, how i can set the range of the 3D indices in the kernel function?