Skip to content
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
6 changes: 6 additions & 0 deletions src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ function Adapt.adapt_storage(to::KernelAdaptor, xs::oneArray{T,N}) where {T,N}
oneDeviceArray{T,N,AS.CrossWorkgroup}(size(xs), ptr, xs.maxsize - xs.offset)
end

# CPU arrays would otherwise only be rejected by the compiler, with an error that dumps the
# full argument type
Adapt.adapt_storage(::KernelAdaptor, xs::Array) =
throw(ArgumentError("""cannot use a CPU array ($(typeof(xs))) in a oneAPI kernel.
Convert it to a GPU array first, e.g. using `oneArray(x)`."""))

# Base.RefValue isn't GPU compatible, so provide a compatible alternative.
# TODO: port improvements from CUDA.jl
struct ZeRefValue{T} <: Ref{T}
Expand Down
11 changes: 11 additions & 0 deletions test/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ end
dims = (16, 16)
len = prod(dims)

@testset "CPU array argument" begin
kernel(a) = return
a = oneArray([1f0])
b = [1f0]
for f in (() -> @oneapi(kernel(b)), () -> a .+ b)
err = try f(); nothing catch err; err end
@test err isa ArgumentError
@test occursin("oneArray", sprint(showerror, err))
end
end

@testset "manually allocated" begin
function kernel(input, output)
i = get_global_id()
Expand Down
Loading