Repository navigation
Conversation
Metal kernels compile with flush-to-zero, so a float32 `greater` reads a positive subnormal as `0.0`. Every symmetric codebook from 3 bits up has a `0.0` boundary, so `f32::from_bits(1)` — one bucket above that boundary on the host — was landing on the boundary on device. The nightly-verify run 46937282079 failed on exactly two values of exactly that shape: device: [... 3, 3, ...] host: [... 4, 3, ...] `boundary_indices_on_device` now compares an unsigned monotonic key whose integer order is the IEEE-754 compare order, so no float compare is involved: fold -0.0 onto +0.0, map NaN to 0 (it is above nothing), then flip the sign bit for non-negative values and every bit for negative ones. Integer compares do not flush. Verified on the night's commit 4d8a05c (Metal, macOS 27.2): - `cache::turbo::` 125 passed, 0 failed (was 2 failed). - `cargo test -p mlxcel-core --lib -- --test-threads=1`: 2687 passed, 7 ignored, 0 failed. - New regression test `device_boundary_indices_keep_subnormals_above_a_zero_boundary` pins the rule at bits 3/4 and head dims 64/128/256; mutation-checked by restoring the float compare, which fails it with `left: [3, 3, 4]` / `right: [4, 4, 4]`. - `cargo fmt --check` and `cargo clippy -p mlxcel-core --lib --tests -- -D warnings` clean. Refs lablup#3652
This branch has not been deployed
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.
Closes #3652.
Problem
The nightly-verify run for
4d8a05c4failedmlxcel-core --libon twodevice-vs-host index tests:
The night's diff named the input class — device
3against host4at twopositions.
Cause
Metal kernels compile with flush-to-zero, so a float32
greaterreads apositive subnormal as
0.0. Every symmetric Turbo codebook from 3 bits uphas a
0.0boundary, sof32::from_bits(1)— one bucket above thatboundary on the host — was landing on the boundary on device.
Probes against
boundary_indices_on_deviceseparate the layers: the uploadround-trip and the sum both keep bits
1,greater(denormal, -1.0)iscorrect, and only
greater(denormal, 0.0)and evendenormal * 2.0flush.Change
boundary_indices_on_devicecompares an unsigned monotonic key instead,whose integer order equals the IEEE compare order, so no float compare takes
part. Two host rules the raw bits do not carry are explicit:
-0.0folds onto+0.0(the host treats them as equal)-inf.The rest is the standard transform: flip the sign bit for non-negative
values, every bit for negative ones.
Verification
On
4d8a05c4, Metal, macOS 27.2, then re-run on the merge base this PRtargets:
cache::turbo::— 125 passed, 0 failed (was 2 failed).cargo test -p mlxcel-core --lib -- --test-threads=1— 2722 passed,7 ignored, 0 failed.
device_boundary_indices_keep_subnormals_above_a_zero_boundarypins therule at bits 3/4 and head dims 64/128/256, negative side included.
Mutation-checked: restoring the float compare fails it with
left: [3, 3, 4]/right: [4, 4, 4].combinations and 41/73 values each — 0 mismatches — before the function
changed.
cargo fmt --checkandcargo clippy -p mlxcel-core --lib --tests -- -D warningsclean.One file,
codebook.rsonly.