MLIR-AIE
Passes.h
Go to the documentation of this file.
1//===- Passes.h - AIE Vector pipeline entry points --------------*- C++ -*-===//
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// (c) Copyright 2022 Xilinx Inc.
8//
9//===----------------------------------------------------------------------===//
10//
11// This header file defines prototypes of all AIE vector pipelines.
12//
13//===----------------------------------------------------------------------===//
14#ifndef AIE_DIALECT_AIEVEC_PIPELINES_PASSES_H
15#define AIE_DIALECT_AIEVEC_PIPELINES_PASSES_H
16
17#include "mlir/Pass/Pass.h"
18#include "mlir/Pass/PassOptions.h"
19
20namespace xilinx {
21enum class AIEArch {
22 AIE, // Original AIE
23 AIE2, // AIE-ML/V2 arch version of AIE
24 AIE2P, // AIE2P arch version of AIE
25 UNKNOWN // Unsupported/Unknown backend
26};
27enum class TargetBackend {
28 CPP, // Convert to aievec targeting C++ backend
29 LLVMIR, // Convert to aievec targeting LLVM IR backend
30 UNKNOWN // Unsupported/Unknown backend
31};
32} // namespace xilinx
33
34namespace xilinx {
35namespace aievec {
36
37// TODO: Create a common base class for all AIEVec pipeline options.
38
39/// Options for the "canonicalize-vector-for-aievec" pipeline.
41 : public mlir::PassPipelineOptions<CanonicalizeVectorForAIEVecOptions> {
42 PassOptions::Option<std::string> aieTarget{
43 *this, "aie-target",
44 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
45 "determine the vector size and available operations."),
46 llvm::cl::init("aie")};
47 PassOptions::Option<std::string> targetBackend{
48 *this, "target-backend",
49 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
50 "will determine the aievec operations used to convert "
51 "from vector dialect."),
52 llvm::cl::init("cpp")};
53 PassOptions::Option<bool> enableBF16Emulation{
54 *this, "bf16-emulation",
55 llvm::cl::desc(
56 "Emulate f32 vector arithmetic using bf16 operations. Inserts "
57 "arith.truncf/arith.extf around f32 vector ops to compute in bf16. "
58 "Trades precision for performance."),
59 llvm::cl::init(false)};
60};
61
62/// Options for the "lower-vector-to-aievec" pipeline.
64 : public mlir::PassPipelineOptions<LowerVectorToAIEVecOptions> {
65 PassOptions::Option<std::string> aieTarget{
66 *this, "aie-target",
67 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
68 "determine the vector size and available operations."),
69 llvm::cl::init("aie")};
70 PassOptions::Option<std::string> targetBackend{
71 *this, "target-backend",
72 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
73 "will determine the aievec operations used to convert "
74 "from vector dialect."),
75 llvm::cl::init("cpp")};
76};
77
78/// Options for the "optimize-aievec" pipeline.
80 : public mlir::PassPipelineOptions<OptimizeAIEVecOptions> {
81 PassOptions::Option<std::string> aieTarget{
82 *this, "aie-target",
83 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
84 "determine the vector size and available operations."),
85 llvm::cl::init("aie")};
86 PassOptions::Option<std::string> targetBackend{
87 *this, "target-backend",
88 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
89 "will determine the aievec operations used to convert "
90 "from vector dialect."),
91 llvm::cl::init("cpp")};
92 PassOptions::Option<unsigned> shiftParam{
93 *this, "shift",
94 llvm::cl::desc("Shift parameter for rounding and saturation"),
95 llvm::cl::init(0)};
96};
97
98/// Options for the "convert-vector-to-aievec" pipeline.
100 : public mlir::PassPipelineOptions<ConvertVectorToAIEVecOptions> {
101 // 'LowerVectorToAIEVec' options
102 // TODO: Review the need for these options.
103 PassOptions::Option<unsigned> shiftParam{
104 *this, "shift",
105 llvm::cl::desc("Shift parameter for rounding and saturation"),
106 llvm::cl::init(0)};
107 PassOptions::Option<unsigned> zeroOffset{
108 *this, "zero-offset",
109 llvm::cl::desc("Zero offset for indicating the location of zeroes in "
110 "convolution filter (useful for 16x16 scheme)"),
111 llvm::cl::init(0)};
112 PassOptions::Option<unsigned> dupFactor{
113 *this, "dup-actor",
114 llvm::cl::desc("Duplication factor for each value in convolution filter "
115 "(useful in 8x8 scheme)"),
116 llvm::cl::init(2)};
117 PassOptions::Option<std::string> aieTarget{
118 *this, "aie-target",
119 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
120 "determine the vector size and available operations."),
121 llvm::cl::init("aie")};
122 PassOptions::Option<std::string> targetBackend{
123 *this, "target-backend",
124 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
125 "will determine the aievec operations used to convert "
126 "from vector dialect."),
127 llvm::cl::init("cpp")};
128 PassOptions::Option<bool> enableBF16Emulation{
129 *this, "bf16-emulation",
130 llvm::cl::desc(
131 "Emulate f32 vector arithmetic using bf16 operations. Inserts "
132 "arith.truncf/arith.extf around f32 vector ops to compute in bf16. "
133 "Trades precision for performance."),
134 llvm::cl::init(false)};
135
136 mlir::LogicalResult parseFromString(mlir::StringRef options) {
137 auto res = PassPipelineOptions::parseFromString(options);
138 if (!failed(res)) {
139 lowerOptions.aieTarget = aieTarget;
140 lowerOptions.targetBackend = targetBackend;
141 canonicalizeOptions.aieTarget = aieTarget;
142 canonicalizeOptions.targetBackend = targetBackend;
143 canonicalizeOptions.enableBF16Emulation = enableBF16Emulation;
144 optimizeOptions.aieTarget = aieTarget;
145 optimizeOptions.targetBackend = targetBackend;
146 optimizeOptions.shiftParam = shiftParam;
147 }
148 return res;
149 }
150
152 return lowerOptions;
153 }
154
157 return canonicalizeOptions;
158 }
159
161 return optimizeOptions;
162 }
163
164private:
165 CanonicalizeVectorForAIEVecOptions canonicalizeOptions;
166 LowerVectorToAIEVecOptions lowerOptions;
167 OptimizeAIEVecOptions optimizeOptions;
168};
169
170//===----------------------------------------------------------------------===//
171// Building and Registering.
172//===----------------------------------------------------------------------===//
173
174/// Adds the "convert-vector-to-aievec" pipeline to the `OpPassManager`. This
175/// pipeline takes `Vector` code, transforms it to make it compatible with the
176/// selected `AIE` target, lowers it to `AIEVec` dialect, and performs some
177/// optimizations based on the target AIE architecture.
178void buildConvertVectorToAIEVec(mlir::OpPassManager &pm,
179 const ConvertVectorToAIEVecOptions &options);
180
182 mlir::OpPassManager &pm, const CanonicalizeVectorForAIEVecOptions &options);
183
184void buildLowerVectorToAIEVec(mlir::OpPassManager &pm,
185 const LowerVectorToAIEVecOptions &options);
186
187void buildOptimizeAIEVec(mlir::OpPassManager &pm,
188 const OptimizeAIEVecOptions &options);
189
190/// Register all pipelines for the AIE Vector dialect.
192
193/// Create a pass that removes unnecessary Copy operations.
194std::unique_ptr<::mlir::Pass> createCopyRemovalPass();
195
196// Create a pass that rewrites the arith dialect to enable the support of
197// dynamic sized tensor/memref for the auto-vectorization to CPP flow.
198std::unique_ptr<::mlir::Pass> createDynamicSizeNoImplicitBroadcastPass();
199
200// Build a pipeline for CLI access to the pass
201// `dynamic-size-no-implicit-broadcast`
202void buildDynamicSizeNoImplicitBroadcastPass(mlir::OpPassManager &pm);
203
204/// Create a pass that splits vector.load + aievec.ups chains to reduce shuffle
205/// operations for AIE2p targets.
206std::unique_ptr<::mlir::Pass> createSplitVectorLoadUpsChainsPass();
207
208/// Create a pass that emulates f32 vector arithmetic using bf16 operations.
209/// Inserts arith.truncf/arith.extf around f32 vector ops to compute in bf16.
210std::unique_ptr<::mlir::Pass> createBF16EmulationPass();
211
212} // namespace aievec
213} // namespace xilinx
214
215#endif // AIE_DIALECT_AIEVEC_PIPELINES_PASSES_H
std::unique_ptr<::mlir::Pass > createCopyRemovalPass()
Create a pass that removes unnecessary Copy operations.
void registerAIEVecPipelines()
Register all pipelines for the AIE Vector dialect.
std::unique_ptr<::mlir::Pass > createSplitVectorLoadUpsChainsPass()
Create a pass that splits vector.load + aievec.ups chains to reduce shuffle operations for AIE2p targ...
void buildLowerVectorToAIEVec(mlir::OpPassManager &pm, const LowerVectorToAIEVecOptions &options)
std::unique_ptr<::mlir::Pass > createBF16EmulationPass()
Create a pass that emulates f32 vector arithmetic using bf16 operations.
std::unique_ptr<::mlir::Pass > createDynamicSizeNoImplicitBroadcastPass()
void buildCanonicalizeVectorForAIEVec(mlir::OpPassManager &pm, const CanonicalizeVectorForAIEVecOptions &options)
void buildConvertVectorToAIEVec(mlir::OpPassManager &pm, const ConvertVectorToAIEVecOptions &options)
Adds the "convert-vector-to-aievec" pipeline to the OpPassManager.
void buildDynamicSizeNoImplicitBroadcastPass(mlir::OpPassManager &pm)
void buildOptimizeAIEVec(mlir::OpPassManager &pm, const OptimizeAIEVecOptions &options)
TargetBackend
Definition Passes.h:27
AIEArch
Definition Passes.h:21
Options for the "canonicalize-vector-for-aievec" pipeline.
Definition Passes.h:41
PassOptions::Option< bool > enableBF16Emulation
Definition Passes.h:53
PassOptions::Option< std::string > targetBackend
Definition Passes.h:47
PassOptions::Option< std::string > aieTarget
Definition Passes.h:42
Options for the "convert-vector-to-aievec" pipeline.
Definition Passes.h:100
const LowerVectorToAIEVecOptions & getLowerVectorToAIEVecOptions() const
Definition Passes.h:151
PassOptions::Option< unsigned > dupFactor
Definition Passes.h:112
PassOptions::Option< std::string > aieTarget
Definition Passes.h:117
PassOptions::Option< std::string > targetBackend
Definition Passes.h:122
PassOptions::Option< unsigned > zeroOffset
Definition Passes.h:107
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:103
mlir::LogicalResult parseFromString(mlir::StringRef options)
Definition Passes.h:136
const CanonicalizeVectorForAIEVecOptions & getCanonicalizeVectorForAIEVecOptions() const
Definition Passes.h:156
PassOptions::Option< bool > enableBF16Emulation
Definition Passes.h:128
const OptimizeAIEVecOptions & getOptimizeAIEVecOptions() const
Definition Passes.h:160
Options for the "lower-vector-to-aievec" pipeline.
Definition Passes.h:64
PassOptions::Option< std::string > aieTarget
Definition Passes.h:65
PassOptions::Option< std::string > targetBackend
Definition Passes.h:70
Options for the "optimize-aievec" pipeline.
Definition Passes.h:80
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:92
PassOptions::Option< std::string > targetBackend
Definition Passes.h:86
PassOptions::Option< std::string > aieTarget
Definition Passes.h:81