Skip to content

[CuTeDSL] Preserve unsigned dtypes in Vector helpers - #3961

Open
taking-lying-flat wants to merge 2 commits into
NVIDIA:mainfrom
taking-lying-flat:fix/vector-helper-dtypes
Open

taking-lying-flat wants to merge 2 commits into
NVIDIA:mainfrom
taking-lying-flat:fix/vector-helper-dtypes

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Dec 2, 2026 •

Copy link
Copy Markdown

Unsigned Vector helpers can silently change the meaning of their results. For example, selecting Uint8 [128, 255] with an all-true mask returns an Int8 Vector; (selected.to(Float32) - 128) * 0.5 then gives [-128, -64.5] instead of [0, 63.5].

Preserve the known DSL element dtype when wrapping results of where, full, broadcast_to, and outerproduct. Capture Numeric scalar dtypes before converting them to MLIR values, including when full has no explicit dtype. This also fixes the full_like, zeros_like, ones_like, and empty_like delegates. Python-literal and untyped MLIR-value inference retain their existing behavior.

Extend the existing Vector test file with two focused Uint8 regressions: eight runtime-input cases covering the four helpers' scalar/Vector branches, plus the numerical dequantization example. The runtime test also checks element extraction, unsigned float conversion, and unsigned min/max IR.

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

  • python -m pytest -q test/python/CuTeDSL/test_vector_reduction_fastmath.py -k TestVectorDtypePreservation: 2 tests and 8 subtests passed. Both regressions and all eight helper cases fail with the main 3e81d0d4 implementations.
  • Supplementary checks outside the repository: 28/28 constant-value checks passed, versus 14/28 on main, covering Uint8/Uint16 and Int8/Float32 controls. CPU JIT execution with runtime Uint8 inputs [128, 255, 1, 64] and mask [True, True, False, True] gives where min/max 0/255, versus -128/64 on main. Runtime full and scalar broadcast_to checks also preserve 128 instead of interpreting it as -128.
  • Black check for the test file, syntax checks for both changed files, and git diff --check pass. No CUDA kernels were run.

The existing fastmath test expects fastmath<reassoc> but these MLIR components emit fastmath<reassoc,nsz>; the same failure reproduces with the unmodified upstream test. Its assertion is unchanged.

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.

1 participant