From: Андрей Шедько/AI Tools Lab /SRR/Engineer/삼성전자 Date: Tue, 29 Jan 2019 20:11:49 +0000 (+0300) Subject: [nnc] DotDumperPass (#2960) X-Git-Tag: nncc_backup~905 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4216144dfc650774ed2fbe2a81fdb0ca0e5cace1;p=platform%2Fcore%2Fml%2Fnnfw.git [nnc] DotDumperPass (#2960) Introduce dotDumper pass for dumping the Model graph after optimizations in dot format Signed-off-by: Andrei Shedko --- diff --git a/contrib/nnc/driver/Driver.cpp b/contrib/nnc/driver/Driver.cpp index 28c73fe..2d641cf 100644 --- a/contrib/nnc/driver/Driver.cpp +++ b/contrib/nnc/driver/Driver.cpp @@ -20,6 +20,7 @@ #include "passes/interpreter/InterpreterPass.h" #include "passes/soft_backend/CPPGenerator.h" +#include "passes/dot_dumper/DumperPass.h" #include "passes/acl_soft_backend/AclCppGenerator.h" #include "support/CommandLine.h" #include "Definitions.h" diff --git a/contrib/nnc/include/passes/dot_dumper/DumperPass.h b/contrib/nnc/include/passes/dot_dumper/DumperPass.h new file mode 100644 index 0000000..c1c603e --- /dev/null +++ b/contrib/nnc/include/passes/dot_dumper/DumperPass.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NNCC_DUMPERPASS_H +#define NNCC_DUMPERPASS_H + +#include "pass/Pass.h" +#include "pass/PassData.h" +#include "core/modelIR/IrDotDumper.h" + +namespace nnc { + +/** + * @brief Dumps the graph to a dot file named %number%.dot + * where %number% is how many times the graph was dumped. + */ +class DumperPass : public Pass { +public: + + PassData run(PassData data) override; + +private: + static int _counter; +}; + +} // namespace nnc +#endif //NNCC_DUMPERPASS_H diff --git a/contrib/nnc/passes/CMakeLists.txt b/contrib/nnc/passes/CMakeLists.txt index 74a46dd..1fa2195 100644 --- a/contrib/nnc/passes/CMakeLists.txt +++ b/contrib/nnc/passes/CMakeLists.txt @@ -3,6 +3,7 @@ # set(DEF_CONV ${NNC_ROOT_SRC_DIR}/utils/def2src.cpp) add_executable(def2src ${DEF_CONV}) +add_subdirectory(dot_dumper) # # FRONTENDs diff --git a/contrib/nnc/passes/dot_dumper/CMakeLists.txt b/contrib/nnc/passes/dot_dumper/CMakeLists.txt new file mode 100644 index 0000000..fd77365 --- /dev/null +++ b/contrib/nnc/passes/dot_dumper/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB_RECURSE DUMPER_SRC ./*.cpp ./*.h) +nnc_add_library(nnc_dumper SHARED ${DUMPER_SRC}) +target_link_libraries(nnc_dumper PRIVATE nnc_core nnc_support) + +# install dumper library +nnc_install_library(nnc_dumper) diff --git a/contrib/nnc/passes/dot_dumper/DumperPass.cpp b/contrib/nnc/passes/dot_dumper/DumperPass.cpp new file mode 100644 index 0000000..9ee1328 --- /dev/null +++ b/contrib/nnc/passes/dot_dumper/DumperPass.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "passes/dot_dumper/DumperPass.h" +#include "core/modelIR/Graph.h" +#include "pass/PassException.h" + +#include +#include + +namespace nnc { + +using namespace mir; +int DumperPass::_counter = 0; + +PassData DumperPass::run(PassData data) { + auto g = static_cast(data); + assert(g); + IrDotDumper dotDumper; + g->accept(&dotDumper); + std::ofstream f_out; + f_out.open(std::to_string(_counter) + ".dot"); + dotDumper.writeDot(f_out); + f_out.close(); + + _counter++; + return g; +} + +} // namespace nnc