Repository navigation
[Driver] The cache identity is the compiler's own toolchain and TOGSim API; a hit keeps its autotuned tile - #423
Merged
Conversation
…he compiler itself resolves _tool_paths imported pytorchsim_triton_compiler.config.CHECKS, which the compiler has never had, so identity()["tools"] was always None: a rebuilt llc, opt, mlir-translate or riscv gcc at the same compiler commit never missed the cache, and the only trace was a warning. _tog_abi digested $TOGSIM_DIR/include/togsim_runtime.h as PyTorchSim resolves it, while the compiler compiles a TOG against togsim.hpp in the TOGSim it resolves and versions it with toolchain.togsim_api_version(). One probe in the compiler's own interpreter now returns toolchain.TOOLS, togsim_api_version() and TOGSIM_INCLUDE. The identity stats those tools and keys the TOG on the stated API version plus a digest of every header in that include directory; config.togsim_include_dir, whose only reader this was, is gone. A probe that cannot answer raises with what the compiler said, instead of leaving the cache guarded by the commit alone. The identity's shape changes, so cached kernels rebuild once. Pin: tests/system/test_cache_identity.py. On the parent: tools is None; tog_abi is a bare digest (b6eb37a7e3659bb7), not the compiler's API version; a compiler interpreter of /bin/false gives an identity anyway. All three pass here (#422).
torchsim_compile writes meta.json after the autotune retries shrink a kernel's fixed_config, but
nothing read it back: a later hit built its launcher from the caller's meta, whose fixed_config is
the untuned one, while kernel.py and the ELF in the workdir are the tuned ones. contract.grid_of then
derives the grid from the wrong block, so the launch runs the wrong number of programs.
On a hit, timing.load_tuned_blocks takes fixed_config from meta.json before the launcher is built.
select._time_tile compiles every candidate afresh and never retries, so its meta.json is the meta it
uses; it needs no change.
Pin: tests/system/test_tuned_blocks_on_hit.py, a hit on a workdir whose meta.json holds XBLOCK 256
for a caller holding 1024. On the parent the launcher keeps {'XBLOCK': 1024}; here it gets 256 and
grid_of gives 16 programs (#422).
This was referenced Oct 23, 2026
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.
Closes #422.
Why
The kernel cache had two holes, both silent:
_tool_pathsimportedpytorchsim_triton_compiler.config.CHECKS, which the compiler has never had, soidentity()["tools"]was always None.$TOGSIM_DIR/include/togsim_runtime.has PyTorchSim resolves it. The compiler compiles a TOG againsttogsim.hppin the TOGSim it resolves, and versions it withtoolchain.togsim_api_version().meta.jsonwas written after the autotune retries and never read, so a hit built its launcher from the caller's untunedfixed_configagainst the tuned ELF.contract.grid_ofthen derived the wrong grid.What changed
toolsis always None (with a warning);tog_abi= sha of PyTorchSim'stogsim_runtime.htoolchain.TOOLS,togsim_api_version()andTOGSIM_INCLUDE. The identity stats those tools.tog_abi={api, headers}: the compiler's stated API version plus a digest of every header in its TOGSim include dir. A probe that cannot answer raises with the compiler's message.config.togsim_include_dir(no other reader) is gone.fixed_configtiming.load_tuned_blockstakesfixed_configfrommeta.jsonbefore the launcher is built.select._time_tilecompiles every candidate afresh and never retries, so it needs no change.The identity's shape changes, so every cached kernel rebuilds once.
Tests
test_cache_identity::test_tools_are_the_compilersNonetest_cache_identity::test_tog_abi_is_the_compilers_togsimb6eb37a7e3659bb7test_cache_identity::test_a_compiler_that_cannot_answer_stops_the_run/bin/falseas the compilertest_tuned_blocks_on_hit{'XBLOCK': 1024}Verification
topk-ptb:pts-base-92028c8, an x86 PTS base on PTB 92028c8. The published 1b35878 images are arm64-only. The compiler is three commits behind the pin.toolchain.TOOLS,togsim_api_version()andTOGSIM_INCLUDEare the same at both.test_patch_scope,test_select,tests/ops/elementwise/test_add.py, andtest_addwithTORCHSIM_TIMING_MODE=1(TOGSim simulated, 1,974 cycles) pass.test_compiler_failurefails the same way on the parent and here:tile_spad_over_budget.py compiled. Its fixture no longer overflows, which predates this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5