NVIDIA / NVIDIA/cutlass

CuTeDSL: width-only f-string format spec emits a malformed device printf format (%8) and silently drops the value

Open
#3,500 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CuTe DSL
Dominant language
C++
Stars
10.5k
Forks
2.1k
Avg merge
3d 11h
Merged PRs (30d)
7

Description

Description

FormattedValue.to_str in cutlass/base_dsl/ast_helpers.py (~lines 731-737) converts a non-empty single-token format_spec into a printf conversion by emitting "%{format_spec[0]}". That is only valid when the spec actually ends in a conversion character. A width-only spec such as {x:8} is legal Python but produces the literal format %8, which consumes no argument and prints garbage.

Unit-level repro (against nvidia-cutlass-dsl==4.7.0):

from cutlass.base_dsl.ast_helpers import FormattedValue
import cutlass

fv = FormattedValue(value=cutlass.Int32(7), conversion=-1, format_spec=["8"])
print(fv.to_str()[0])    # prints: %8
fv = FormattedValue(value=cutlass.Int32(7), conversion=-1, format_spec=[".2f"])
print(fv.to_str()[0])    # prints: %.2f  (fine)

End-to-end, cute.printf(f"[{x:8}]") with a dynamic x makes the device print [ 8]-style text where the value never appears: the kernel receives format string [%8] plus an unconsumed vararg. No diagnostic is raised.

Suggested fix

Validate that the spec terminates in a known conversion character. Either raise DiagId.UNSUP_FSTRING_FORMAT for specs without one, or map a bare numeric spec to a sensible default conversion per the value's dtype (e.g. append d for integer types, f/g for float types) so {x:8} keeps its Python meaning.

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 in cutlass/base_dsl/ast_helpers.py at FormattedValue.to_str around lines 731-737, then reproduce the width-only and %.2f cases from the issue. Trace how format_spec becomes the device printf format and verify that a bare numeric spec no longer emits an argument-free format; completion should also cover the diagnostic or dtype-based behavior chosen for unsupported specs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.