MLIR 24.0.0git
GPUToROCDLPipeline.cpp
Go to the documentation of this file.
1//===- GPUToROCDLPipeline.cpp - Lowering pipeline to ROCDL/AMDGPU --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements a sink pipeline that lowers a payload containing
10// `gpu.launch` / `gpu.module` ops to AMDGPU/ROCDL and emits an AMDGCN binary
11// blob via `gpu-module-to-binary`. It is the AMD counterpart of
12// `gpu-lower-to-nvvm-pipeline` and `gpu-lower-to-xevm-pipeline`.
13//
14//===----------------------------------------------------------------------===//
15
37
38using namespace mlir;
39
40namespace {
41
42//===----------------------------------------------------------------------===//
43// Common pipeline
44//===----------------------------------------------------------------------===//
45void buildCommonPassPipeline(
47 std::string arch = ROCDL::resolveArchOption(options.arch, options.chip).str();
48 // Lower AMDGPU dialect ops (e.g. amdgpu.lds_barrier, amdgpu.dpp,
49 // amdgpu.mfma, amdgpu.dot, ...) to ROCDL intrinsics first, while they may
50 // still live in unout-lined `gpu.launch` bodies. Mirrors the way NVVM's
51 // pipeline runs `convert-nvgpu-to-nvvm` before kernel outlining.
52 ConvertAMDGPUToROCDLPassOptions amdgpuToROCDLOpt;
53 amdgpuToROCDLOpt.arch = arch;
54 pm.addPass(createConvertAMDGPUToROCDLPass(amdgpuToROCDLOpt));
55
61
62 GpuROCDLAttachTargetOptions rocdlTargetOptions;
63 rocdlTargetOptions.arch = arch;
64 rocdlTargetOptions.abiVersion = options.abiVersion;
65 rocdlTargetOptions.optLevel = options.optLevel;
66 rocdlTargetOptions.waveSize = options.waveSize;
67 pm.addPass(createGpuROCDLAttachTarget(rocdlTargetOptions));
68
71 ConvertIndexToLLVMPassOptions convertIndexToLLVMPassOpt;
72 convertIndexToLLVMPassOpt.indexBitwidth = options.indexBitWidth;
73 pm.addPass(createConvertIndexToLLVMPass(convertIndexToLLVMPassOpt));
76}
77
78//===----------------------------------------------------------------------===//
79// GPUModule-specific stuff.
80//===----------------------------------------------------------------------===//
81void buildGpuPassPipeline(OpPassManager &pm,
83 std::string arch = ROCDL::resolveArchOption(options.arch, options.chip).str();
85 opt.arch = arch;
86 opt.waveSize = options.waveSize;
87 opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
88 opt.indexBitwidth = options.indexBitWidth;
89 // Always declare HIP as the runtime so that gpu.printf etc. lower to the
90 // matching runtime entry points exposed by `libmlir_rocm_runtime.so`.
92 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToROCDLOps(opt));
93 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
94 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
96}
97
98//===----------------------------------------------------------------------===//
99// Host Post-GPU pipeline
100//===----------------------------------------------------------------------===//
101void buildHostPostPipeline(
104 opt.hostBarePtrCallConv = options.hostUseBarePtrCallConv;
105 opt.kernelBarePtrCallConv = options.kernelUseBarePtrCallConv;
107
108 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
109 gpuModuleToBinaryPassOptions.compilationTarget = options.binaryFormat;
110 gpuModuleToBinaryPassOptions.cmdOptions = options.cmdOptions;
111 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
116}
117
118} // namespace
119
122 // Common pipelines
123 buildCommonPassPipeline(pm, options);
124
125 // GPUModule-specific stuff
126 buildGpuPassPipeline(pm, options);
127
128 // Host post-GPUModule-specific stuff
129 buildHostPostPipeline(pm, options);
130}
131
134 "gpu-lower-to-rocdl-pipeline",
135 "The default pipeline lowers main dialects (arith, memref, scf, vector, "
136 "gpu) to ROCDL. It starts by lowering GPU code to the specified "
137 "compilation target (default is fatbin) then lowers the host code.",
139}
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition PassManager.h:46
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition Pass.cpp:393
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
StringRef resolveArchOption(StringRef arch, StringRef deprecatedAlias)
Returns the target architecture that a pass should parse, given its arch option and the value of the ...
void registerGPUToROCDLPipeline()
void buildLowerToROCDLPassPipeline(OpPassManager &pm, const GPUToROCDLPipelineOptions &options)
Adds the GPU to ROCDL pipeline to the given pass manager.
std::unique_ptr<::mlir::Pass > createExpandStridedMetadataPass()
Include the generated interface declarations.
std::unique_ptr<::mlir::Pass > createSCFToControlFlowPass()
std::unique_ptr<::mlir::Pass > createConvertMathToLLVMPass()
std::unique_ptr<::mlir::Pass > createConvertFuncToLLVMPass()
std::unique_ptr<::mlir::Pass > createConvertIndexToLLVMPass()
std::unique_ptr<::mlir::Pass > createReconcileUnrealizedCastsPass()
std::unique_ptr<::mlir::Pass > createArithToLLVMConversionPass()
std::unique_ptr<::mlir::Pass > createCanonicalizerPass()
std::unique_ptr<::mlir::Pass > createLowerAffinePass()
std::unique_ptr<::mlir::Pass > createGpuROCDLAttachTarget()
std::unique_ptr<::mlir::Pass > createConvertGpuOpsToROCDLOps()
std::unique_ptr<::mlir::Pass > createConvertAMDGPUToROCDLPass()
std::unique_ptr<::mlir::Pass > createGpuToLLVMConversionPass()
std::unique_ptr<::mlir::Pass > createGpuModuleToBinaryPass()
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
std::unique_ptr<::mlir::Pass > createCSEPass()
Definition CSE.cpp:177
std::unique_ptr<::mlir::Pass > createGpuKernelOutliningPass()
::mlir::gpu::amd::Runtime runtime
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Options for the gpu to rocdl pipeline.
Definition Passes.h:69