[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
mark14wu
added a commit
that referenced
this pull request
Jul 10, 2026
Resolves the PR #361 merge conflict (CI could not run on the merge ref). Main brings the merged #435 LoopSite refactor and the Gluon Blackwell test coverage (#456-#459). Resolutions: - race_detector.py _process_pending_check: keep the branch's _unsupported_capture early-return guard on top of main's version. - core/frontend/base.py: take main's simplified _LangPatchScope wholesale (3-tuple changes, no set_item/mark_removed) — the branch's 4-tuple machinery has no remaining callers on either side, and the auto-merge hybrid would have crashed restore(). - Adapt the race detector's loop hooks to #435's LoopSite keying: hook params and loop_stack matching use LoopSite (a hashable NamedTuple) instead of bare linenos; _finished_loop_iter_subs keys become LoopSites (two loops at the same function-relative line in different files no longer share bookkeeping). - simulation/gluon.py: broaden the optional gfx1250 import guard — a triton at the declared floor (>= 3.6.0) lacks the newer submodules (cluster/tdm/...) and the narrow is_hip_gfx1250-only guard killed every consumer at collection time on such installs. Full suite: 717 passed; the only delta vs the pre-merge baseline is inside the environment-dependent gluon family (4 old failures fixed by main, 3 new tests hit the local triton-3.6.0 x numpy-2 interpreter boundary that CI's environment does not).
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)