[nnc] DotDumperPass (#2960)
authorАндрей Шедько/AI Tools Lab /SRR/Engineer/삼성전자 <a.shedko@samsung.com>
Tue, 29 Jan 2019 20:11:49 +0000 (23:11 +0300)
committerEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Tue, 29 Jan 2019 20:11:49 +0000 (23:11 +0300)
Introduce dotDumper pass for dumping the Model graph after optimizations
in dot format

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
contrib/nnc/driver/Driver.cpp
contrib/nnc/include/passes/dot_dumper/DumperPass.h [new file with mode: 0644]
contrib/nnc/passes/CMakeLists.txt
contrib/nnc/passes/dot_dumper/CMakeLists.txt [new file with mode: 0644]
contrib/nnc/passes/dot_dumper/DumperPass.cpp [new file with mode: 0644]

index 28c73fe..2d641cf 100644 (file)
@@ -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 (file)
index 0000000..c1c603e
--- /dev/null
@@ -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
index 74a46dd..1fa2195 100644 (file)
@@ -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 (file)
index 0000000..fd77365
--- /dev/null
@@ -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 (file)
index 0000000..9ee1328
--- /dev/null
@@ -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 <fstream>
+#include <fstream>
+
+namespace nnc {
+
+using namespace mir;
+int DumperPass::_counter = 0;
+
+PassData DumperPass::run(PassData data) {
+  auto g = static_cast<Graph*>(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