diff --git a/Project.toml b/Project.toml index f4f0554..8beb91b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,11 +1,9 @@ name = "Roentgen" uuid = "b0d14063-c48a-4081-83d5-5a5ab48cb495" authors = ["lmejn <33491793+lmejn@users.noreply.github.com>"] -version = "0.13.6" +version = "0.13.7" [deps] -Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" DICOM = "a26e6606-dd52-5f6a-a97f-4f611373d757" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -29,6 +27,13 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" +[weakdeps] +Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" + +[extensions] +RoentgenCUDAExt = "CUDA" + [compat] Adapt = "3" CUDA = "4, 5" @@ -54,4 +59,4 @@ SparseArrays = "1" StaticArrays = "1" Test = "1" WriteVTK = "1" -julia = "1.8" +julia = "1.9" diff --git a/ext/RoentgenCUDAExt.jl b/ext/RoentgenCUDAExt.jl new file mode 100644 index 0000000..154a62f --- /dev/null +++ b/ext/RoentgenCUDAExt.jl @@ -0,0 +1,32 @@ +module RoentgenCUDAExt + +using Roentgen + +import Roentgen.AbstractBeamlet, Roentgen.AbstractExternalSurface, Roentgen.AbstractDoseAlgorithm + +using CUDA +import Adapt + +function dose_fluence_matrix(::Type{CuArray}, pos, beamlets::AbstractArray{<:AbstractBeamlet}, + surf::AbstractExternalSurface, calc::AbstractDoseAlgorithm; kwargs...) + D = CUDA.zeros(length(pos), length(beamlets)) + dose_fluence_matrix!(D, pos, beamlets, surf, calc; kwargs...) +end + +function dose_fluence_matrix!(D::CuArray, pos, beamlets::AbstractArray{<:AbstractBeamlet}, + surf::AbstractExternalSurface, calc::AbstractDoseAlgorithm; + maxradius=100.) + _assert_size(D, pos, beamlets) + D .= point_dose.(vec(pos), permutedims(vec(beamlets)), Ref(surf), Ref(calc), maxradius) +end + +function Adapt.adapt_structure(to, surf::CylindricalSurface) + cu_rho = Adapt.adapt_structure(to, surf.rho) + CylindricalSurface(surf.y, surf.ϕ, cu_rho) +end + +Adapt.@adapt_structure DoseVolume +Adapt.@adapt_structure LinearSurface +Adapt.@adapt_structure FinitePencilBeamKernel + +end diff --git a/src/DoseCalculationAlgorithms/FinitePencilBeamKernel.jl b/src/DoseCalculationAlgorithms/FinitePencilBeamKernel.jl index 702add0..a4e632c 100644 --- a/src/DoseCalculationAlgorithms/FinitePencilBeamKernel.jl +++ b/src/DoseCalculationAlgorithms/FinitePencilBeamKernel.jl @@ -112,8 +112,6 @@ function FinitePencilBeamKernel(parameters::AbstractMatrix, args...) FinitePencilBeamKernel(SVector{5}.(eachcol(parameters)), args...) end -Adapt.@adapt_structure FinitePencilBeamKernel - """ FinitePencilBeamKernel(filename::String) diff --git a/src/DoseFluenceMatrix.jl b/src/DoseFluenceMatrix.jl index bb5dafd..c22329c 100644 --- a/src/DoseFluenceMatrix.jl +++ b/src/DoseFluenceMatrix.jl @@ -24,13 +24,6 @@ function dose_fluence_matrix(T::Type{<:AbstractMatrix}, pos, beamlets::AbstractA dose_fluence_matrix!(D, pos, beamlets, surf, calc; kwargs...) end -function dose_fluence_matrix(::Type{CuArray}, pos, beamlets::AbstractArray{<:AbstractBeamlet}, - surf::AbstractExternalSurface, calc::AbstractDoseAlgorithm; - kwargs...) - D = CUDA.zeros(length(pos), length(beamlets)) - dose_fluence_matrix!(D, pos, beamlets, surf, calc; kwargs...) -end - function dose_fluence_matrix(::Type{SparseMatrixCSC}, pos, beamlets::AbstractArray{<:AbstractBeamlet}, surf::AbstractExternalSurface, calc::AbstractDoseAlgorithm; kwargs...) @@ -93,13 +86,6 @@ function dose_fluence_matrix!(D::AbstractArray, pos, beamlets::AbstractArray{<:A D end -function dose_fluence_matrix!(D::CuArray, pos, beamlets::AbstractArray{<:AbstractBeamlet}, - surf::AbstractExternalSurface, calc::AbstractDoseAlgorithm; - maxradius=100.) - _assert_size(D, pos, beamlets) - D .= point_dose.(vec(pos), permutedims(vec(beamlets)), Ref(surf), Ref(calc), maxradius) -end - """ _assert_size(D, pos, beamlets) diff --git a/src/DoseVolume.jl b/src/DoseVolume.jl index 656fb87..60f00a2 100644 --- a/src/DoseVolume.jl +++ b/src/DoseVolume.jl @@ -44,4 +44,3 @@ function dose_fluence_matrix(T, vol::AbstractDoseVolume, beamlets, calc; kwargs. kwargs...) end -Adapt.@adapt_structure DoseVolume diff --git a/src/ExternalSurfaces.jl b/src/ExternalSurfaces.jl index 40d5a23..91f234f 100644 --- a/src/ExternalSurfaces.jl +++ b/src/ExternalSurfaces.jl @@ -194,8 +194,6 @@ position and normal at gantry angles. """ LinearSurface -Adapt.@adapt_structure LinearSurface - LinearSurface(p, n) = LinearSurface(vcat.(p, n)) function LinearSurface(ϕg, p, n) @@ -363,11 +361,6 @@ function CylindricalSurface(mesh::SimpleMesh, y::AbstractRange, nϕ::Int=181) CylindricalSurface(ϕ, y, I, center) end -function Adapt.adapt_structure(to, surf::CylindricalSurface) - cu_rho = Adapt.adapt_structure(to, surf.rho) - CylindricalSurface(surf.y, surf.ϕ, cu_rho) -end - """ CylindricalSurface(mesh::SimpleMesh, Δy::Real[, nϕ=181]) diff --git a/src/Roentgen.jl b/src/Roentgen.jl index cb93730..eb177d4 100644 --- a/src/Roentgen.jl +++ b/src/Roentgen.jl @@ -4,10 +4,6 @@ module Roentgen using SparseArrays using StaticArrays -# CUDA -using CUDA -import Adapt - # Coordinates using CoordinateTransformations using Rotations