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};
54
55/// Options for the "lower-vector-to-aievec" pipeline.
57 : public mlir::PassPipelineOptions<LowerVectorToAIEVecOptions> {
58 PassOptions::Option<std::string> aieTarget{
59 *this, "aie-target",
60 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
61 "determine the vector size and available operations."),
62 llvm::cl::init("aie")};
63 PassOptions::Option<std::string> targetBackend{
64 *this, "target-backend",
65 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
66 "will determine the aievec operations used to convert "
67 "from vector dialect."),
68 llvm::cl::init("cpp")};
69};
70
71/// Options for the "optimize-aievec" pipeline.
73 : public mlir::PassPipelineOptions<OptimizeAIEVecOptions> {
74 PassOptions::Option<std::string> aieTarget{
75 *this, "aie-target",
76 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
77 "determine the vector size and available operations."),
78 llvm::cl::init("aie")};
79 PassOptions::Option<std::string> targetBackend{
80 *this, "target-backend",
81 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
82 "will determine the aievec operations used to convert "
83 "from vector dialect."),
84 llvm::cl::init("cpp")};
85 PassOptions::Option<unsigned> shiftParam{
86 *this, "shift",
87 llvm::cl::desc("Shift parameter for rounding and saturation"),
88 llvm::cl::init(0)};
89};
90
91/// Options for the "convert-vector-to-aievec" pipeline.
93 : public mlir::PassPipelineOptions<ConvertVectorToAIEVecOptions> {
94 // 'LowerVectorToAIEVec' options
95 // TODO: Review the need for these options.
96 PassOptions::Option<unsigned> shiftParam{
97 *this, "shift",
98 llvm::cl::desc("Shift parameter for rounding and saturation"),
99 llvm::cl::init(0)};
100 PassOptions::Option<unsigned> zeroOffset{
101 *this, "zero-offset",
102 llvm::cl::desc("Zero offset for indicating the location of zeroes in "
103 "convolution filter (useful for 16x16 scheme)"),
104 llvm::cl::init(0)};
105 PassOptions::Option<unsigned> dupFactor{
106 *this, "dup-actor",
107 llvm::cl::desc("Duplication factor for each value in convolution filter "
108 "(useful in 8x8 scheme)"),
109 llvm::cl::init(2)};
110 PassOptions::Option<std::string> aieTarget{
111 *this, "aie-target",
112 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
113 "determine the vector size and available operations."),
114 llvm::cl::init("aie")};
115 PassOptions::Option<std::string> targetBackend{
116 *this, "target-backend",
117 llvm::cl::desc("Select translation backend: \"cpp\" or \"llvmir\". This "
118 "will determine the aievec operations used to convert "
119 "from vector dialect."),
120 llvm::cl::init("cpp")};
121
122 mlir::LogicalResult parseFromString(mlir::StringRef options) {
123 auto res = PassPipelineOptions::parseFromString(options);
124 if (!failed(res)) {
125 lowerOptions.aieTarget = aieTarget;
126 lowerOptions.targetBackend = targetBackend;
127 canonicalizeOptions.aieTarget = aieTarget;
128 canonicalizeOptions.targetBackend = targetBackend;
129 optimizeOptions.aieTarget = aieTarget;
130 optimizeOptions.targetBackend = targetBackend;
131 optimizeOptions.shiftParam = shiftParam;
132 }
133 return res;
134 }
135
137 return lowerOptions;
138 }
139
142 return canonicalizeOptions;
143 }
144
146 return optimizeOptions;
147 }
148
149private:
150 CanonicalizeVectorForAIEVecOptions canonicalizeOptions;
151 LowerVectorToAIEVecOptions lowerOptions;
152 OptimizeAIEVecOptions optimizeOptions;
153};
154
155//===----------------------------------------------------------------------===//
156// Building and Registering.
157//===----------------------------------------------------------------------===//
158
159/// Adds the "convert-vector-to-aievec" pipeline to the `OpPassManager`. This
160/// pipeline takes `Vector` code, transforms it to make it compatible with the
161/// selected `AIE` target, lowers it to `AIEVec` dialect, and performs some
162/// optimizations based on the target AIE architecture.
163void buildConvertVectorToAIEVec(mlir::OpPassManager &pm,
164 const ConvertVectorToAIEVecOptions &options);
165
167 mlir::OpPassManager &pm, const CanonicalizeVectorForAIEVecOptions &options);
168
169void buildLowerVectorToAIEVec(mlir::OpPassManager &pm,
170 const LowerVectorToAIEVecOptions &options);
171
172void buildOptimizeAIEVec(mlir::OpPassManager &pm,
173 const OptimizeAIEVecOptions &options);
174
175/// Register all pipelines for the AIE Vector dialect.
177
178/// Create a pass that removes unnecessary Copy operations.
179std::unique_ptr<::mlir::Pass> createCopyRemovalPass();
180
181// Create a pass that rewrites the arith dialect to enable the support of
182// dynamic sized tensor/memref for the auto-vectorization to CPP flow.
183std::unique_ptr<::mlir::Pass> createDynamicSizeNoImplicitBroadcastPass();
184
185// Build a pipeline for CLI access to the pass
186// `dynamic-size-no-implicit-broadcast`
187void buildDynamicSizeNoImplicitBroadcastPass(mlir::OpPassManager &pm);
188
189} // namespace aievec
190} // namespace xilinx
191
192#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.
void buildLowerVectorToAIEVec(mlir::OpPassManager &pm, const LowerVectorToAIEVecOptions &options)
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< 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:93
const LowerVectorToAIEVecOptions & getLowerVectorToAIEVecOptions() const
Definition Passes.h:136
PassOptions::Option< unsigned > dupFactor
Definition Passes.h:105
PassOptions::Option< std::string > aieTarget
Definition Passes.h:110
PassOptions::Option< std::string > targetBackend
Definition Passes.h:115
PassOptions::Option< unsigned > zeroOffset
Definition Passes.h:100
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:96
mlir::LogicalResult parseFromString(mlir::StringRef options)
Definition Passes.h:122
const CanonicalizeVectorForAIEVecOptions & getCanonicalizeVectorForAIEVecOptions() const
Definition Passes.h:141
const OptimizeAIEVecOptions & getOptimizeAIEVecOptions() const
Definition Passes.h:145
Options for the "lower-vector-to-aievec" pipeline.
Definition Passes.h:57
PassOptions::Option< std::string > aieTarget
Definition Passes.h:58
PassOptions::Option< std::string > targetBackend
Definition Passes.h:63
Options for the "optimize-aievec" pipeline.
Definition Passes.h:73
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:85
PassOptions::Option< std::string > targetBackend
Definition Passes.h:79
PassOptions::Option< std::string > aieTarget
Definition Passes.h:74