Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image GPU loading in preprocimage #44

Merged
merged 13 commits into from
Aug 16, 2022
6 changes: 5 additions & 1 deletion src/imfilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function imfilter_cpu(img, krn)
end

function imfilter_gpu(img, krn)
imfilter_gpu(img |> CuArray, krn)
end

function imfilter_gpu(img::CuArray, krn)
juliohm marked this conversation as resolved.
Show resolved Hide resolved
# retrieve basic info
N = ndims(img)
T = eltype(img)
Expand All @@ -16,7 +20,7 @@ function imfilter_gpu(img, krn)
padkrn = padarray(krn, Fill(zero(T), ntuple(i->0, N), padsize))

# perform ifft(fft(img) .* conj.(fft(krn)))
fftimg = img |> CuArray |> CUFFT.fft
fftimg = img |> CUFFT.fft
fftkrn = padkrn |> CuArray |> CUFFT.fft
juliohm marked this conversation as resolved.
Show resolved Hide resolved
result = (fftimg .* conj.(fftkrn)) |> CUFFT.ifft

Expand Down
2 changes: 1 addition & 1 deletion src/iqsim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function iqsim(trainimg::AbstractArray{T,N}, tilesize::Dims{N},
rtile = CartesianIndex(start):CartesianIndex(finish)

# selected training image dataevent
TIdev = view(TI, rtile)
TIdev = view_kernel(TI, rtile)

# boundary cut mask
cutmask .= false
Expand Down
27 changes: 25 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,32 @@ function activation(hard, tile)
buff
end

function array_cpu(array)
array
end

function array_gpu(array)
array |> CuArray
end

const array_kernel = CUDA.functional() ? array_gpu : array_cpu

function view_cpu(array, I)
view(array, I)
end

function view_gpu(array, I)
array[I] |> Array
end
juliohm marked this conversation as resolved.
Show resolved Hide resolved

const view_kernel = CUDA.functional() ? view_gpu : view_cpu

function imagepreproc(trainimg, soft, geoconfig)
padsize = geoconfig.padsize

TI = Float64.(trainimg)
replace!(TI, NaN => 0.)
TI_kernel = TI |> array_kernel
juliohm marked this conversation as resolved.
Show resolved Hide resolved

SOFT = map(soft) do (aux, auxTI)
prepend = ntuple(i->0, ndims(TI))
Expand All @@ -70,10 +91,12 @@ function imagepreproc(trainimg, soft, geoconfig)
replace!(AUX, NaN => 0.)
replace!(AUXTI, NaN => 0.)

AUX, AUXTI
AUXTI_kernel = AUXTI |> array_kernel

AUX, AUXTI_kernel
juliohm marked this conversation as resolved.
Show resolved Hide resolved
end

TI, SOFT
TI_kernel, SOFT
end

function finddisabled(trainimg, geoconfig)
Expand Down