Add bindacl project to use ACL from NNAPI (#114)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 21 Mar 2018 23:32:41 +0000 (08:32 +0900)
committer서상민/동작제어Lab(SR)/Senior Engineer/삼성전자 <sangmin7.seo@samsung.com>
Wed, 21 Mar 2018 23:32:41 +0000 (08:32 +0900)
This will introduce bindacl project to enable binding of ACL from NNAPI
This patch is a copy of logging without logging and does not include ACL for staring point

CMakeLists.txt
experiments/CMakeLists.txt [new file with mode: 0644]
experiments/bindacl/CMakeLists.txt [new file with mode: 0644]
experiments/bindacl/README.md [new file with mode: 0644]
experiments/bindacl/src/nnapi_acl.cc [new file with mode: 0644]

index 88019ea..3ef0293 100644 (file)
@@ -69,3 +69,4 @@ endforeach()
 add_subdirectory(externals)
 add_subdirectory(tools)
 add_subdirectory(src)
+add_subdirectory(experiments)
diff --git a/experiments/CMakeLists.txt b/experiments/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c614e75
--- /dev/null
@@ -0,0 +1 @@
+add_subdirectory(bindacl)
diff --git a/experiments/bindacl/CMakeLists.txt b/experiments/bindacl/CMakeLists.txt
new file mode 100644 (file)
index 0000000..444e8d8
--- /dev/null
@@ -0,0 +1,10 @@
+file(GLOB_RECURSE NNAPI_BINDACL_SRCS "src/*.cc")
+
+# TODO: fix nnapi.h location
+set(NNAPI_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/tools/nnapi_bindings/include)
+
+add_library(exp_bindacl SHARED ${NNAPI_BINDACL_SRCS})
+target_include_directories(exp_bindacl PUBLIC ${NNAPI_INCLUDE_DIR})
+
+# we need the library name to be 'neuralnetworks' and this will do the trick
+set_target_properties(exp_bindacl PROPERTIES OUTPUT_NAME neuralnetworks)
diff --git a/experiments/bindacl/README.md b/experiments/bindacl/README.md
new file mode 100644 (file)
index 0000000..8587d89
--- /dev/null
@@ -0,0 +1,13 @@
+Build
+```
+CROSS_BUILD=1 TARGET_ARCH=armv7l make
+CROSS_BUILD=1 TARGET_ARCH=armv7l make install
+```
+
+Test
+```
+USE_NNAPI=1 \
+LD_LIBRARY_PATH="$(pwd)/Product/obj/experiments/bindacl" \
+Product/out/bin/tflite_run \
+[T/F Lite Flatbuffer Model Path]
+```
diff --git a/experiments/bindacl/src/nnapi_acl.cc b/experiments/bindacl/src/nnapi_acl.cc
new file mode 100644 (file)
index 0000000..8e21858
--- /dev/null
@@ -0,0 +1,160 @@
+#include <nnapi.h>
+#include <stdexcept>
+#include <iostream>
+#include <string>
+#include <map>
+#include <cassert>
+#include <boost/format.hpp>
+
+//
+// Asynchronous Event
+//
+struct ANeuralNetworksEvent
+{
+};
+
+ResultCode ANeuralNetworksEvent_wait(ANeuralNetworksEvent* event)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksEvent_free(ANeuralNetworksEvent* event)
+{
+  delete event;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+//
+// Memory
+//
+struct ANeuralNetworksMemory
+{
+  // 1st approach - Store all the data inside ANeuralNetworksMemory object
+  // 2nd approach - Store metadata only, and defer data loading as much as possible
+};
+
+ResultCode ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset, ANeuralNetworksMemory** memory)
+{
+  *memory = new ANeuralNetworksMemory;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksMemory_free(ANeuralNetworksMemory* memory)
+{
+  delete memory;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+//
+// Model
+//
+struct ANeuralNetworksModel
+{
+  // ANeuralNetworksModel should be a factory for Graph IR (a.k.a ISA Frontend)
+  // TODO Record # of operands
+  uint32_t numOperands;
+
+  ANeuralNetworksModel() : numOperands(0)
+  {
+    // DO NOTHING
+  }
+};
+
+ResultCode ANeuralNetworksModel_create(ANeuralNetworksModel** model)
+{
+  *model = new ANeuralNetworksModel;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_free(ANeuralNetworksModel* model)
+{
+  delete model;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_addOperand(ANeuralNetworksModel* model, const ANeuralNetworksOperandType *type)
+{
+  model->numOperands += 1;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index, const void* buffer, size_t length)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel* model, int32_t index, const ANeuralNetworksMemory* memory, size_t offset, size_t length)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_addOperation(ANeuralNetworksModel* model, ANeuralNetworksOperationType type, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksModel_finish(ANeuralNetworksModel* model)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+//
+// Compilation
+//
+struct ANeuralNetworksCompilation
+{
+  // ANeuralNetworksCompilation should hold a compiled IR
+};
+
+ResultCode ANeuralNetworksCompilation_create(ANeuralNetworksModel* model, ANeuralNetworksCompilation** compilation)
+{
+  *compilation = new ANeuralNetworksCompilation;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation* compilation)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+//
+// Execution
+//
+struct ANeuralNetworksExecution
+{
+  // ANeuralNetworksExecution corresponds to NPU::Interp::Session
+};
+
+ResultCode ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution)
+{
+  *execution = new ANeuralNetworksExecution;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+// ANeuralNetworksExecution_setInput and ANeuralNetworksExecution_setOutput specify HOST buffer for input/output
+ResultCode ANeuralNetworksExecution_setInput(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const void* buffer, size_t length)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const void* buffer, size_t length)
+{
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event)
+{
+  *event = new ANeuralNetworksEvent;
+  return ANEURALNETWORKS_NO_ERROR;
+}
+
+ResultCode ANeuralNetworksExecution_free(ANeuralNetworksExecution* execution)
+{
+  delete execution;
+  return ANEURALNETWORKS_NO_ERROR;
+}