• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_
18 #define MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include "include/lite_utils.h"
24 
25 namespace mindspore {
26 namespace registry {
27 class PassBase;
28 using PassBasePtr = std::shared_ptr<PassBase>;
29 /// \brief PassPosition defined where to place user's pass.
30 enum MS_API PassPosition { POSITION_BEGIN = 0, POSITION_END = 1 };
31 
32 /// \brief PassRegistry defined registration of Pass.
33 class MS_API PassRegistry {
34  public:
35   /// \brief Constructor of PassRegistry to register pass.
36   ///
37   /// \param[in] pass_name Define the name of the pass, a string which should guarantee uniqueness.
38   /// \param[in] pass Define pass instance.
39   PassRegistry(const std::string &pass_name, const PassBasePtr &pass);
40 
41   /// \brief Constructor of PassRegistry to assign which passes are required for external extension.
42   ///
43   /// \param[in] position Define the place where assigned passes will run.
44   /// \param[in] names Define the names of the passes.
45   PassRegistry(PassPosition position, const std::vector<std::string> &names);
46 
47   /// \brief Destructor of PassRegistrar.
48   ~PassRegistry() = default;
49 
50   /// \brief Static method to obtain external scheduling task assigned by user.
51   ///
52   /// \param[in] position Define the place where assigned passes will run.
53   ///
54   /// \return Passes' Name Vector.
55   static std::vector<std::string> GetOuterScheduleTask(PassPosition position);
56 
57   /// \brief Static method to obtain pass instance according to passes' name.
58   ///
59   /// \param[in] pass_names Define the name of pass.
60   ///
61   /// \return Pass Instance Vector.
62   static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name);
63 };
64 
65 /// \brief Defined registering macro to register Pass, which called by user directly.
66 ///
67 /// \param[in] name Define the name of the pass, a string which should guarantee uniqueness.
68 /// \param[in] pass Define pass instance.
69 #define REG_PASS(name, pass) \
70   static mindspore::registry::PassRegistry g_##name##PassReg(#name, std::make_shared<pass>());
71 
72 /// \brief Defined assigning macro to assign Passes, which called by user directly.
73 ///
74 /// \param[in] position Define the place where assigned passes will run.
75 /// \param[in] names Define the names of the passes.
76 #define REG_SCHEDULED_PASS(position, names) static mindspore::registry::PassRegistry g_##position(position, names);
77 }  // namespace registry
78 }  // namespace mindspore
79 
80 #endif  // MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_
81