Skip to content

[CuTeDSL] Preserve Float32 results for integer Vector division - #3923

Open
taking-lying-flat wants to merge 4 commits into
NVIDIA:mainfrom
taking-lying-flat:fix/vector-true-division-dtype
Open

taking-lying-flat wants to merge 4 commits into
NVIDIA:mainfrom
taking-lying-flat:fix/vector-true-division-dtype

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Nov 22, 2026 •

Copy link
Copy Markdown

Related to #3871; complements #3872, which fixes the TensorSSA path.

Integer Vector true division produces floating-point values, but wrapping them with the input integer dtype truncates element extraction: [1, 3, 5, 7] / 2 yields [0, 1, 2, 3] instead of [0.5, 1.5, 2.5, 3.5].

In __truediv__ and __rtruediv__, promote integer/Boolean vectors and Vector operands to Float32 before scalar coercion or broadcasting, and preserve that result dtype. This also prevents Python float operands from raising std::bad_cast and runtime Float32 scalars such as 2.5 from being narrowed to integers. Floating-point vectors retain their dtype.

Extend the existing test/python/CuTeDSL/test_vector_reduction_fastmath.py with one parameterized division regression test. It covers Int32/Int8/Uint8/Int64/Boolean plus Float16/Float64 controls, forward/reverse division, and Python int/float, runtime Float32 scalar and Vector operands. Each of the 56 combinations checks runtime-input IR, result/extracted-element types and constant-folded values using the same module. No new test file or CUDA GPU is required.

Validation with this checkout and nvidia-cutlass-dsl==4.9.0.dev1 MLIR components:

  • python -m pytest -q test/python/CuTeDSL/test_vector_reduction_fastmath.py -k TestVectorTrueDiv: 1 test and 56 subtests passed.
  • Removing the division fixes reproduces failures in all 40 integer/Boolean combinations; the 16 floating-point controls still pass.
  • Black check for the test file, Python syntax checks and git diff --check pass.

The pre-existing reduction test has an unrelated exact-string mismatch with these MLIR components (fastmath<reassoc,nsz> versus fastmath<reassoc>), reproduced before and after the division changes. Its assertion is unchanged.

@fengxie fengxie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing. Can you add regression test egression test under test/python/CuTeDSL?

It can cover Int32/Int8/Uint8/Int64/Boolean Vector true division (forward & reverse, Python int/float, runtime Float32 scalar, and Vector operands) plus Float16/Float64 controls, matching test_tensor_ssa_truediv.py in #3872

@fengxie fengxie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. LGTM. Approved with a small nit.

if not self._dtype.is_float:
rhs = self.to(Float32, loc=loc, ip=ip)
if isinstance(other, Vector):
other = other.to(Float32, loc=loc, ip=ip)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may convert Float64 to Float32 losing precision. How about using this?

if isinstance(other, Vector) and not other._dtype.is_float:
    ...

This branch has not been deployed

No deployments
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.

2 participants