ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::exec::feature::nhwc::Reader< T > Class Template Reference

#include <Reader.h>

Collaboration diagram for onert::exec::feature::nhwc::Reader< T >:

Public Types

using Strides = ir::FeatureShape
 

Public Member Functions

 Reader (const ir::FeatureShape &shape, const Strides &strides, const T *ptr, size_t len)
 
 Reader (const backend::ITensor *tensor)
 
at (uint32_t batch, uint32_t row, uint32_t col, uint32_t ch) const final
 Get the value used by four indexes.
 
at (uint32_t row, uint32_t col, uint32_t ch) const final
 Get the value used by three indexes.
 
- Public Member Functions inherited from onert::exec::feature::Reader< T >
virtual ~Reader ()=default
 Destruct Reader object using default destructor.
 

Protected Member Functions

const T & getRef (uint32_t batch, uint32_t row, uint32_t col, uint32_t ch) const
 

Detailed Description

template<typename T>
class onert::exec::feature::nhwc::Reader< T >

Definition at line 36 of file Reader.h.

Member Typedef Documentation

◆ Strides

template<typename T >
using onert::exec::feature::nhwc::Reader< T >::Strides = ir::FeatureShape

Definition at line 39 of file Reader.h.

Constructor & Destructor Documentation

◆ Reader() [1/2]

template<typename T >
onert::exec::feature::nhwc::Reader< T >::Reader ( const ir::FeatureShape shape,
const Strides strides,
const T *  ptr,
size_t  len 
)
inline

Definition at line 41 of file Reader.h.

42 : _shape{shape}, _strides{strides}, _ptr{reinterpret_cast<const uint8_t *>(ptr)}, _len{len}
43 {
44 assert(len == static_cast<size_t>(strides.N != 0 ? shape.N * strides.N
45 : strides.H != 0 ? shape.H * strides.H
46 : strides.W != 0 ? shape.W * strides.W
47 : shape.C * strides.C));
48 }
C
Definition infer.py:52

References onert::ir::FeatureShape::C, onert::ir::FeatureShape::H, onert::ir::FeatureShape::N, and onert::ir::FeatureShape::W.

◆ Reader() [2/2]

template<typename T >
onert::exec::feature::nhwc::Reader< T >::Reader ( const backend::ITensor tensor)
inline

Definition at line 51 of file Reader.h.

52 : _ptr{tensor->buffer() + tensor->calcOffset({0, 0, 0, 0})}, _len{tensor->total_size()}
53 {
54 const auto start_offset = tensor->calcOffset({0, 0, 0, 0});
55 auto shape = tensor->getShape();
56 _strides.C = shape.dim(3) == 1 ? 0 : tensor->calcOffset({0, 0, 0, 1}) - start_offset;
57 _strides.W = shape.dim(2) == 1 ? 0 : tensor->calcOffset({0, 0, 1, 0}) - start_offset;
58 _strides.H = shape.dim(1) == 1 ? 0 : tensor->calcOffset({0, 1, 0, 0}) - start_offset;
59 _strides.N = shape.dim(0) == 1 ? 0 : tensor->calcOffset({1, 0, 0, 0}) - start_offset;
60
61 _shape.C = shape.dim(3);
62 _shape.W = shape.dim(2);
63 _shape.H = shape.dim(1);
64 _shape.N = shape.dim(0);
65 }

Member Function Documentation

◆ at() [1/2]

template<typename T >
T onert::exec::feature::nhwc::Reader< T >::at ( uint32_t  batch,
uint32_t  ch,
uint32_t  row,
uint32_t  col 
) const
inlinefinalvirtual

Get the value used by four indexes.

Parameters
[in]batchThe batch index
[in]chThe depth index
[in]rowThe height index
[in]colThe width index
Returns
The value at the offset

Implements onert::exec::feature::Reader< T >.

Definition at line 68 of file Reader.h.

69 {
70 return getRef(batch, row, col, ch);
71 }
const T & getRef(uint32_t batch, uint32_t row, uint32_t col, uint32_t ch) const
Definition Reader.h:75

◆ at() [2/2]

template<typename T >
T onert::exec::feature::nhwc::Reader< T >::at ( uint32_t  ch,
uint32_t  row,
uint32_t  col 
) const
inlinefinalvirtual

Get the value used by three indexes.

Parameters
[in]chThe depth index
[in]rowThe height index
[in]colThe width index
Returns
The value at the offset

Implements onert::exec::feature::Reader< T >.

Definition at line 72 of file Reader.h.

72{ return getRef(0, row, col, ch); }

◆ getRef()

template<typename T >
const T & onert::exec::feature::nhwc::Reader< T >::getRef ( uint32_t  batch,
uint32_t  row,
uint32_t  col,
uint32_t  ch 
) const
inlineprotected

Definition at line 75 of file Reader.h.

76 {
77 const auto offset = feature_index_to_byte_offset(batch, row, col, ch);
78
79 const T *ptr = reinterpret_cast<const T *>(_ptr + offset);
80
81 return *ptr;
82 }
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References offset().

Referenced by onert::exec::feature::nhwc::View< T >::at(), and onert::exec::feature::nhwc::View< T >::at().


The documentation for this class was generated from the following file: