[Mlir-commits] [mlir] [mlir][gpu][nvptx] Remove null terminator when outputting PTX (PR #133019)
Mehdi Amini
llvmlistbot at llvm.org
Wed Apr 2 04:18:34 PDT 2025
joker-eph wrote:
I dug a bit more to see how things are fitting.
The `moduleToObject` interface is returning a "bag of bytes" (as materialized by the use of `SmallVector<char, 0>` and not any `*String*` class), as such there shouldn't be an expectation of null termination in the output of `moduleToObject`.
When the output is embedded in the IR, we will always add a null terminator since we store it as a `StringAttr`, but with the correct size (that is not including the null terminator): https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Support/StorageUniquer.h#L112-L114
However we currently have also a null terminator within the string:
```
gpu.binary @kernel_module1 [#gpu.object<#nvvm.target<chip = "sm_70">, properties = {O = 2 : i32}, assembly = "//\0A// Generated by NVIDIA NVVM Compiler\0A//\0A// Compiler Build ID: UNKNOWN\0A// UNKNOWN\0A// Based on LLVM 20.0.0git\0A//\0A\0A.version 6.0\0A.target sm_70\0A.address_size 64\0A\0A\09// .globl\09kernel\0A\0A.visible .func kernel()\0A{\0A\0A\0A\09ret;\0A\0A}\0A\00">]
```
See the `\00` at the end of the string.
So this change LGTM.
https://github.com/llvm/llvm-project/pull/133019
More information about the Mlir-commits
mailing list