[MetaXGPU] Use ties-to-even rounding for tirx.round on the MACA target#43
Open
Lfan-ke wants to merge 1 commit into
Open
[MetaXGPU] Use ties-to-even rounding for tirx.round on the MACA target#43Lfan-ke wants to merge 1 commit into
Lfan-ke wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the MACA math codegen rules in intrin_rule_maca.cc to map the 'round' function to 'nearbyint' (for 64-bit floats) and 'nearbyintf' (for 32-bit floats) to use ties-to-even rounding, matching constant-folding semantics. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Author
|
@codex review please. read code at pr and repositories. |
Signed-off-by: 林晨 (Leo Cheng) <chengkelfan@qq.com>
Lfan-ke
force-pushed
the
fix/maca-round-ties-to-even
branch
from
July 14, 2026 07:41
bce586a to
6284d5b
Compare
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.
Problem
MACAMathlowerstirx.roundtoround/roundf, which round halfway cases away from zero. Every other backend in the tree lowers it to nearbyint, which under the default rounding mode rounds halfway cases to even:src/backend/cuda/codegen/intrin_rule_cuda.cc:41-45returnsnearbyintfor fp64 andnearbyintffor fp32src/target/llvm/intrin_rule_llvm.cc:91-93dispatchestirx.roundtollvm::Intrinsic::nearbyintSo the same graph rounds
0.5to1.0on a MACA device and to0.0everywhere else, and a value that gets constant-folded at compile time disagrees with the same value computed on device. Only exact halfway inputs diverge, so this stays invisible under random test data.fp16 is already correct: it maps to
hrint, which is ties-to-even.Changes
MACAMathreturnsnearbyintfor fp64 andnearbyintffor fp32, matching the CUDA rule it was forked from.tirx.nearbyintis unaffected — it already lowered to the same function.Test Plan
tests/python/codegen/test_target_codegen_maca_round.pyon a MetaX C500 (MACA 3.5.3.20). Both cases feed the eight halfway values±0.5, ±1.5, ±2.5, ±3.5, which are the only inputs the two rules disagree on:nearbyintfand does not callroundf0, 2, 2, 4, -0, -2, -2, -4Test Result
Reverting the two lines in
intrin_rule_maca.ccand rebuilding turns both cases red, so the test does exercise the changed lowering: