Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / compiler / LoweredGraph.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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 __ONERT_COMPILER_LOWERED_GRAPH_H__
18 #define __ONERT_COMPILER_LOWERED_GRAPH_H__
19
20 #include "compiler/BackendResolver.h"
21 #include "compiler/Compiler.h"
22 #include "compiler/GraphLowerInfo.h"
23 #include "compiler/ILoweredGraph.h"
24 #include "ir/Graph.h"
25
26 namespace onert
27 {
28 namespace compiler
29 {
30
31 /**
32  * @brief Class that contains lowering information on graph.
33  *        In addition, after lowering, operands in graph will be set to "dynamic"
34  *        if the shape of output of an operation cannot be decided at compilation time.
35  */
36 class LoweredGraph : public ILoweredGraph
37 {
38 public:
39   LoweredGraph(const ir::Graph &graph, const compiler::CompilerOptions &options);
40
41   ir::Graph &graph() override { return _graph; }
42   const ir::Graph &graph() const override { return _graph; }
43   const compiler::GraphLowerInfo &lower_info() const override { return _lower_info_map; }
44   compiler::GraphLowerInfo &lower_info() override { return _lower_info_map; }
45   std::shared_ptr<ir::OperationIndexMap<int64_t>> indexed_ranks() { return _indexed_ranks; }
46
47   void setHasDynamicTensor(ir::OperationIndex ind, bool val) override
48   {
49     _has_dynamic_tensor_map.emplace(ind, val);
50   }
51   bool getHasDynamicTensor(ir::OperationIndex ind) const override
52   {
53     auto itr = _has_dynamic_tensor_map.find(ind);
54     return (itr == _has_dynamic_tensor_map.end()) ? false : itr->second;
55   }
56
57 private:
58   void makeLowerInfo(const compiler::BackendResolver &backend_resolver);
59   void dumpLowerInfo();
60   void lowerGraph(const compiler::CompilerOptions &options);
61
62 private:
63   /**
64    *  @brief  Copy of target graph for lowering
65    *  @note   It uses copy of graph, not reference.
66    *          It allows the original graph can be compiled multiple times.
67    */
68   ir::Graph _graph;
69   std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
70   compiler::GraphLowerInfo _lower_info_map;
71   ir::OperationIndexMap<bool> _has_dynamic_tensor_map;
72 };
73
74 } // namespace compiler
75 } // namespace onert
76
77 #endif // __ONERT_COMPILER_LOWERED_GRAPH_H__