From: 장지섭/동작제어Lab(SR)/Engineer/삼성전자 Date: Mon, 11 Jun 2018 06:19:57 +0000 (+0900) Subject: [PureACL] Support other type of operand for setting tensorinput in execution (#1642) X-Git-Tag: 0.2~632 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ddbaadfc90c28a2ada09aca2d87f8a821fb35e6;p=platform%2Fcore%2Fml%2Fnnfw.git [PureACL] Support other type of operand for setting tensorinput in execution (#1642) This commit supports other type of operand for setting tensorinput in execution. Signed-off-by: jiseob.jang --- diff --git a/runtimes/pure_arm_compute/src/execution.cc b/runtimes/pure_arm_compute/src/execution.cc index 1bf7a8b..9810382 100644 --- a/runtimes/pure_arm_compute/src/execution.cc +++ b/runtimes/pure_arm_compute/src/execution.cc @@ -104,6 +104,36 @@ static void asVectorSource(ANeuralNetworksExecution *execution, int32_t type, in } } +static void asTensorSource(ANeuralNetworksExecution *execution, int32_t type, int32_t index, + const nnfw::util::tensor::Shape &shape, const void *buffer, + size_t length) +{ + switch (type) + { + case ANEURALNETWORKS_FLOAT32: + case ANEURALNETWORKS_TENSOR_FLOAT32: + execution->source>(index, shape, reinterpret_cast(buffer), + length); + break; + case ANEURALNETWORKS_INT32: + case ANEURALNETWORKS_TENSOR_INT32: + execution->source>(index, shape, + reinterpret_cast(buffer), length); + break; + case ANEURALNETWORKS_UINT32: + execution->source>(index, shape, + reinterpret_cast(buffer), length); + break; + case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM: + execution->source>(index, shape, + reinterpret_cast(buffer), length); + break; + default: + throw std::runtime_error("Not supported, yet"); + break; + } +} + static void asFeatureSource(ANeuralNetworksExecution *execution, int32_t type, int32_t index, const nnfw::util::feature::Shape &shape, const void *buffer, size_t length) @@ -267,8 +297,7 @@ int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution *execution, int32 { const auto &operand_shape = operands.at(operand_index).shape().asTensor(); - execution->source(index, operand_shape, reinterpret_cast(buffer), - length); + asTensorSource(execution, input_type, index, operand_shape, buffer, length); } else if (operands.at(operand_index).shape().rank() == 4) { diff --git a/runtimes/pure_arm_compute/src/internal/TensorSource.h b/runtimes/pure_arm_compute/src/internal/TensorSource.h index dede71f..dc479db 100644 --- a/runtimes/pure_arm_compute/src/internal/TensorSource.h +++ b/runtimes/pure_arm_compute/src/internal/TensorSource.h @@ -8,10 +8,10 @@ #include "internal/nnapi/tensor/Reader.h" #include "internal/arm_compute/tensor/View.h" -class TensorSource final : public Source +template class TensorSource final : public Source { public: - TensorSource(const nnfw::util::tensor::Shape &shape, const uint8_t *base, const size_t size) + TensorSource(const nnfw::util::tensor::Shape &shape, const T *base, const size_t size) : _shape{shape}, _base{base}, _size{size} { // DO NOTHING @@ -20,8 +20,12 @@ public: public: void push(::arm_compute::ITensor &tensor) const override { - const ::internal::nnapi::tensor::Reader from{_shape, _base, _size}; - ::internal::arm_compute::tensor::View into{&tensor}; + // TODO Should replace the Construct parameter of Reader and View from uint8_t * with typename + // T. + // Inevitably casting must be done. + const ::internal::nnapi::tensor::Reader from{ + _shape, reinterpret_cast(_base), _size}; + ::internal::arm_compute::tensor::View into{&tensor}; ::nnfw::util::tensor::iterate(_shape) << [&](const nnfw::util::tensor::Index &index_nnapi) { const auto value = from.at(index_nnapi); @@ -34,7 +38,7 @@ public: private: const nnfw::util::tensor::Shape _shape; - const uint8_t *const _base; + const T *const _base; const size_t _size; };