#include "internal/kernels/cpufallback/MaxPoolLayer.h"
#include "internal/kernels/cpufallback/ConcatLayer.h"
#include "internal/kernels/cpufallback/FullyConnectedLayer.h"
+#include "internal/kernels/cpufallback/ReshapeLayer.h"
#include "logging.h"
Stage StageGenerator::generate(const ::internal::tflite::op::Reshape::Node &node)
{
- throw std::runtime_error("NYI");
+ const ::internal::tflite::operand::Index output_index{node.param().output_index};
+ const ::internal::tflite::operand::Index input_index{node.param().input_index};
+
+ struct Param
+ {
+ int output_index;
+ int input_index;
+
+ ::internal::tflite::operand::Shape ofm_shape{1};
+ ::internal::tflite::operand::Shape ifm_shape{1};
+ };
+
+ Param param;
+
+ param.output_index = output_index.asInt();
+ param.input_index = input_index.asInt();
+
+ param.ofm_shape = _ctx.at(output_index).shape();
+ param.ifm_shape = _ctx.at(input_index).shape();
+
+ auto tensors = _tensor_builder;
+
+ return [tensors, param](IExecutionBuilder &builder) {
+ auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
+
+ std::unique_ptr<::internal::kernels::cpu::ReshapeLayer> fn{
+ new ::internal::kernels::cpu::ReshapeLayer};
+
+ fn->configure(input_alloc->buffer(), param.ifm_shape, output_alloc->buffer(), param.ofm_shape);
+
+ builder.append(std::move(fn));
+ };
}
Stage StageGenerator::generate(const ::internal::tflite::op::Softmax::Node &node)
return shape;
}
+size_t sizeOfData(OperandType type, const std::vector<uint32_t> &dimensions)
+{
+ size_t size = 4;
+
+ switch (type)
+ {
+ case OperandType::FLOAT32:
+ case OperandType::INT32:
+ case OperandType::UINT32:
+ case OperandType::TENSOR_FLOAT32:
+ case OperandType::TENSOR_INT32:
+ size = 4;
+ break;
+ case OperandType::TENSOR_QUANT8_ASYMM:
+ size = 1;
+ break;
+ default:
+ throw std::runtime_error("Not supported operand type.");
+ break;
+ }
+
+ for (auto d : dimensions)
+ {
+ size *= d;
+ }
+
+ return size;
+}
+
} // namespace cpu
} // namespace kernels
} // namespace internal
Shape convertShape(const ::internal::tflite::operand::Shape &o);
+uint32_t sizeOfData(OperandType type, const std::vector<uint32_t> &dimensions);
+
} // namespace cpu
} // namespace kernels
} // namespace internal
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ * 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.
+ */
+
+#include "ReshapeLayer.h"
+
+#include "tensorflow/contrib/lite/kernels/internal/optimized/optimized_ops.h"
+#include "tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h"
+#include "internal/kernels/cpufallback/OperationUtils.h"
+
+namespace internal
+{
+namespace kernels
+{
+namespace cpu
+{
+
+bool ReshapeLayer::reshapeGeneric()
+{
+ size_t count = sizeOfData(_inputShape.type, _inputShape.dimensions);
+ memcpy(reinterpret_cast<void *>(_outputData), reinterpret_cast<const void *>(_inputData), count);
+ return true;
+}
+
+void ReshapeLayer::configure(uint8_t *inputData, const internal::tflite::operand::Shape &inputShape,
+ uint8_t *outputData,
+ const internal::tflite::operand::Shape &outputShape)
+{
+ _inputData = inputData;
+ _inputShape = convertShape(inputShape);
+ _outputData = outputData;
+ _outputShape = convertShape(outputShape);
+}
+
+void ReshapeLayer::run() { reshapeGeneric(); }
+
+} // namespace cpu
+} // namespace kernels
+} // namespace internal
--- /dev/null
+#ifndef __INTERNAL_KERNELS_CPU_RESHAPELAYER_H__
+#define __INTERNAL_KERNELS_CPU_RESHAPELAYER_H__
+
+#include <NeuralNetworks.h>
+
+#include <arm_compute/runtime/IFunction.h>
+
+#include "internal/Model.h"
+#include "internal/kernels/cpufallback/OperationUtils.h"
+
+using namespace internal::kernels::cpu;
+
+namespace internal
+{
+namespace kernels
+{
+namespace cpu
+{
+
+class ReshapeLayer : public ::arm_compute::IFunction
+{
+public:
+ ReshapeLayer() {}
+
+public:
+ bool reshapeGeneric();
+
+ void configure(uint8_t *inputData, const internal::tflite::operand::Shape &inputShape,
+ uint8_t *outputData, const internal::tflite::operand::Shape &outputShape);
+
+ void run();
+
+private:
+ uint8_t *_inputData;
+ uint8_t *_outputData;
+
+ Shape _inputShape;
+ Shape _outputShape;
+};
+
+} // namespace cpu
+} // namespace kernels
+} // namespace internal
+
+#endif // __INTERNAL_KERNELS_CPU_RESHAPELAYER_H__