Remove nnapi dependency in neurun (#5153)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 8 May 2019 01:08:08 +0000 (10:08 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 8 May 2019 01:08:08 +0000 (10:08 +0900)
Remove nnapi dependency in neurun core and backend code

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
20 files changed:
runtimes/neurun/backend/acl_cl/CMakeLists.txt
runtimes/neurun/backend/acl_cl/StageGenerator.cc
runtimes/neurun/backend/acl_cl/kernel/CMakeLists.txt
runtimes/neurun/backend/acl_neon/StageGenerator.cc
runtimes/neurun/backend/cpu/CMakeLists.txt
runtimes/neurun/backend/cpu/kernel/AvgPoolLayer.h
runtimes/neurun/backend/cpu/kernel/CMakeLists.txt
runtimes/neurun/backend/cpu/kernel/ConcatLayer.h
runtimes/neurun/backend/cpu/kernel/ConvolutionLayer.h
runtimes/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.h
runtimes/neurun/backend/cpu/kernel/FullyConnectedLayer.h
runtimes/neurun/backend/cpu/kernel/MaxPoolLayer.h
runtimes/neurun/backend/cpu/kernel/OperationUtils.cc
runtimes/neurun/backend/cpu/kernel/OperationUtils.h
runtimes/neurun/backend/cpu/kernel/PermuteLayer.h
runtimes/neurun/backend/cpu/kernel/ReshapeLayer.h
runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.h
runtimes/neurun/core/CMakeLists.txt
runtimes/neurun/core/include/util/Utils.h
runtimes/neurun/core/include/util/feature/nhwc/View.h

index 4489643..c2f1fd6 100644 (file)
@@ -18,7 +18,6 @@ add_library(${LIB_NEURUN_BACKEND_ACL_CL} SHARED ${SOURCES})
 target_include_directories(${LIB_NEURUN_BACKEND_ACL_CL} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
 target_include_directories(${LIB_NEURUN_BACKEND_ACL_CL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
-target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} nnapi-header)
 target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} arm_compute)
 target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} arm_compute_ex)
 target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} ${LIB_NEURUN_KERNEL_ACL_CL})
index f77966c..204f442 100644 (file)
@@ -36,8 +36,6 @@
 
 #include "util/logging.h"
 
-#include "NeuralNetworks.h"
-
 #include "util/Utils.h"
 
 #include "acl_common/Convert.h"
@@ -86,8 +84,6 @@ private:
   void appendReLU6(::arm_compute::ICLTensor *tensor);
 
 public:
-  // TODO Remove NNAPI dependency
-  void append(FuseCode code, ::arm_compute::ICLTensor *tensor);
   void append(model::Activation code, ::arm_compute::ICLTensor *tensor);
 
 private:
@@ -136,37 +132,6 @@ void ActivationBuilder::appendReLU6(::arm_compute::ICLTensor *ifm_alloc)
   _builder.append(std::move(acl_fn));
 }
 
-void ActivationBuilder::append(FuseCode code, ::arm_compute::ICLTensor *ifm_alloc)
-{
-  switch (code)
-  {
-    case ANEURALNETWORKS_FUSED_NONE:
-    {
-      // DO NOTHING
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU:
-    {
-      appendReLU(ifm_alloc);
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU1:
-    {
-      appendReLU1(ifm_alloc);
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU6:
-    {
-      appendReLU6(ifm_alloc);
-      break;
-    }
-    default:
-    {
-      throw std::runtime_error("Not supported, yet");
-    }
-  }
-}
-
 void ActivationBuilder::append(model::Activation code, ::arm_compute::ICLTensor *ifm_alloc)
 {
   switch (code)
index 0338ca8..1dbeba3 100644 (file)
@@ -12,7 +12,6 @@ target_include_directories(${LIB_NEURUN_KERNEL_ACL_CL} PUBLIC ${NEURUN_INCLUDE_D
 target_include_directories(${LIB_NEURUN_KERNEL_ACL_CL} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
 target_include_directories(${LIB_NEURUN_KERNEL_ACL_CL} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../..)
 
-target_link_libraries(${LIB_NEURUN_KERNEL_ACL_CL} nnapi-header)
 target_link_libraries(${LIB_NEURUN_KERNEL_ACL_CL} arm_compute)
 target_link_libraries(${LIB_NEURUN_KERNEL_ACL_CL} ${LIB_NEURUN_BACKEND_ACL_COMMON})
 
index ffd75e7..f80a933 100644 (file)
@@ -38,8 +38,6 @@
 
 #include "util/logging.h"
 
-#include "NeuralNetworks.h"
-
 #include "util/Utils.h"
 
 #include "acl_common/Convert.h"
@@ -88,8 +86,6 @@ private:
   void appendReLU6(::arm_compute::ITensor *tensor);
 
 public:
-  // TODO Remove NNAPI dependency
-  void append(FuseCode code, ::arm_compute::ITensor *tensor);
   void append(model::Activation code, ::arm_compute::ITensor *tensor);
 
 private:
@@ -138,37 +134,6 @@ void ActivationBuilder::appendReLU6(::arm_compute::ITensor *ifm_alloc)
   _builder.append(std::move(acl_fn));
 }
 
-void ActivationBuilder::append(FuseCode code, ::arm_compute::ITensor *ifm_alloc)
-{
-  switch (code)
-  {
-    case ANEURALNETWORKS_FUSED_NONE:
-    {
-      // DO NOTHING
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU:
-    {
-      appendReLU(ifm_alloc);
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU1:
-    {
-      appendReLU1(ifm_alloc);
-      break;
-    }
-    case ANEURALNETWORKS_FUSED_RELU6:
-    {
-      appendReLU6(ifm_alloc);
-      break;
-    }
-    default:
-    {
-      throw std::runtime_error("Not supported, yet");
-    }
-  }
-}
-
 void ActivationBuilder::append(model::Activation act, ::arm_compute::ITensor *ifm_alloc)
 {
   switch (act)
index 9b25f64..fb75d6e 100644 (file)
@@ -11,7 +11,6 @@ list(REMOVE_ITEM SOURCES ${TESTS})
 
 add_library(${LIB_NEURUN_BACKEND_CPU} SHARED ${SOURCES})
 
-target_link_libraries(${LIB_NEURUN_BACKEND_CPU} nnapi-header)
 target_link_libraries(${LIB_NEURUN_BACKEND_CPU} nnfw_lib_misc)
 target_link_libraries(${LIB_NEURUN_BACKEND_CPU} nnfw_lib_cpp14)
 target_link_libraries(${LIB_NEURUN_BACKEND_CPU} ${LIB_NEURUN_KERNEL_CPU})
index 5941d18..57f8f5c 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index 2b67ee7..1ebf501 100644 (file)
@@ -4,7 +4,6 @@ add_library(${LIB_NEURUN_KERNEL_CPU} STATIC ${SOURCES})
 
 target_include_directories(${LIB_NEURUN_KERNEL_CPU} PUBLIC ${NEURUN_INCLUDE_DIR})
 
-target_link_libraries(${LIB_NEURUN_KERNEL_CPU} nnapi-header)
 target_link_libraries(${LIB_NEURUN_KERNEL_CPU} nnfw_lib_misc nnfw_lib_cker)
 
 set_target_properties(${LIB_NEURUN_KERNEL_CPU} PROPERTIES POSITION_INDEPENDENT_CODE ON)
index ac54b7a..af958b1 100644 (file)
@@ -18,8 +18,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_CONCATLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_CONCATLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index a0df8a5..b48a4a6 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index 1a869f7..e1e0892 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__
 #define __NEURUN_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index 9574803..71f424c 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index 0991b73..05fad12 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index d2333af..a976d65 100644 (file)
@@ -104,34 +104,6 @@ void QuantizeMultiplierGreaterThanOne(double double_multiplier, int32_t *quantiz
   *quantized_multiplier = static_cast<int32_t>(q_fixed);
 }
 
-void CalculateActivationRangeFloat(int32_t activation, float *activation_min, float *activation_max)
-{
-  if (activation == ANEURALNETWORKS_FUSED_RELU)
-  {
-    *activation_min = 0.f;
-    *activation_max = std::numeric_limits<float>::max();
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_RELU6)
-  {
-    *activation_min = 0.f;
-    *activation_max = 6.f;
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_RELU1)
-  {
-    *activation_min = -1.f;
-    *activation_max = 1.f;
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_NONE)
-  {
-    *activation_min = std::numeric_limits<float>::lowest();
-    *activation_max = std::numeric_limits<float>::max();
-  }
-  else
-  {
-    std::cout << "Unsupported fused activation function." << std::endl;
-  }
-}
-
 void CalculateActivationRangeFloat(model::Activation activation, float *activation_min,
                                    float *activation_max)
 {
@@ -161,42 +133,6 @@ void CalculateActivationRangeFloat(model::Activation activation, float *activati
   }
 }
 
-void CalculateActivationRangeUint8(int32_t activation, const Shape &outputShape, int32_t *act_min,
-                                   int32_t *act_max)
-{
-  const int32_t qmin = std::numeric_limits<uint8_t>::min();
-  const int32_t qmax = std::numeric_limits<uint8_t>::max();
-  const auto scale = outputShape.scale;
-  const auto zero_point = outputShape.offset;
-  auto quantize = [scale, zero_point](float f) {
-    return zero_point + static_cast<int32_t>(std::round(f / scale));
-  };
-  if (activation == ANEURALNETWORKS_FUSED_RELU)
-  {
-    *act_min = std::max(qmin, quantize(0.0));
-    *act_max = qmax;
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_RELU6)
-  {
-    *act_min = std::max(qmin, quantize(0.0));
-    *act_max = std::min(qmax, quantize(6.0));
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_RELU1)
-  {
-    *act_min = std::max(qmin, quantize(-1.0));
-    *act_max = std::min(qmax, quantize(1.0));
-  }
-  else if (activation == ANEURALNETWORKS_FUSED_NONE)
-  {
-    *act_min = qmin;
-    *act_max = qmax;
-  }
-  else
-  {
-    std::cout << "Unsupported fused activation function." << std::endl;
-  }
-}
-
 void CalculateActivationRangeUint8(model::Activation activation, const Shape &outputShape,
                                    int32_t *act_min, int32_t *act_max)
 {
index 1d917f6..9e0abe9 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NNFW_SUPPORT_NNAPI_OPERATION_UTILS_H__
 #define __NNFW_SUPPORT_NNAPI_OPERATION_UTILS_H__
 
-#include <NeuralNetworks.h>
-
 #include <iostream>
 #include <limits>
 #include <vector>
@@ -112,16 +110,9 @@ void GetQuantizedConvolutionMultipler(const Shape &inputShape, const Shape &filt
 void QuantizeMultiplierGreaterThanOne(double double_multiplier, int32_t *quantized_multiplier,
                                       int *left_shift);
 
-// TODO Remove CalculateActivationRangeFloat(int32_t, float*, float*)
-void CalculateActivationRangeFloat(int32_t activation, float *activation_min,
-                                   float *activation_max);
 void CalculateActivationRangeFloat(model::Activation activation, float *activation_min,
                                    float *activation_max);
 
-// TODO Remove int32_t(FuseCode) activation CalculateActivationRangeUint8(int32_t, Shape, int32_t*,
-// int32_t*)
-void CalculateActivationRangeUint8(int32_t activation, const Shape &outputShape, int32_t *act_min,
-                                   int32_t *act_max);
 void CalculateActivationRangeUint8(model::Activation activation, const Shape &outputShape,
                                    int32_t *act_min, int32_t *act_max);
 
index a5d89d1..5f11a60 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "util/feature/nhwc/View.h"
index 01f8676..017d8e1 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_RESHAPELAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_RESHAPELAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index d06900e..4f631cd 100644 (file)
@@ -17,8 +17,6 @@
 #ifndef __NEURUN_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__
 #define __NEURUN_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__
 
-#include <NeuralNetworks.h>
-
 #include <exec/IFunction.h>
 
 #include "OperationUtils.h"
index 3bb8346..10dbb63 100644 (file)
@@ -4,6 +4,5 @@ add_library(neurun-core STATIC ${SOURCES})
 set_target_properties(neurun-core PROPERTIES POSITION_INDEPENDENT_CODE ON)
 target_include_directories(neurun-core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
 target_include_directories(neurun-core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
-target_link_libraries(neurun-core nnapi-header) # TODO Remove this dependency
 target_link_libraries(neurun-core nnfw_lib_misc nnfw_lib_cpp14 dl)
 target_compile_options(neurun-core PRIVATE -Wall -Wextra -Werror)
index a99024d..4520528 100644 (file)
@@ -23,8 +23,6 @@
 #ifndef __NEURUN_UTIL_UTILS_H__
 #define __NEURUN_UTIL_UTILS_H__
 
-// TODO remove include "NeuralNetworks.h"
-#include "NeuralNetworks.h"
 #include "model/InternalType.h"
 
 #define UNUSED_RELEASE(a) (void)(a)
index e4b8e80..8acf973 100644 (file)
@@ -18,6 +18,7 @@
 #define __NEURUN_UTIL_FEATURE_NHWC_VIEW_H__
 
 #include <cassert>
+#include <cstddef>
 
 #include "Utils.h"
 #include "util/Utils.h"