• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-2023 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_CORE_UTILS_InterpretNodeRecorder_H_
18 #define MINDSPORE_CORE_UTILS_InterpretNodeRecorder_H_
19 
20 #include "ir/anf.h"
21 #include "utils/hash_set.h"
22 #include "mindapi/base/macros.h"
23 
24 namespace mindspore {
25 class MS_CORE_API InterpretNodeRecorder {
26  public:
27   explicit InterpretNodeRecorder(InterpretNodeRecorder &&) = delete;
28   explicit InterpretNodeRecorder(const InterpretNodeRecorder &) = delete;
29   InterpretNodeRecorder &operator=(const InterpretNodeRecorder &) = delete;
30   InterpretNodeRecorder &operator=(InterpretNodeRecorder &&) = delete;
31   static InterpretNodeRecorder &GetInstance();
32 
PushPyInterpretNode(const AnfNodePtr & node)33   void PushPyInterpretNode(const AnfNodePtr &node) { (void)py_interpret_nodes_.emplace(node); }
PyInterpretNodes()34   const mindspore::HashSet<AnfNodePtr> &PyInterpretNodes() const { return py_interpret_nodes_; }
35 
PushPyExecuteNode(const AnfNodePtr & node)36   void PushPyExecuteNode(const AnfNodePtr &node) {
37     const auto &cnode = dyn_cast<CNode>(node);
38     MS_EXCEPTION_IF_NULL(cnode);
39     (void)cnode->inputs();  // Bind its inputs node.
40     (void)py_execute_nodes_.emplace(node);
41   }
PyExecuteNodes()42   const mindspore::HashSet<AnfNodePtr> &PyExecuteNodes() const { return py_execute_nodes_; }
43 
Clear()44   void Clear() {
45     py_interpret_nodes_.clear();
46     py_execute_nodes_.clear();
47   }
48 
49  protected:
50   InterpretNodeRecorder() = default;
51   virtual ~InterpretNodeRecorder() = default;
52 
53  private:
54   mindspore::HashSet<AnfNodePtr> py_interpret_nodes_;
55   mindspore::HashSet<AnfNodePtr> py_execute_nodes_;
56 };
57 }  // namespace mindspore
58 #endif  // MINDSPORE_CORE_UTILS_InterpretNodeRecorder_H_
59