MLIR 22.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::createXeGPUSubgroupDistribute());
81 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
82 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
84 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
85 pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUVectorLinearize());
86 }
87 pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
88 pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeGPUToXeVMPass());
89 {
90 ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
91 gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
92 pm.addNestedPass<gpu::GPUModuleOp>(
93 createConvertGpuOpsToLLVMSPVOps(gpuToLLVMSPVOptions));
94 }
95 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
96 pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
97}
98
99//===----------------------------------------------------------------------===//
100// Post-GPU pipeline for both Host and GPU.
101//===----------------------------------------------------------------------===//
102void buildPostGPUCommonPassPipeline(
104 // builtin.module scope passes.
105 pm.addPass(createSCFToControlFlowPass());
106 pm.addPass(memref::createExpandStridedMetadataPass());
107 {
108 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
109 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
110 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
111 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
112 }
113 pm.addPass(createLowerAffinePass());
114 pm.addPass(createConvertVectorToLLVMPass());
115 pm.addPass(createConvertToLLVMPass());
116 pm.addPass(createReconcileUnrealizedCastsPass());
117 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
118 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
119 // gpu-module-to-binary
120 {
121 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
122 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
123 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
124 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
125 }
126}
127} // namespace
128
131 // Pre-GPU common pipelines.
132 buildPreGPUCommonPassPipeline(pm, options);
133
134 // GPUModule-specific stuff.
135 buildGPUPassPipeline(pm, options);
136
137 // Post-GPU pipeline for both Host and GPU.
138 buildPostGPUCommonPassPipeline(pm, options);
139}
140
143 "gpu-lower-to-xevm-pipeline",
144 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
145 "code to the "
146 "specified compilation target (default is fatbin) then lowers the host "
147 "code.",
149}
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...