[Test] Pin CUDA round ties-to-even on exact midpoints - #20274
Open
LngelKyo wants to merge 1 commit into
Open
Conversation
The CUDA rule lowers tirx.round to nearbyint/nearbyintf (float32/64) and hrint (float16/bfloat16), with a comment that this matches constant- folding semantics, but no test exercised exact midpoints on the CUDA path: test_vectorized_intrin1 feeds np.random values with atol=1e-3, which cannot distinguish ties-to-even from ties-away-from-zero. Add test_round_ties_to_even: the midpoint vector from apache#19368/apache#20131, compared against np.round with zero tolerance. It runs through the shared sched() helper, so both the nvcc and nvrtc compile paths are covered via the autouse fixture.
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.
test_vectorized_intrin1exercisestvm.tirx.roundon the CUDA path withnp.random.uniform(0, 1)inputs andatol=1e-3, which cannot distinguish ties-to-even from ties-away-from-zero: exact midpoints (0.5, 1.5, 2.5, ...) never occur in random data. The CUDA rule lowerstirx.roundtonearbyint/nearbyintf(src/backend/cuda/codegen/intrin_rule_cuda.cc:42-46, with the comment "Use nearbyint (ties-to-even) for round to match constant-folding semantics"), so the intended tie rule is already encoded — but nothing pinned it on this backend.Scope follows the review on #20252, verbatim:
A midpoint test in the CUDA codegen file is that instruction's second half.
What this test does
tir.roundto ties-to-even across all backends #19368 / [BugFix] Align default (C) tirx.round lowering to ties-to-even #20131 (0.5, 1.5, 2.5, 3.5, -0.5, -1.5, -2.5, -3.5), tiled ×16 to fill the 128 lanessched()assumes (1 block × 32 threads × float4).np.round(rtol=0, atol=0).assert_allclosetreats -0.0 and +0.0 as equal, so a separatenp.signbitassertion pins thatround(-0.5)must produce -0.0.hrintis not covered here, consistent withtest_vectorized_intrin1skipping round on fp16.Verification (my run): RTX A6000, driver 610.43.02, CUDA 13.0.88, LLVM 15.0.7, TVM at eaf710e on 5e49b34.
test_round_ties_to_even[nvcc]/[nvrtc]: both PASSED.round/roundfmakes both params FAIL, with 64 of 128 lanes off by one (0.5→1, 2.5→3, -0.5→-1, -2.5→-3). Restoring the rule turns both green again.uvx ruff@0.12.3 checkandformat --checkclean.cc @tlopex @yongwww @swjng — follows up on #20252 (CI will likely need approval as before).