Repository navigation
Conversation
Triton's signed `//` and `%` round toward zero (-63 // 64 == 0, -63 % 64 == -63), but the symbolic engine lowered them to Z3's integer division and remainder, which are Euclidean (-1 and 1). The interpreter computes the truncated value, so a branch on it and an address built from it disagreed: a sliding-window start `(pid * B - (B - 1)) // B * B` was 0 in Triton and -B in the model (false positive), and `(pid - 1) % N` was N - 1 in the model instead of -1 (missed out-of-bounds access). Lower signed `//` to a truncating quotient and `%` to the matching remainder; unsigned operations keep Z3's semantics, which agree for non-negative values. The NumPy fallback for `idiv` without a frontend concrete function also truncates now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016HMpCLXdUVNfMbJTj8aHE2
Performance Benchmark
Iterations: 1 warmup + 20 measured |
This branch has not been deployed
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
Triton's signed integer
//and%round toward zero, as in C:-63 // 64 == 0and-63 % 64 == -63. The interpreter computes these values, on the GPU and underTRITON_INTERPRET=1.BinarySymbolicExpr._op_idivand_op_mod, however, lowered them to Z3's integer/and%, which are Euclidean and give-1and1. Whenever the dividend can be negative, the model and the program disagree:lo = (pid * B - (B - 1)) // B * Bis 0 forpid == 0in Triton. The model gave-B, so the loadx + lo + tl.arange(0, B)was reported. A branch such asif lo < 0:does not help, because it is evaluated on the concrete, truncated value.(pid - 1) % Nis-1forpid == 0in Triton, sotl.load(x + (pid - 1) % N)readsx[-1]. The model gaveN - 1and reported nothing.This PR lowers signed
//to the truncating quotientIf(a >= 0, a / b, -((-a) / b)), and signed%toa - b * trunc(a / b). Unsigned operations keep Z3's semantics, which agree for non-negative values. The NumPy fallback inBinarySymbolicExpr.concretizefor anidivwithout a frontend concrete function usednp.floor_divide; it truncates now as well, so that both paths agree.Tests
tests/unit/test_symbolic_client.py:test_signed_idiv_and_mod_round_toward_zero: every sign combination. The cases with a negative dividend fail on main.test_signed_idiv_of_symbolic_dividend_rounds_toward_zero:(pid - 63) // 64is 0 forpid == 0. It fails on main.test_unsigned_idiv_and_mod_evaltest_idiv_concretize_without_frontend_fn_rounds_toward_zero: the NumPy fallback. It fails on main.tests/end_to_end/test_sanitizer.py:test_signed_division_rounds_toward_zero: the sliding window above, in bounds. Main reports it.test_signed_modulo_keeps_the_sign_of_the_dividend: thex[-1]load above. Main misses it.pytest tests/: 366 passed, 6 skipped on main; 378 passed, 6 skipped with this PR (Python 3.12, Triton 3.8.0).ruff checkandruff format --check(v0.1.9) pass on the changed files.mypy(v1.8.0) reports no new errors.buildjob installs Triton 3.9.0 and then Triton main. With those, about 96 tests of the existing suite fail whatever the change (the run on [FIX] Stop the sanitizer from skipping repeated launches #518 also has 96 failures), mostly with'SymbolicScalarDType' object has no attribute 'scalar'or'SymbolicExprDataWrapper' object has no attribute 'astype'. The new end-to-end tests fail there with the same errors as the existing sanitizer tests; the new unit tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_016HMpCLXdUVNfMbJTj8aHE2