From 873b821e87a21d5689caa71fa67e1f0b8904a049 Mon Sep 17 00:00:00 2001 From: =?utf8?q?TANUJ=20TEKRIWAL/SRI-Bangalore-System=20SW/=2E/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 11 Apr 2018 05:10:25 +0530 Subject: [PATCH] Enable RESHAPE of CpuExecutor. (#496) Add the RESHAPE operation file and enable the operation in CpuExecutor. Signed-off-by: Tanuj Tekriwal --- src/runtime/ref/nn/common/CMakeLists.txt | 1 + src/runtime/ref/nn/common/CpuExecutor.cpp | 2 + src/runtime/ref/nn/common/operations/Reshape.cpp | 102 +++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/runtime/ref/nn/common/operations/Reshape.cpp diff --git a/src/runtime/ref/nn/common/CMakeLists.txt b/src/runtime/ref/nn/common/CMakeLists.txt index 4d184fb..3b6677e 100644 --- a/src/runtime/ref/nn/common/CMakeLists.txt +++ b/src/runtime/ref/nn/common/CMakeLists.txt @@ -20,6 +20,7 @@ SET (CUR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/operations/FullyConnected.cpp ${CMAKE_CURRENT_SOURCE_DIR}/operations/Pooling.cpp ${CMAKE_CURRENT_SOURCE_DIR}/operations/SimpleMath.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/operations/Reshape.cpp ) SET (SRCS ${SRCS} diff --git a/src/runtime/ref/nn/common/CpuExecutor.cpp b/src/runtime/ref/nn/common/CpuExecutor.cpp index 06b44db..a49164c 100644 --- a/src/runtime/ref/nn/common/CpuExecutor.cpp +++ b/src/runtime/ref/nn/common/CpuExecutor.cpp @@ -1093,6 +1093,7 @@ int CpuExecutor::executeOperation(const Operation& operation) { outShape); } } break; +#endif //REF_ANN case OperationType::RESHAPE: { if (!allParametersPresent(2, 1)) { return ANEURALNETWORKS_BAD_DATA; @@ -1113,6 +1114,7 @@ int CpuExecutor::executeOperation(const Operation& operation) { reinterpret_cast(output.buffer), outShape); } break; +#if 0 //REF-ANN case OperationType::RESIZE_BILINEAR: { if (!allParametersPresent(3, 1)) { return ANEURALNETWORKS_BAD_DATA; diff --git a/src/runtime/ref/nn/common/operations/Reshape.cpp b/src/runtime/ref/nn/common/operations/Reshape.cpp new file mode 100644 index 0000000..6c46965 --- /dev/null +++ b/src/runtime/ref/nn/common/operations/Reshape.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Contains the implementation of the operations. + +#define LOG_TAG "Operations" + +#include "Operations.h" +#include "OperationsUtils.h" + +#include "internal/optimized/optimized_ops.h" + +namespace android { +namespace nn { + +bool reshapeGeneric(const void* inputData, const Shape& inputShape, + void* outputData, const Shape& outputShape) { + size_t count = sizeOfData(inputShape.type, inputShape.dimensions); + memcpy(outputData, inputData, count); + return true; +} + +bool resizeBilinearFloat32(const float* inputData, const Shape& inputShape, + float* outputData, const Shape& outputShape) { + int32_t height = (int32_t) getSizeOfDimension(outputShape, 1); + int32_t width = (int32_t) getSizeOfDimension(outputShape, 2); + + int32_t outDimData[2] = {height, width}; + // We have to fake a tensor here, to satisfy ResizeBilinear(). + Shape outDimShape; + outDimShape.dimensions = {1, 1, 1, 2}; + + optimized_ops::ResizeBilinear( + inputData, convertShapeToDims(inputShape), + outDimData, convertShapeToDims(outDimShape), + outputData, convertShapeToDims(outputShape)); + return true; +} + +bool depthToSpaceGeneric(const uint8_t* inputData, const Shape& inputShape, + int32_t blockSize, + uint8_t* outputData, const Shape& outputShape) { + if (inputShape.type == OperandType::TENSOR_FLOAT32) { + optimized_ops::DepthToSpace( + reinterpret_cast(inputData), + convertShapeToDims(inputShape), + blockSize, + reinterpret_cast(outputData), + convertShapeToDims(outputShape)); + } else if (inputShape.type == OperandType::TENSOR_QUANT8_ASYMM) { + optimized_ops::DepthToSpace( + reinterpret_cast(inputData), + convertShapeToDims(inputShape), + blockSize, + reinterpret_cast(outputData), + convertShapeToDims(outputShape)); + } else { + LOG(ERROR) << "Unsupported data type"; + return false; + } + return true; +} + +bool spaceToDepthGeneric(const uint8_t* inputData, const Shape& inputShape, + int32_t blockSize, + uint8_t* outputData, const Shape& outputShape) { + if (inputShape.type == OperandType::TENSOR_FLOAT32) { + optimized_ops::SpaceToDepth( + reinterpret_cast(inputData), + convertShapeToDims(inputShape), + blockSize, + reinterpret_cast(outputData), + convertShapeToDims(outputShape)); + } else if (inputShape.type == OperandType::TENSOR_QUANT8_ASYMM) { + optimized_ops::SpaceToDepth( + reinterpret_cast(inputData), + convertShapeToDims(inputShape), + blockSize, + reinterpret_cast(outputData), + convertShapeToDims(outputShape)); + } else { + LOG(ERROR) << "Unsupported data type"; + return false; + } + return true; +} + +} // namespace nn +} // namespace android -- 2.7.4