FlyDSL icon indicating copy to clipboard operation
FlyDSL copied to clipboard

Preserve logical signedness for Pointer and Tensor integer dtypes

Open sjfeng1999 opened this issue 5 months ago • 0 comments

DSL currently uses signless MLIR integer types as the canonical storage representation for integer Numeric types. For example, both fx.Int32.ir_type and fx.Uint32.ir_type lower to signless i32.

This is fine for storage, but the logical signedness can be lost when reconstructing DSL values from IR types. In particular, fx.Uint32 / fx.Uint8 values may be reconstructed as fx.Int32 / fx.Int8 because the wrapper only sees the signless MLIR type.

import torch

import flydsl.compiler as flyc
import flydsl.expr as fx


@flyc.kernel
def pointer_dtype_kernel(p: fx.Pointer):
    print("kernel pointer element_type:", p.element_type)


@flyc.jit
def pointer_dtype_launch(p: fx.Pointer, stream: fx.Stream = fx.Stream(None)):
    print("jit pointer element_type:", p.element_type)
    pointer_dtype_kernel(p).launch(grid=(1, 1, 1), block=(1, 1, 1), stream=stream)


t = torch.zeros(1, device="cuda", dtype=torch.int32)
pointer_dtype_launch(flyc.from_c_void_p(fx.Uint32, t.data_ptr()), stream=torch.cuda.Stream())
torch.cuda.synchronize()

Actual output:

jit pointer element_type: Int32
kernel pointer element_type: Int32

Expected output:

jit pointer element_type: Uint32
kernel pointer element_type: Uint32

sjfeng1999 avatar Jun 17 '26 07:06 sjfeng1999