OpenCL: keep coarse grained SVM managed allocations mapped for the host while idle - #1537
Merged
Merged
Conversation
…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
Collaborator
Author
|
/run-aurora-ci |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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