Update aclbind experiment to link with acl (#150)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 23 Mar 2018 00:00:25 +0000 (09:00 +0900)
committer서상민/동작제어Lab(SR)/Senior Engineer/삼성전자 <sangmin7.seo@samsung.com>
Fri, 23 Mar 2018 00:00:25 +0000 (09:00 +0900)
* aclbind experiment to link with acl

This will update aclbind experiment program to link with current ACL

experiments/CMakeLists.txt
experiments/bindacl/CMakeLists.txt
experiments/bindacl/README.md
experiments/bindacl/src/nnapi_acl.cc

index c614e75..546fe2f 100644 (file)
@@ -1 +1,3 @@
-add_subdirectory(bindacl)
+if(${TARGET_ARCH_BASE} STREQUAL "arm")
+  add_subdirectory(bindacl)
+endif()
index 444e8d8..6943137 100644 (file)
@@ -3,8 +3,19 @@ file(GLOB_RECURSE NNAPI_BINDACL_SRCS "src/*.cc")
 # TODO: fix nnapi.h location
 set(NNAPI_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/tools/nnapi_bindings/include)
 
+# TODO: fix acl location
+set(ACL_DIR ${CMAKE_SOURCE_DIR}/externals/acl)
+
+set(ACL_INCLUDES ${ACL_DIR}
+                 ${ACL_DIR}/include)
+set(ACL_LIBS arm_compute_graph arm_compute arm_compute_core)
+
+link_directories(${CMAKE_INSTALL_PREFIX}/lib)
+
 add_library(exp_bindacl SHARED ${NNAPI_BINDACL_SRCS})
-target_include_directories(exp_bindacl PUBLIC ${NNAPI_INCLUDE_DIR})
+target_include_directories(exp_bindacl PUBLIC ${NNAPI_INCLUDE_DIR}
+                                              ${ACL_INCLUDES})
+target_link_libraries(exp_bindacl ${ACL_LIBS})
 
 # we need the library name to be 'neuralnetworks' and this will do the trick
 set_target_properties(exp_bindacl PROPERTIES OUTPUT_NAME neuralnetworks)
index 8587d89..8b1bbc7 100644 (file)
@@ -7,7 +7,7 @@ CROSS_BUILD=1 TARGET_ARCH=armv7l make install
 Test
 ```
 USE_NNAPI=1 \
-LD_LIBRARY_PATH="$(pwd)/Product/obj/experiments/bindacl" \
+LD_LIBRARY_PATH="$(pwd)/Product/out/lib:$(pwd)/Product/obj/experiments/bindacl" \
 Product/out/bin/tflite_run \
 [T/F Lite Flatbuffer Model Path]
 ```
index 8e21858..24a8bad 100644 (file)
@@ -5,6 +5,10 @@
 #include <map>
 #include <cassert>
 #include <boost/format.hpp>
+// ACL Headers
+#include <arm_compute/graph/Graph.h>
+#include <utils/GraphUtils.h>
+#include <utils/Utils.h>
 
 //
 // Asynchronous Event
@@ -128,11 +132,47 @@ ResultCode ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation* compila
 struct ANeuralNetworksExecution
 {
   // ANeuralNetworksExecution corresponds to NPU::Interp::Session
+
+  arm_compute::graph::Graph graph;
 };
 
 ResultCode ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution)
 {
+  std::cout << __FUNCTION__ << " +++" << std::endl;
   *execution = new ANeuralNetworksExecution;
+
+  using arm_compute::DataType;
+  using arm_compute::graph::Tensor;
+  using arm_compute::graph::TargetHint;
+  using arm_compute::graph::Graph;
+  using arm_compute::TensorInfo;
+  using arm_compute::TensorShape;
+
+  ANeuralNetworksExecution* execlocal = *execution;
+  arm_compute::graph::Graph& graph = execlocal->graph;
+
+  TargetHint target_hint;
+#if 0
+  std::string image;
+  std::string label;
+  constexpr float mean_r = 122.68f; // Mean value to subtract from red channel
+  constexpr float mean_g = 116.67f; // Mean value to subtract from green channel
+  constexpr float mean_b = 104.01f; // Mean value to subtract from blue channel
+#endif
+
+  // 0 = NEON, 1 = OpenCL
+  // arm_compute::graph_utils can't be used with 'using'
+  target_hint = arm_compute::graph_utils::set_target_hint(1);
+
+  graph << target_hint
+#if 0
+  // TODO: fix load library fail when get_input_accessor() is used
+        << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32),
+                  arm_compute::graph_utils::get_input_accessor(image, mean_r, mean_g, mean_b))
+#endif
+        ;
+
+  std::cout << __FUNCTION__ << " ---" << std::endl;
   return ANEURALNETWORKS_NO_ERROR;
 }
 
@@ -149,7 +189,17 @@ ResultCode ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* executio
 
 ResultCode ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event)
 {
+  std::cout << __FUNCTION__ << " +++" << std::endl;
   *event = new ANeuralNetworksEvent;
+
+#if 0
+  // graph.run() fails with segment fail when only target_hint is added.
+  // after fix adding 'Tensor' we may call graph.run()
+  arm_compute::graph::Graph& graph = execution->graph;
+  graph.run();
+#endif
+
+  std::cout << __FUNCTION__ << " ---" << std::endl;
   return ANEURALNETWORKS_NO_ERROR;
 }