cutlass icon indicating copy to clipboard operation
cutlass copied to clipboard

[BUG] CuTe DSL: Uint8 pointers become Int8 inside kernels

Open ruiling-smartbear opened this issue 3 weeks ago • 0 comments

Which component has the problem? CuTe DSL

Describe the bug

A pointer to unsigned integer data loses its signedness inside a kernel. A cute.Pointer argument made with make_ptr(cutlass.Uint8, ...) arrives as Int8, and so do ptr + k, a loop-carried pointer and Tensor.iterator of a Uint8 tensor. make_tensor over any of them gives an Int8 tensor, and values above 127 read back negative.

Steps/Code to reproduce bug

import torch
import cutlass
import cutlass.cute as cute
from cutlass.cute.runtime import from_dlpack, make_ptr

@cute.kernel
def k(p: cute.Pointer, out: cute.Tensor):
    print("p.dtype:", p.dtype)
    t = cute.make_tensor(p, cute.make_layout(4))
    out.store(t.load().to(cutlass.Float32))

@cute.jit
def run(p: cute.Pointer, out: cute.Tensor):
    k(p, out).launch(grid=[1, 1, 1], block=[1, 1, 1])

x = torch.tensor([200, 128, 255, 1], dtype=torch.uint8, device="cuda")
out = torch.zeros(4, device="cuda")
run(make_ptr(cutlass.Uint8, x.data_ptr(), cute.AddressSpace.gmem, assumed_align=4), from_dlpack(out))
torch.cuda.synchronize()
print(out.tolist())
p.dtype: Int8
[-56.0, -128.0, -1.0, 1.0]

Expected behavior

p.dtype is Uint8 and the output is [200.0, 128.0, 255.0, 1.0].

Environment details

nvidia-cutlass-dsl 4.8.1 (latest on PyPI), torch 2.9.0, Python 3.13, Cloud (Modal), A10G (sm_86). The code involved is unchanged on main (b2f249a).

Additional context

MLIR integers are signless, and the pointer is rebuilt from its MLIR value with the dtype read back from the MLIR type: in runtime._Pointer.__new_from_mlir_values__, _Pointer.__add__, _Pointer.__new_from_mlir_values__ and _Tensor._derive_iterator. Slicing and local_tile keep Uint8, since they pass the tensor's dtype along. Fixed in #3853.

ruiling-smartbear avatar Nov 08 '26 20:11 ruiling-smartbear