Skip to content

fix(cutile): use unordered compare for float != - #1546

Open
Rachit2323 wants to merge 1 commit into
NVIDIA:mainfrom
Rachit2323:fix/cutile-float-ne-unordered
Open

Rachit2323 wants to merge 1 commit into
NVIDIA:mainfrom
Rachit2323:fix/cutile-float-ne-unordered

Conversation

@Rachit2323

@Rachit2323 Rachit2323 commented Oct 18, 2026 •

Copy link
Copy Markdown

Summary

Float != is using an ordered compare, but it should be unordered.

Rust says a != b has to be the opposite of a == b. With floats, NaN is not equal to anything, not even itself. So NaN == NaN is false, which means NaN != NaN has to be true. Only the unordered compare gives that. With the ordered one, x != x always comes out false, so the normal way of checking for NaN stops working. Nothing warns you, you just get a wrong answer.

The SIMT side already handles this, see #123. cuTile never got the same fix.

Changes

compile_binary_op.rs was passing "ordered" for all six float comparisons. Now the ordering comes from the operator instead. Only != changes, the other five stay ordered.

Here is the IR for if a != b with two f32 values, before and after:

before:  %30 = cmpf not_equal ordered   %5, %6 : tile<f32> -> tile<i1>
after:   %30 = cmpf not_equal unordered %5, %6 : tile<f32> -> tile<i1>

I compiled ==, < and >= in the same kernel to check they did not move.
They are unchanged.

The two other cmp_ordering_attr calls in compile_cuda_tile_op.rs take the ordering from the user's own cmpf argument, so I left those alone.

Testing

Added two unit tests: != must be unordered, and the other five must stay ordered.

cargo test -p cutile-compiler --lib    140 passed, 7 failed
same command on main                   138 passed, 7 failed

The same 7 tests fail on main too. They need the tileiras binary and I do not have it installed, so they are not related to this change. cargo fmt --check and cargo clippy are both clean.

The before and after IR above came from KernelCompiler, which compiles to Tile IR text on the host. No GPU was needed.

  • SIMT Justfile check - not run, this change is in cutile-rs
  • Running an example - not run, I do not have a GPU
  • New example added - not needed

Checklist

  • All commits signed off
  • SPDX headers on new source files - no new files added

Signed-off-by: Rachit2323 <atreyrachit23@gmail.com>
@Rachit2323
Rachit2323 requested a review from elibol as a code owner October 18, 2026 16:22
@copy-pr-bot

copy-pr-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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