Skip to content

[extended] Fixes from Tactics' default pipeline on HPCAgent-Bench (weekend of 2026-11-28) - #2811

Draft
nicolasribeiro2028 wants to merge 8 commits into
spcl:extendedfrom
nicolasribeiro2028:thesis/offload-copy-back-device-home
Draft

nicolasribeiro2028 wants to merge 8 commits into
spcl:extendedfrom
nicolasribeiro2028:thesis/offload-copy-back-device-home

Conversation

@nicolasribeiro2028

@nicolasribeiro2028 nicolasribeiro2028 commented Nov 28, 2026 •

Copy link
Copy Markdown

Summary

This PR collects the DaCe extended fixes found while running Tactics' default pipeline on HPCAgent-Bench kernels over the weekend of 2026-11-28. Each fix is a separate commit with its own regression test and gets a section below. They were checked on top of dace-extended 1.0.5, the release Tactics pins, so they reach Tactics through the next release after 1.0.5.

Fixes so far:

  1. [58d8cf7] OffloadToAccelerator drops the copy-back of a host-written device argument.
  2. [a27570d] PruneConnectors prunes a connector that an ordering node still names, then cannot remove its descriptor.
  3. [e9a7ca6] overapproximate does not bound a tile clipped inside a ceiling, so a GPU thread-block size conflicts with gpu_block_size.
  4. [9fe03b5] CPF's device entry binds the GPU context as the state's first initializer.
  5. [3935704] CPF's CUB functors cannot deduce an accumulator over two operand types (int8_t scan into int64_t).
  6. [1702bed] A thread-block map below a megakernel leaves it untiled, and the cooperative launch takes its thread range for the grid.
  7. [774047f] Scope allocation hoisting moves a buffer to the SDFG entry although its size symbol is assigned in the loop (QE cegterg heap overrun).

1. OffloadToAccelerator drops the copy-back of a host-written device argument

Symptom. On the GPU target, every program whose kernels hold a ScatterConflictCheck fails to build. nvcc rejects the CPF unit: too many initializer values on <name>_state_t __cpf_state{&__cpf_context};. The programs are sparse_cholesky, qe_vexx_k, ilu0 and lulesh, on dace-extended 1.0.4 and 1.0.5.

Cause. ScatterConflictCheck declares its flag and its scratch array as host_connectors. When the node's operands are device arguments, which happens to a body offloaded with every argument in device memory, the pass computes those two in host twins. Both are also written in full before any read, so they are in _no_copy_in_needed. insert_copies dropped every host-to-device copy of a name in that set. That filter is meant for the dead fill of a host array's device twin, but for an argument whose home is the device, the same direction is the copy back of its result. The arguments were never written, so the body became dead code, and CPF rendered an empty entry with an empty state struct.

Fix. Keep the copy when the argument is stored on the device (offload_to_accelerator.py, insert_copies).

Tests.

  • New: tests/passes/offload_to_accelerator_test.py::test_a_host_pinned_result_is_copied_back_into_its_device_argument. It fails before the fix and passes after.
  • tests/passes/offload_to_accelerator_test.py and tests/transformations/gpu_transform_test.py: with and without the fix, the same 12 tests fail on a machine without a GPU, cupy or a CUDA compiler. Nothing else changes.
  • Through Tactics (4c639ab, dace-extended 1.0.5 with this commit applied), the rendered units now carry gpu_context and a body that runs the check and copies both results back: ilu0 (1 kernel), sparse_cholesky (2), qe_vexx_k (2). The nvcc build has not been run yet.

Not in this commit. The pass still copies the two arguments device-to-host before the call. The copy is dead traffic but harmless.

2. PruneConnectors prunes a connector that an ordering node still names

Symptom. npbench nbody fails in CPF's prepare, on both targets: ValueError: Cannot remove data descriptor softening: it is accessed by node softening in state state120 (cpf.py:1135 → prune_connectors.py:182 → sdfg.remove_data).

Cause. Inside the nested SDFG, the access node of softening carries only empty memlets: it orders two nodes and reads nothing. read_and_write_sets therefore leaves the container out, so _get_prune_sets pruned the connector, and apply then could not remove the descriptor while the node still named it.

Fix. _get_prune_sets keeps a connector whose container has an access node in the body but is neither read nor written there. Every other pruning is unchanged: a container the body reads or writes is already in read_and_write_sets.

Tests.

  • New: tests/transformations/prune_connectors_test.py::test_prune_connectors_keeps_a_connector_an_ordering_node_names. It fails before the fix (the same ValueError) and passes after.
  • prune_connectors_test.py and prune_connectors_subset_container_test.py: with and without the fix, the same 9 tests fail on a machine that cannot compile DaCe programs (CompilerConfigurationError). Nothing else changes.
  • The SDFG saved from Tactics (nbody extcall_for0): apply_transformations_repeated(PruneConnectors) raises before the fix and validates after.
  • Through Tactics 4c639ab on dace-extended 1.0.5 with fixes 1 and 2 applied: nbody on the CPU target builds all 8 kernels, each passes its own check, and the whole program is correct against the NumPy reference. On the GPU target, extcall_for0 now renders; the GPU build has not been run.

3. overapproximate does not bound a tile clipped inside a ceiling

Symptom. npbench stockham_fft on the GPU target: InferGPUGridAndBlockSize refuses kernels doall16 and doall27 with Both the gpu_block_size property and internal thread-block maps were defined with conflicting sizes. The sizes it detects are [16, 16, 1] against [-g + ceiling(Min(g + 15, ceiling(R**k) - 1)) + 1, 16, 1], and similarly [16, 4, 8] for doall27.

Cause. The thread-block map is a 16-wide tile clipped at a ceiling-valued bound. overapproximate bounds Min(a, b) + c but not a Min wrapped in a ceiling, so the extent stayed symbolic and compared unequal to the block size. The schedule itself is consistent: the bounded extent is exactly the block size.

Fix. ceiling is monotonic, so ceiling(Min(x, y)) equals Min(ceiling(x), ceiling(y)). _overapproximate rewrites it that way before the Min rule. An argument that is a polynomial with integer coefficients in integer-typed DaCe symbols (g + 15) is already an integer and keeps no ceiling.

Tests.

  • New: tests/symbolic_test.py::test_a_tile_clipped_by_a_ceiling_bound_overapproximates_to_its_full_tile. It fails before the fix and passes after; it also checks that a fractional argument still rounds up.
  • tests/symbolic_test.py: 42 passed.
  • Through Tactics 4c639ab on dace-extended 1.0.5 with fixes 1-3 applied: stockham_fft renders all 8 kernels on the GPU target. doall16 launches dim3(16, 16, 1) and doall27 launches dim3(16, 4, 8), each matching its gpu_block_size. The GPU build has not been run.

4. CPF's device entry binds the GPU context as the state's first initializer

Symptom. This is the error fix 1 surfaced. nvcc reports too many initializer values on <name>_state_t __cpf_state{&__cpf_context}; whenever a unit's state struct has no field at all.

Cause. device_entry_prologue brace-initializes the state with the context pointer, which assumes gpu_context is the struct's first field. A unit with no device code has no such field. The same assumption also breaks if another field comes first.

Fix. Value-initialize the state (__cpf_state{}), then assign __cpf_state.gpu_context = &__cpf_context; by name, and only when the struct declares the field. framecode passes has_context from the state struct's fields.

Tests.

  • New: tests/codegen/cpf/test_emission_cuda.py::test_a_device_entry_binds_its_context_by_name and ::test_a_device_entry_with_no_context_field_binds_none. Both fail before the change and pass after.
  • tests/codegen/cpf: with and without the change, the same tests fail on a machine without a CUDA toolchain. The only other difference, test_loop_comment_fixes_2.py::test_a_gpu_fallback_arm_says_it_runs_on_the_host_and_what_it_copies, depends on the hash seed: it fails on the same seeds (2, 3, 4, 7 of 0-7) with and without the PR.

5. CPF's CUB functors cannot deduce an accumulator over two operand types

Symptom. dbcsr on the GPU target: nvcc fails inside CUB's DispatchScan<const int8_t*, int64_t*, cpf_cub_plus, ...> with AccumT=<error-type>.

Cause. The unit calls DeviceScan::ExclusiveScan(in: int8_t*, out: int64_t*, cpf_cub_plus(), init: int64_t). CUB deduces the accumulator from op(init, input), which here is op(int64_t, int8_t). cpf_cub_plus::operator() is template <typename T> T (const T&, const T&), and T cannot be deduced from two different types.

Fix. cub_functor builds all four functors (plus, multiplies, minimum, maximum). Each one gains an overload over two types that works in std::common_type_t<T, U>. The one-type template is more specialized and still wins on equal types, so a same-type scan or reduction is unchanged.

Tests.

  • New: tests/codegen/cpf/test_emission_cuda.py::test_a_cub_functor_deduces_an_accumulator_over_two_types, for each of the four functors. It compiles the emitted functor with the host C++ compiler and asserts the deduction CUB makes: invoke_result_t<f, int64_t, int8_t> is int64_t, (int8_t, int8_t) stays int8_t, and (float, double) is double. Before the fix the host compiler reports the same deduction failure; after it, all four pass.
  • tests/codegen/cpf and tests/passes/offload_to_accelerator_test.py: with and without the fix, the same tests fail on a machine without a GPU toolchain, apart from the new tests and the hash-seed-dependent comment test noted in fix 4.
  • Through Tactics 4c639ab on dace-extended 1.0.5 with fixes 1-5 applied: dbcsr renders all 12 GPU kernels, and both scan units carry the mixed overload. The nvcc build has not been run yet.

6. A thread-block map below a megakernel leaves it untiled, and the launch takes its thread range for the grid

Symptom. qe_vexx_k on the GPU target: the whole program aborts with extcall_doall129_..._megakernel_0 launch failed (grid 67584,1,1 block 256,1,1): too many blocks in cooperative launch. A smaller program with a Transpose per iteration in one of two merged kernels fails instead at InferGPUGridAndBlockSize with conflicting sizes ([256, 1, 1], [16, 4, 8]). Both happen on base ef3ad61 too; they are not caused by fixes 1-5.

Cause. launch_cooperatively gives the megakernel map a range in threads, 0:nblk*256, and each thread runs its own grid-stride iterations. ComputePersistentKernelRange sizes nblk as the resident blocks (264 on a GH200). Normally AddThreadBlockMaps tiles that map and the grid is nblk. But a thread-block map can appear below the megakernel later: a map's default schedule in a GPU_Device scope is GPU_ThreadBlock, and a library node inside may expand as a block collective (qe_vexx_k's copy_psi_to_tg became copy_psi_to_tg_lanes, 0:256). With such a map below it, AddThreadBlockMaps leaves the megakernel untiled, and InferGPUGridAndBlockSize takes the thread range for the grid: 256 * nblk = 67584 blocks. DaCe's own test_a_cooperative_kernel_launches_cooperatively_and_sizes_its_grid passes only because its body has no such map.

Fix. A megakernel (explicit_sync: its grid is final) has no thread-block level, so nothing below it may take one.

  • New pass SequentialMegakernelBodies, placed after ExpandLibraryNodes and before AddThreadBlockMaps, runs every thread-block map below an explicit_sync kernel sequentially in its thread.
  • in_kernel_block_implementation offers no block collective below such a kernel (runs_per_thread), so a library node there takes a per-thread lowering instead of code that indexes the block's threads.

Tests.

  • New: tests/transformations/megakernel_test.py::test_a_megakernel_body_keeps_no_thread_block_map_and_launches_its_resident_blocks. It renders the two-kernel Transpose program and asserts one cooperative launch with block 256 and grid nblk. Without the pass it fails with the block-size conflict.
  • New: ::test_a_library_node_in_a_megakernel_takes_no_block_collective.
  • Related files (megakernel, tests/codegen/cpf, offload, the GPU specialization pass tests, and the in-kernel block collective library tests), with and without this commit on the same branch: no test fails only with the commit. The only difference is the hash-seed-dependent comment test of fix 4. The GPU-run tests in these files were not run (no GPU).
  • The SDFG Tactics renders for qe_vexx_k extcall_doall129, and Tactics 8d5a24e on dace-extended 1.0.5 with fixes 1-6: the cooperative launch is dim3(tmp1) with tmp1 = the resident blocks. The run on a GPU has not happened yet.

7. Scope allocation hoisting keeps the first size of a buffer the loop resizes

Symptom. QE cegterg (qe_cegterg) through Tactics aborts in its whole-program run on both targets: free(): invalid size (CPU) and free(): invalid next size (fast) (GPU target, whose Davidson kernel stays on the CPU). Reproduced in a Linux container on Tactics v0.1.4 with dace-extended 1.0.5. Under gdb the abort is the delete[] of pivots at the end of the kernel extcall_for42.

Cause. np.linalg.inv's expansion sizes its _pivots scratch int[nbase_iter], Scope lifetime. Its only use is one state inside the Davidson loop, so determine_allocation_lifetime places the allocation at the SDFG entry so the loop does not reallocate it (framecode.py, the branch that keeps desc.lifetime Scope and moves only the placement). The placement checked only that the size symbols are free in the SDFG. nbase_iter is free, a kernel argument, but the loop also assigns it (nbase_iter = nbase_iter + notcnv_iter, growing from nvec to 4 * nvec). So the buffer got the entry size, and LAPACKE_zgetrf/zgetri wrote up to four times as many pivots into it. Builds whose heap layout differs run past the overrun silently.

Fix. The hoist also requires that no size symbol is assigned on an interstate edge, or iterated by a loop, anywhere in the SDFG's tree. That scan moves out of persistent_size_symbols into reassigned_symbols (transformation/passes/persistent_transients.py), so the Persistent and the hoisted-Scope placements use one rule.

Tests.

  • New: tests/codegen/scope_allocation_hoisting_test.py::test_size_reassigned_in_the_loop_is_not_hoisted (a heap buffer sized by a free n that an interstate edge in the loop grows). It fails before the fix (the buffer is allocated at loop depth 0) and passes after.
  • New: ::test_size_reassigned_in_the_loop_numerics. Before the fix it corrupts the heap (corrupted double-linked list at exit); after, it passes cleanly.
  • The allocation tests in tests/codegen (*alloc*, *transient*, scope_allocation_hoisting, symbol_dependent_alloc_in_conditional, view_allocation*), tests/codegen/cpf, tests/passes/persistent_transients_test.py, and the LAPACK and linalg library tests, with and without this commit, on CPU in a Linux arm64 container: the same 11 tests fail on both (8 need MKL, 3 CPF scan emission tests), and 2 more pass with the commit, which are the new tests.
  • Through Tactics on qe_cegterg (CPU target, preset S, container): pivots is now allocated inside the loop after the subspace size is set and freed in the same iteration. On v0.1.4 with this commit the whole program runs to the end without the abort; on Working PR from 2026-11-28: fixes from the default pipeline and agent runs (base for the next experiments) tactics#123 7a40c72 too, also under gdb. The output was not graded: the container cannot run the bench's reference.

Checked on a GPU (CSCS Daint, GH200)

Tactics 8d5a24e drives dace-extended 1.0.5 with this PR's commits applied, at preset S. The bench graded each program against its own reference.

Program Fixes involved CPU target GPU target
ilu0 1, 4 correct correct (4 kernels on the GPU)
sparse_cholesky 1, 4 correct correct (4 on the GPU; NumPy reference)
nbody 2 correct, 8/8 kernels correct (5 on the GPU)
dbcsr 5 correct correct (9 on the GPU, int8 scans included)
qe_vexx_k 1, 4, 6 correct correct with fix 6 (10 on the GPU)
stockham_fft 3 correct builds and every kernel is exact at every stage; the whole program's y is still wrong, under investigation and not attributed to this PR yet

Before these fixes, none of these programs built on the GPU target.

  • The rows for fixes 1-5 come from job 5478369 (fixes 1-5) and the qe_vexx_k row from job 5478649 (fixes 1-6).
  • In job 5478369 the touched DaCe test files ran on this branch and on ef3ad61. The same 15 tests failed on both, all for want of CuPy in that environment, and 9 more passed on this branch, which are the new tests.

🤖 Generated with Claude Code

nicolasribeiro2028 and others added 6 commits November 28, 2026 12:07
A device argument a host library connector writes (ScatterConflictCheck's flag
and scratch) is computed in its host twin. When the argument is also written
in full before any read, it is in _no_copy_in_needed, and insert_copies dropped
every host-to-device copy of it. That set exists to spare a host array the fill
of its device twin; for an argument whose home is the device the same direction
is the copy back of its result. Without it the argument was never written, the
body was dead code, and CPF rendered an empty entry whose empty state struct
nvcc rejects (`too many initializer values` on `__cpf_state`).

Keep the copy when the argument is stored on the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An inner access node that carries only empty memlets orders two nodes and
reads nothing, so read_and_write_sets leaves its container out and the
connector was pruned. apply then tried to remove the descriptor while the node
still named it, and raised (npbench nbody's `softening` in CPF's prepare:
`Cannot remove data descriptor softening: it is accessed by node softening`).

Leave such a connector in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GPU thread-block map tiled by 16 and clipped at a ceiling-valued bound has
the extent -g + ceiling(Min(g + 15, ceiling(R**k) - 1)) + 1. The ceiling
around the Min kept it from the Min(a, b) + c rule, so the extent stayed
symbolic and conflicted with the kernel's gpu_block_size of 16 (npbench
stockham_fft on GPU: "Both the gpu_block_size property and internal
thread-block maps were defined with conflicting sizes").

ceiling is monotonic, so ceiling(Min(x, y)) is Min(ceiling(x), ceiling(y));
an argument that is a polynomial with integer coefficients in integer DaCe
symbols is already an integer and keeps no ceiling. Rewritten that way, the
extent bounds to 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The entry brace-initialized its state with the context pointer, which assumes
gpu_context is the struct's first field. A unit with no device code has no
such field, and nvcc rejected the empty struct's initializer as `too many
initializer values` (Tactics' GPU ScatterConflictCheck kernels before fix 1).

Value-initialize the state, then assign the gpu_context field by name, and
only when the struct declares it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CUB deduces a scan's accumulator from op(init, input). An int8_t scan into
int64_t with an int64_t initial value calls the operator on two types, which
the one-type template operator() of cpf_cub_plus cannot deduce, and CUB's
DispatchScan instantiated with AccumT=<error-type> (dbcsr on the GPU target).

Each of the four functors gains an overload over two types that works in their
common type. The one-type template is more specialized and still wins on equal
types, so a same-type scan or reduction is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A megakernel's map spans threads (its range is nblk * block_size), and each
thread runs its own grid-stride iterations. A thread-block map that appeared
below it later (the default schedule of a map in a GPU_Device scope, or a
library node expanded as a block collective) stopped AddThreadBlockMaps from
tiling the kernel, so the launch took the thread range for the grid: 256 times
more blocks than a cooperative launch holds (qe_vexx_k on the GPU target: "too
many blocks in cooperative launch", grid 67584), or a block-size conflict.

- SequentialMegakernelBodies, after ExpandLibraryNodes and before
  AddThreadBlockMaps, runs every thread-block map below an explicit_sync
  kernel sequentially in its thread.
- in_kernel_block_implementation offers no block collective below an
  explicit_sync kernel (runs_per_thread), so a library node there takes a
  per-thread lowering instead of code that indexes the block's threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nicolasribeiro2028 added a commit to spcl/tactics that referenced this pull request Nov 29, 2026
dace-extended 1.0.6 (released 2026-11-29) shifts a loop such as range(1, T) to
start at 0. With it, 7 unit tests and 1 integration test fail on this branch's
parent 8d5a24e as well (split_doall, tree_view, comm_subsets, durbin costing,
the middle loop value, quickstart's jacobi loops), and all of them pass on
1.0.5. There is no lock file, so CI took 1.0.6. The pin keeps this PR on the
version its runs use (1.0.5 with spcl/dace#2811 applied) until Tactics is
adapted to 1.0.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nicolasribeiro2028 and others added 2 commits November 30, 2026 12:53
A Scope-lifetime array used in one state of a loop is placed at the SDFG entry
so the loop does not reallocate it. The placement checked only that the size
symbols are free in the SDFG. A free symbol can still be assigned inside the
loop (read before written, `n = n + 8`), and then the entry allocation keeps
the first size while later iterations use a larger one.

QE cegterg hit this through Tactics: np.linalg.inv's `_pivots` scratch,
`int[nbase_iter]`, was allocated once at kernel entry with nbase_iter = nvec,
while the Davidson loop grows nbase_iter to 4 * nvec and LAPACKE_zgetrf writes
that many pivots. The program aborted with `free(): invalid size`.

The hoist now also requires that no size symbol is assigned on an interstate
edge or iterated by a loop anywhere in the SDFG's tree. That scan moves from
persistent_size_symbols into reassigned_symbols, so both placements use the
same rule.

Tests: tests/codegen/scope_allocation_hoisting_test.py gains
test_size_reassigned_in_the_loop_is_not_hoisted (fails before: buf at loop
depth 0) and test_size_reassigned_in_the_loop_numerics (corrupted the heap
before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A conditional without an else is placed for its one real arm, since the
fall-through arm added for the missing else uses nothing. When that arm is
the conditional's own sequential fallback (a branch holding a pinned loop),
it is host code that copies in and out inside itself, so its host use is no
entry location. Taken as one, the device-to-host copy sat before the
conditional and the copy back after it, and every execution paid both, the
arm taken or not.

qe_vexx_k's `if okvan and tqr` scatter into `rhoc` moved 1.77 MB to the host
and back once per band pair this way: about 0.9 GB per call at the
norm-conserving configuration, which never takes the arm.

The check is narrower than in_sequential_specialization_arm, which is also
true for blocks nested in the arm: applied to the conditional inside the
fallback loop's body, the loop lost its host locations and copied once per
iteration. The new test covers both shapes (copies only inside the arm,
none inside the loop) and, on a GPU, both flag values against NumPy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicolasribeiro2028

Copy link
Copy Markdown
Author

b10eec3a0c OffloadToAccelerator: a one-armed fallback copies only inside its arm

Problem. __populate_open_node_sets places a conditional for its one real arm (the fall-through arm added for a missing else uses nothing). When that arm is the conditional's own pinned sequential fallback, its host use became the conditional's entry location: the device-to-host copy went before the conditional and the copy back after it, on every execution, arm taken or not.

Fix. New is_own_fallback_arm(conditional, block); in that case the open node takes no location from the arm, which copies inside itself. Narrower than in_sequential_specialization_arm, which is also true for blocks nested in the arm (using it made the fallback loop copy once per iteration).

Test. tests/offloading/one_armed_fallback_copies_test.py: 2 CPU tests (copies only inside the arm, none inside the loop; flat body and a body with a nested conditional) fail on 774047f913, pass here; 4 GPU tests (arm taken and not taken, against NumPy) pass.

Results (Daint GH200, job 5511888, via Tactics on HPCAgent-Bench qe_vexx_k, preset M, all kernels on the GPU):

774047f913 b10eec3a0c
Copies per call 609 (~984 MB) 95 (~78 MB)
Time per call (72 host threads) 41.1-42.0 ms 29.1, 29.8 ms (one run 43.5 ms, not explained)
qe_vexx_k, 11 configs x 3 shapes 33/33 33/33
  • CPU tests (-m "not gpu", offloading, offload_to_accelerator, taskloop, loop_to_scan, runtime_versioning, known_parallel_loops): 411/411.
  • GPU-marked offloading tests: same results on both commits. 29 tests did not run (CuPy missing in that environment).

This branch has not been deployed

No deployments
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