Skip to content

OpenCL: keep coarse grained SVM managed allocations mapped for the host while idle - #1537

Merged
pvelesko merged 2 commits into
mainfrom
2026-08-30-github-1535-coarse-svm-managed-map
Sep 2, 2026
Merged

OpenCL: keep coarse grained SVM managed allocations mapped for the host while idle#1537
pvelesko merged 2 commits into
mainfrom
2026-08-30-github-1535-coarse-svm-managed-map

Conversation

@pvelesko

Copy link
Copy Markdown
Collaborator

On OpenCL devices with only coarse grained SVM (Mali G52, rusticl) the host may only touch hipMallocManaged memory between clEnqueueSVMMap and clEnqueueSVMUnmap, so plain host stores between launches were lost. With AllocationStrategy::CoarseGrainSVM the context now keeps every managed allocation mapped while no work is in flight: unmapped on the queue before a kernel launch, SVM memcpy, memfill or migrate, mapped again (blocking, read/write) when a stream, the device or an event synchronises with the host. Fine grained SVM and Intel USM are untouched. Adds TestFix1535ManagedHostStoreBetweenLaunches, verified on rusticl (W6400) and Mali G52.

Fixes #1535

…e grained SVM

On OpenCL devices that only support coarse grained SVM (Mali G52, rusticl on
AMD) a plain host store to hipMallocManaged memory made between two launches
never reaches the device, and a host read after synchronisation returns the
host's own stale value. TestFix1535ManagedHostStoreBetweenLaunches writes the
managed pointer from the host before the first launch, between two launches
and after hipDeviceSynchronize, and reads it after hipDeviceSynchronize and
after a blocking hipMemcpy, checking what the device and the host observe.
Skips when managedMemory == 0.

Fails on rusticl (W6400, coarse grained buffer SVM only), 3 of 3 runs:
device saw 0 0 100 (expected 1 2 3), host saw 2 then 3 (expected 102 then 3).
Fails on Mali G52 (salami), 3 of 3 runs:
device saw 1 1 101 (expected 1 2 3), host saw 2 then 3 (expected 102 then 3).
Passes on the Intel CPU OpenCL runtime (fine grained SVM).

Issue: #1535
…st while idle

HIP lets the host dereference hipMallocManaged memory whenever the device is
idle, even on devices where concurrentManagedAccess == 0. The OpenCL spec
only defines host access to a coarse grained SVM buffer between
clEnqueueSVMMap and clEnqueueSVMUnmap, and the runtime only mapped inside
its own hipMemcpy paths, so on devices with coarse grained SVM only (Mali
G52, rusticl on AMD) a plain host store between two launches was lost and a
host read after synchronisation returned stale data.

With AllocationStrategy::CoarseGrainSVM the context now tracks every
hipMallocManaged allocation (hipMemoryTypeUnified) and its map state:

  - a new allocation is mapped for read/write right away so the host can
    initialise it;
  - every mapped allocation is unmapped on the queue before a kernel launch,
    an SVM memcpy, an SVM memfill or an SVM migrate, so the unmap is ordered
    before the command on the in-order queue;
  - every unmapped allocation is mapped again (blocking, CL_MAP_READ |
    CL_MAP_WRITE) when a queue finishes (hipStreamSynchronize,
    hipDeviceSynchronize, blocking hipMemcpy) or an event wait returns
    control to the host, after waiting on markers from every queue that has
    had work submitted since its last finish;
  - a mapped allocation is unmapped before it is freed.

The map commands run on a dedicated in-order queue of the context so that
hipMallocManaged and a synchronising stream do not wait behind unrelated
work on a user stream. Fine grained SVM, Intel USM and BufferDevAddr are
untouched, and the device still reports directManagedMemAccessFromHost and
concurrentManagedAccess as 0.

TestFix1535ManagedHostStoreBetweenLaunches now passes on rusticl (W6400)
and on Mali G52 (salami), 6 of 6 runs each, and the Intel CPU OpenCL
runtime is unchanged.

Fixes: #1535
@pvelesko

Copy link
Copy Markdown
Collaborator Author

/run-aurora-ci

@pvelesko
pvelesko marked this pull request as ready for review September 2, 2026 05:57
@pvelesko
pvelesko merged commit ca92f38 into main Sep 2, 2026
18 of 19 checks passed
@pvelesko
pvelesko deleted the 2026-08-30-github-1535-coarse-svm-managed-map branch September 2, 2026 05:58
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.

OpenCL: hipMallocManaged on coarse grained SVM devices (Mali, rusticl) advertises managedMemory but host stores outside SVM map/unmap are lost

1 participant