Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Apr 9, 2024
1 parent 7734190 commit 1e5f0d6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ Base.:(==)(x::CuPtr, y::CuPtr) = UInt(x) == UInt(y)
Base.:(<)(x::CuPtr, y::CuPtr) = UInt(x) < UInt(y)
Base.:(-)(x::CuPtr, y::CuPtr) = UInt(x) - UInt(y)

if VERSION >= v"1.12.0-DEV.225"
Base.:(+)(x::CuPtr{T}, y::Integer) where T =
reinterpret(CuPtr{T}, Base.add_ptr(reinterpret(Ptr{T}, x), (y % UInt) % UInt))
Base.:(-)(x::CuPtr{T}, y::Integer) where T =
reinterpret(CuPtr{T}, Base.sub_ptr(reinterpret(Ptr{T}, x), (y % UInt) % UInt))
else
Base.:(+)(x::CuPtr, y::Integer) = oftype(x, Base.add_ptr(UInt(x), (y % UInt) % UInt))
Base.:(-)(x::CuPtr, y::Integer) = oftype(x, Base.sub_ptr(UInt(x), (y % UInt) % UInt))
end
Base.:(+)(x::Integer, y::CuPtr) = y + x


Expand Down Expand Up @@ -186,8 +193,15 @@ Base.:(==)(x::CuArrayPtr, y::CuArrayPtr) = UInt(x) == UInt(y)
Base.:(<)(x::CuArrayPtr, y::CuArrayPtr) = UInt(x) < UInt(y)
Base.:(-)(x::CuArrayPtr, y::CuArrayPtr) = UInt(x) - UInt(y)

if VERSION >= v"1.12.0-DEV.225"
Base.:(+)(x::CuArrayPtr{T}, y::Integer) where T =
reinterpret(CuArrayPtr{T}, Base.add_ptr(reinterpret(Ptr{T}, x), (y % UInt) % UInt))
Base.:(-)(x::CuArrayPtr{T}, y::Integer) where T =
reinterpret(CuArrayPtr{T}, Base.sub_ptr(reinterpret(Ptr{T}, x), (y % UInt) % UInt))
else
Base.:(+)(x::CuArrayPtr, y::Integer) = oftype(x, Base.add_ptr(UInt(x), (y % UInt) % UInt))
Base.:(-)(x::CuArrayPtr, y::Integer) = oftype(x, Base.sub_ptr(UInt(x), (y % UInt) % UInt))
end
Base.:(+)(x::Integer, y::CuArrayPtr) = y + x


Expand Down

0 comments on commit 1e5f0d6

Please sign in to comment.