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.
44 pm.addPass(createCSEPass());
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 }
55 pm.addPass(createLowerAffinePass());
56 pm.addNestedPass<func::FuncOp>(createGpuAsyncRegionPass());
57}
58
59//===----------------------------------------------------------------------===//
60// GPUModule-specific stuff.
61//===----------------------------------------------------------------------===//
62void buildGPUPassPipeline(OpPassManager &pm,
64 xegpu::XeGPUPropagateLayoutOptions laneLayoutOptions;
65 laneLayoutOptions.indexBitWidth = options.use64bitIndex ? 64 : 32;
66 laneLayoutOptions.layoutKind = "lane";
67 pm.addNestedPass<ModuleOp>(createCSEPass());
68 if (options.xegpuOpLevel == "workgroup") {
69 xegpu::XeGPUPropagateLayoutOptions sgLayoutOptions;
70 sgLayoutOptions.layoutKind = "subgroup";
71 pm.addNestedPass<gpu::GPUModuleOp>(
72 xegpu::createXeGPUPropagateLayout(sgLayoutOptions));
73 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUWgToSgDistribute());
74 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
75 pm.addNestedPass<gpu::GPUModuleOp>(createLowerAffinePass());
76 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
77 xegpu::XeGPUPropagateLayoutOptions instDataOptions;
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>(createCSEPass());
83 }
84 if (options.xegpuOpLevel == "subgroup" ||
85 options.xegpuOpLevel == "workgroup") {
86 pm.addNestedPass<gpu::GPUModuleOp>(
87 xegpu::createXeGPUPropagateLayout(laneLayoutOptions));
88 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUPeepHoleOptimizer());
89 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
90 pm.addNestedPass<gpu::GPUModuleOp>(
91 xegpu::createXeGPUPropagateLayout(laneLayoutOptions));
92 pm.addNestedPass<gpu::GPUModuleOp>(
93 xegpu::createXeGPUSgToWiDistributeExperimental());
94 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
95 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
96 pm.addNestedPass<gpu::GPUModuleOp>(createLoopInvariantCodeMotionPass());
97 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
98 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUVectorLinearize());
99 }
100 pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
101 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeGPUToXeVMPass());
102 {
103 ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
104 gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
105 pm.addNestedPass<gpu::GPUModuleOp>(
106 createConvertGpuOpsToLLVMSPVOps(gpuToLLVMSPVOptions));
107 }
108 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
109 pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
110}
111
112//===----------------------------------------------------------------------===//
113// Post-GPU pipeline for both Host and GPU.
114//===----------------------------------------------------------------------===//
115void buildPostGPUCommonPassPipeline(
117 // builtin.module scope passes.
118 pm.addPass(createSCFToControlFlowPass());
119 pm.addPass(memref::createExpandStridedMetadataPass());
120 {
121 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
122 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
123 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
124 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
125 }
126 pm.addPass(createLowerAffinePass());
127 pm.addPass(createConvertVectorToLLVMPass());
128 pm.addPass(createConvertToLLVMPass());
129 pm.addPass(createReconcileUnrealizedCastsPass());
130 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
131 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
132 // XeVM-to-LLVM must be the last pass before gpu-module-to-binary.
133 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeVMToLLVMPass());
134 // gpu-module-to-binary
135 {
136 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
137 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
138 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
139 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
140 }
141}
142} // namespace
143
146 // Pre-GPU common pipelines.
147 buildPreGPUCommonPassPipeline(pm, options);
148
149 // GPUModule-specific stuff.
150 buildGPUPassPipeline(pm, options);
151
152 // Post-GPU pipeline for both Host and GPU.
153 buildPostGPUCommonPassPipeline(pm, options);
154}
155
158 "gpu-lower-to-xevm-pipeline",
159 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
160 "code to the "
161 "specified compilation target (default is fatbin) then lowers the host "
162 "code.",
164}
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.
Include the generated interface declarations.
std::unique_ptr< Pass > createCanonicalizerPass(const GreedyRewriteConfig &config, ArrayRef< std::string > disabledPatterns={}, ArrayRef< std::string > enabledPatterns={})
Creates an instance of the Canonicalizer pass with the specified config.
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...