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 }
55 pm.addNestedPass<func::FuncOp>(createGpuAsyncRegionPass());
56}
57
58//===----------------------------------------------------------------------===//
59// GPUModule-specific stuff.
60//===----------------------------------------------------------------------===//
61void buildGPUPassPipeline(OpPassManager &pm,
63 if (options.xegpuOpLevel == "workgroup") {
65 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
67 layoutOptions.layoutKind = "inst";
68 pm.addNestedPass<gpu::GPUModuleOp>(
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") {
77 layoutOptions.layoutKind = "lane";
78 pm.addNestedPass<gpu::GPUModuleOp>(
81 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
82 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
84 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
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());
97}
98
99//===----------------------------------------------------------------------===//
100// Post-GPU pipeline for both Host and GPU.
101//===----------------------------------------------------------------------===//
102void buildPostGPUCommonPassPipeline(
104 // builtin.module scope passes.
107 {
108 GpuToLLVMConversionPassOptions gpuToLLVMOptions;
109 gpuToLLVMOptions.hostBarePtrCallConv = options.hostBarePtrCallConv;
110 gpuToLLVMOptions.kernelBarePtrCallConv = options.kernelBarePtrCallConv;
111 pm.addPass(createGpuToLLVMConversionPass(gpuToLLVMOptions));
112 }
116 // gpu-module-to-binary
117 {
118 GpuModuleToBinaryPassOptions gpuToModuleBinOptions;
119 gpuToModuleBinOptions.compilationTarget = options.binaryFormat;
120 gpuToModuleBinOptions.cmdOptions = options.cmdOptions;
121 pm.addPass(createGpuModuleToBinaryPass(gpuToModuleBinOptions));
122 }
123}
124} // namespace
125
128 // Pre-GPU common pipelines.
129 buildPreGPUCommonPassPipeline(pm, options);
130
131 // GPUModule-specific stuff.
132 buildGPUPassPipeline(pm, options);
133
134 // Post-GPU pipeline for both Host and GPU.
135 buildPostGPUCommonPassPipeline(pm, options);
136}
137
140 "gpu-lower-to-xevm-pipeline",
141 "The default GPU to XeVM lowering pipeline. It starts by lowering GPU "
142 "code to the "
143 "specified compilation target (default is fatbin) then lowers the host "
144 "code.",
146}
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 > 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 > 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.
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...