Add TFLite IR visitor skeleton (#274)
authorDmitry Mozolev/AI Tools Lab/Engineer/삼성전자 <d.mozolev@samsung.com>
Thu, 31 May 2018 13:03:45 +0000 (16:03 +0300)
committerSergey Vostokov/AI Tools Lab/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Thu, 31 May 2018 13:03:45 +0000 (16:03 +0300)
Add TFLite IR visitor skeleton

Adds skeleton for the TFLite IR visitor,
additionally saves pointers to some useful model contents.

Signed-off-by: Dmitry Mozolev <d.mozolev@samsung.com>
contrib/nnc/libs/frontend/tflite/CMakeLists.txt
contrib/nnc/libs/frontend/tflite/include/tflite_ir_visitor.h [new file with mode: 0644]
contrib/nnc/libs/frontend/tflite/src/tflite_ir_visitor.cpp [new file with mode: 0644]

index f7c2ce3..f48037c 100644 (file)
@@ -14,6 +14,7 @@ FlatBuffers_Generate(FB_GEN
 
 set(tflite_importer_sources ${CMAKE_CURRENT_SOURCE_DIR}/src/tflite_walker.cpp
                             ${CMAKE_CURRENT_SOURCE_DIR}/src/tflite_dump_visitor.cpp
+                            ${CMAKE_CURRENT_SOURCE_DIR}/src/tflite_ir_visitor.cpp
                             ${CMAKE_CURRENT_SOURCE_DIR}/src/tflite_v3_importer.cpp)
 file(GLOB tflite_importer_headers include/*.h)
 list(APPEND tflite_importer_headers ${FB_GEN_SOURCES})
diff --git a/contrib/nnc/libs/frontend/tflite/include/tflite_ir_visitor.h b/contrib/nnc/libs/frontend/tflite/include/tflite_ir_visitor.h
new file mode 100644 (file)
index 0000000..d339c4d
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef NNCC_TFLITE_IR_VISITOR_H
+#define NNCC_TFLITE_IR_VISITOR_H
+
+#include "flatbuffers/flatbuffers.h"
+
+#include "schema_v3.h"
+#include "tflite_visitor.h"
+
+using namespace v3_tflite;
+
+namespace nncc
+{
+namespace contrib
+{
+namespace frontend
+{
+namespace tflite
+{
+
+class IrVisitor : public Visitor
+{
+public:
+  void visit(const Model *) override;
+  void visit(const SubGraph *) override;
+  void visit(const Tensor *) override;
+  void visit(const OperatorCode *) override;
+  void visit(const Operator *) override;
+  void visit(const Buffer *) override;
+
+private:
+  const flatbuffers::Vector<flatbuffers::Offset<OperatorCode>> *opcodes = nullptr;
+  const flatbuffers::Vector<flatbuffers::Offset<Tensor>> *tensors = nullptr;
+  const flatbuffers::Vector<flatbuffers::Offset<Buffer>> *buffers = nullptr;
+};
+
+} // namespace tflite
+} // namespace frontend
+} // namespace contrib
+} // namespace nncc
+
+#endif // NNCC_TFLITE_IR_VISITOR_H
diff --git a/contrib/nnc/libs/frontend/tflite/src/tflite_ir_visitor.cpp b/contrib/nnc/libs/frontend/tflite/src/tflite_ir_visitor.cpp
new file mode 100644 (file)
index 0000000..8ce78c5
--- /dev/null
@@ -0,0 +1,41 @@
+#include <stdexcept>
+
+#include "tflite_ir_visitor.h"
+
+namespace nncc
+{
+namespace contrib
+{
+namespace frontend
+{
+namespace tflite
+{
+
+void IrVisitor::visit(const Model *m)
+{
+  opcodes = m->operator_codes();
+  buffers = m->buffers();
+
+  throw std::runtime_error{"Not yet implemented"};
+}
+
+void IrVisitor::visit(const SubGraph *s)
+{
+  tensors = s->tensors();
+
+  throw std::runtime_error{"Not yet implemented"};
+}
+
+void IrVisitor::visit(const Operator *op)
+{
+  throw std::runtime_error{"Not yet implemented"};
+}
+
+void IrVisitor::visit(const Tensor *t) { throw std::runtime_error{"Not yet implemented"}; }
+void IrVisitor::visit(const OperatorCode *) { throw std::runtime_error{"Not yet implemented"}; }
+void IrVisitor::visit(const Buffer *) { throw std::runtime_error{"Not yet implemented"}; }
+
+} // namespace tflite
+} // namespace frontend
+} // namespace contrib
+} // namespace nncc