Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for nightly #2240

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -512,7 +512,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
function typetagdata(a::CuArray, i=1; type=Mem.Device)
PT = if type == Mem.Device
CuPtr{UInt8}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,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...)

# re-use the parent kernel's seed to avoid need for the RNG
make_seed(::DeviceKernel) = kernel_state().random_seed
Expand Down
2 changes: 1 addition & 1 deletion src/device/intrinsics/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const cuprint_specifiers = Dict(
fmt *= string(T.parameters[1])
else
@warn("@cuprint does not support values of type $T")
fmt *= "$(string(T.parameters[1]))(...)"
fmt *= "$(T)(...)"
end
end

Expand Down
11 changes: 7 additions & 4 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ using Base.Cartesian
# TODO: it should still be possible to use the same technique;
# Base.LogicalIndex basically contains the same as our `findall` here does.
Base.to_index(::CuArray, I::AbstractArray{Bool}) = findall(I)
## same for the trailing Array{Bool} optimization (see `_maybe_linear_logical_index` in Base)
Base.to_indices(A::CuArray, 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::CuArray, I::Tuple{AbstractArray{Bool}}) = (Base.to_index(A, I[1]),)
else
Base.to_indices(A::CuArray, inds,
I::Tuple{Union{Array{Bool,N}, BitArray{N}}}) where {N} =
(Base.to_index(A, I[1]),)
end


## find*
Expand Down