Repository navigation
[CuTeDSL] Keep -0.0 and 0.0 constants apart in the IR constant cache - #3849
Open
Zhonglin1231 wants to merge 1 commit into
Open
Zhonglin1231 wants to merge 1 commit into
Zhonglin1231 wants to merge 1 commit into
Conversation
const() goes through an lru_cache keyed on the Python value. 0.0 and -0.0 compare equal and hash alike, so whichever zero a kernel materialized first came back for the other one too: storing Float32(0.0) and then Float32(-0.0) wrote +0.0 twice. Build -0.0 uncached so it can neither hit nor seed the +0.0 entry. Co-authored-by: Ruilin Gao <229880965+ruiling-smartbear@users.noreply.github.com> Signed-off-by: Zhong Lin <125393049+Zhonglin1231@users.noreply.github.com>
fengxie
approved these changes
Nov 6, 2026
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.
Fixes #3845.
const()goes through_const_cached, anlru_cachekeyed on the Python value.0.0and-0.0compare equal and hash alike, so whichever zero a kernel materialized first came back for the other one too. This builds-0.0through the uncached function (__wrapped__, set byfunctools.wrapsinlru_cache_ir), so it can neither hit nor seed the+0.0entry. Every other value is cached as before.mathin this module is the MLIR dialect, so the stdlibcopysignis imported as_copysign.Test
test/python/CuTeDSL/test_negative_zero_constant.pystoresFloat32(0.0)andFloat32(-0.0)in one kernel, in both orders, and checks the sign bits. It needs a CUDA GPU and skips without one.On an A10G with nvidia-cutlass-dsl 4.8.1, both orders fail without the fix (sign bits
[False, False]and[True, True]) and pass with it.