fix print_layout printf format in device code (#2688)

* fix print_layout printf format in device code

* Replace %.*s format specifier with explicit loop
* Remove unused delim variable

The printf format %.*s with dynamic width does not work correctly
in CUDA device code, causing literal %.*s to appear in output.

Fixes #2496

* Update include/cute/util/print_tensor.hpp

Co-authored-by: Cris Cecka <ccecka@users.noreply.github.com>

* Update include/cute/util/print_tensor.hpp

Co-authored-by: Cris Cecka <ccecka@users.noreply.github.com>

---------

Co-authored-by: Cris Cecka <ccecka@users.noreply.github.com>
This commit is contained in:
Amin Sedaghat
2025-12-09 19:57:56 -05:00
committed by GitHub
parent c6dfdf8375
commit 49bd6bf1ba

View File

@@ -50,7 +50,6 @@ print_layout(Layout const& layout) // (m,n) -> idx
CUTE_STATIC_ASSERT_V(rank(layout) == Int<2>{});
int idx_width = num_digits(cosize(layout)) + 2;
const char* delim = "+-----------------------";
print(layout); print("\n");
@@ -63,7 +62,12 @@ print_layout(Layout const& layout) // (m,n) -> idx
for (int m = 0; m < size<0>(layout); ++m) {
// Header
print(" ");
for (int n = 0; n < size<1>(layout); ++n) { printf("%.*s", idx_width+1, delim); }
for (int n = 0; n < size<1>(layout); ++n) {
printf("+");
for (int i = 0; i < idx_width; ++i) {
printf("-");
}
}
printf("+\n");
// Values
printf("%2d ", m); // Row indices
@@ -72,7 +76,12 @@ print_layout(Layout const& layout) // (m,n) -> idx
}
// Footer
print(" ");
for (int n = 0; n < size<1>(layout); ++n) { printf("%.*s", idx_width+1, delim); }
for (int n = 0; n < size<1>(layout); ++n) {
printf("+");
for (int i = 0; i < idx_width; ++i) {
printf("-");
}
}
printf("+\n");
}