[Mlir-commits] [mlir] [mlir][gpu][nvptx] Remove null terminator when outputting PTX (PR #133019)

Fabian Mora llvmlistbot at llvm.org
Tue Mar 25 17:01:10 PDT 2025


fabianmcg wrote:

> Looking around I couldn't find if there was a convention to what should be outputted by `moduleToObject`. I did see that the ROCDL target omits the null terminator (https://github.com/llvm/llvm-project/blob/main/mlir/lib/Target/LLVM/ROCDL/Target.cpp#L440).

They don't have it because there's no JIT path for ROCm.

> @fabianmcg do you remember if there was a specific reason the null terminator got added in [5093413](https://github.com/llvm/llvm-project/commit/5093413a5007b017a530edbeed42d32bfd18b126) and only for NVPTX?

Yes, that was added for the ptx-JIT execution path, see the driver function https://github.com/llvm/llvm-project/blob/main/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp#L143-L144
 Aaccording to the [CUDA driver docs](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MODULE.html#group__CUDA__MODULE_1g9e8047e9dbf725f0cd7cafd18bfd4d12) it requires a null-terminated function.
> The image may be a cubin or fatbin as output by nvcc, or a NULL-terminated PTX, either as output by nvcc or hand-written. 

Also, FWIW `\0` is ASCII https://en.wikipedia.org/wiki/ASCII

https://github.com/llvm/llvm-project/pull/133019


More information about the Mlir-commits mailing list