summaryrefslogtreecommitdiff
path: root/runtimes/pure_arm_compute/src/internal/nnapi/tensor
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/pure_arm_compute/src/internal/nnapi/tensor')
-rw-r--r--runtimes/pure_arm_compute/src/internal/nnapi/tensor/ConstView.h36
-rw-r--r--runtimes/pure_arm_compute/src/internal/nnapi/tensor/Reader.h62
-rw-r--r--runtimes/pure_arm_compute/src/internal/nnapi/tensor/View.h49
3 files changed, 116 insertions, 31 deletions
diff --git a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/ConstView.h b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/ConstView.h
index 38d1b291b..6a3fff646 100644
--- a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/ConstView.h
+++ b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/ConstView.h
@@ -14,6 +14,12 @@
* limitations under the License.
*/
+/**
+ * @file        ConstView.h
+ * @brief       This file contains ConstView class
+ * @ingroup     COM_AI_RUNTIME
+ */
+
#ifndef __INTERNAL_NNAPI_TENSOR_CONST_VIEW_H__
#define __INTERNAL_NNAPI_TENSOR_CONST_VIEW_H__
@@ -27,21 +33,36 @@ namespace nnapi
namespace tensor
{
+/**
+ * @brief Wrapper class to read tensor values
+ * @tparam T The tensor element type
+ */
template <typename T> class ConstView
{
public:
- ConstView(const ::nnfw::util::tensor::Shape &shape, const uint8_t *ptr, size_t len)
+ /**
+ * @brief Construct a ConstView class
+ * @param[in] shape Tensor shape
+ * @param[in] ptr The base pointer of actual data
+ * @param[in] len The number of bytes
+ */
+ ConstView(const ::nnfw::misc::tensor::Shape &shape, const uint8_t *ptr, size_t len)
: _shape{shape}, _ptr{ptr}, _len{len}
{
// DO NOTHING
}
public:
- const nnfw::util::tensor::Shape &shape(void) const { return _shape; }
+ const nnfw::misc::tensor::Shape &shape(void) const { return _shape; }
private:
// TODO Make this as a helper function, and share it for both View<T> and ConstView<T>
- uint32_t offset_of(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Calculate offset for the given tensor index
+ * @param[in] index Tensor index
+ * @return The calculated offset
+ */
+ uint32_t offset_of(const nnfw::misc::tensor::Index &index) const
{
if (_shape.rank() == 0)
{
@@ -61,7 +82,12 @@ private:
}
public:
- T at(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Get the value on the given index
+ * @param[in] index Flattened tensor index
+ * @return The value on the given index
+ */
+ T at(const nnfw::misc::tensor::Index &index) const
{
const auto offset = offset_of(index);
@@ -71,7 +97,7 @@ public:
}
private:
- const nnfw::util::tensor::Shape _shape;
+ const nnfw::misc::tensor::Shape _shape;
private:
const uint8_t *const _ptr;
diff --git a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/Reader.h b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/Reader.h
index fe89e572e..cc51db594 100644
--- a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/Reader.h
+++ b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/Reader.h
@@ -14,11 +14,17 @@
* limitations under the License.
*/
+/**
+ * @file        Reader.h
+ * @brief       This file contains Reader class
+ * @ingroup     COM_AI_RUNTIME
+ */
+
#ifndef __INTERNAL_NNAPI_TENSOR_READER_H__
#define __INTERNAL_NNAPI_TENSOR_READER_H__
#include <vector>
-#include "util/tensor/Reader.h"
+#include "misc/tensor/Reader.h"
namespace internal
{
@@ -27,11 +33,20 @@ namespace nnapi
namespace tensor
{
-template <typename T> class Reader final : public nnfw::util::tensor::Reader<T>
+/**
+ * @brief Wrapper class to read tensor values
+ * @tparam T The tensor element type
+ */
+template <typename T> class Reader final : public nnfw::misc::tensor::Reader<T>
{
public:
- // NOTE The parameter len denotes the number of bytes.
- Reader(const ::nnfw::util::tensor::Shape &shape, const T *ptr, size_t len)
+ /**
+ * @brief Construct a Reader class
+ * @param[in] shape Tensor shape
+ * @param[in] ptr The base pointer of actual data
+ * @param[in] len The number of bytes
+ */
+ Reader(const ::nnfw::misc::tensor::Shape &shape, const T *ptr, size_t len)
: _shape{shape}, _ptr{ptr}
{
assert(shape.element_nums() * sizeof(T) == len);
@@ -39,10 +54,19 @@ public:
}
public:
- const nnfw::util::tensor::Shape &shape(void) const { return _shape; }
+ /**
+ * @brief Get shape object
+ * @return The shape as const reference
+ */
+ const nnfw::misc::tensor::Shape &shape(void) const { return _shape; }
public:
- T at(const nnfw::util::tensor::Index &index_nnapi) const override
+ /**
+ * @brief Get the value on the given index
+ * @param[in] index_nnapi Flattened tensor index
+ * @return The value on the given index
+ */
+ T at(const nnfw::misc::tensor::Index &index_nnapi) const override
{
uint32_t offset = 0;
@@ -53,17 +77,19 @@ public:
}
private:
- /*
- Assuming that shape is [d4, .. , d1] and data is stored at a pointer ptr,
- we need to calculate the offset of index [i4, .. i1] as follows:
- offset = i4 * (d3 * d2 * d1) +
- i3 * (d2 * d1) +
- i2 * (d1) +
- i1
- So (d4 * d3 * d2 * d1) or (d3 * d2 * d1) or (d2 * d1) happens whenever offset is calculate.
- To minimize this repetitive calculation,
- _stridess[n] contains _spape[n-1]*_spape[n-2]*_spape[0]
- */
+ /**
+ * @brief Initializes @c _stridess
+ * @return N/A
+ * @note Assuming that shape is [d4, .. , d1] and data is stored at a pointer ptr,
+ we need to calculate the offset of index [i4, .. i1] as follows:
+ offset = i4 * (d3 * d2 * d1) +
+ i3 * (d2 * d1) +
+ i2 * (d1) +
+ i1
+ So (d4 * d3 * d2 * d1) or (d3 * d2 * d1) or (d2 * d1) happens whenever offset is
+ calculate. To minimize this repetitive calculation,
+ _stridess[n] contains _spape[n-1]*_spape[n-2]*_spape[0]
+ */
void initialize(void)
{
for (int r = 0; r < _shape.rank(); r++)
@@ -76,7 +102,7 @@ private:
}
private:
- nnfw::util::tensor::Shape _shape;
+ nnfw::misc::tensor::Shape _shape;
private:
const T *_ptr;
diff --git a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/View.h b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/View.h
index 80e1bb057..f8f297f97 100644
--- a/runtimes/pure_arm_compute/src/internal/nnapi/tensor/View.h
+++ b/runtimes/pure_arm_compute/src/internal/nnapi/tensor/View.h
@@ -14,11 +14,16 @@
* limitations under the License.
*/
+/**
+ * @file View.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines internal::nnapi::tensor::View class
+ */
#ifndef __INTERNAL_NNAPI_TENSOR_VIEW_H__
#define __INTERNAL_NNAPI_TENSOR_VIEW_H__
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
+#include "misc/tensor/Shape.h"
+#include "misc/tensor/Index.h"
namespace internal
{
@@ -27,20 +32,38 @@ namespace nnapi
namespace tensor
{
+/**
+ * @brief Class to access tensor's element information using index
+ */
template <typename T> class View
{
public:
+ /**
+ * @brief Construct a new View object
+ * @param[in] shape Shape of tensor
+ * @param[in] ptr Pointer to tensor data
+ * @param[in] len Size of tensor (byte)
+ */
// NOTE The parameter len denotes the number of bytes.
- View(const ::nnfw::util::tensor::Shape &shape, T *ptr, size_t len) : _shape{shape}, _ptr{ptr}
+ View(const ::nnfw::misc::tensor::Shape &shape, T *ptr, size_t len) : _shape{shape}, _ptr{ptr}
{
assert(shape.element_nums() * sizeof(T) == len);
}
public:
- const nnfw::util::tensor::Shape &shape(void) const { return _shape; }
+ /**
+ * @brief Get shape of tensor
+ * @return Shape of tensor
+ */
+ const nnfw::misc::tensor::Shape &shape(void) const { return _shape; }
private:
- uint32_t offset_of(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Get position of element using index in tensor
+ * @param[in] index Index of element
+ * @return Position of element
+ */
+ uint32_t offset_of(const nnfw::misc::tensor::Index &index) const
{
if (_shape.rank() == 0)
{
@@ -60,14 +83,24 @@ private:
}
public:
- T at(const nnfw::util::tensor::Index &index) const
+ /**
+ * @brief Get value of element at index
+ * @param[in] index Index of element
+ * @return Value of element at index
+ */
+ T at(const nnfw::misc::tensor::Index &index) const
{
const auto offset = offset_of(index);
return _ptr[offset];
}
- T &at(const nnfw::util::tensor::Index &index)
+ /**
+ * @brief Get reference of element at index
+ * @param[in] index Index of element
+ * @return Reference of element at index
+ */
+ T &at(const nnfw::misc::tensor::Index &index)
{
const auto offset = offset_of(index);
@@ -75,7 +108,7 @@ public:
}
private:
- nnfw::util::tensor::Shape _shape;
+ nnfw::misc::tensor::Shape _shape;
private:
T *_ptr;