Repository navigation
Flag kernels whose temporaries are sized while they run, instead of refusing the program (#121) - #122
Conversation
…efusing the program (#121) A temporary sized by a value the kernel reads or computes while it runs (lavamd's neighbor_counts[l]) has no caller that can allocate it, so widen_scratch raised UnsupportedNest and default_scopes stopped the program at stage 3. Only Tactics' own per-kernel checks need that size; the built kernel allocates its temporaries itself. - widen_scratch raises RuntimeSizedScratch, naming every such array; prepare catches it and gives the kernel no NumPy oracle (unspelled), with its arguments minus the scratch. - default_scopes reports the arrays in KernelScope.runtime_sized; the kernel's check is left to the whole program, and default_build gives it its first configuration instead of a sweep (the sweep raised ValueError on any kernel without an oracle). - Placement keeps a flagged kernel on the CPU; run-on-gpu on one is refused with why. - The whole-program run passes a scalar input the program takes as a symbol (ls3df_scf's dvol, warpx_esirkepov_deposition's do_ionization), which raised KeyError at init. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ning temporaries shorten_temporaries renamed every generated program container with replace_dict, the __sym_out_<s> scalar a loop kernel exports its symbol through among them (qe_cegterg's __sym_out_nbase_iter became tmp165). replace_dict rewrites the kernel's abi_order (a string-list property) and, through ExternalCall.rename_symbols, its body, but not its _out_ connectors, so node_boundary took the output for a symbol and stage 5 raised KeyError: 'tmp165' in abi_ready_copy. A container bound to an ExternalCall is part of the kernel's interface and now keeps its name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
| Where | Name |
|---|---|
| its output connectors | _out___sym_out_nbase_iter (prefixed) |
its abi_order |
__sym_out_nbase_iter (bare) |
its body (standalone_sdfg) |
__sym_out_nbase_iter (bare) |
Why. After stage 3, default_scopes → bump() → normalize_labels → shorten_temporaries gives every generated program container a short name: __sym_out_nbase_iter → tmp165, __sym_out_notcnv_iter → tmp166. The rename is a replace_dict on the program, which reaches the kernel node in two ways:
replace_properties_dictrewrites every string-list property, andabi_orderis one.ExternalCall.rename_symbolstreats everyabi_ordername with no connector of the same name as a symbol, and renames it in the body too. The connectors carry the_in_/_out_prefix, so a bare name never matches one.
The connectors keep the old name. node_boundary then sorts abi_order against the connectors, finds tmp165 and tmp166 in neither, and takes them for symbols. abi_ready_copy raises KeyError: 'tmp165', because the body has no such symbol.
Fix. temporary_renames leaves out every container an ExternalCall of the program reads or writes (new kernel_bound in tactics/ir/names.py). Those names are the kernel's interface, and shorten_temporaries has no way to rename all three spellings together. shorten_temporaries already renames a nested SDFG's connectors with its containers (rename_connectors), but ExternalCall kernels had no such path. The only visible cost is that a container bound to a kernel keeps a long generated name in the tree, such as __sym_out_nbase_iter.
Test. tests/test_kernel_symbol_outputs.py (tagged reproducer) uses a five-line program whose sequential loop counts into m, which z[0:m] reads after it. On 7038cd3 it fails as the bug does ({'__sym_out_m'} <= {'N', 'm', 'tmp2', 'x', 'y'}); with the fix it passes. mypy, mypy tests, ruff, the header check and tests/test_normalize.py pass.
qe_cegterg now. It runs all 7 stages in the local container (CPU, preset S; Tactics afc49d9 + this PR, dace-extended 1.0.4, HPCAgent-Bench abef4b636). Its whole-program output is not checked there: the container has no reference for it. The numba and C references cannot run (SealError: mount('proc', ...), as for every kernel there), and the bench's NumPy function raises KeyError: 'gamma_only', which is not among the program's parameters. That also happens on unchanged main, so it is not from this PR. The C or numba reference should work on Daint; not run there yet.
🤖 Generated with Claude Code
Addresses #121. Draft: the full test suite is still running locally.
Problem
In 5 bench kernels a temporary is sized by a value the kernel reads or computes while it runs (
lavamd:count = int(neighbor_counts[l]), thennp.empty(1 + count)).widen_scratchcannot size such a buffer for the caller, sodefault_scopesraisedUnsupportedNestand the program stopped at stage 3.Only Tactics' own per-kernel checks need that size: the NumPy oracle and
make_inputs. The built kernel (the CPF unit) allocates its temporaries itself, and itsabi_orderleaves them out.Change
widen_scratchraisesRuntimeSizedScratch(UnsupportedNest)naming every such array.preparecatches it and gives the kernel no NumPy oracle (unspelled, the same path as a kernel NumPy cannot spell), with its arguments minus the scratch.KernelScope.runtime_sizedlists the arrays.default_buildgives it its first configuration instead of a sweep: undercodegen="sweep"the sweep raisedValueErroron any kernel without an oracle.run-on-gpuon one is refused with the reason.The whole-program check then failed on 2 kernels for an unrelated reason, fixed here too. A scalar parameter that canonicalization turns into a symbol (
ls3df_scf'sdvolandtol,warpx_esirkepov_deposition'sdo_ionization) arrives as a 0-d input, not a size, soinitraisedKeyError.time_programnow passes such inputs as symbol values (program_symbols).Results
Local arm64 Linux container, CPU target, preset S, default stages. Tactics
afc49d9,dace-extended1.0.4, HPCAgent-Benchabef4b636.mainlavamdcp2k_grid_integratels3df_scfwarpx_esirkepov_depositionqe_cegtergmain)SealError: mount('proc', ...)).lavamd,cp2k_grid_integrateandqe_cegtergthe flagged kernel is placed on the CPU, and forcing it onto the GPU is refused.tests/test_runtime_sized_scratch.pyandtests/test_program_scalar_symbols.py(tagged reproducers). The test files of the touched modules pass (112 tests);mypyandmypy testsare clean; ruff and the header check pass. pyright reports the same 50 errors on these files as onmain.Follow-ups
qe_cegtergstopped at stage 5 (KeyError: 'tmp165') on a renaming bug that hits any kernel exporting a symbol. Fixed inf750122, explained in the comment below.qe_cegterg's whole-program output (needs Daint), GPU builds, timings.🤖 Generated with Claude Code