Skip to content

Commit

Permalink
Fixes for Julia 1.11 (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Apr 4, 2024
1 parent 4488033 commit 8a82d03
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
33 changes: 16 additions & 17 deletions lib/cudadrv/module/linker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,30 @@ end
Add PTX code to a pending link operation.
"""
function add_data!(link::CuLink, name::String, code::String)
data = unsafe_wrap(Vector{UInt8}, code)

# there shouldn't be any embedded NULLs
checked_data = Base.unsafe_convert(Cstring, data)

res = unsafe_cuLinkAddData_v2(link, JIT_INPUT_PTX, pointer(checked_data), length(data),
name, 0, C_NULL, C_NULL)
if res == ERROR_NO_BINARY_FOR_GPU ||
res == ERROR_INVALID_IMAGE ||
res == ERROR_INVALID_PTX
throw(CuError(res, unsafe_string(pointer(link.options[JIT_ERROR_LOG_BUFFER]))))
elseif res != SUCCESS
throw_api_error(res)
GC.@preserve code begin
# cuLinkAddData takes a Ptr{Cvoid} instead of a Cstring, because it accepts both
# source and binary, so do the conversion (ensuring no embedded NULLs) ourselves
data = Base.unsafe_convert(Cstring, code)

res = unsafe_cuLinkAddData_v2(link, JIT_INPUT_PTX, pointer(data), length(code),
name, 0, C_NULL, C_NULL)
if res == ERROR_NO_BINARY_FOR_GPU ||
res == ERROR_INVALID_IMAGE ||
res == ERROR_INVALID_PTX
throw(CuError(res, unsafe_string(pointer(link.options[JIT_ERROR_LOG_BUFFER]))))
elseif res != SUCCESS
throw_api_error(res)
end
end
end

"""
add_data!(link::CuLink, name::String, data::Vector{UInt8}, type::CUjitInputType)
add_data!(link::CuLink, name::String, data::Vector{UInt8})
Add object code to a pending link operation.
"""
function add_data!(link::CuLink, name::String, data::Vector{UInt8})
res = unsafe_cuLinkAddData_v2(link, JIT_INPUT_OBJECT, pointer(data), length(data),
res = unsafe_cuLinkAddData_v2(link, JIT_INPUT_OBJECT, data, length(data),
name, 0, C_NULL, C_NULL)
if res == ERROR_NO_BINARY_FOR_GPU ||
res == ERROR_INVALID_IMAGE ||
Expand All @@ -97,8 +98,6 @@ function add_data!(link::CuLink, name::String, data::Vector{UInt8})
elseif res != SUCCESS
throw_api_error(res)
end

return
end

"""
Expand Down
7 changes: 7 additions & 0 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,14 @@ end

## memory copying

if VERSION >= v"1.11.0-DEV.753"
function typetagdata(a::Array, i=1)
ptr_or_offset = Int(a.ref.ptr_or_offset)
@ccall(jl_genericmemory_typetagdata(a.ref.mem::Any)::Ptr{UInt8}) + ptr_or_offset + i - 1
end
else
typetagdata(a::Array, i=1) = ccall(:jl_array_typetagdata, Ptr{UInt8}, (Any,), a) + i - 1
end
typetagdata(a::CuArray, i=1) =
convert(CuPtr{UInt8}, a.storage.buffer) + a.maxsize + a.offset + i - 1

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ No keyword arguments are supported.
DeviceKernel{F,tt}(f, fun, kernel_state())
end

(kernel::DeviceKernel)(args...; kwargs...) = call(kernel, args...; kwargs...)
@inline (kernel::DeviceKernel)(args::Vararg{Any,N}; kwargs...) where {N} =
call(kernel, args...; kwargs...)


## other
Expand Down
11 changes: 8 additions & 3 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ using Base.Cartesian
# Base.LogicalIndex basically contains the same as our `findall` here does.
Base.to_index(::AbstractGPUArray, I::AbstractArray{Bool}) = findall(I)
## same for the trailing Array{Bool} optimization (see `_maybe_linear_logical_index` in Base)
Base.to_indices(A::AbstractGPUArray, inds,
I::Tuple{Union{Array{Bool,N}, BitArray{N}}}) where {N} =
(Base.to_index(A, I[1]),)
if VERSION >= v"1.11.0-DEV.1157"
Base.to_indices(A::AbstractGPUArray, inds,
I::Tuple{AbstractArray{Bool}}) = (Base.to_index(A, I[1]),)
else
Base.to_indices(A::AbstractGPUArray, inds,
I::Tuple{Union{Array{Bool,N}, BitArray{N}}}) where {N} =
(Base.to_index(A, I[1]),)
end


## find*
Expand Down

0 comments on commit 8a82d03

Please sign in to comment.