summaryrefslogtreecommitdiff
path: root/runtimes/pure_arm_compute/src/internal/arm_compute
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/pure_arm_compute/src/internal/arm_compute')
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/Cast.cc165
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h170
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/feature/View.h61
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/kernel/View.h42
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/matrix/View.h36
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/tensor/View.h37
6 files changed, 410 insertions, 101 deletions
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.cc b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.cc
new file mode 100644
index 000000000..ff2f79309
--- /dev/null
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.cc
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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 "internal/arm_compute/Cast.h"
+
+#include "internal/Swizzle.h"
+
+::arm_compute::Coordinates getARMComputeAxises(uint32_t rank)
+{
+ ::arm_compute::Coordinates res{};
+
+ res.set_num_dimensions(rank);
+
+ for (uint32_t axis = 0; axis < rank; ++axis)
+ {
+ res.set(axis, ToARMComputeAxis(rank, axis).value());
+ }
+
+ return res;
+}
+
+::arm_compute::Coordinates asARMComputeCoordinates(const ::arm_compute::Coordinates &runtime_coord,
+ const ::arm_compute::Coordinates &axises)
+{
+ ::arm_compute::Coordinates id{};
+ assert(runtime_coord.num_dimensions() == axises.num_dimensions());
+ for (size_t i = 0; i < runtime_coord.num_dimensions(); ++i)
+ {
+ id.set(axises[i], runtime_coord[i]);
+ }
+ return id;
+}
+
+// Restructure runtime_permutationVector to ACL_permutationVector
+::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank,
+ const int32_t *runtime_pv)
+{
+ // rank upto 4 is supported
+ assert(rank <= 4);
+ assert(runtime_pv != nullptr);
+
+ int new_pv[4] = {0};
+ ::arm_compute::Coordinates axises = getARMComputeAxises(rank);
+
+ if (rank == 4)
+ {
+ /**
+ axises = {3,1,0,2}
+ NNAPI PermutationVector
+ N 0 3
+ H 1 1
+ W 2 0
+ C 3 2
+ **/
+ new_pv[0] = axises[runtime_pv[2]];
+ new_pv[1] = axises[runtime_pv[1]];
+ new_pv[2] = axises[runtime_pv[3]];
+ new_pv[3] = axises[runtime_pv[0]];
+ }
+ else
+ {
+ /**
+ mapping/axises = {rank-1 to 0}
+ CHW --------> WHC
+ or
+ WH ----------> HW
+ **/
+ for (int id = 0; id < rank; ++id)
+ {
+ new_pv[id] = axises[runtime_pv[rank - id - 1]];
+ }
+ }
+
+ return ::arm_compute::PermutationVector{new_pv[0], new_pv[1], new_pv[2], new_pv[3]};
+}
+
+::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
+ bool apply_dim_correction)
+{
+ const uint32_t rank = shape.rank();
+
+ ::arm_compute::TensorShape res{};
+
+ res.set_num_dimensions(rank);
+
+ for (uint32_t axis = 0; axis < rank; ++axis)
+ {
+ // NOTE In some cases, in incorrect dimensions is required.
+ // For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of
+ // LSTM is used as the weight of the FullyConnected.
+ // The FullyConnected's weight must be greater or equal than 2-dimensions.
+ // However, if the dimension correction is applied to input_to_input_weights with input_size
+ // equal to 1, it will be changed to 1-D.
+ // So input_to_input_weights is not used by the weight of FullyConnected.
+ res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis), apply_dim_correction);
+ }
+
+ return res;
+}
+
+::arm_compute::DataType asDataType(const int32_t type)
+{
+ switch (type)
+ {
+ case ANEURALNETWORKS_FLOAT32:
+ case ANEURALNETWORKS_TENSOR_FLOAT32:
+ return ::arm_compute::DataType::F32;
+ case ANEURALNETWORKS_INT32:
+ case ANEURALNETWORKS_TENSOR_INT32:
+ return ::arm_compute::DataType::S32;
+ case ANEURALNETWORKS_UINT32:
+ return ::arm_compute::DataType::U32;
+ case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM:
+ return ::arm_compute::DataType::QASYMM8;
+ default:
+ throw std::runtime_error("Not supported, yet");
+ break;
+ }
+}
+
+::arm_compute::ActivationLayerInfo asActivationInfo(FuseCode code)
+{
+ switch (code)
+ {
+ case ANEURALNETWORKS_FUSED_NONE:
+ return ::arm_compute::ActivationLayerInfo{};
+ case ANEURALNETWORKS_FUSED_RELU:
+ return ::arm_compute::ActivationLayerInfo{
+ ::arm_compute::ActivationLayerInfo::ActivationFunction::RELU};
+ case ANEURALNETWORKS_FUSED_RELU1:
+ return ::arm_compute::ActivationLayerInfo{
+ ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 1.0f, -1.0f};
+ case ANEURALNETWORKS_FUSED_RELU6:
+ return ::arm_compute::ActivationLayerInfo{
+ ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.0f};
+ default:
+ throw std::runtime_error("Not supported, yet");
+ break;
+ }
+}
+
+::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset)
+{
+ return ::arm_compute::QuantizationInfo(scale, offset);
+}
+
+::arm_compute::TensorInfo asTensorInfo(const ::arm_compute::TensorShape &shape, const int32_t type,
+ const float scale, const int32_t zeroPoint)
+{
+ return ::arm_compute::TensorInfo(shape, 1, asDataType(type),
+ asQuantizationInfo(scale, zeroPoint));
+}
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
index e2ceb8fef..42b547feb 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
@@ -14,104 +14,98 @@
* limitations under the License.
*/
+/**
+ * @file Cast.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines casting functions from internal object to arm compute object
+ */
#ifndef __ARM_COMPUTE_CAST_H__
+#define __ARM_COMPUTE_CAST_H__
+#include <arm_compute/core/Coordinates.h>
+#include <arm_compute/core/TensorInfo.h>
#include <arm_compute/core/TensorShape.h>
+#include <arm_compute/core/Types.h>
-#include "internal/Swizzle.h"
-#include "internal/Model.h"
-
-inline ::arm_compute::Coordinates getARMComputeAxises(uint32_t rank)
-{
- ::arm_compute::Coordinates res{};
-
- res.set_num_dimensions(rank);
-
- for (uint32_t axis = 0; axis < rank; ++axis)
- {
- res.set(axis, ToARMComputeAxis(rank, axis).value());
- }
-
- return res;
-}
-
-inline ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
- bool apply_dim_correction = true)
-{
- const uint32_t rank = shape.rank();
+#include <NeuralNetworks.h>
- ::arm_compute::TensorShape res{};
-
- res.set_num_dimensions(rank);
-
- for (uint32_t axis = 0; axis < rank; ++axis)
- {
- // NOTE In some cases, in incorrect dimensions is required.
- // For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of
- // LSTM is used as the weight of the FullyConnected.
- // The FullyConnected's weight must be greater or equal than 2-dimensions.
- // However, if the dimension correction is applied to input_to_input_weights with input_size
- // equal to 1, it will be changed to 1-D.
- // So input_to_input_weights is not used by the weight of FullyConnected.
- res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis), apply_dim_correction);
- }
-
- return res;
-}
+#include "internal/Model.h"
-::arm_compute::DataType asDataType(const int32_t type)
-{
- switch (type)
- {
- case ANEURALNETWORKS_FLOAT32:
- case ANEURALNETWORKS_TENSOR_FLOAT32:
- return ::arm_compute::DataType::F32;
- case ANEURALNETWORKS_INT32:
- case ANEURALNETWORKS_TENSOR_INT32:
- return ::arm_compute::DataType::S32;
- case ANEURALNETWORKS_UINT32:
- return ::arm_compute::DataType::U32;
- case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM:
- return ::arm_compute::DataType::QASYMM8;
- default:
- throw std::runtime_error("Not supported, yet");
- break;
- }
-}
+/**
+ * @brief Generate arm compute coordinate object from rank
+ * @param[in] rank Rank number
+ * @return Coordinate object
+ */
+::arm_compute::Coordinates getARMComputeAxises(uint32_t rank);
+
+/**
+ * @brief Generate arm compute coordinate object from runtime coordinate object
+ * @param[in] runtime_coord Runtime coordinates object
+ * @param[in] axises Coordinates for axises to map runtime-coordinates to
+ * arm_compute-coordinates
+ * @return Arm_compute coordinate object
+ */
+::arm_compute::Coordinates asARMComputeCoordinates(const ::arm_compute::Coordinates &runtime_coord,
+ const ::arm_compute::Coordinates &axises);
+
+/**
+* @brief Generate arm compute permutation vector from runtime permutation vector
+* @param[in] rank Rank number supported upto 4
+* @param[in] runtime_pv Integer array for runtime permutation vector
+* @return Permutation vector of arm compute
+*/
+::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank,
+ const int32_t *runtime_pv);
+/**
+ * @brief Cast from shape of internal to arm compute
+ * @param[in] shape Internal shape object
+ * @param[in] apply_dim_correction Flag to state whether apply dimension correction after setting
+ * one dimension in arm compute
+ * @return TensorShape object of arm compute
+ */
+::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
+ bool apply_dim_correction = true);
-::arm_compute::ActivationLayerInfo asActivationInfo(FuseCode code)
-{
- switch (code)
- {
- case ANEURALNETWORKS_FUSED_NONE:
- return ::arm_compute::ActivationLayerInfo{};
- case ANEURALNETWORKS_FUSED_RELU:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::RELU};
- case ANEURALNETWORKS_FUSED_RELU1:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 1.0f, -1.0f};
- case ANEURALNETWORKS_FUSED_RELU6:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.0f};
- default:
- throw std::runtime_error("Not supported, yet");
- break;
- }
-}
+/**
+ * @brief Cast from data type enum of NNAPI to arm compute
+ * @param[in] type NNAPI data type
+ * @return Data type of arm compute
+ */
+::arm_compute::DataType asDataType(const int32_t type);
-::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset)
-{
- return ::arm_compute::QuantizationInfo(scale, offset);
-}
+/**
+ * @brief Cast from NNAPI activation type enum to activation object of arm compute
+ * @param[in] code NNAPI activation type
+ * @return ActivationLayerInfo object of arm compute
+ */
+::arm_compute::ActivationLayerInfo asActivationInfo(FuseCode code);
+/**
+ * @brief Generate quantization info object of arm compute
+ * @param[in] scale Scale of quantization
+ * @param[in] offset Offset of quantization
+ * @return QuantizationInfo object of arm compute
+ */
+::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset);
+
+/**
+ * @brief Cast from internal tensor info to tensor info object of arm compute
+ * @param[in] shape Tensor shape
+ * @param[in] type Tensor type
+ * @param[in] scale Scale of tensor quantization
+ * @param[in] zeroPoint Zeropoint of tensor quantization
+ * @return TensorInfo object of arm compute
+ */
::arm_compute::TensorInfo asTensorInfo(const ::arm_compute::TensorShape &shape, const int32_t type,
- const float scale = 0.0f, const int32_t zeroPoint = 0)
-{
- return ::arm_compute::TensorInfo(shape, 1, asDataType(type),
- asQuantizationInfo(scale, zeroPoint));
-}
-
+ const float scale = 0.0f, const int32_t zeroPoint = 0);
+
+/**
+ * @brief Set value to arm compute tensor with casting
+ * @param[in] value Value to set
+ * @param[out] to Target tensor of arm compute
+ * @param[in] id Position of element
+ * @return N/A
+ */
template <typename FromT>
void copyCast(const FromT value, ::arm_compute::ITensor *to, const ::arm_compute::Coordinates &id)
{
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/feature/View.h b/runtimes/pure_arm_compute/src/internal/arm_compute/feature/View.h
index 9d19021ae..c989ef4c2 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/feature/View.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/feature/View.h
@@ -14,10 +14,15 @@
* limitations under the License.
*/
+/**
+ * @file View.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines internal::arm_compute::feature::View class
+ */
#ifndef __INTERNAL_ARM_COMPUTE_FEATURE_VIEW_H__
#define __INTERNAL_ARM_COMPUTE_FEATURE_VIEW_H__
-#include "util/feature/Reader.h"
+#include "misc/feature/Reader.h"
#include <arm_compute/core/ITensor.h>
@@ -28,15 +33,29 @@ namespace arm_compute
namespace feature
{
-template <typename T> class View final : public nnfw::util::feature::Reader<T>
+/**
+ * @brief Class to access feature's element
+ */
+template <typename T> class View final : public nnfw::misc::feature::Reader<T>
{
public:
+ /**
+ * @brief Construct a new View object
+ * @param[in] tensor Feature to support access
+ */
View(::arm_compute::ITensor *tensor) : _tensor{tensor}
{
// DO NOTHING
}
public:
+ /**
+ * @brief Get value of element in 3D feature using channel, row and column
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Value of element
+ */
T at(uint32_t ch, uint32_t row, uint32_t col) const override
{
const auto offset = feature_index_to_byte_offset(ch, row, col);
@@ -46,6 +65,14 @@ public:
return *ptr;
}
+ /**
+ * @brief Get value of element in 4D feature using batch, channel, row and column
+ * @param[in] batch Batch index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Value of element
+ */
T at(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const override
{
const auto offset = feature_index_to_byte_offset(batch, ch, row, col);
@@ -56,6 +83,13 @@ public:
}
public:
+ /**
+ * @brief Get reference of element in 3D feature using channel, row and column
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Reference of element
+ */
T &at(uint32_t ch, uint32_t row, uint32_t col)
{
const auto offset = feature_index_to_byte_offset(ch, row, col);
@@ -65,6 +99,14 @@ public:
return *ptr;
}
+ /**
+ * @brief Get reference of element in 4D feature using batch, channel, row and column
+ * @param[in] batch Batch index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Reference of element
+ */
T &at(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col)
{
const auto offset = feature_index_to_byte_offset(batch, ch, row, col);
@@ -75,12 +117,27 @@ public:
}
private:
+ /**
+ * @brief Get offset of element in 3D feature
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Offset of element
+ */
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});
}
+ /**
+ * @brief Get offset of element in 4D feature
+ * @param[in] batch Batch index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Offset of element
+ */
size_t feature_index_to_byte_offset(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const
{
// ARM Compute uses CHW ordering
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/kernel/View.h b/runtimes/pure_arm_compute/src/internal/arm_compute/kernel/View.h
index 28054d7c8..399cdf913 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/kernel/View.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/kernel/View.h
@@ -14,11 +14,16 @@
* limitations under the License.
*/
+/**
+ * @file View.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines internel::arm_compute::kernel::View class
+ */
#ifndef __INTERNAL_ARM_COMPUTE_KERNEL_VIEW_H__
#define __INTERNAL_ARM_COMPUTE_KERNEL_VIEW_H__
-#include "util/kernel/Shape.h"
-#include "util/kernel/Reader.h"
+#include "misc/kernel/Shape.h"
+#include "misc/kernel/Reader.h"
#include <arm_compute/core/ITensor.h>
@@ -29,15 +34,30 @@ namespace arm_compute
namespace kernel
{
-template <typename T> class View final : public nnfw::util::kernel::Reader<T>
+/**
+ * @brief Class to access kernel's element
+ */
+template <typename T> class View final : public nnfw::misc::kernel::Reader<T>
{
public:
+ /**
+ * @brief Construct a new View object
+ * @param[in] tensor Kernel to support access
+ */
View(::arm_compute::ITensor *tensor) : _tensor{tensor}
{
// DO NOTHING
}
public:
+ /**
+ * @brief Get value of element in kernel
+ * @param[in] nth Kernel index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Value of element
+ */
T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
{
const auto offset = kernel_index_to_byte_offset(nth, ch, row, col);
@@ -48,6 +68,14 @@ public:
}
public:
+ /**
+ * @brief Get reference of element in kernel
+ * @param[in] nth Kernel index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Reference of element
+ */
T &at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col)
{
const auto offset = kernel_index_to_byte_offset(nth, ch, row, col);
@@ -58,6 +86,14 @@ public:
}
private:
+ /**
+ * @brief Get offset of element in kernel
+ * @param[in] nth Kernel index
+ * @param[in] ch Channel index
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Offset of element
+ */
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});
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/matrix/View.h b/runtimes/pure_arm_compute/src/internal/arm_compute/matrix/View.h
index e3534294f..305fff729 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/matrix/View.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/matrix/View.h
@@ -14,11 +14,16 @@
* limitations under the License.
*/
+/**
+ * @file View.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines internal::arm_compute::matrix::View class
+ */
#ifndef __INTERNAL_ARM_COMPUTE_MATRIX_VIEW_H__
#define __INTERNAL_ARM_COMPUTE_MATRIX_VIEW_H__
-#include "util/matrix/Shape.h"
-#include "util/matrix/Reader.h"
+#include "misc/matrix/Shape.h"
+#include "misc/matrix/Reader.h"
#include <arm_compute/core/ITensor.h>
@@ -29,15 +34,28 @@ namespace arm_compute
namespace matrix
{
-template <typename T> class View final : public nnfw::util::matrix::Reader<T>
+/**
+ * @brief Class to access matrix's element
+ */
+template <typename T> class View final : public nnfw::misc::matrix::Reader<T>
{
public:
+ /**
+ * @brief Construct a new View object
+ * @param[in] tensor Matrix to support access
+ */
View(::arm_compute::ITensor *tensor) : _tensor{tensor}
{
// DO NOTHING
}
public:
+ /**
+ * @brief Get value of element in matrix
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Value of element
+ */
T at(uint32_t row, uint32_t col) const override
{
const auto offset = matrix_index_to_byte_offset(row, col);
@@ -48,6 +66,12 @@ public:
}
public:
+ /**
+ * @brief Get reference of element in matrix
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Refence of element
+ */
T &at(uint32_t row, uint32_t col)
{
const auto offset = matrix_index_to_byte_offset(row, col);
@@ -58,6 +82,12 @@ public:
}
private:
+ /**
+ * @brief Get offset of element in matrix
+ * @param[in] row Row index
+ * @param[in] col Column index
+ * @return Offset of element
+ */
size_t matrix_index_to_byte_offset(uint32_t row, uint32_t col) const
{
return _tensor->info()->offset_element_in_bytes(::arm_compute::Coordinates{col, row});
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/tensor/View.h b/runtimes/pure_arm_compute/src/internal/arm_compute/tensor/View.h
index 0d8f2ab81..372bd682d 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/tensor/View.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/tensor/View.h
@@ -14,11 +14,16 @@
* limitations under the License.
*/
+/**
+ * @file View.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines internal::arm_compute::tensor::View class
+ */
#ifndef __INTERNAL_ARM_COMPUTE_TENSOR_VIEW_H__
#define __INTERNAL_ARM_COMPUTE_TENSOR_VIEW_H__
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
+#include "misc/tensor/Shape.h"
+#include "misc/tensor/Index.h"
#include <arm_compute/core/ITensor.h>
@@ -29,16 +34,28 @@ namespace arm_compute
namespace tensor
{
+/**
+ * @brief Class to access tensor's element
+ */
template <typename T> class View
{
public:
+ /**
+ * @brief Construct a new View object
+ * @param[in] tensor Tensor to support access
+ */
View(::arm_compute::ITensor *tensor) : _tensor{tensor}
{
// DO NOTHING
}
private:
- uint32_t byte_offset_of(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Get offset of element in tensor
+ * @param[in] index Index of element
+ * @return Offset of element
+ */
+ uint32_t byte_offset_of(const nnfw::misc::tensor::Index &index) const
{
// NOTE index.rank() >= _tensor->info()->num_dimensions() should hold here
const uint32_t rank = index.rank();
@@ -56,7 +73,12 @@ private:
}
public:
- T at(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Get value of element in tensor
+ * @param[in] index Index of element
+ * @return Value of element
+ */
+ T at(const nnfw::misc::tensor::Index &index) const
{
const auto offset = byte_offset_of(index);
@@ -65,7 +87,12 @@ public:
return *ptr;
}
- T &at(const nnfw::util::tensor::Index &index)
+ /**
+ * @brief Get reference of element in tensor
+ * @param[in] index Index of element
+ * @return Reference of element
+ */
+ T &at(const nnfw::misc::tensor::Index &index)
{
const auto offset = byte_offset_of(index);