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
33
34using namespace mlir;
35
36namespace {
37//===----------------------------------------------------------------------===//
38// Pre-GPU common pipeline for both Host and GPU.
39//===----------------------------------------------------------------------===//
40void buildPreGPUCommonPassPipeline(
42 // builtin.module scope passes.
45 {
46 GpuXeVMAttachTargetOptions xevmTargetOptions;
47 xevmTargetOptions.moduleMatcher = options.xevmModuleMatcher;
48 xevmTargetOptions.triple = options.zebinTriple;
49 xevmTargetOptions.chip = options.zebinChip;
50 xevmTargetOptions.optLevel = options.optLevel;
51 xevmTargetOptions.cmdOptions = options.cmdOptions;
52 pm.addPass(createGpuXeVMAttachTarget(xevmTargetOptions));
53 }
54 pm.addPass(createLowerAffinePass());
55 pm.addNestedPass<func::FuncOp>(createGpuAsyncRegionPass());
56}
57
58//===----------------------------------------------------------------------===//
59// GPUModule-specific stuff.
60//===----------------------------------------------------------------------===//
61void buildGPUPassPipeline(OpPassManager &pm,
63 if (options.xegpuOpLevel == "workgroup") {
64 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUWgToSgDistribute());
65 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
66 xegpu::XeGPUPropagateLayoutOptions layoutOptions;
67 layoutOptions.layoutKind = "inst";
68 pm.addNestedPass<gpu::GPUModuleOp>(
69 xegpu::createXeGPUPropagateLayout(layoutOptions));
70 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUBlocking());
71 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
72 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
73 }
74 if (options.xegpuOpLevel == "subgroup" ||
75 options.xegpuOpLevel == "workgroup") {
76 xegpu::XeGPUPropagateLayoutOptions layoutOptions;
77 layoutOptions.layoutKind = "lane";
78 pm.addNestedPass<gpu::GPUModuleOp>(
79 xegpu::createXeGPUPropagateLayout(layoutOptions));
80 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUPeepHoleOptimizer());
81 pm.addNestedPass<gpu::GPUModuleOp>(
82 xegpu::createXeGPUPropagateLayout(layoutOptions));
83 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUSubgroupDistribute());
84 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
85 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
87 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
88 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUVectorLinearize());
89 }
90 pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
91 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeGPUToXeVMPass());
92 {
93 ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
94 gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
95 pm.addNestedPass<gpu::GPUModuleOp>(
96 createConvertGpuOpsToLLVMSPVOps(gpuToLLVMSPVOptions));
97 }
98 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
99 pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
100}
101
102//===----------------------------------------------------------------------===//
103// Post-GPU pipeline for both Host and GPU.
104//===----------------------------------------------------------------------===//
105void buildPostGPUCommonPassPipeline(
107 // builtin.module scope passes.
108 pm.addPass(createSCFToControlFlowPass());
109 pm.addPass(memref::createExpandStridedMetadataPass());
110 {
111 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
112 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
113 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
114 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
115 }
116 pm.addPass(createLowerAffinePass());
117 pm.addPass(createConvertVectorToLLVMPass());
118 pm.addPass(createConvertToLLVMPass());
119 pm.addPass(createReconcileUnrealizedCastsPass());
120 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
121 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
122 // gpu-module-to-binary
123 {
124 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
125 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
126 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
127 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
128 }
129}
130} // namespace
131
134 // Pre-GPU common pipelines.
135 buildPreGPUCommonPassPipeline(pm, options);
136
137 // GPUModule-specific stuff.
138 buildGPUPassPipeline(pm, options);
139
140 // Post-GPU pipeline for both Host and GPU.
141 buildPostGPUCommonPassPipeline(pm, options);
142}
143
146 "gpu-lower-to-xevm-pipeline",
147 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
148 "code to the "
149 "specified compilation target (default is fatbin) then lowers the host "
150 "code.",
152}
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 > createCSEPass()
Creates a pass to perform common sub expression elimination.
Definition CSE.cpp:412
std::unique_ptr< Pass > createLoopInvariantCodeMotionPass()
Creates a loop invariant code motion pass that hoists loop invariant instructions out of the loop.
std::unique_ptr< Pass > createCanonicalizerPass()
Creates an instance of the Canonicalizer pass, configured with default settings (which can be overrid...
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...