MLIR 23.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
35
36using namespace mlir;
37
38namespace {
39
40//===----------------------------------------------------------------------===//
41// Common pipeline
42//===----------------------------------------------------------------------===//
43void buildCommonPassPipeline(
45 // Lower AMDGPU dialect ops (e.g. amdgpu.lds_barrier, amdgpu.dpp,
46 // amdgpu.mfma, amdgpu.dot, ...) to ROCDL intrinsics first, while they may
47 // still live in unout-lined `gpu.launch` bodies. Mirrors the way NVVM's
48 // pipeline runs `convert-nvgpu-to-nvvm` before kernel outlining.
49 ConvertAMDGPUToROCDLPassOptions amdgpuToROCDLOpt;
50 amdgpuToROCDLOpt.chipset = options.chip;
51 pm.addPass(createConvertAMDGPUToROCDLPass(amdgpuToROCDLOpt));
52
58
59 GpuROCDLAttachTargetOptions rocdlTargetOptions;
60 rocdlTargetOptions.triple = options.triple;
61 rocdlTargetOptions.chip = options.chip;
62 rocdlTargetOptions.features = options.features;
63 rocdlTargetOptions.abiVersion = options.abiVersion;
64 rocdlTargetOptions.optLevel = options.optLevel;
65 rocdlTargetOptions.wave64Flag = options.wave64;
66 pm.addPass(createGpuROCDLAttachTarget(rocdlTargetOptions));
67
70 ConvertIndexToLLVMPassOptions convertIndexToLLVMPassOpt;
71 convertIndexToLLVMPassOpt.indexBitwidth = options.indexBitWidth;
72 pm.addPass(createConvertIndexToLLVMPass(convertIndexToLLVMPassOpt));
75}
76
77//===----------------------------------------------------------------------===//
78// GPUModule-specific stuff.
79//===----------------------------------------------------------------------===//
80void buildGpuPassPipeline(OpPassManager &pm,
83 opt.chipset = options.chip;
84 opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
85 opt.indexBitwidth = options.indexBitWidth;
86 // Always declare HIP as the runtime so that gpu.printf etc. lower to the
87 // matching runtime entry points exposed by `libmlir_rocm_runtime.so`.
89 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToROCDLOps(opt));
90 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
91 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
93}
94
95//===----------------------------------------------------------------------===//
96// Host Post-GPU pipeline
97//===----------------------------------------------------------------------===//
98void buildHostPostPipeline(
101 opt.hostBarePtrCallConv = options.hostUseBarePtrCallConv;
102 opt.kernelBarePtrCallConv = options.kernelUseBarePtrCallConv;
104
105 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
106 gpuModuleToBinaryPassOptions.compilationTarget = options.binaryFormat;
107 gpuModuleToBinaryPassOptions.cmdOptions = options.cmdOptions;
108 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
113}
114
115} // namespace
116
119 // Common pipelines
120 buildCommonPassPipeline(pm, options);
121
122 // GPUModule-specific stuff
123 buildGpuPassPipeline(pm, options);
124
125 // Host post-GPUModule-specific stuff
126 buildHostPostPipeline(pm, options);
127}
128
131 "gpu-lower-to-rocdl-pipeline",
132 "The default pipeline lowers main dialects (arith, memref, scf, vector, "
133 "gpu) to ROCDL. It starts by lowering GPU code to the specified "
134 "compilation target (default is fatbin) then lowers the host code.",
136}
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:392
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
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