-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathpass_manager.h
54 lines (43 loc) · 1.62 KB
/
pass_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
// ATTENTION: The code in this file is highly EXPERIMENTAL.
// Adventurous users should note that the APIs will probably change.
#include <vector>
#include "onnxoptimizer/pass.h"
namespace ONNX_NAMESPACE {
namespace optimization {
// An analysis returned from the run done by a manager
struct PassManagerAnalysis {};
struct EmptyPassManagerAnalysis : PassManagerAnalysis {};
// Base class of all PassManager's. The class should be able to add new passes
// as well as run the passes given a graph.
class PassManager {
public:
PassManager();
virtual ~PassManager();
virtual void add(std::shared_ptr<Pass> P) = 0;
virtual std::shared_ptr<PassManagerAnalysis> run(Graph& graph) = 0;
};
// The GeneralPassManager has no restriction on type of Pass and runs the passes
// once in a linear fashion.
class GeneralPassManager : public PassManager {
public:
GeneralPassManager() {}
~GeneralPassManager() override;
void add(std::shared_ptr<Pass> pass) override;
std::shared_ptr<PassManagerAnalysis> run(Graph& graph) override;
protected:
// use vector here to ensure the order of the passes
// for some pass, order is critical, for example,
// split_init and split_predict should be the last in the list
std::vector<std::shared_ptr<Pass>> passes;
};
// Exhibits the same behavior as GeneralPassManager but will instead check
// whether or not fixed point optimization is needed.
class FixedPointPassManager : public GeneralPassManager {
std::shared_ptr<PassManagerAnalysis> run(Graph& graph) override;
};
} // namespace optimization
} // namespace ONNX_NAMESPACE