cutlass icon indicating copy to clipboard operation
cutlass copied to clipboard

[BUG] CuTe DSL: TensorSSA.reduce() with MAX or MIN fails for integer tensors

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

Which component has the problem? CuTe DSL

Describe the bug

TensorSSA.reduce() with ReductionOp.MAX or ReductionOp.MIN fails to compile for integer tensors. ADD and MUL work.

Steps/Code to reproduce bug

import torch
import cutlass.cute as cute
from cutlass import Int32
from cutlass.cute.runtime import from_dlpack

@cute.kernel
def k(a: cute.Tensor, out: cute.Tensor):
    out[0] = a.load().reduce(cute.ReductionOp.MAX, Int32(-(2**31)), 0)

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

a = torch.tensor([3, -7, 9, 2], dtype=torch.int32, device="cuda")
out = torch.zeros(1, dtype=torch.int32, device="cuda")
run(from_dlpack(a), from_dlpack(out))
error[INTERNAL]: The compiler could not build valid IR for this code.
  error: IR verification failed: error: unknown: 'vector.reduction' op unsupported reduction type
         ''i32'' for kind 'maximumf'

Expected behavior

out is [9].

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

reduce() in cute/tensor.py maps MAX and MIN to maximumf and minimumf for every element type. Integers need maxsi/minsi, or maxui/minui for unsigned types. I have a fix with a test and will open a PR.

ruiling-smartbear avatar Nov 09 '26 04:11 ruiling-smartbear