Hello,
To pass part of a multidimensional array in Julia on the CPU on has to use the SubArray type in the function arguments.
This does not seem to be the case for Julia on the GPU.
Excerpted from the MWE below:
@views image_display!(
test_array[:, :, :, 3],
test_cu_array[:, :, :, 3],
a_title,
kth_slice
)
function image_display!(
an_array::SubArray{Float64, 3}, # CPU: SubArray specified
a_cu_array::CuArray{Float32, 3}, # GPU: No SubArray specified
a_title::Vector{String},
k_slc::Int64
)
Before jumping to conclusions, as I could not find anything in the CUDA docs, I’d like to confirm if this is indeed the case;
that one can pass partial CuArrays as in the MApparentlyWE listed below:
# test_CUDA_SubArray_v1.jl
using ColorSchemes
using CUDA
using GLMakie
using Random
function image_display!(
an_array::SubArray{Float64, 3},
a_cu_array::CuArray{Float32, 3},
a_title::Vector{String},
k_slc::Int64
)
fig = Figure(size = (1920, 1080), figure_padding = 8, backgroundcolor = :gray80)
grd_1_1 = fig[1, 1] = GridLayout()
grd_1_2 = fig[1, 2] = GridLayout()
axs_1_1 =
GLMakie.Axis(
grd_1_1[1, 1],
aspect = DataAspect(), title = string(a_title[1], "[:, :, ", string(k_slc), "]")
)
axs_1_2 =
GLMakie.Axis(
grd_1_2[1, 1],
aspect = DataAspect(), title = string(a_title[2], "[:, :, ", string(k_slc), "]")
)
image!(
axs_1_1, an_array[:, :, k_slc], colormap = ColorSchemes.linear_grey_0_100_c0_n256, interpolate = false
)
image!(
axs_1_2,
Array{Float64}(a_cu_array[:, :, k_slc]), colormap = ColorSchemes.linear_grey_0_100_c0_n256, interpolate = false
)
wait(Makie.display(fig, scalefactor = 3.0))
end
function main()
n_rows = 256
n_cols = 256
n_slcs = 192
# Test array
test_array = Array{Float64, 4}(undef, (n_rows, n_cols, n_slcs, 3))
rand!(test_array)
# CUDA test array
test_cu_array = CuArray{Float32}(test_array)
@show typeof(test_cu_array)
println("")
# Debug
kth_slice = 96
a_title = ["test CPU SubArray", "test GPU array"]
@views image_display!(
test_array[:, :, :, 1],
test_cu_array[:, :, :, 1],
a_title,
kth_slice
)
@views image_display!(
test_array[:, :, :, 2],
test_cu_array[:, :, :, 2],
a_title,
kth_slice
)
@views image_display!(
test_array[:, :, :, 3],
test_cu_array[:, :, :, 3],
a_title,
kth_slice
)
end
begin
main()
end