Skip to content

Submit work through per-task immediate command lists - #610

Draft
michel2323 wants to merge 1 commit into
scratch-hedgefrom
immediate-command-lists
Draft

Submit work through per-task immediate command lists#610
michel2323 wants to merge 1 commit into
scratch-hedgefrom
immediate-command-lists

Conversation

@michel2323

Copy link
Copy Markdown
Member

Stacked on #609 (the base branch); this PR's own diff is the immediate-command-list rework. GitHub will retarget to main when #609 merges.

Every kernel launch, copy, and fill used to create a fresh ZeCommandList, submit it to the task's command queue, and drop the reference — leaving destruction of thousands of driver objects (lists, command buffers, heaps) to finalizer timing. Under launch storms that garbage is what pushes the driver into allocation failure, where NEO's error handling is at its worst (see #609). It is also pure overhead: ~8x in per-dispatch submission latency (measured with a microbenchmark on PVC; formal numbers will be attached before undrafting).

This PR replaces the per-dispatch machinery with a per-task oneStream holding one in-order asynchronous immediate command list: appends submit directly, and the per-dispatch garbage class disappears entirely. Measured on Aurora (PVC, LTS): a pressure loop that accumulates 10,003 live command lists in 2,000 iterations on current main accumulates zero with this PR, and a reproducer that reliably dies at the driver's allocation wall on main (6/6 runs, OOM in retry_reclaim) survives 6/6 with the fix, including the first spilling submission.

Design notes:

  • oneMKL ordering. oneMKL needs a real command queue for SYCL interop, so each stream lazily creates a companion queue — a separate execution stream, which makes the previously implicit ordering between Julia kernels and oneMKL calls explicit: sycl_queue host-synchronizes the immediate list before handing out the SYCL queue (Julia → MKL), and a dirty flag makes the next Julia-side submission drain the companion queue (MKL → Julia; one Bool load on the fast path). FFT plans capture their queue at construction, so their _exec! methods apply the boundary themselves. New interleave tests (broadcast → gemm → broadcast with no intermediate synchronization, 100 iterations, vs CPU reference) cover this.
  • No fallback path. Support is probed by creating the list, not by zeDriverGetApiVersion: the Aurora LTS driver reports API 1.6 while fully implementing in-order immediate lists (they are DPC++'s production submission path on PVC). For the same reason the code avoids 1.9-only loader entrypoints such as zeCommandListIsImmediate. Drivers that genuinely reject the creation get a clear error.
  • LTS drain-before-free. The queue registry becomes a stream registry: before a buffer with possibly in-flight work is freed, both the immediate list and the companion queue of every registered stream are drained. Immediate lists get the same bounded-timeout finalizer drain as queues (destroying a busy immediate list is illegal on every stack).
  • ONEAPI_SYNC_EACH_SUBMISSION now host-synchronizes the list after each append. The dropped-tail driver bug it works around was only ever observed on the queue-submission path; whether it exists at all on immediate lists is left for a future oversubscription re-test (the knob is kept).
  • KA.priority! swaps the task's stream for one with the requested priority. Explicit @oneapi queue=... still submits through a per-dispatch list, and the Guard NEO's scratch allocation with a spill-triggered drain #609 hedge covers both paths (per-stream and per-queue high-water marks).

Full test suite on Aurora LTS (PVC, ONEAPI_LTS=1, 12 workers): 10,900 pass; the single failure is a pre-existing host-side AVX512-FP16 Float16 issue unrelated to this change (fails identically on main). Also green: KernelAbstractions testsuite (2,218), the new level-zero immediate-list block, FFT interleave, and a two-task alloc/free churn test exercising the cross-task drain.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WSFxSBXtckG3BVAT12wYkf

Every kernel launch, copy, and fill used to create a fresh command list,
submit it to the task's command queue, and drop the reference — leaving
destruction of thousands of driver objects (lists, command buffers, heaps)
to finalizer timing. Under launch storms that garbage is what pushes the
driver into allocation failure, where NEO's error handling is at its worst
(the scratch path aborts outright). It is also pure overhead: the
per-dispatch list costs ~8x in submission latency.

Replace the per-dispatch machinery with a per-task oneStream holding one
in-order asynchronous immediate command list: appends submit directly, and
the garbage source disappears entirely. Level Zero >= 1.9 is required; there
is no fallback submission path.

oneMKL work still needs a real command queue for SYCL interop, so each
stream lazily creates a companion queue — a separate execution stream, which
makes the previously implicit ordering between Julia kernels and oneMKL
calls explicit: sycl_queue drains the immediate list before handing out the
SYCL queue (Julia -> MKL), and a dirty flag makes the next Julia-side
submission drain the companion queue (MKL -> Julia). FFT plans capture
their queue at construction, so their _exec! methods apply the boundary
themselves.

The LTS drain-before-free machinery follows the shape change: the queue
registry becomes a stream registry, draining both the immediate list and
the companion queue before a buffer referenced by in-flight work is freed;
immediate lists get the same bounded-drain finalizer as queues. The
sync-each-submission workaround now host-synchronizes the list after each
append. KA.priority! swaps the task's stream for one with the requested
priority. The scratch hedge moves to the stream, and remains on the
explicit-queue compatibility path (@oneapi queue=...), which still submits
through a per-dispatch list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WSFxSBXtckG3BVAT12wYkf
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.05%. Comparing base (1ee7863) to head (6dd1263).

Files with missing lines Patch % Lines
src/context.jl 65.57% 21 Missing ⚠️
lib/level-zero/cmdlist.jl 80.00% 4 Missing ⚠️
src/memory.jl 50.00% 1 Missing ⚠️
src/pool.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           scratch-hedge     #610      +/-   ##
=================================================
+ Coverage          78.80%   79.05%   +0.25%     
=================================================
  Files                 50       50              
  Lines               3505     3571      +66     
=================================================
+ Hits                2762     2823      +61     
- Misses               743      748       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant