#include "util/kernel/Shape.h"
#include "util/kernel/Reader.h"
-#include "backend/acl_cl/operand/ICLTensor.h"
+#include "backend/interface/operand/ITensor.h"
+#include "util/feature/Coordinate4D.h"
#include <cassert>
template <> class View<float> final : public nnfw::util::kernel::Reader<float>
{
public:
- View(::neurun::backend::acl_cl::operand::ICLTensor *tensor) : _tensor{tensor}
+ View(::neurun::backend::operand::ITensor *tensor) : _tensor{tensor}
{
- assert(tensor->data_type() == ::arm_compute::DataType::F32);
-
_shape.N = tensor->dimension(3);
_shape.C = tensor->dimension(2);
_shape.H = tensor->dimension(1);
private:
size_t kernel_index_to_byte_offset(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const
{
- return _tensor->info()->offset_element_in_bytes(::arm_compute::Coordinates{col, row, ch, nth});
+ return _tensor->calcOffset(
+ neurun::util::feature::Coordinate4D{static_cast<int32_t>(nth), static_cast<int32_t>(row),
+ static_cast<int32_t>(col), static_cast<int32_t>(ch)});
}
private:
::nnfw::util::kernel::Shape _shape;
- ::neurun::backend::acl_cl::operand::ICLTensor *_tensor;
+ ::neurun::backend::operand::ITensor *_tensor;
};
} // namespace kernel
size_t ICLTensor::num_dimensions() const { return info()->num_dimensions(); }
+size_t ICLTensor::calcOffset(const neurun::util::feature::Coordinate4D &coords)
+{
+ int32_t N = coords.n();
+ int32_t C = coords.c();
+ int32_t H = coords.h();
+ int32_t W = coords.w();
+
+ ::arm_compute::Coordinates coordinates{W, H, C, N};
+ return info()->offset_element_in_bytes(coordinates);
+}
+
arm_compute::DataType ICLTensor::data_type() const { return info()->data_type(); }
uint8_t *ICLTensor::buffer() const { return handle()->buffer(); }
size_t total_size() const override;
size_t dimension(size_t index) const override;
size_t num_dimensions() const override;
+ size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) override;
public:
arm_compute::DataType data_type() const;
#include "Tensor.h"
+#define NO_USE(a) (void)(a)
+
namespace neurun
{
namespace backend
namespace operand
{
-// NO IMPLEMENTATION YET
+size_t Tensor::calcOffset(const neurun::util::feature::Coordinate4D &coords)
+{
+ NO_USE(coords);
+ throw std::runtime_error("offset_element_in_bytes is not supported for cpu::Tensor now.");
+}
} // namespace operand
} // namespace cpu
size_t dimension(size_t index) const override { return _info.shape().dim(index); }
size_t num_dimensions() const override { return _info.shape().dims().size(); }
size_t total_size() const override { return _info.total_size(); }
+ size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) override;
private:
compiler::TensorInfo _info;
#include <cstring>
#include <cstdint>
+#include "util/feature/Coordinate4D.h"
+
namespace neurun
{
namespace backend
virtual size_t total_size() const = 0;
virtual size_t dimension(size_t index) const = 0;
virtual size_t num_dimensions() const = 0;
+ virtual size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) = 0;
};
} // namespace operand
#include "util/feature/nhwc/View.h"
#include "util/feature/nchw/View.h"
#include <util/feature/IndexIterator.h>
-#include "backend/interface/operand/ITensor.h"
// TODO Remove these dependencies to arm_compute lib
+#include "backend/acl_cl/operand/ICLTensor.h"
#include <arm_compute/core/Window.h>
#include <arm_compute/core/Helpers.h>
#include "util/feature/nchw/View.h"
#include "util/feature/nhwc/Reader.h"
#include <util/feature/IndexIterator.h>
-#include "backend/interface/operand/ITensor.h"
// TODO Remove these dependencies to arm_compute lib
+#include "backend/acl_cl/operand/ICLTensor.h"
#include <arm_compute/core/Window.h>
#include <arm_compute/core/Helpers.h>
#include "util/feature/Reader.h"
-#include "backend/acl_cl/operand/ICLTensor.h"
+#include "backend/interface/operand/ITensor.h"
+#include "util/feature/Coordinate4D.h"
#include <cassert>
template <typename T> class View final : public nnfw::util::feature::Reader<T>
{
public:
- View(::neurun::backend::acl_cl::operand::ICLTensor *tensor) : _tensor{tensor}
+ View(::neurun::backend::operand::ITensor *tensor) : _tensor{tensor}
{
- assert(tensor->data_type() == ::arm_compute::DataType::F32);
-
// TODO Validate whether tensor is a feature map, or not
_shape.C = tensor->dimension(2);
}
private:
- size_t feature_index_to_byte_offset(uint32_t ch, uint32_t row, uint32_t col) const
- {
- // ARM Compute uses CHW ordering
- return _tensor->info()->offset_element_in_bytes(::arm_compute::Coordinates{col, row, ch});
- }
- size_t feature_index_to_byte_offset(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const
+ size_t feature_index_to_byte_offset(uint32_t batch, uint32_t ch = 0, uint32_t row = 0,
+ uint32_t col = 0) const
{
- // ARM Compute uses CHW ordering
- return _tensor->info()->offset_element_in_bytes(
- ::arm_compute::Coordinates{col, row, ch, batch});
+ return _tensor->calcOffset(
+ neurun::util::feature::Coordinate4D{static_cast<int32_t>(batch), static_cast<int32_t>(row),
+ static_cast<int32_t>(col), static_cast<int32_t>(ch)});
}
private:
::nnfw::util::feature::Shape _shape;
- ::neurun::backend::acl_cl::operand::ICLTensor *_tensor;
+ ::neurun::backend::operand::ITensor *_tensor;
};
} // namespace nchw