Add nnc interpreter test main and test info schema (#869)
authorDmitry Mozolev/AI Tools Lab /SRR/Engineer/삼성전자 <d.mozolev@samsung.com>
Fri, 3 Aug 2018 14:18:15 +0000 (17:18 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Fri, 3 Aug 2018 14:18:15 +0000 (17:18 +0300)
Added nnc interpreter test main file a flatbuffers schema
describing NN operator parameters needed for testing.

Signed-off-by: Dmitry Mozolev <d.mozolev@samsung.com>
contrib/nnc/libs/backend/interpreter/CMakeLists.txt
contrib/nnc/libs/backend/interpreter/test/CMakeLists.txt [new file with mode: 0644]
contrib/nnc/libs/backend/interpreter/test/gen/op_info.fbs [new file with mode: 0644]
contrib/nnc/libs/backend/interpreter/test/src/main.cpp [new file with mode: 0644]

diff --git a/contrib/nnc/libs/backend/interpreter/test/CMakeLists.txt b/contrib/nnc/libs/backend/interpreter/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8db47d6
--- /dev/null
@@ -0,0 +1,31 @@
+nncc_find_package(FlatBuffers REQUIRED)
+
+# Compile flatbuffers schemas
+# Produces FB_GEN_SOURCES and FB_GEN_INCLUDE_DIRS variables
+set(GENERATED_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
+FlatBuffers_Generate(FB_GEN
+                     ${GENERATED_OUTPUT_DIR}
+                     ${CMAKE_CURRENT_SOURCE_DIR}/gen
+                     op_info.fbs)
+
+file(GLOB SOURCES src/*.cpp)
+file(GLOB HEADERS include/*.h)
+
+add_executable(interpreter_op_test ${SOURCES} ${HEADERS} ${FB_GEN_SOURCES})
+
+file(GLOB TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR}/test_data/*_data.fb)
+foreach(TEST_DATA_ITEM ${TEST_DATA})
+    get_filename_component(TEST_NAME ${TEST_DATA_ITEM} NAME_WE)
+    string(REPLACE "_data" "" TEST_NAME ${TEST_NAME})
+
+    add_test(NAME interpreter_${TEST_NAME}_test
+             COMMAND interpreter_op_test ${TEST_DATA_ITEM}
+             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+endforeach()
+
+target_include_directories(interpreter_op_test PRIVATE ${FB_GEN_INCLUDE_DIRS})
+target_include_directories(interpreter_op_test PRIVATE include)
+
+target_link_libraries(interpreter_op_test PRIVATE gtest flatbuffers
+                                                  nnc_core nncc_core nnc_interpreter_core
+                                                  nn_import_common)
diff --git a/contrib/nnc/libs/backend/interpreter/test/gen/op_info.fbs b/contrib/nnc/libs/backend/interpreter/test/gen/op_info.fbs
new file mode 100644 (file)
index 0000000..8be43fd
--- /dev/null
@@ -0,0 +1,52 @@
+namespace opinfo;
+
+file_extension "opinfo";
+
+enum OperatorType : byte {
+  FULLY_CONNECTED = 0,
+  CONV_2D,
+  DEPTHWISE_CONV_2D,
+  POOL_2D,
+  RESHAPE,
+  CONCATENATION,
+  RELU,
+  CAPPED_RELU,
+  BIAS_ADD,
+  SOFTMAX,
+}
+
+enum PadType : byte {
+  SAME,
+  VALID
+}
+
+enum PoolType : byte {
+  MAXPOOL,
+  AVGPOOL
+}
+
+table Shape {
+  dims:[int];
+}
+
+table Tensor {
+  shape:Shape;
+  data:[float];
+}
+
+table OperatorInfo {
+  op:OperatorType;
+  inputs:[Tensor];
+  kernels:[Tensor];
+  results:[Tensor];
+  padType:PadType;
+  poolType:PoolType;
+  shapes:[Shape];
+  axis:int;
+}
+
+table OperatorInfoList {
+  infos:[OperatorInfo];
+}
+
+root_type OperatorInfoList;
diff --git a/contrib/nnc/libs/backend/interpreter/test/src/main.cpp b/contrib/nnc/libs/backend/interpreter/test/src/main.cpp
new file mode 100644 (file)
index 0000000..df29589
--- /dev/null
@@ -0,0 +1,38 @@
+#include <string>
+#include <fstream>
+#include <memory>
+
+#include "gtest/gtest.h"
+#include "op_info_generated.h"
+
+using namespace opinfo;
+
+std::string opInfoBuf;
+const OperatorInfoList* list;
+
+static void readOpInfo(const std::string& filename)
+{
+  using istrbufiter = std::istreambuf_iterator<char>;
+
+  std::ifstream ifs(filename, std::ios::binary);
+
+  if (ifs.fail())
+  {
+    std::cout << "Problem with opening " << filename << std::endl;
+    exit(1);
+  }
+
+  opInfoBuf.assign((istrbufiter(ifs)), istrbufiter());
+}
+
+int main(int argc, char *argv[])
+{
+  if (argc <= 1)
+    return 1;
+
+  readOpInfo(std::string(argv[1]));
+  list = GetOperatorInfoList(reinterpret_cast<const void*>(opInfoBuf.c_str()));
+
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}