Skip to content

Level Zero: back hipMallocManaged with shared USM where host USM has no atomics - #1514

Open
pvelesko wants to merge 6 commits into
mainfrom
2026-08-29-github-1489-managed-shared-usm
Open

Level Zero: back hipMallocManaged with shared USM where host USM has no atomics#1514
pvelesko wants to merge 6 commits into
mainfrom
2026-08-29-github-1489-managed-shared-usm

Conversation

@pvelesko

Copy link
Copy Markdown
Collaborator

On Intel Data Center GPU Max (Aurora PVC) under Level Zero, zeDeviceGetMemoryAccessProperties reports host USM as RW without ATOMIC while single-device shared USM is RW|ATOMIC. hipMallocManaged was always backed by zeMemAllocHost, so a device atomicAdd on managed memory silently produced 0 (32-bit) or faulted with AtomicAccessViolation (64-bit), which kills Kokkos HIPManagedSpace and its ScatterView test.

The memory access capabilities are now queried once per device and, only for hipMemoryTypeUnified, the allocation uses zeMemAllocShared associated with the device when host USM lacks ATOMIC and single-device shared USM has it. Every other device keeps host USM (issues #131 and #1110). CHIP_L0_MANAGED_USM=auto|host|shared overrides the gate, hostNativeAtomicSupported and concurrentManagedAccess are derived from the queried capabilities, and TestFixManagedMemoryDeviceAtomics covers 32-bit and 64-bit device atomics on managed memory including the hipMemAdvise and hipMemPrefetchAsync pattern Kokkos uses.

Fixes #1489

On Intel Data Center GPU Max (PVC) under Level Zero, hipMallocManaged memory
is backed by zeMemAllocHost and PVC host USM has no ATOMIC access capability,
so a device atomicAdd on a u32 counter silently leaves it at 0 and a u64
atomic raises AtomicAccessViolation. The test runs the 32-bit and 64-bit
kernels separately so the log shows the mismatch before a fault kills the
process, and also exercises hipMemAdvise(SetCoarseGrain) and
hipMemPrefetchAsync the way Kokkos HIPManagedSpace does.

#1489
…tomics

On Intel Data Center GPU Max (PVC) zeDeviceGetMemoryAccessProperties reports
hostAllocCapabilities = RW (no ATOMIC) while
sharedSingleDeviceAllocCapabilities = RW|ATOMIC. hipMallocManaged was always
backed by zeMemAllocHost, so device atomics on managed memory silently
produced 0 (32-bit) or faulted with AtomicAccessViolation (64-bit), which
kills Kokkos HIPManagedSpace and its ScatterView test.

Query the memory access capabilities once per device and, only for
hipMemoryTypeUnified, allocate with zeMemAllocShared associated with the
device when host USM lacks ATOMIC and single-device shared USM has it.
Every other device keeps host USM (issues #131 and #1110: shared USM page
migration on Arc dGPUs unmapped the host side). CHIP_L0_MANAGED_USM=
auto|host|shared overrides the capability gate and the choice is logged at
info level. hipHostMalloc stays on host USM. The per-queue SharedBuf_
scratch allocations are now requested as hipMemoryTypeHost, which is the
same zeMemAllocHost call they made before, so they never take the managed
path (and never need the active device during queue construction).

hostNativeAtomicSupported and concurrentManagedAccess are now derived from
the queried capabilities instead of being hardcoded, and the comment that
claimed zeMemAllocShared was already in use is gone.

Fixes #1489
…emoryDeviceAtomics

On a coarse-grain SVM device (rusticl/radeonsi on the AMD W6400 CI runner)
a plain host store to hipMallocManaged memory is not visible to the device
unless it goes through the runtime's clEnqueueSVMMap/Unmap; the test's
`C64->Min = ~0ull` was never seen by the kernel, so atomicMin reported 0.
That is the documented rusticl managed-memory gap, not the atomics
capability this test covers, so the initial values now go through
hipMemcpy. Verified on rusticl W6400 and Intel OpenCL CPU.
…shared USM

The auto gate for CHIP_L0_MANAGED_USM chose zeMemAllocShared whenever host
USM lacked ATOMIC and single-device shared USM had it. Arc A380 reports
exactly that (host RW, shared RW|ATOMIC) and the x86 Intel GPU CI lane then
crashed in Unit_hipMemFaultStackAllocation_Check with SIGSEGV: without
CONCURRENT the driver migrates shared pages by mprotect'ing the host mapping
PROT_NONE and resolving the fault in its own SIGSEGV handler, and Catch2's
non-chaining fatal-condition handler steals that signal (issue #446).

Intel's driver sets CONCURRENT on sharedSingleDeviceAllocCapabilities only
when page migration is done by the kernel driver, which leaves the host
mapping valid (NEO ProductHelperHw::getSingleDeviceSharedMemCapabilities).
Require that bit as well, so the auto gate keeps host USM on Arc and on
Data Center GPU Max with the stock driver, and picks shared USM where the
driver reports RW|ATOMIC|CONCURRENT (Data Center GPU Max with
NEOReadDebugKeys=1 UseKmdMigration=1). CHIP_L0_MANAGED_USM=shared still
forces shared USM for applications that need managed-memory atomics on
Data Center GPU Max and install no SIGSEGV handler of their own.
…ed memory

concurrentManagedAccess was taken from sharedSingleDeviceAllocCapabilities
even when hipMallocManaged is backed by host USM, so it described a kind
the application never gets. Take it from the capabilities of whichever USM
kind managedUsesSharedUsm() selected; hostNativeAtomicSupported stays
tied to hostAllocCapabilities since it is about host memory.
…=shared

The auto gate now selects shared USM on Level Zero only where the driver
reports concurrent access for it, which neither Arc nor Data Center GPU
Max does with the stock driver, and on Data Center GPU Max the default
host USM has no device atomics at all. Force the shared USM path from
CTest so the reproducer for #1489 keeps exercising the code it was written
for; the test installs no SIGSEGV handler, so the driver's page migration
works in it. Other backends ignore the variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Level Zero: device atomics on hipMallocManaged memory abort with AtomicAccessViolation on PVC

1 participant