Skip to content

HipPrintf: Inline literal %s strings into format string#1123

Merged
pvelesko merged 5 commits intomainfrom
fix-1122-printf
Mar 10, 2026
Merged

HipPrintf: Inline literal %s strings into format string#1123
pvelesko merged 5 commits intomainfrom
fix-1122-printf

Conversation

@pvelesko
Copy link
Copy Markdown
Collaborator

IGC fails when SPIR-V printf has UniformConstant pointer as %s arg.
For literal strings, inline content directly into the format string.
Dynamic strings still use _cl_print_str char-by-char fallback.

Fixes #1122

Fix the format specifier parser to detect all %[flags][width][.precision]s
patterns (e.g. %-8s, %8.5s, %*s), not just bare %s. This fixes crashes on
PoCL/macOS where modified %s args remained in the wrong address space.

Three strategies for string specifiers:
1. Bare %s with literal: inline content into format string
2. Modified %s with literal: clone string to constant address space
3. Dynamic strings: use _cl_print_str fallback

Also:
- Add null check to _cl_print_str to match AMD/nvidia behavior
- Add TestPrintfStaticString compiler test
- Exclude printf tests when CHIP_MALI_GPU_WORKAROUNDS is ON (Mali-G52
  has non-functional OpenCL printf)
- Remove now-passing printf tests from known_failures.yaml
- Update HIP submodule with printf test fixes (flexible comparison,
  SPIR-V platform support, Catch2 compatibility)

Fixes: #1122
Mali GPUs require the cl_arm_printf vendor extension to receive kernel
printf output. Register a callback via CL_PRINTF_CALLBACK_ARM context
property when the extension is detected, forwarding output to stdout.

Tested on Mali-G52: all 4 printf tests pass (Unit_printf_flags,
Unit_printf_specifier, hipcc-TestPrintfLonePercent, cuda-simplePrintf).
The inlining of bare %s literals is not an IGC-specific workaround —
it avoids the general OpenCL address space mismatch where HIP string
literals are in UniformConstant (AS 0) but OpenCL printf expects
Constant (AS 2). The IGC bug was fixed in driver 26.05.37020.3.
@pvelesko pvelesko merged commit 2475950 into main Mar 10, 2026
24 checks passed
@pvelesko pvelesko deleted the fix-1122-printf branch March 10, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using printf with the %s specifier, like in __assert_fail, causes chipStar to split the call into several

1 participant