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