Repository navigation
Declare indirect access on compiled kernels - #662
Merged
Merged
Conversation
Kernels receive their arrays as `oneDeviceArray` structs, so every USM pointer they dereference is an indirect access as far as Level Zero is concerned. Without declaring that, the driver only maps allocations we explicitly made resident, and a shared allocation that reuses the address of a freed one reads as zeros on the GPU. That made reductions of `SharedBuffer`-backed arrays intermittently return 0 (#661). Fixes #661.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #662 +/- ##
==========================================
+ Coverage 79.35% 79.36% +0.01%
==========================================
Files 57 57
Lines 4083 4085 +2
==========================================
+ Hits 3240 3242 +2
Misses 843 843 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
Going to look into removing the LTS workarounds once the ALCF CI is back online. |
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.
Fixes #661.
Reductions of
SharedBuffer-backed arrays intermittently returned 0. This isn't a synchronization race, isn't caused by #654, and isn't specific to the LTS stack or Julia 1.13. It reproduces on an Arc A750 with the rolling stack and Julia 1.12, with one thread or several, and with or withoutONEAPI_SYNC_EACH_SUBMISSION. In some processes 30–80% of the reductions fail.Cause
It only happens when a shared allocation reuses the address of one that was freed. Looping the testset with a
GC.gc()every 10 iterations, 1511 of 1512 failures had a reused input address. Keeping every array alive gave no failures at all. Simple kernels that only read or only write a shared array were fine, andHostBuffer/DeviceBuffernever failed.Kernels get their arrays as
oneDeviceArraystructs, so to Level Zero every USM pointer they dereference is an indirect access. We never declared that (zeKernelSetIndirectAccesswas wrapped but unused). The driver therefore only maps allocations we explicitly made resident withzeContextMakeMemoryResident, andreleasefrees without evicting. A new shared allocation at a freed address then isn't visible to the kernel, which reads zeros. Removingmake_residentfor shared buffers raises the failure rate to 100%, which is consistent with this.That this showed up as a 1.13-only flake on Aurora is probably GC timing: whether a shared array from an earlier test was collected and its address reused before this testset runs.
Fix
Set the
DEVICE | HOST | SHAREDindirect-access flags once, when a compiled kernel is linked. As far as I know, SYCL's Level Zero adapter does the same for every kernel. Kernels built directly throughoneL0are unaffected.I preferred this to evicting before free, which also fixes the reproducer. Eviction isn't queue-ordered, so evicting a buffer from a finalizer while in-flight work still uses it risks a GPU page fault on the rolling stack, as the existing comment in
releasenotes.Results on the A750, 2000 iterations with
GC.gc()every 10:mainmake_residentkept (this PR)make_residentremovedmake_residentfor shared buffersLaunch overhead with 600 extra live allocations: about +0.2–0.35 µs per async launch (7.6 → 7.9 µs), and no measurable difference for launch+sync.
Test
The new
reusing freed $B allocationstestset allocates two arrays per iteration, frees them in alternating order and runs periodic GCs. Whether a reused allocation reads as zeros depends on allocator state: the existing testset passes in a fresh process, which is why #649 didn't catch this. With this much churn, the test failed in 8 of 8 processes without the fix (73–100 of 100 iterations bad) and passes with it.Locally (A750, Julia 1.12)
array,executionandlevel-zeropass. Still to do:make_resident(and the host-buffer "NotPresent pagefault" workaround inpool.jl, which looks like the same bug) may no longer be needed.