Description
What we found
DaCe synchronizes the GPU stream far more than needed in qe_vexx_k's GPU program. Results are correct; the cost is time. The host calls cudaStreamSynchronize after every GPU state, also between two kernels on the same in-order stream where nothing on the host reads GPU data:
__cpf_runkernel_extcall_for3_doall102_47_0_11(__state, Tmp43, exxbuff_w_0_0_0, result, k2, npol, nrxxs, __cpf_current_stream);
cpf_gpu_check(cudaStreamSynchronize(__state->gpu_context->streams[0])); // codegen state footer (cuda.py)
cpf_gpu_check(cudaStreamSynchronize(gpu_streams[0])); // stream wiring sync taskletPer whole-program call (preset M, all 13 kernels on the GPU, Daint GH200, Nsight Systems, job 5511888):
| Per call | |
|---|---|
cudaStreamSynchronize |
2,898 calls, 21.1 ms of host time |
| Call time (under Nsight) | 37.9 ms |
| GPU busy | 13.0 ms (kernels 1-8 µs each, FFTs 2.9 µs) |
| Kernel launches | 3,862 (~12 ms of host time) |
The band-pair loop launches ~15 tiny kernels per pair for 256 pairs. With a wait after each, the host cannot queue the next launch while the GPU runs the last one, so the GPU idles about two thirds of the call.
Why it happens. AutoGPUStreamScheduler (dace/transformation/passes/gpu_specialization/gpu_stream_scheduling.py) would place waits only where the host reads GPU results. But it falls back to PerComponentGPUStreamScheduler for the whole SDFG as soon as one node anywhere mixes host and GPU work:
AutoGPUStreamScheduler: 1 top-level node(s) mix host and GPU work
(first: NestedSDFG 'nested_state43_for_inline' in state 'state182' (SDFG 'extcall_for3'));
falling back to PerComponentGPUStreamScheduler.
classify_node(NestedSDFG)folds the whole inner SDFG;mixed_nodes()collectsMIXEDnodes at any depth; one hit ->assign_mixed_streams()-> per-component rule (classify_sync_points): a kernel exit writing GPU memory -> wait at the end of its state. Every state.- The offending node sits outside the pair loop, at the top level of
extcall_for3. It is a guarded specialization (if51): a pinned host fallback loop (for24, a gather intoTmp24overngm) and its GPU parallel arm (doall189). One such node -> waits in all 256 pairs. - It stays nested because
MapToForLoop(map_for_loop.py,inline_after) cannot inline it: its output goes through a reshape view,Tmp24[0:nrxxs] <-> Tmp23[0:n3, 0:n2, 0:n1], andInlineMultistateSDFG.can_be_appliedrefuses any view at the boundary (isolate_nested_sdfg's test also fails). Five nested SDFGs in this kernel are refused this way. - The waits come in pairs because
cuda.py's state footer adds its own wait (lines ~1547-1566) on top of the sync tasklet the stream wiring inserts. - Not this kernel only: two other units of the same program fall back too, on
state 'stage_copyin'(a stateSplitStateByGPUClasscould not split).
The fallback warning is easy to miss: runs with PYTHONWARNINGS=ignore hide it.
What needs to be found
A way to keep the default rule, wait only before a host read of GPU data, for a program that contains a nested SDFG mixing host and GPU work, instead of switching the whole SDFG to a wait after every state. The required waits stay required: a missing one means the host reads unfinished GPU data and the results are silently wrong, so whatever the fix, it has to be shown correct before it is fast.
Candidate directions (none implemented):
- Treat such a nested SDFG as a host level of its own.
AutoGPUStreamScheduler.splice_host_readsalready places waits inside a nested SDFG that holdsgpu_streams(the ICON host-map body case); the classification falls back before that path runs. A nested SDFG at host level (not inside a map) whose inside is host control flow plus GPU maps would be a host level, notMIXED, and the stream wiring would give itgpu_streams. - Fall back per state, not per SDFG. Only the
MIXEDstates get the per-state waits; the Auto rule holds everywhere else. - Inline the node. Let
InlineMultistateSDFGhandle a boundary reshape view (recreate the view in each inlined state that touches it). Removes theMIXEDnode itself, but touches a core transformation every inliner uses. - Drop the duplicate wait. Skip
cuda.py's state-footer wait when the stream wiring already placed its syncs (is_stream_wiring_applied). Small and low-risk, but a small gain: the second wait runs on an idle stream.
Questions: which direction fits the design of gpu_stream_scheduling.py, and who should review a change there? How to test it: qe_vexx_k on all 11 configurations x 3 shapes on the GPU, DaCe's -m gpu tests with CuPy installed, and a regression test (a mixed host-level nested SDFG keeps the Auto rule and gets waits only before host reads)?
What the fix can gain
This kernel (estimate, not measured). With waits only at real host reads (per-band scalars such as any_match / min_expr / max_expr, copy-backs, the call's end), ~2,900 waits -> on the order of 100 per call. The call is then bound by the ~3,900 launches (~12 ms of host time) and the GPU work (~13 ms), which overlap: ~13-15 ms per call, about 2x over the current 29 ms and ~3.5-4x over the bench's numba baseline (53 ms).
Measured so far on the same kernel (job 5511888, 72 host threads, one GPU): copy placement fix alone (local b10eec3a0c on 774047f913, not pushed) took v10 from 41.7 to 29.1-29.8 ms, from 1.27x to 1.80x over numba.
In general. Any GPU program that DaCe lowers with a host loop launching many small kernels, and that contains one mixed nested SDFG anywhere, pays a wait per state per iteration. The gain grows with the number of short kernels per call: when kernels take a few µs, a host wait plus a launch (~5-10 µs) per kernel is most of the time, and removing the waits lets launches overlap GPU work. How many programs are affected is not known yet; a cheap first count needs no GPU: render each GPU-target kernel of the bench with PYTHONWARNINGS=always::UserWarning and count the falling back to PerComponentGPUStreamScheduler warnings.
Versions and repro
- DaCe:
774047f913([extended] Fixes from Tactics' default pipeline on HPCAgent-Bench (weekend of 2026-11-28) dace#2811 overlay) ondace-extended1.0.5; Tactics: Working PR from 2026-11-28: fixes from the default pipeline and agent runs (base for the next experiments) #123e303f87; HPCAgent-Bench 1.0.5. qe_vexx_k, preset M, GPU target: default moves and scopes, thenrun-on-gpuon the 3 sequential loop kernels ([k.name for k in s.list_kernels() if not k.parallel]), then the default placement.- Render the kernels with
PYTHONWARNINGS=always::UserWarning: the fallback warning forextcall_for3appears without a GPU. - Diagnostic probes (monkeypatch only, no DaCe change) and the Nsight profile are available on request.
Activity
[-]GPU: one mixed nested SDFG makes the stream scheduler sync after every kernel (qe_vexx_k: ~2,900 cudaStreamSynchronize per call)[/-][+]GPU: DaCe waits on the stream after every kernel when one nested SDFG mixes host and GPU work (qe_vexx_k: ~2,900 cudaStreamSynchronize per call)[/+]nicolasribeiro2028 commentedon Dec 2, 2026
Fallback count. 180
scientific_computingkernels (HPCAgent-Bench 1.0.5, Tacticse303f87, DaCe774047f913), default GPU pipeline at preset S, units rendered only. 175 rendered (4 timeouts,kmeanscrashed); 155 have GPU units.7 of 155 kernels (12 units) fall back to
PerComponentGPUStreamScheduler:state 'stage_copyin'in sort library unitsqe_vexx_k,qe_regterg,sparse_cholesky,ilu0,qe_vloc_psi_k_accNestedSDFG 'loop_body'(this issue)quatrex_rgf,qe_vloc_psi_k_accstate 'block'in a BLAS library unitlaplacian_stencil_3dLower bound: default placement keeps sequential loops on the CPU; the
qe_vexx_kcase above needs them on the GPU. Cost in these 7 kernels not measured.