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
36
37using namespace mlir;
38
39namespace {
40//===----------------------------------------------------------------------===//
41// Pre-GPU common pipeline for both Host and GPU.
42//===----------------------------------------------------------------------===//
43void buildPreGPUCommonPassPipeline(
45 // builtin.module scope passes.
48 {
49 GpuXeVMAttachTargetOptions xevmTargetOptions;
50 xevmTargetOptions.moduleMatcher = options.xevmModuleMatcher;
51 xevmTargetOptions.triple = options.zebinTriple;
52 xevmTargetOptions.chip = options.zebinChip;
53 xevmTargetOptions.optLevel = options.optLevel;
54 xevmTargetOptions.cmdOptions = options.cmdOptions;
55 pm.addPass(createGpuXeVMAttachTarget(xevmTargetOptions));
56 }
58 pm.addNestedPass<func::FuncOp>(createGpuAsyncRegionPass());
59}
60
61//===----------------------------------------------------------------------===//
62// GPUModule-specific stuff.
63//===----------------------------------------------------------------------===//
64void buildGPUPassPipeline(OpPassManager &pm,
66 xegpu::XeGPUPropagateLayoutOptions laneLayoutOptions;
67 laneLayoutOptions.indexBitWidth = options.use64bitIndex ? 64 : 32;
68 laneLayoutOptions.layoutKind = "lane";
69 pm.addNestedPass<ModuleOp>(createCSEPass());
70 if (options.xegpuOpLevel == "workgroup") {
72 sgLayoutOptions.layoutKind = "subgroup";
73 pm.addNestedPass<gpu::GPUModuleOp>(
74 xegpu::createXeGPUPropagateLayout(sgLayoutOptions));
76 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
77 pm.addNestedPass<gpu::GPUModuleOp>(createLowerAffinePass());
78 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
80 instDataOptions.layoutKind = "inst";
81 pm.addNestedPass<gpu::GPUModuleOp>(
82 xegpu::createXeGPUPropagateLayout(instDataOptions));
83 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUBlocking());
84 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
85 }
86 if (options.xegpuOpLevel == "subgroup" ||
87 options.xegpuOpLevel == "workgroup") {
88 pm.addNestedPass<gpu::GPUModuleOp>(
89 xegpu::createXeGPUPropagateLayout(laneLayoutOptions));
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 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
101 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
102 }
103 pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
104 ConvertXeGPUToXeVMPassOptions xegpuToXeVMOptions;
105 xegpuToXeVMOptions.use64bitIndex = options.use64bitIndex;
106 pm.addNestedPass<gpu::GPUModuleOp>(
107 createConvertXeGPUToXeVMPass(xegpuToXeVMOptions));
108 {
109 ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
110 gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
111 pm.addNestedPass<gpu::GPUModuleOp>(
112 createConvertGpuOpsToLLVMSPVOps(gpuToLLVMSPVOptions));
113 }
114 // Legalize math/arith ops on floating-point types that the XeVM target
115 // cannot handle natively (e.g. bf16) by wrapping them with extf/truncf
116 // around a supported type (defaulting to f32).
117 {
119 mathExtendOptions.extraTypeStrs.assign(options.mathExtendExtraTypes.begin(),
120 options.mathExtendExtraTypes.end());
121 mathExtendOptions.targetTypeStr = options.supportedTargetTypes;
122 pm.addNestedPass<gpu::GPUModuleOp>(
123 math::createMathExtendToSupportedTypes(mathExtendOptions));
124 }
125 {
127 arithEmulateOptions.sourceTypeStrs.assign(
128 options.unsupportedSourceTypes.begin(),
129 options.unsupportedSourceTypes.end());
130 arithEmulateOptions.targetTypeStr = options.supportedTargetTypes;
131 pm.addNestedPass<gpu::GPUModuleOp>(
132 arith::createArithEmulateUnsupportedFloats(arithEmulateOptions));
133 }
134 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
136}
137
138//===----------------------------------------------------------------------===//
139// Post-GPU pipeline for both Host and GPU.
140//===----------------------------------------------------------------------===//
141void buildPostGPUCommonPassPipeline(
143 // builtin.module scope passes.
146 {
147 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
148 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
149 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
150 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
151 }
156 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
157 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
158 // XeVM-to-LLVM must be the last pass before gpu-module-to-binary.
159 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeVMToLLVMPass());
160 // gpu-module-to-binary
161 {
162 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
163 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
164 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
165 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
166 }
167}
168} // namespace
169
172 // Pre-GPU common pipelines.
173 buildPreGPUCommonPassPipeline(pm, options);
174
175 // GPUModule-specific stuff.
176 buildGPUPassPipeline(pm, options);
177
178 // Post-GPU pipeline for both Host and GPU.
179 buildPostGPUCommonPassPipeline(pm, options);
180}
181
184 "gpu-lower-to-xevm-pipeline",
185 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
186 "code to the "
187 "specified compilation target (default is fatbin) then lowers the host "
188 "code.",
190}
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.
std::unique_ptr<::mlir::Pass > createArithEmulateUnsupportedFloats()
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 > createMathExtendToSupportedTypes()
std::unique_ptr<::mlir::Pass > createExpandStridedMetadataPass()
std::unique_ptr<::mlir::Pass > createXeGPUWgToSgDistribute()
std::unique_ptr<::mlir::Pass > createXeGPUVectorLinearize()
std::unique_ptr<::mlir::Pass > createXeGPUSgToLaneDistribute()
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<::mlir::Pass > createConvertToLLVMPass()
std::unique_ptr<::mlir::Pass > createSCFToControlFlowPass()
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 > createCanonicalizerPass()
std::unique_ptr<::mlir::Pass > createConvertXeGPUToXeVMPass()
std::unique_ptr<::mlir::Pass > createLowerAffinePass()
std::unique_ptr<::mlir::Pass > createGpuXeVMAttachTarget()
std::unique_ptr<::mlir::Pass > createConvertMathToXeVM()
std::unique_ptr<::mlir::Pass > createLoopInvariantCodeMotionPass()
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()
std::unique_ptr<::mlir::Pass > createCSEPass()
Definition CSE.cpp:177
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
::llvm::SmallVector< std::string > sourceTypeStrs
Definition Passes.h:20
::llvm::SmallVector< std::string > extraTypeStrs
Definition Passes.h:113