MLIR-AIE 1.4.5.dev
Passes.h
Go to the documentation of this file.
1//===- Passes.h - AIE Vector pipeline entry points --------------*- C++ -*-===//
2//
3// Copyright (C) 2022 Xilinx, Inc.
4// Copyright (C) 2022-2026 Advanced Micro Devices, Inc.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This header file defines prototypes of all AIE vector pipelines.
10//
11//===----------------------------------------------------------------------===//
12#ifndef AIE_DIALECT_AIEVEC_PIPELINES_PASSES_H
13#define AIE_DIALECT_AIEVEC_PIPELINES_PASSES_H
14
15#include "mlir/Pass/Pass.h"
16#include "mlir/Pass/PassOptions.h"
17
18namespace xilinx {
19enum class AIEArch {
20 AIE, // Original AIE
21 AIE2, // AIE-ML/V2 arch version of AIE
22 AIE2P, // AIE2P arch version of AIE
23 UNKNOWN // Unsupported/Unknown backend
24};
25} // namespace xilinx
26
27namespace xilinx {
28namespace aievec {
29
30// TODO: Create a common base class for all AIEVec pipeline options.
31
32/// Options for the "canonicalize-vector-for-aievec" pipeline.
34 : public mlir::PassPipelineOptions<CanonicalizeVectorForAIEVecOptions> {
35 PassOptions::Option<std::string> aieTarget{
36 *this, "aie-target",
37 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
38 "determine the vector size and available operations."),
39 llvm::cl::init("aie")};
40 PassOptions::Option<bool> enableBF16Emulation{
41 *this, "bf16-emulation",
42 llvm::cl::desc(
43 "Run f32 vector arithmetic on the bf16 datapath: multiplies and "
44 "transcendentals take inputs rounded to bf16, sums stay f32."),
45 llvm::cl::init(false)};
46};
47
48/// Options for the "lower-vector-to-aievec" pipeline.
50 : public mlir::PassPipelineOptions<LowerVectorToAIEVecOptions> {
51 PassOptions::Option<std::string> aieTarget{
52 *this, "aie-target",
53 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
54 "determine the vector size and available operations."),
55 llvm::cl::init("aie")};
56};
57
58/// Options for the "optimize-aievec" pipeline.
60 : public mlir::PassPipelineOptions<OptimizeAIEVecOptions> {
61 PassOptions::Option<std::string> aieTarget{
62 *this, "aie-target",
63 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
64 "determine the vector size and available operations."),
65 llvm::cl::init("aie")};
66 PassOptions::Option<unsigned> shiftParam{
67 *this, "shift",
68 llvm::cl::desc("Shift parameter for rounding and saturation"),
69 llvm::cl::init(0)};
70};
71
72/// Options for the "convert-vector-to-aievec" pipeline.
74 : public mlir::PassPipelineOptions<ConvertVectorToAIEVecOptions> {
75 // 'LowerVectorToAIEVec' options
76 // TODO: Review the need for these options.
77 PassOptions::Option<unsigned> shiftParam{
78 *this, "shift",
79 llvm::cl::desc("Shift parameter for rounding and saturation"),
80 llvm::cl::init(0)};
81 PassOptions::Option<unsigned> zeroOffset{
82 *this, "zero-offset",
83 llvm::cl::desc("Zero offset for indicating the location of zeroes in "
84 "convolution filter (useful for 16x16 scheme)"),
85 llvm::cl::init(0)};
86 PassOptions::Option<unsigned> dupFactor{
87 *this, "dup-actor",
88 llvm::cl::desc("Duplication factor for each value in convolution filter "
89 "(useful in 8x8 scheme)"),
90 llvm::cl::init(2)};
91 PassOptions::Option<std::string> aieTarget{
92 *this, "aie-target",
93 llvm::cl::desc("Select AIE version: \"aie\" or \"aie2\". This will "
94 "determine the vector size and available operations."),
95 llvm::cl::init("aie")};
96 PassOptions::Option<bool> enableBF16Emulation{
97 *this, "bf16-emulation",
98 llvm::cl::desc(
99 "Run f32 vector arithmetic on the bf16 datapath: multiplies and "
100 "transcendentals take inputs rounded to bf16, sums stay f32."),
101 llvm::cl::init(false)};
102
103 mlir::LogicalResult parseFromString(mlir::StringRef options) {
104 auto res = PassPipelineOptions::parseFromString(options);
105 if (!failed(res)) {
106 lowerOptions.aieTarget = aieTarget;
107 canonicalizeOptions.aieTarget = aieTarget;
108 canonicalizeOptions.enableBF16Emulation = enableBF16Emulation;
109 optimizeOptions.aieTarget = aieTarget;
110 optimizeOptions.shiftParam = shiftParam;
111 }
112 return res;
113 }
114
116 return lowerOptions;
117 }
118
121 return canonicalizeOptions;
122 }
123
125 return optimizeOptions;
126 }
127
128private:
129 CanonicalizeVectorForAIEVecOptions canonicalizeOptions;
130 LowerVectorToAIEVecOptions lowerOptions;
131 OptimizeAIEVecOptions optimizeOptions;
132};
133
134//===----------------------------------------------------------------------===//
135// Building and Registering.
136//===----------------------------------------------------------------------===//
137
138/// Adds the "convert-vector-to-aievec" pipeline to the `OpPassManager`. This
139/// pipeline takes `Vector` code, transforms it to make it compatible with the
140/// selected `AIE` target, lowers it to `AIEVec` dialect, and performs some
141/// optimizations based on the target AIE architecture.
142void buildConvertVectorToAIEVec(mlir::OpPassManager &pm,
143 const ConvertVectorToAIEVecOptions &options);
144
146 mlir::OpPassManager &pm, const CanonicalizeVectorForAIEVecOptions &options);
147
148void buildLowerVectorToAIEVec(mlir::OpPassManager &pm,
149 const LowerVectorToAIEVecOptions &options);
150
151void buildOptimizeAIEVec(mlir::OpPassManager &pm,
152 const OptimizeAIEVecOptions &options);
153
154/// Register all pipelines for the AIE Vector dialect.
156
157/// Create a pass that removes unnecessary Copy operations.
158std::unique_ptr<::mlir::Pass> createCopyRemovalPass();
159
160// Create a pass that rewrites the arith dialect to enable the support of
161// dynamic sized tensor/memref for the auto-vectorization to CPP flow.
162std::unique_ptr<::mlir::Pass> createDynamicSizeNoImplicitBroadcastPass();
163
164// Build a pipeline for CLI access to the pass
165// `dynamic-size-no-implicit-broadcast`
166void buildDynamicSizeNoImplicitBroadcastPass(mlir::OpPassManager &pm);
167
168/// Create a pass that splits vector.load + aievec.ups chains to reduce shuffle
169/// operations for AIE2p targets.
170std::unique_ptr<::mlir::Pass> createSplitVectorLoadUpsChainsPass();
171
172/// Create a pass that runs f32 vector arithmetic on the bf16 datapath:
173/// multiplies and transcendentals take inputs rounded to bf16, sums stay f32.
174std::unique_ptr<::mlir::Pass> createBF16EmulationPass();
175
176} // namespace aievec
177} // namespace xilinx
178
179#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 runs f32 vector arithmetic on the bf16 datapath: multiplies and transcendentals ta...
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)
AIEArch
Definition Passes.h:19
Options for the "canonicalize-vector-for-aievec" pipeline.
Definition Passes.h:34
PassOptions::Option< bool > enableBF16Emulation
Definition Passes.h:40
PassOptions::Option< std::string > aieTarget
Definition Passes.h:35
Options for the "convert-vector-to-aievec" pipeline.
Definition Passes.h:74
const LowerVectorToAIEVecOptions & getLowerVectorToAIEVecOptions() const
Definition Passes.h:115
PassOptions::Option< unsigned > dupFactor
Definition Passes.h:86
PassOptions::Option< std::string > aieTarget
Definition Passes.h:91
PassOptions::Option< unsigned > zeroOffset
Definition Passes.h:81
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:77
mlir::LogicalResult parseFromString(mlir::StringRef options)
Definition Passes.h:103
const CanonicalizeVectorForAIEVecOptions & getCanonicalizeVectorForAIEVecOptions() const
Definition Passes.h:120
PassOptions::Option< bool > enableBF16Emulation
Definition Passes.h:96
const OptimizeAIEVecOptions & getOptimizeAIEVecOptions() const
Definition Passes.h:124
Options for the "lower-vector-to-aievec" pipeline.
Definition Passes.h:50
PassOptions::Option< std::string > aieTarget
Definition Passes.h:51
Options for the "optimize-aievec" pipeline.
Definition Passes.h:60
PassOptions::Option< unsigned > shiftParam
Definition Passes.h:66
PassOptions::Option< std::string > aieTarget
Definition Passes.h:61