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
2 changes: 1 addition & 1 deletion docs/src/api/kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ used by `@oneapi`. Returns a callable kernel object.

Convert arguments for kernel execution. This function is called for every argument passed to
a kernel, allowing customization of argument conversion. By default, it converts `oneArray`
to `oneDeviceArray`.
to `oneDeviceArray`, and `ZePtr{T}` to `LLVMPtr{T,AS.CrossWorkgroup}`.


## Basic Kernel Example
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ struct KernelAdaptor
end
KernelAdaptor() = KernelAdaptor(nothing)

# convert oneAPI host pointers to device pointers
Adapt.adapt_storage(to::KernelAdaptor, p::ZePtr{T}) where {T} = reinterpret(Ptr{T}, p)
# device pointers are passed as global pointers; a plain `Ptr` is a private pointer in SPIR-V
Adapt.adapt_storage(to::KernelAdaptor, p::ZePtr{T}) where {T} =
reinterpret(LLVMPtr{T,AS.CrossWorkgroup}, p)

# convert oneAPI host arrays to device arrays
function Adapt.adapt_storage(to::KernelAdaptor, xs::oneArray{T,N}) where {T,N}
Expand Down
17 changes: 16 additions & 1 deletion test/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,28 @@ end

if VERSION < v"1.12"
a = oneArray(Float32[0])
@oneapi kernel(pointer(a))
@oneapi kernel(reinterpret(Ptr{Float32}, pointer(a)))
@test Array(a) == [42]
else
@test_broken false
end
end

@testset "device pointer arguments" begin
# pointers to device memory are passed to kernels as global pointers; a plain `Ptr`
# would be a private pointer in SPIR-V, losing the store (#458)
function kernel(ptr, val)
unsafe_store!(ptr, val)
return
end

for B in (oneL0.DeviceBuffer, oneL0.SharedBuffer, oneL0.HostBuffer)
a = oneVector{Int,B}([1])
@oneapi kernel(pointer(a), 42)
@test Array(a) == [42]
end
end

############################################################################################

# A chain of N live accumulators forces the register allocator to spill once N exceeds
Expand Down
Loading