Skip to content

Commit e54bba2

Browse files
authored
Merge pull request #14 from JuliaImageRecon/nh/gpuFix
Move GPU extension kernels to KernelAbstractions.jl
2 parents e1df52f + 1c16198 commit e54bba2

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearOperatorCollection"
22
uuid = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
33
authors = ["Tobias Knopp <[email protected]> and contributors"]
4-
version = "2.0.7"
4+
version = "2.0.8"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
@@ -21,17 +21,19 @@ RadonKA = "86de8297-835b-47df-b249-c04e8db91db5"
2121

2222
[compat]
2323
julia = "1.9"
24-
GPUArrays = "8, 9, 10"
25-
JLArrays = "0.1"
24+
GPUArrays = "11"
25+
KernelAbstractions = "0.9"
26+
JLArrays = "0.2"
2627
NFFT = "0.13"
27-
LinearOperators = "2.3.3"
28+
LinearOperators = "2"
2829
RadonKA = "0.6"
2930
Wavelets = "0.9, 0.10"
3031
Reexport = "1.0"
3132
FFTW = "1.0"
3233

3334
[weakdeps]
3435
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
36+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
3537
NFFT = "efe261a4-0d2b-5849-be55-fc731d526b0d"
3638
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
3739
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,64 @@
11
function LinearOperatorCollection.grad!(res::vecT, img::vecT, shape::NTuple{N,Int64}, di::CartesianIndex{N}) where {vecT <: AbstractGPUVector, N}
22
res = reshape(res, shape .- Tuple(di))
3+
backend = get_backend(res)
4+
5+
@kernel cpu = false inbounds = true function grad_kernel!(res, img, di)
6+
idx = @index(Global, Cartesian)
7+
res[idx] = img[idx] - img[idx + di]
8+
end
39

410
if length(res) > 0
5-
gpu_call(grad_kernel!, res, reshape(img,shape), di)
11+
kernel = grad_kernel!(backend)
12+
kernel(res, reshape(img, shape), di, ndrange = size(res))
613
end
714

815
return res
916
end
1017

11-
function grad_kernel!(ctx, res, img, di)
12-
idx = @cartesianidx(res)
13-
@inbounds res[idx] = img[idx] - img[idx + di]
14-
return nothing
15-
end
1618

1719
# adjoint of directional gradients
1820
function LinearOperatorCollection.grad_t!(res::vecT, g::vecT, shape::NTuple{N,Int64}, di::CartesianIndex{N}) where {T, vecT <: AbstractGPUVector{T}, N}
1921
res_ = reshape(res,shape)
2022
g_ = reshape(g, shape .- Tuple(di))
23+
backend = get_backend(res)
2124

2225
fill!(res, zero(T))
2326
if length(g_) > 0
24-
gpu_call(grad_t_kernel_1!, res_, g_, di, elements = length(g))
25-
gpu_call(grad_t_kernel_2!, res_, g_, di, elements = length(g))
27+
kernel1 = grad_t_kernel_1!(backend)
28+
kernel2 = grad_t_kernel_2!(backend)
29+
kernel1(res_, g_, di, ndrange = size(g_))
30+
kernel2(res_, g_, di, ndrange = size(g_))
2631
end
32+
33+
return res
2734
end
2835

29-
function grad_t_kernel_1!(ctx, res, g, di)
30-
idx = @cartesianidx(g)
31-
@inbounds res[idx] += g[idx]
32-
return nothing
36+
@kernel cpu = false inbounds = true function grad_t_kernel_1!(res, g, di)
37+
idx = @index(Global, Cartesian)
38+
res[idx] += g[idx]
3339
end
3440

35-
function grad_t_kernel_2!(ctx, res, g, di)
36-
idx = @cartesianidx(g)
37-
@inbounds res[idx + di] -= g[idx]
38-
return nothing
41+
@kernel cpu = false inbounds = true function grad_t_kernel_2!(res, g, di)
42+
idx = @index(Global, Cartesian)
43+
res[idx + di] -= g[idx]
3944
end
4045

46+
4147
function LinearOperatorCollection.grad_t!(res::vecT, g::vecT, shape::NTuple{N,Int64}, dirs, dims, dim_ends, tmp) where {T, vecT <: AbstractGPUVector{T}, N}
4248
dim_start = 1
4349
res = reshape(res, shape)
50+
backend = get_backend(res)
4451

4552
fill!(res, zero(eltype(res)))
53+
kernel1 = grad_t_kernel_1!(backend)
54+
kernel2 = grad_t_kernel_2!(backend)
4655
for (i, di) in enumerate(dirs)
4756
g_ = reshape(view(g, dim_start:dim_ends[i]), shape .- Tuple(di))
4857
if length(g_) > 0
49-
gpu_call(grad_t_kernel_1!, res, g_, di, elements = length(g))
50-
gpu_call(grad_t_kernel_2!, res, g_, di, elements = length(g))
58+
kernel1(res, g_, di, ndrange = size(g_))
59+
kernel2(res, g_, di, ndrange = size(g_))
5160
end
5261
dim_start = dim_ends[i] + 1
5362
end
63+
return res
5464
end

ext/LinearOperatorGPUArraysExt/LinearOperatorGPUArraysExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module LinearOperatorGPUArraysExt
22

3-
using LinearOperatorCollection, GPUArrays
3+
using LinearOperatorCollection, GPUArrays, GPUArrays.KernelAbstractions # Hacky but with [KernelAbstractions, GPUArrays] the extension didnt trigger
44

55
include("GradientOp.jl")
66

0 commit comments

Comments
 (0)