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_DRAWER_H_ 18 #define MINDSPORE_LITE_SRC_COMMON_DRAW_DRAWER_H_ 19 20 #include <string> 21 22 #include "src/executor/sub_graph_kernel.h" 23 24 #ifdef ENABLE_CLOUD_INFERENCE 25 #include "src/extendrt/graph_compiler/compile_result.h" 26 #endif 27 28 namespace mindspore { 29 namespace lite { 30 class Drawer { 31 public: Instance()32 static Drawer &Instance() { 33 static Drawer instance; 34 return instance; 35 } 36 37 void Init(); 38 39 void Reset(); 40 41 std::string GetNextFileName(const std::string &name); 42 43 void Draw(const kernel::SubGraphKernel *graph, const std::string &name = ""); 44 #ifdef ENABLE_CLOUD_INFERENCE 45 void Draw(const CompileResult *graph, const std::string &name = ""); 46 #endif 47 48 private: 49 Drawer() = default; 50 bool SaveDotFile(const std::string &dot_name, const std::string &dot_content); 51 52 bool enabled_{false}; 53 std::string base_dir_; 54 size_t count_{0}; 55 }; 56 } // namespace lite 57 58 #if (defined Debug) && (defined ENABLE_DRAW) 59 #define InitDotDrawer() mindspore::lite::Drawer::Instance().Init() 60 #define DrawDot(graph, name) mindspore::lite::Drawer::Instance().Draw(graph, name) 61 #else 62 #define InitDotDrawer() 63 #define DrawDot(graph, name) 64 #endif 65 } // namespace mindspore 66 67 #endif // MINDSPORE_LITE_SRC_COMMON_DRAW_DRAWER_H_ 68