Skip to content

[Test] Pin CUDA round ties-to-even on exact midpoints - #20274

Open
LngelKyo wants to merge 1 commit into
apache:mainfrom
LngelKyo:test/cuda-round-ties-to-even
Open

[Test] Pin CUDA round ties-to-even on exact midpoints#20274
LngelKyo wants to merge 1 commit into
apache:mainfrom
LngelKyo:test/cuda-round-ties-to-even

Conversation

@LngelKyo

@LngelKyo LngelKyo commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

test_vectorized_intrin1 exercises tvm.tirx.round on the CUDA path with np.random.uniform(0, 1) inputs and atol=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 lowers tirx.round to nearbyint / 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:

Please limit this test to the regression-relevant host targets (llvm and c) instead of enumerating every backend. Most of these device targets are skipped in CI, so this list adds maintenance cost without guaranteeing coverage. Backend-specific lowering should be tested in the corresponding codegen tests when needed.

A midpoint test in the CUDA codegen file is that instruction's second half.

What this test does

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.
  • Negative control: reverting the CUDA rule to round/roundf makes 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 check and format --check clean.

cc @tlopex @yongwww @swjng — follows up on #20252 (CI will likely need approval as before).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant