[REFACTOR] Key loop hooks by LoopSite#435
Merged
Merged
Conversation
# Conflicts: # triton_viz/core/patch.py
Performance Benchmark
Iterations: 1 warmup + 20 measured |
Member
|
Closing as stale during PR cleanup. |
Remove the int fallback for loop hook identifiers: LoopIter now rejects bare line numbers, LoopContext.lineno is renamed to loop_site and typed as LoopSite, and the profiler drops its _loop_lineno compat helper. ClientManager hook signatures are annotated accordingly.
Strengthen the loop-site unit test to assert each site's cached iterator constraint binds its own variable (a lineno-only cache key would hand one site the other's constraint). Add a cross-file nested-loop OOB end-to-end test: device jit helpers currently run un-rewritten so the inner loop unrolls concretely, and the test guards that the OOB stays reported if device-function loops are ever wired into the symbolic loop hooks.
Jokeren
approved these changes
Jul 7, 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.
Summary
Refactor loop hook identity from a bare function-relative
linenoto aLoopSitethat combines the rewritten loop line number with a stable source-file token.Triton's interpreter parses each jit function with
defat line 1, so loops in different files can share a function-relative line number. With bare-lineno identity, two such loops collide in two places insideSymbolicClient:loop_i_{lineno}— both loops would share one symbolic variable;(lineno, start, stop, step)— distinct loop sites could hit each other's cached constraint.Scope note (verified experimentally): these collisions are an identity-correctness hazard, not a currently reproducible end-to-end mischeck. Device jit functions are executed un-rewritten (
_jit_function_callcalls the raw fn), so nested cross-file loops never reach the loop hooks today, and sequential launches that share a lineno also share the variable name and the cache key consistently, which yields correct constraints. The fix removes the latent collision and becomes load-bearing if device-function loops are ever wired into the loop hooks.Changes
LoopSiteandloop_file_tokenin the loop patching layer.LoopSitethrough loop hook dispatch from the Triton frontend and client manager.LoopSiteas the only loop identity:LoopIterraisesNotImplementedErroron bare line numbers, andClientManagerhook signatures are annotated withLoopSite.LoopContext.linenotoloop_siteand key symbolic loop context/constraint caches strictly byLoopSite.loop_site.lineno), dropping its int-compat helper.Known limitation
The profiler still aggregates
loop_infoby bareloop_site.lineno, so loops at the same relative line in different files still merge in profiler reports (pre-existing behavior, kept intentionally; possible follow-up).Validation
uv run pytest tests/unit/test_symbolic_client.pyuv run pytest tests/end_to_end/test_sanitizer.py::test_loop_deferred_checks_after_context tests/end_to_end/test_sanitizer.py::test_cross_file_same_relative_lineno_loops_detect_oob tests/unit/test_profiler.pyuv run pytest tests/unit/test_sanitizer.py -k loop(loop-affineLoopContextconstruction)uv run pytest tests/unit/test_utils.py -k sanitizer_trace(traceback tests constructingLoopContext)