{
auto setter = [&](::arm_compute::ITensor &tensor) { execution->source(n).push(tensor); };
- auto objects = plan.operands().at(model.inputs.at(n));
+ auto objects = plan.common_operands().at(model.inputs.at(n));
for (auto object : objects)
{
{
auto getter = [&](::arm_compute::ITensor &tensor) { execution->sink(n).pull(tensor); };
- auto objects = plan.operands().at(model.outputs.at(n));
+ auto objects = plan.common_operands().at(model.outputs.at(n));
for (auto object : objects)
{
#include "internal/nnapi/feature/View.h"
#include "internal/nnapi/feature/Reader.h"
+#include "internal/common/Tensor.h"
+
struct Sink
{
virtual ~Sink() = default;
public:
void pull(::arm_compute::ITensor &tensor) const override
{
+ // Only for common tensor now
+ assert(typeid(tensor) == typeid(::internal::common::Tensor));
+
float *base = reinterpret_cast<float *>(_base);
for (int32_t n = 0; n < _vlen; ++n)
public:
void pull(::arm_compute::ITensor &tensor) const override
{
- // TODO: This is just workaround codes, It needs to refactor.
- if (typeid(tensor) == typeid(::internal::cpu::Tensor))
- {
- const ::internal::nnapi::feature::Reader<float> from{_shape, tensor.buffer(), _size};
- ::internal::nnapi::feature::View<float> into{_shape, _base, _size};
+ // Only for common tensor now
+ assert(typeid(tensor) == typeid(::internal::common::Tensor));
- ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
- const auto value = from.at(ch, row, col);
- into.at(ch, row, col) = value;
- };
- }
- else if (typeid(tensor) == typeid(::arm_compute::CLTensor))
- {
- const ::internal::arm_compute::feature::View<float> from{&tensor};
- ::internal::nnapi::feature::View<float> into{_shape, _base, _size};
+ // nnapi tensor ordering == common tensor ordering
+ const ::internal::nnapi::feature::Reader<float> from{_shape, tensor.buffer(), _size};
+ ::internal::nnapi::feature::View<float> into{_shape, _base, _size};
- ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
- const auto value = from.at(ch, row, col);
- into.at(ch, row, col) = value;
- };
- }
+ ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
}
private:
#include "backend/acl_cl/feature/View.h"
+#include "internal/common/Tensor.h"
+
struct Source
{
virtual ~Source() = default;
public:
void push(::arm_compute::ITensor &tensor) const override
{
+ // Only for common tensor now
+ assert(typeid(tensor) == typeid(::internal::common::Tensor));
+
auto base = reinterpret_cast<const float *>(_base);
for (int32_t n = 0; n < _vlen; ++n)
public:
void push(::arm_compute::ITensor &tensor) const override
{
- // TODO: This is just workaround codes, It needs to refactor.
- if (typeid(tensor) == typeid(::internal::cpu::Tensor))
- {
- const ::internal::nnapi::feature::Reader<float> from{_shape, _base, _size};
- ::internal::nnapi::feature::View<float> into{_shape, tensor.buffer(), _size};
+ // Only for common tensor now
+ assert(typeid(tensor) == typeid(::internal::common::Tensor));
- ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
- const auto value = from.at(ch, row, col);
- into.at(ch, row, col) = value;
- };
- }
- else if (typeid(tensor) == typeid(::arm_compute::CLTensor))
- {
- const ::internal::nnapi::feature::Reader<float> from{_shape, _base, _size};
- ::internal::arm_compute::feature::View<float> into{&tensor};
+ // nnapi tensor ordering == common tensor ordering
+ const ::internal::nnapi::feature::Reader<float> from{_shape, _base, _size};
+ ::internal::nnapi::feature::View<float> into{_shape, tensor.buffer(), _size};
- ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
- const auto value = from.at(ch, row, col);
- into.at(ch, row, col) = value;
- };
- }
+ ::nnfw::util::feature::iterate(_shape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
}
private:
#include "TensorConvertFromCommonLayer.h"
-#include "logging.h"
+#include "internal/nnapi/feature/Reader.h"
+#include "backend/acl_cl/feature/View.h"
+
+#include <util/feature/IndexIterator.h>
+#include <arm_compute/runtime/CL/CLScheduler.h>
namespace neurun
{
bool TensorConvertFromCommonLayer::convert()
{
- VERBOSE(TensorConvertFromCommonLayer)
- << "Tensor conversion from common, but it is not yet implemented." << std::endl;
- return true;
+ auto inputBuffer = _inputTensor->buffer();
+ auto inputSize = _inputTensor->info()->total_size();
+
+ auto &queue = ::arm_compute::CLScheduler::get().queue();
+
+ _outputTensor->map(queue);
+
+ if (_tensorShape.rank() == 2)
+ {
+ const auto len = _tensorShape.dim(1);
+
+ auto base = reinterpret_cast<const float *>(inputBuffer);
+
+ for (int32_t n = 0; n < len; ++n)
+ {
+ auto from = base + n;
+ auto into =
+ reinterpret_cast<float *>(_outputTensor->ptr_to_element(::arm_compute::Coordinates{n}));
+
+ *into = *from;
+ }
+ }
+ else if (_tensorShape.rank() == 4)
+ {
+ auto featureShape = _tensorShape.asFeature();
+
+ const ::internal::nnapi::feature::Reader<float> from{featureShape, inputBuffer, inputSize};
+ ::internal::arm_compute::feature::View<float> into{_outputTensor};
+
+ ::nnfw::util::feature::iterate(featureShape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
+ }
+
+ _outputTensor->unmap(queue);
}
void TensorConvertFromCommonLayer::configure(::internal::common::Tensor *inputTensor,
#include "TensorConvertToCommonLayer.h"
-#include "logging.h"
+#include "backend/acl_cl/feature/View.h"
+#include "internal/nnapi/feature/View.h"
+
+#include <util/feature/IndexIterator.h>
+#include <arm_compute/runtime/CL/CLScheduler.h>
namespace neurun
{
bool TensorConvertToCommonLayer::convert()
{
- VERBOSE(TensorConvertToCommonLayer)
- << "Tensor conversion to common, but it is not yet implemented." << std::endl;
- return true;
+ auto outputBuffer = _outputTensor->buffer();
+ auto outputSize = _outputTensor->info()->total_size();
+
+ auto &queue = ::arm_compute::CLScheduler::get().queue();
+
+ _inputTensor->map(queue);
+
+ if (_tensorShape.rank() == 2)
+ {
+ const auto len = _tensorShape.dim(1);
+
+ auto base = reinterpret_cast<float *>(outputBuffer);
+
+ for (int32_t n = 0; n < len; ++n)
+ {
+ auto from = reinterpret_cast<const float *>(
+ _inputTensor->ptr_to_element(::arm_compute::Coordinates{n}));
+ auto into = base + n;
+
+ *into = *from;
+ }
+ }
+ else if (_tensorShape.rank() == 4)
+ {
+ auto featureShape = _tensorShape.asFeature();
+
+ const ::internal::arm_compute::feature::View<float> from{_inputTensor};
+ ::internal::nnapi::feature::View<float> into{featureShape, outputBuffer, outputSize};
+
+ ::nnfw::util::feature::iterate(featureShape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
+ }
+
+ _inputTensor->unmap(queue);
}
void TensorConvertToCommonLayer::configure(::arm_compute::ICLTensor *inputTensor,
#include "TensorConvertFromCommonLayer.h"
-#include "logging.h"
+#include "internal/nnapi/feature/Reader.h"
+#include "internal/nnapi/feature/View.h"
+
+#include <util/feature/IndexIterator.h>
namespace neurun
{
bool TensorConvertFromCommonLayer::convert()
{
- VERBOSE(TensorConvertFromCommonLayer)
- << "Tensor conversion from common, but it is not yet implemented." << std::endl;
- return true;
+ auto inputBuffer = _inputTensor->buffer();
+ auto inputSize = _inputTensor->info()->total_size();
+
+ auto outputBuffer = _outputTensor->buffer();
+ auto outputSize = _outputTensor->info()->total_size();
+
+ if (_tensorShape.rank() == 2)
+ {
+ const auto len = _tensorShape.dim(1);
+
+ auto base = reinterpret_cast<const float *>(inputBuffer);
+
+ for (int32_t n = 0; n < len; ++n)
+ {
+ auto from = base + n;
+ auto into =
+ reinterpret_cast<float *>(_outputTensor->ptr_to_element(::arm_compute::Coordinates{n}));
+
+ *into = *from;
+ }
+ }
+ else if (_tensorShape.rank() == 4)
+ {
+ auto featureShape = _tensorShape.asFeature();
+
+ const ::internal::nnapi::feature::Reader<float> from{featureShape, inputBuffer, inputSize};
+ ::internal::nnapi::feature::View<float> into{featureShape, outputBuffer, outputSize};
+
+ ::nnfw::util::feature::iterate(featureShape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
+ }
}
void TensorConvertFromCommonLayer::configure(::internal::common::Tensor *inputTensor,
#include "TensorConvertToCommonLayer.h"
-#include "logging.h"
+#include "internal/nnapi/feature/Reader.h"
+#include "internal/nnapi/feature/View.h"
+
+#include <util/feature/IndexIterator.h>
namespace neurun
{
bool TensorConvertToCommonLayer::convert()
{
- VERBOSE(ConvertToCommon) << "Tensor conversion to common, but it is not yet implemented."
- << std::endl;
- return true;
+ auto inputBuffer = _inputTensor->buffer();
+ auto inputSize = _inputTensor->info()->total_size();
+
+ auto outputBuffer = _outputTensor->buffer();
+ auto outputSize = _outputTensor->info()->total_size();
+
+ if (_tensorShape.rank() == 2)
+ {
+ const auto len = _tensorShape.dim(1);
+
+ auto base = reinterpret_cast<float *>(outputBuffer);
+
+ for (int32_t n = 0; n < len; ++n)
+ {
+ auto from = reinterpret_cast<const float *>(
+ _inputTensor->ptr_to_element(::arm_compute::Coordinates{n}));
+ auto into = base + n;
+
+ *into = *from;
+ }
+ }
+ else if (_tensorShape.rank() == 4)
+ {
+ auto featureShape = _tensorShape.asFeature();
+
+ const ::internal::nnapi::feature::Reader<float> from{featureShape, inputBuffer, inputSize};
+ ::internal::nnapi::feature::View<float> into{featureShape, outputBuffer, outputSize};
+
+ ::nnfw::util::feature::iterate(featureShape) << [&](uint32_t ch, uint32_t row, uint32_t col) {
+ const auto value = from.at(ch, row, col);
+ into.at(ch, row, col) = value;
+ };
+ }
}
void TensorConvertToCommonLayer::configure(::internal::cpu::Tensor *inputTensor,