[MLIR][GPU] Define gpu.printf op and its lowerings
authorKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Wed, 8 Dec 2021 23:28:06 +0000 (23:28 +0000)
committerKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Thu, 9 Dec 2021 15:54:31 +0000 (15:54 +0000)
commite1da62910e140cf45eafec64193c813e79796f05
tree34ed1d2138fd59af37327a72a7f9e3b47601ccc0
parentdef8b952ebc00b0ad0fa4196ae27b11a385087ad
[MLIR][GPU] Define gpu.printf op and its lowerings

- Define a gpu.printf op, which can be lowered to any GPU printf() support (which is present in CUDA, HIP, and OpenCL). This op only supports constant format strings and scalar arguments
- Define the lowering of gpu.pirntf to a call to printf() (which is what is required for AMD GPUs when using OpenCL) as well as to the hostcall interface present in the AMD Open Compute device library, which is the interface present when kernels are running under HIP.
- Add a "runtime" enum that allows specifying which of the possible runtimes a ROCDL kernel will be executed under or that the runtime is unknown. This enum controls how gpu.printf is lowered

This change does not enable lowering for Nvidia GPUs, but such a lowering should be possible in principle.

And:
[MLIR][AMDGPU] Always set amdgpu-implicitarg-num-bytes=56 on kernels

This is something that Clang always sets on both OpenCL and HIP kernels, and failing to include it causes mysterious crashes with printf() support.

In addition, revert the max-flat-work-group-size to (1, 256) to avoid triggering bugs in the AMDGPU backend.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D110448
14 files changed:
mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h
mlir/include/mlir/Conversion/GPUToROCDL/Runtimes.h [new file with mode: 0644]
mlir/include/mlir/Conversion/Passes.td
mlir/include/mlir/Dialect/GPU/GPUOps.td
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h
mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
mlir/lib/Conversion/PassDetail.h
mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
mlir/lib/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.cpp
mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl-hip.mlir [new file with mode: 0644]
mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl-opencl.mlir [new file with mode: 0644]
mlir/test/Dialect/GPU/ops.mlir
mlir/test/Integration/GPU/ROCM/printf.mlir [new file with mode: 0644]