G
YouTube TikTok Games
Skip to content

[CuTeDSL] Sign-extend signed to wider unsigned integer conversions - #3847

Open
Zhonglin1231 wants to merge 1 commit into
NVIDIA:mainfrom
Zhonglin1231:cutedsl-signed-to-unsigned-sext
Open

Zhonglin1231 wants to merge 1 commit into
NVIDIA:mainfrom
Zhonglin1231:cutedsl-signed-to-unsigned-sext

Conversation

@Zhonglin1231

Copy link
Copy Markdown

Fixes #3843.

int_to_int widened Signed -> Unsigned with arith.extui, so a runtime Int8(-1).to(Uint32) gave 255, while the constant path, numpy and C give 4294967295. This widens with arith.extsi, as the same-signedness branch right below already does, and keeps extui for 1-bit sources for the same reason that branch does.

        # Signed -> Unsigned: widen with sign extension, as a C cast does,
        # (uint32_t)(int8_t)-1 == 0xFFFFFFFF
        if dst_width > src_width:
            if src_width > 1:
                return arith.extsi(dst_mlir_type, a, loc=loc, ip=ip)
            return arith.extui(dst_mlir_type, a, loc=loc, ip=ip)

Narrowing and the other branches are unchanged.

Test

test/python/CuTeDSL/test_signed_to_unsigned.py converts [-1, -128, 0, 5, 127] in a kernel for all six signed to wider unsigned pairs and checks the bits against torch's signed widening. It needs a CUDA GPU and skips without one, like test_keep_ir.py.

On an A10G with nvidia-cutlass-dsl 4.8.1, all six pairs fail without the fix (Int8 -1 to Uint32 gives 255) and pass with it.

int_to_int widened Signed -> Unsigned with arith.extui, so a runtime
Int8(-1).to(Uint32) gave 255. The constant path, numpy and C all give
4294967295, and every signed to wider unsigned pair had the same
mismatch. Widen with arith.extsi, as the same-signedness branch already
does, and keep extui for 1-bit sources.

Co-authored-by: Ruilin Gao <229880965+ruiling-smartbear@users.noreply.github.com>
Signed-off-by: Zhong Lin <125393049+Zhonglin1231@users.noreply.github.com>

@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.

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.

[BUG] CuTe DSL: signed to wider unsigned conversion zero-extends at runtime

2 participants