Skip to content

Commit

Permalink
Avoid capturing MArrays in BoundsError
Browse files Browse the repository at this point in the history
This quirk allows bounds checking of `MArray`s on device in more cases.
This is a workaround to address
<JuliaGPU/CUDA.jl#2313>.

This change was proposed upstream here
   <JuliaGPU/CUDA.jl#2314>
and is no longer needed if accepted upstream.
  • Loading branch information
lcw committed Apr 3, 2024
1 parent 6debc90 commit 8c16db2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/RavenCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module RavenCUDAExt
import Raven
import Adapt
import MPI
import StaticArrays

isdefined(Base, :get_extension) ? (using CUDA) : (using ..CUDA)
isdefined(Base, :get_extension) ? (using CUDA.CUDAKernels) : (using ..CUDA.CUDAKernels)
Expand Down Expand Up @@ -58,4 +59,11 @@ else
Adapt.adapt_storage(::CUDA.KernelAdaptor, ::MPI.Comm) = nothing
end

CUDA.@device_override function Base.checkbounds(A::StaticArrays.MArray, I...)
@inline
checkbounds(Bool, A, I...) ||
CUDA.@print_and_throw("BoundsError while indexing an MArray.")
nothing
end

end # module RavenCUDAExt

0 comments on commit 8c16db2

Please sign in to comment.