Conversation
`round` and its `rbits` operand have a PTX lowering only for an f32 source, in
the four codegen groups that consult `cast_round` themselves. Every other source
dtype reaches a vectorized branch that emits the plain conversion helper and
returns, so it never reaches the rejection at the end of the cast lowering. The
requested rounding mode was dropped silently:
for i in T.vectorized(8):
B[i] = T.cast(A[i], "float8_e4m3fn", round="rs", rbits=T.uint32(seed))
emitted `__tl_cvt_half2_to_fp8x2`, the round-to-nearest helper, with no `rbits`
operand anywhere; the output was bit-identical across seeds and identical to a
cast with no rounding argument at all. The same cast written in a `T.serial`
loop was rejected with "round 'rs' is not supported for cast from float16 to
float8_e4m3fn", so one request had two outcomes decided only by the loop form.
Refuse it for a non-f32 source before the vectorized branches, with the message
the scalar path already produces. An f32 source is untouched and still takes the
stochastic path.
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: tile-ai/tilelang/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe CUDA cast code generator now rejects annotated rounding modes when the source type is not FP32. New tests cover rejection of stochastic rounding and lowering of vectorized FP16-to-FP8 casts without a rounding mode. ChangesCast rounding validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Unsupported rounded non-f32 casts now fail instead of silently ignoring the rounding request, while unrounded vectorized casts remain supported. No concrete merge-blocking risk is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Refs #3301 (F318).
Why
roundand itsrbitsoperand have a PTX lowering only for an f32 source, in the four codegen groups that consultcast_roundthemselves. Every other source dtype reaches a vectorized branch that emits the plain conversion helper and returns, before the rejection at the end of the cast lowering is reached. The requested rounding mode was dropped silently:with
Ainfloat16emitted__tl_cvt_half2_to_fp8x2, the round-to-nearest helper, and norbitsoperand anywhere in the generated CUDA. The output was bit-identical acrossseedvalues0x0,0xFFFFFFFFand0x12345678, and identical to the same cast with no rounding argument at all. The scalar form of the same cast was rejected:So one request had two outcomes, decided only by whether the loop was vectorized.
What changed
A non-f32 source with a non-empty
roundis rejected before the vectorized branches, with the message the scalar path already produces. An f32 source is untouched and still takes the stochastic path through the groups that handle it.Verification
Two cases added to
testing/python/language/test_tilelang_cast_rounding.py, the test module for this feature: the rejection of a vectorizedrscast fromfloat16, and a control that the same vectorized cast with no rounding mode still lowers and still emits__tl_cvt_half2_to_fp8x2. The rejection fails on an unmodified tree withDID NOT RAISE Exception; the control passes in both states.test_tilelang_cast_rounding.py,test_tilelang_language_fp8.py,testing/python/quantize/andtest_tilelang_language_vectorized_cast.py: 134 passed, 1 skipped, 19 failed. Those 19 fail identically on an unmodified tree and are an environment limit, not a regression:This machine is
sm_120, so the tests that needsm_100acannot build there. The count is 19 with and without the change.The kernel cache was cleared before each run.
pre-commit run --files <changed files>: all 13 hooks pass.Summary
Reject vectorized casts that request rounding when the source dtype is not
float32. The check uses the existing scalar-path error message.float32conversion paths remain unchanged.Add tests that check rejection of vectorized
float16casts withround="rs"and verify that casts without a rounding mode still lower to the half-to-FP8 conversion helper.Tests
The author reports 134 passed, 1 skipped, and 19 failed across the listed test suites. The author attributes the failures to the test machine's
sm_120architecture, which cannot build tests requiringsm_100aorsm_103a; the author reports the same failures on an unmodified tree. The author also reports that all 13 pre-commit hooks passed. These results were not independently verified.C++ style / lint notes
The change touches C++ source covered by
docs/developer_guide/cpp_style.md, but it does not change the documented style rules. The CI configuration includes the “C++ API Style Audit (warning only)” step. No audit result or current style findings were supplied.Verified end to end, together with the other contributions from this batch: VERIFICATION.md