NVIDIA / NVIDIA/cutlass

[FEA] CuteDSL have all ops gracefully handle floats or other arithmetic types

Open
#2,588 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

? - Needs Triage CuTe DSL feature request inactive-30d inactive-90d
Dominant language
C++
Stars
10.5k
Forks
2.1k
Avg merge
3d 11h
Merged PRs (30d)
7

Description

Which component requires the feature?

CuTe DSL

Feature Request

Summary

import cutlass.cute as cute
import cutlass
import operator

@cute.jit
def convert_arith_to_ssa(fail: cutlass.Constexpr = True):
    a = cute.full((4), 1.0, dtype=cutlass.Int32)
    b = 5.0
    # Patch
    # b = cute.full_like(a, b)
    print(f"Types: {type(a)} {type(b)}")
    cond = operator.le(a, b)
    print(f"Type result: {type(cond)}")
    d = cute.where(cond, a, b)
    print(f"Type result: {type(d)}")

convert_arith_to_ssa()

If you keep the b as a float the above program prints:

❯ python cutey/learn.py
Types: <class 'cutlass.cute.core.TensorSSA'> <class 'float'>
Type result: <class 'cutlass.cute.core.TensorSSA'>
Traceback (most recent call last):
  File "/home/drisspg/.conda/envs/dev/lib/python3.12/site-packages/nvidia_cutlass_dsl/python_packages/cutlass/base_dsl/dsl.py", line 1117, in build_ir_module
    result = funcBody(*ir_args, **ir_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drisspg/.conda/envs/dev/lib/python3.12/site-packages/nvidia_cutlass_dsl/python_packages/cutlass/base_dsl/dsl.py", line 260, in __call__
    ret = self.__func__(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drisspg/meta/my_scripts/cutey/learn.py", line 480, in convert_arith_to_ssa
    d = cute.where(cond, a, b)
        ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drisspg/.conda/envs/dev/lib/python3.12/site-packages/nvidia_cutlass_dsl/python_packages/cutlass/cute/core.py", line 6496, in where
    if x.dtype != y.dtype:
                  ^^^^^^^
AttributeError: 'float' object has no attribute 'dtype'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/drisspg/meta/my_scripts/cutey/learn.py", line 502, in <module>
    convert_arith_to_ssa(fail=False)
  File "/home/drisspg/.conda/envs/dev/lib/python3.12/site-packages/nvidia_cutlass_dsl/python_packages/cutlass/base_dsl/dsl.py", line 1132, in build_ir_module
    raise DSLRuntimeError(
cutlass.base_dsl.common.DSLRuntimeError: DSLRuntimeError: 💥💥💥 Error during runtime code generation for function `convert_arith_to_ssa` 💥💥💥

If you convert b to tensorSSA you get then all good. It would be pretty sweet if for all binary ops between TensorSSA + arithmetic types could handle this automatically by promoting the scalar to a TensorSSA with matching shape and dtype

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cute.where and the TensorSSA arithmetic and comparison paths shown in the example, including operator.le; inspect how scalar operands are handled before dtype and shape checks. Extend promotion across binary operations so arithmetic values work with matching TensorSSA shape and dtype, then verify the example succeeds and add focused regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.