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 17 #ifndef MINDSPORE_LITE_SRC_COMMON_DRAW_GRAPHVIZ_GRAPH_BUILDER_H_ 18 #define MINDSPORE_LITE_SRC_COMMON_DRAW_GRAPHVIZ_GRAPH_BUILDER_H_ 19 20 #include <utility> 21 #include <vector> 22 #include <string> 23 #include <memory> 24 #include <unordered_map> 25 #include "src/common/log_adapter.h" 26 #include "src/common/draw/graphviz_graph.h" 27 #include "src/common/draw/adapter_graph.h" 28 #include "src/tensor.h" 29 #include "include/errorcode.h" 30 31 namespace mindspore::lite { 32 class GVGraphBuilder { 33 public: 34 std::shared_ptr<GVGraph> Build(const std::shared_ptr<AdapterGraph> &graph); 35 36 void AppendGraphInputNode(const lite::Tensor &tensor); 37 void AppendWeightNode(const lite::Tensor &tensor, const std::string &id, const std::string &label); 38 int AppendComputeNode(const AdapterNode &node); 39 int AppendGraphOutputNode(const std::vector<lite::Tensor *> &out_tensors); 40 41 protected: 42 static GVNode *CreateComputeNode(const AdapterNode &node); 43 int LinkNodes(const AdapterNode &node, const GVNode &gv_node); 44 void AppendOutTensorMap(const lite::Tensor *tensor, lite::GVNode *node, size_t out_index); 45 std::pair<lite::GVNode *, size_t> GetBelongingGVNode(const lite::Tensor *tensor) const; 46 47 std::shared_ptr<GVGraph> gv_graph_{nullptr}; 48 std::string name_; 49 std::unordered_map<const lite::Tensor *, std::pair<lite::GVNode *, size_t>> gv_node_out_tensor_map_; 50 }; 51 } // namespace mindspore::lite 52 53 #endif // MINDSPORE_LITE_SRC_COMMON_DRAW_GRAPHVIZ_GRAPH_BUILDER_H_ 54