Skip to content
Draft
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
7 changes: 5 additions & 2 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,12 @@ function Base.fill!(A::oneDenseArray{T}, val) where T
val = convert(T, val)
sizeof(T) == 0 && return A

# execute! is async, so we need to allocate the pattern in USM memory
# and keep it alive until the operation completes.
# execute! is async, so we need to allocate the pattern in USM memory and keep it alive
# until the operation completes. The fill reads this host buffer on the GPU, so it must
# be made resident on the device like any other USM a kernel reads (see
# `allocate(::Type{oneL0.HostBuffer}, ...)`).
buf = oneL0.host_alloc(context(A), sizeof(T), Base.datatype_alignment(T))
oneL0.make_resident(context(A), device(), buf)
unsafe_store!(convert(Ptr{T}, buf), val)
unsafe_fill!(context(A), device(), pointer(A), convert(ZePtr{T}, buf), length(A))
synchronize(global_queue(context(A), device()))
Expand Down
8 changes: 7 additions & 1 deletion src/pool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ end

function allocate(::Type{oneL0.HostBuffer}, ctx, dev, bytes::Int, alignment::Int)
bytes == 0 && return oneL0.HostBuffer(ZE_NULL, bytes, ctx)
host_alloc(ctx, bytes, alignment)
buf = host_alloc(ctx, bytes, alignment)
# Host USM must be made resident on the device, exactly like the device and shared
# allocations above. A GPU kernel that reads a non-resident host buffer can take a
# NotPresent pagefault under GC/allocation churn, even though host USM is nominally
# device-accessible.
make_resident(ctx, dev, buf)
return buf
end

function release(buf::oneL0.AbstractBuffer)
Expand Down
Loading