[enco] Introduce Andoird NN DataType enum (#1089)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 20 Aug 2018 07:21:02 +0000 (16:21 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 20 Aug 2018 07:21:02 +0000 (16:21 +0900)
This commit introduces Android NN DataType enum, which is a part of ANN
IR that enco internally uses.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/CMakeLists.txt
contrib/enco/core/src/ANN/IR/DType.cpp [new file with mode: 0644]
contrib/enco/core/src/ANN/IR/DType.h [new file with mode: 0644]
contrib/enco/core/src/ANN/IR/DType.test.cpp [new file with mode: 0644]

index e108102..ca42bd6 100644 (file)
@@ -1,4 +1,6 @@
 file(GLOB_RECURSE SOURCES "src/*.cpp")
+file(GLOB_RECURSE TESTS "src/*.test.cpp")
+list(REMOVE_ITEM SOURCES ${TESTS})
 
 add_library(enco_core STATIC ${SOURCES})
 set_target_properties(enco_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
@@ -6,3 +8,14 @@ target_include_directories(enco_core PRIVATE src)
 target_include_directories(enco_core PUBLIC include)
 target_link_libraries(enco_core coco_core)
 target_link_libraries(enco_core coco_generic)
+
+nncc_find_package(GTest QUIET)
+
+if(NOT GTest_FOUND)
+  return()
+endif(NOT GTest_FOUND)
+
+add_executable(enco_core_test ${TESTS})
+target_link_libraries(enco_core_test gtest_main)
+target_link_libraries(enco_core_test enco_core)
+add_test(enco_core_test enco_core_test)
diff --git a/contrib/enco/core/src/ANN/IR/DType.cpp b/contrib/enco/core/src/ANN/IR/DType.cpp
new file mode 100644 (file)
index 0000000..294c0a2
--- /dev/null
@@ -0,0 +1,9 @@
+#include "DType.h"
+
+namespace ann
+{
+
+template <> DType dtype<int32_t>(void) { return DType::S32; }
+template <> DType dtype<float>(void) { return DType::F32; }
+
+} // namespace ann
diff --git a/contrib/enco/core/src/ANN/IR/DType.h b/contrib/enco/core/src/ANN/IR/DType.h
new file mode 100644 (file)
index 0000000..4146cea
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __ANN_IR_DTYPE_H__
+#define __ANN_IR_DTYPE_H__
+
+#include <cstdint>
+
+namespace ann
+{
+
+enum class DType
+{
+  UNK,
+  S32,
+  F32
+};
+
+template <typename T> DType dtype(void);
+
+} // namespace ann
+
+#endif // __ANN_IR_DTYPE_H__
diff --git a/contrib/enco/core/src/ANN/IR/DType.test.cpp b/contrib/enco/core/src/ANN/IR/DType.test.cpp
new file mode 100644 (file)
index 0000000..63d14af
--- /dev/null
@@ -0,0 +1,9 @@
+#include "DType.h"
+
+#include <gtest/gtest.h>
+
+TEST(ANN_IR_DTYPE, dtype)
+{
+  ASSERT_EQ(ann::dtype<int>(), ann::DType::S32);
+  ASSERT_EQ(ann::dtype<float>(), ann::DType::F32);
+}