• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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 #ifndef MINDSPORE_PI_JIT_ALLOCATOR_H
17 #define MINDSPORE_PI_JIT_ALLOCATOR_H
18 
19 #include <utility>
20 #include <vector>
21 #include "pipeline/jit/pi/graph_capture/node.h"
22 
23 namespace mindspore {
24 namespace pijit {
25 
26 class Instr;
27 class LoopInfo;
28 class Allocator {
29  public:
30   Allocator() = default;
31   ~Allocator();
32 
instr_pool()33   const std::vector<Instr *> &instr_pool() const { return instr_pool_; }
node_pool()34   const std::vector<AbstractNode *> &node_pool() const { return node_pool_; }
35 
36   InstrNode *NewInstrNode(int op, int arg);
37   ValueNode *NewValueNode(AObject *a, int b, int c, const std::vector<ValueNode *> &d);
38 
39   template <class T, typename... Args>
NewNode(Args &&...args)40   T *NewNode(Args &&... args) {
41     T *v = new T(std::forward<Args>(args)...);
42     AddNodePool(v);
43     return v;
44   }
45 
46   template <class T, typename... Args>
NewInstr(Args &&...args)47   T *NewInstr(Args &&... args) {
48     T *v = new T(std::forward<Args>(args)...);
49     AddInstrPool(v);
50     return v;
51   }
52 
53   template <class T, typename... Args>
NewLoopInfo(Args &&...args)54   T *NewLoopInfo(Args &&... args) {
55     T *v = new T(std::forward<Args>(args)...);
56     AddLoopPool(v);
57     return v;
58   }
59 
60  private:
AddInstrPool(Instr * v)61   void AddInstrPool(Instr *v) { instr_pool_.push_back(v); }
AddNodePool(AbstractNode * v)62   void AddNodePool(AbstractNode *v) { node_pool_.push_back(v); }
AddLoopPool(LoopInfo * v)63   void AddLoopPool(LoopInfo *v) { loop_pool_.push_back(v); }
64 
65   std::vector<Instr *> instr_pool_;
66   std::vector<AbstractNode *> node_pool_;
67   std::vector<LoopInfo *> loop_pool_;
68 };
69 }  // namespace pijit
70 }  // namespace mindspore
71 
72 #endif  // MINDSPORE_PI_JIT_ALLOCATOR_H
73