summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>2019-03-28 15:30:23 +0900
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-03-28 15:30:23 +0900
commitdee9a3d3c61c464241db6f6858609ca772759ad7 (patch)
tree747017e967818fb60c8510000a09bbaf1ff74fd1 /runtimes
parentb425807196464b75b4c2ad676e23cc65216f0bfe (diff)
downloadnnfw-dee9a3d3c61c464241db6f6858609ca772759ad7.tar.gz
nnfw-dee9a3d3c61c464241db6f6858609ca772759ad7.tar.bz2
nnfw-dee9a3d3c61c464241db6f6858609ca772759ad7.zip
Introduce concat kernel (#4887)
Introduce concat kernel from tflite Use concat kernel in cpu backend Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/neurun/backend/cpu/kernel/CMakeLists.txt2
-rw-r--r--runtimes/neurun/backend/cpu/kernel/ConcatLayer.cc29
-rw-r--r--runtimes/neurun/backend/cpu/kernel/OperationUtils.h22
3 files changed, 37 insertions, 16 deletions
diff --git a/runtimes/neurun/backend/cpu/kernel/CMakeLists.txt b/runtimes/neurun/backend/cpu/kernel/CMakeLists.txt
index 6617d627e..1f35ce975 100644
--- a/runtimes/neurun/backend/cpu/kernel/CMakeLists.txt
+++ b/runtimes/neurun/backend/cpu/kernel/CMakeLists.txt
@@ -7,7 +7,7 @@ target_include_directories(${LIB_NEURUN_KERNEL_CPU} PUBLIC ${CMAKE_SOURCE_DIR}/e
target_link_libraries(${LIB_NEURUN_KERNEL_CPU} nnapi-header)
target_link_libraries(${LIB_NEURUN_KERNEL_CPU} tensorflow-lite)
-target_link_libraries(${LIB_NEURUN_KERNEL_CPU} nnfw_lib_misc)
+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)
set_target_properties(${LIB_NEURUN_KERNEL_CPU} PROPERTIES OUTPUT_NAME kernel_cpu)
diff --git a/runtimes/neurun/backend/cpu/kernel/ConcatLayer.cc b/runtimes/neurun/backend/cpu/kernel/ConcatLayer.cc
index dbe15fca6..16fe4eb61 100644
--- a/runtimes/neurun/backend/cpu/kernel/ConcatLayer.cc
+++ b/runtimes/neurun/backend/cpu/kernel/ConcatLayer.cc
@@ -17,9 +17,10 @@
#include "ConcatLayer.h"
-#include "tensorflow/contrib/lite/kernels/internal/optimized/optimized_ops.h"
#include "OperationUtils.h"
+#include <cker/operation/Concatenation.h>
+
namespace neurun
{
namespace backend
@@ -40,18 +41,18 @@ bool ConcatLayer::concatenationFloat32()
{
uint32_t num_inputs = _inputShapes.size();
- tflite::ConcatenationParams op_params;
+ nnfw::cker::ConcatenationParams op_params;
op_params.axis = _axis;
op_params.inputs_count = num_inputs;
- std::vector<::tflite::RuntimeShape *> inputDimsPtr;
- std::vector<::tflite::RuntimeShape> inputDims;
+ std::vector<nnfw::cker::Shape *> inputDimsPtr;
+ std::vector<nnfw::cker::Shape> inputDims;
inputDimsPtr.reserve(num_inputs);
inputDims.reserve(num_inputs);
for (uint32_t i = 0; i < num_inputs; i++)
{
- inputDims.push_back(convertShapeToTFLiteShape(_inputShapes[i]));
+ inputDims.push_back(convertShapeToCkerShape(_inputShapes[i]));
inputDimsPtr.push_back(&inputDims[i]);
}
@@ -62,9 +63,8 @@ bool ConcatLayer::concatenationFloat32()
inputFloatPtrs.emplace_back(reinterpret_cast<const float *>(ptr));
}
- ::tflite::optimized_ops::Concatenation<float>(
- op_params, inputDimsPtr.data(), inputFloatPtrs.data(),
- convertShapeToTFLiteShape(_outputShape), _outputData.f);
+ nnfw::cker::Concatenation<float>(op_params, inputDimsPtr.data(), inputFloatPtrs.data(),
+ convertShapeToCkerShape(_outputShape), _outputData.f);
return true;
}
bool ConcatLayer::concatenationQuant8()
@@ -79,7 +79,7 @@ bool ConcatLayer::concatenationQuant8()
input_scales[i] = _inputShapes[i].scale;
}
- tflite::ConcatenationParams op_params;
+ nnfw::cker::ConcatenationParams op_params;
op_params.axis = _axis;
op_params.inputs_count = num_inputs;
op_params.input_zeropoint = input_zeropoints.data();
@@ -87,19 +87,18 @@ bool ConcatLayer::concatenationQuant8()
op_params.output_zeropoint = _outputShape.offset;
op_params.output_scale = _outputShape.scale;
- std::vector<::tflite::RuntimeShape *> inputDimsPtr;
- std::vector<::tflite::RuntimeShape> inputDims;
+ std::vector<nnfw::cker::Shape *> inputDimsPtr;
+ std::vector<nnfw::cker::Shape> inputDims;
inputDimsPtr.reserve(num_inputs);
inputDims.reserve(num_inputs);
for (uint32_t i = 0; i < num_inputs; i++)
{
- inputDims.push_back(convertShapeToTFLiteShape(_inputShapes[i]));
+ inputDims.push_back(convertShapeToCkerShape(_inputShapes[i]));
inputDimsPtr.push_back(&inputDims[i]);
}
- ::tflite::optimized_ops::Concatenation<uint8_t>(
- op_params, inputDimsPtr.data(), _inputDataPtrs.data(),
- convertShapeToTFLiteShape(_outputShape), _outputData.u8);
+ nnfw::cker::Concatenation<uint8_t>(op_params, inputDimsPtr.data(), _inputDataPtrs.data(),
+ convertShapeToCkerShape(_outputShape), _outputData.u8);
return true;
}
diff --git a/runtimes/neurun/backend/cpu/kernel/OperationUtils.h b/runtimes/neurun/backend/cpu/kernel/OperationUtils.h
index 0b0649ecd..f38cec072 100644
--- a/runtimes/neurun/backend/cpu/kernel/OperationUtils.h
+++ b/runtimes/neurun/backend/cpu/kernel/OperationUtils.h
@@ -23,6 +23,8 @@
#include <limits>
#include <vector>
+#include <cker/Shape.h>
+
#include "tensorflow/contrib/lite/c/builtin_op_data.h"
#include "tensorflow/contrib/lite/kernels/internal/types.h"
#include "tensorflow/contrib/lite/kernels/internal/tensor.h"
@@ -107,6 +109,26 @@ inline ::tflite::RuntimeShape convertShapeToTFLiteShape(const Shape &shape)
return ::tflite::GetTensorShape(raw_shape);
}
+inline nnfw::cker::Shape convertShapeToCkerShape(const Shape &shape)
+{
+ std::vector<int32_t> raw_shape;
+ raw_shape.resize(4);
+
+ for (uint32_t i = 0; i < 4; ++i)
+ {
+ if (i >= shape.dimensions.size())
+ {
+ raw_shape[i] = 1;
+ }
+ else
+ {
+ raw_shape[i] = shape.dimensions[i];
+ }
+ }
+
+ return nnfw::cker::GetShape(raw_shape);
+}
+
inline TfLiteFusedActivation convertFusedActivation(FuseCode act)
{
if (act == ANEURALNETWORKS_FUSED_NONE)