MLIR 23.0.0git
GPUToXeVMPipeline.cpp
Go to the documentation of this file.
1//===- GPUToXeVMPipeline.cpp - Lowering pipeline to XeVM/LLVM -------------===//
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 pass for testing the lowering to XeVM as a generally
10// usable sink pass. If XeGPU ops are used, it expects the MLIR code to have
11// XeGPU ops already embedded in gpu code.
12//
13//===----------------------------------------------------------------------===//
14
34
35using namespace mlir;
36
37namespace {
38//===----------------------------------------------------------------------===//
39// Pre-GPU common pipeline for both Host and GPU.
40//===----------------------------------------------------------------------===//
41void buildPreGPUCommonPassPipeline(
43 // builtin.module scope passes.
46 {
47 GpuXeVMAttachTargetOptions xevmTargetOptions;
48 xevmTargetOptions.moduleMatcher = options.xevmModuleMatcher;
49 xevmTargetOptions.triple = options.zebinTriple;
50 xevmTargetOptions.chip = options.zebinChip;
51 xevmTargetOptions.optLevel = options.optLevel;
52 xevmTargetOptions.cmdOptions = options.cmdOptions;
53 pm.addPass(createGpuXeVMAttachTarget(xevmTargetOptions));
54 }
56 pm.addNestedPass<func::FuncOp>(createGpuAsyncRegionPass());
57}
58
59//===----------------------------------------------------------------------===//
60// GPUModule-specific stuff.
61//===----------------------------------------------------------------------===//
62void buildGPUPassPipeline(OpPassManager &pm,
64 xegpu::XeGPUPropagateLayoutOptions laneLayoutOptions;
65 laneLayoutOptions.layoutKind = "lane";
66 pm.addNestedPass<ModuleOp>(createCSEPass());
68 if (options.xegpuOpLevel == "workgroup") {
70 sgLayoutOptions.layoutKind = "subgroup";
71 pm.addNestedPass<gpu::GPUModuleOp>(
72 xegpu::createXeGPUPropagateLayout(sgLayoutOptions));
74 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
75 pm.addNestedPass<gpu::GPUModuleOp>(createLowerAffinePass());
76 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
78 instDataOptions.layoutKind = "inst";
79 pm.addNestedPass<gpu::GPUModuleOp>(
80 xegpu::createXeGPUPropagateLayout(instDataOptions));
81 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUBlocking());
82 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
83 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
84 }
85 if (options.xegpuOpLevel == "subgroup" ||
86 options.xegpuOpLevel == "workgroup") {
87 pm.addNestedPass<gpu::GPUModuleOp>(
88 xegpu::createXeGPUPropagateLayout(laneLayoutOptions));
90 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
91 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
92 pm.addNestedPass<gpu::GPUModuleOp>(
93 xegpu::createXeGPUPropagateLayout(laneLayoutOptions));
95 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
96 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
98 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
100 }
101 pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
102 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeGPUToXeVMPass());
103 {
104 ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
105 gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
106 pm.addNestedPass<gpu::GPUModuleOp>(
107 createConvertGpuOpsToLLVMSPVOps(gpuToLLVMSPVOptions));
108 }
109 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
111}
112
113//===----------------------------------------------------------------------===//
114// Post-GPU pipeline for both Host and GPU.
115//===----------------------------------------------------------------------===//
116void buildPostGPUCommonPassPipeline(
118 // builtin.module scope passes.
121 {
122 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
123 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
124 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
125 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
126 }
131 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
132 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
133 // XeVM-to-LLVM must be the last pass before gpu-module-to-binary.
134 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeVMToLLVMPass());
135 // gpu-module-to-binary
136 {
137 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
138 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
139 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
140 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
141 }
142}
143} // namespace
144
147 // Pre-GPU common pipelines.
148 buildPreGPUCommonPassPipeline(pm, options);
149
150 // GPUModule-specific stuff.
151 buildGPUPassPipeline(pm, options);
152
153 // Post-GPU pipeline for both Host and GPU.
154 buildPostGPUCommonPassPipeline(pm, options);
155}
156
159 "gpu-lower-to-xevm-pipeline",
160 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
161 "code to the "
162 "specified compilation target (default is fatbin) then lowers the host "
163 "code.",
165}
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 registerGPUToXeVMPipeline()
void buildLowerToXeVMPassPipeline(OpPassManager &pm, const GPUToXeVMPipelineOptions &options)
Adds the GPU to XeVM pipeline to the given pass manager.
std::unique_ptr<::mlir::Pass > createExpandStridedMetadataPass()
std::unique_ptr<::mlir::Pass > createXeGPUSubgroupDistribute()
std::unique_ptr<::mlir::Pass > createXeGPUWgToSgDistribute()
std::unique_ptr<::mlir::Pass > createXeGPUVectorLinearize()
std::unique_ptr<::mlir::Pass > createXeGPUPeepHoleOptimizer()
std::unique_ptr<::mlir::Pass > createXeGPUBlocking()
std::unique_ptr<::mlir::Pass > createXeGPUPropagateLayout()
Include the generated interface declarations.
std::unique_ptr< Pass > createCSEPass()
Creates a pass to perform common sub expression elimination.
Definition CSE.cpp:412
std::unique_ptr<::mlir::Pass > createConvertToLLVMPass()
std::unique_ptr<::mlir::Pass > createSCFToControlFlowPass()
std::unique_ptr< Pass > createLoopInvariantCodeMotionPass()
Creates a loop invariant code motion pass that hoists loop invariant instructions out of the loop.
std::unique_ptr<::mlir::Pass > createConvertGpuOpsToLLVMSPVOps()
std::unique_ptr<::mlir::Pass > createReconcileUnrealizedCastsPass()
std::unique_ptr<::mlir::Pass > createConvertVectorToLLVMPass()
std::unique_ptr<::mlir::Pass > createGpuAsyncRegionPass()
std::unique_ptr<::mlir::Pass > createConvertXeGPUToXeVMPass()
std::unique_ptr<::mlir::Pass > createLowerAffinePass()
std::unique_ptr<::mlir::Pass > createGpuXeVMAttachTarget()
std::unique_ptr< Pass > createCanonicalizerPass()
Creates an instance of the Canonicalizer pass, configured with default settings (which can be overrid...
std::unique_ptr<::mlir::Pass > createConvertMathToXeVM()
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 > createConvertXeVMToLLVMPass()
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...