ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::exec::feature::nchw::Reader< T > Class Template Reference

#include <Reader.h>

Collaboration diagram for onert::exec::feature::nchw::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 (backend::ITensor *tensor)
 
at (uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const final
 Get the value used by four indexes.
 
at (uint32_t ch, uint32_t row, uint32_t col) 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 ch, uint32_t row, uint32_t col) const
 

Detailed Description

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

Definition at line 30 of file Reader.h.

Member Typedef Documentation

◆ Strides

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

Definition at line 33 of file Reader.h.

Constructor & Destructor Documentation

◆ Reader() [1/2]

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

Definition at line 35 of file Reader.h.

36 : _shape{shape}, _strides{strides}, _ptr{reinterpret_cast<const uint8_t *>(ptr)}, _len{len}
37 {
38 assert(len == static_cast<size_t>(strides.N != 0 ? shape.N * strides.N
39 : strides.C != 0 ? shape.C * strides.C
40 : strides.H != 0 ? shape.H * strides.H
41 : shape.W * strides.W));
42 }
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::nchw::Reader< T >::Reader ( backend::ITensor tensor)
inline

Definition at line 45 of file Reader.h.

46 : _ptr{tensor->buffer() + tensor->calcOffset({0, 0, 0, 0})}, _len{tensor->total_size()}
47 {
48 const auto start_offset = tensor->calcOffset({0, 0, 0, 0});
49 auto shape = tensor->getShape();
50 _strides.W = shape.dim(3) == 1 ? 0 : tensor->calcOffset({0, 0, 0, 1}) - start_offset;
51 _strides.H = shape.dim(2) == 1 ? 0 : tensor->calcOffset({0, 0, 1, 0}) - start_offset;
52 _strides.C = shape.dim(1) == 1 ? 0 : tensor->calcOffset({0, 1, 0, 0}) - start_offset;
53 _strides.N = shape.dim(0) == 1 ? 0 : tensor->calcOffset({1, 0, 0, 0}) - start_offset;
54
55 _shape.W = shape.dim(3);
56 _shape.H = shape.dim(2);
57 _shape.C = shape.dim(1);
58 _shape.N = shape.dim(0);
59 }

Member Function Documentation

◆ at() [1/2]

template<typename T >
T onert::exec::feature::nchw::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 62 of file Reader.h.

63 {
64 return getRef(batch, ch, row, col);
65 }
const T & getRef(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const
Definition Reader.h:69

◆ at() [2/2]

template<typename T >
T onert::exec::feature::nchw::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 66 of file Reader.h.

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

◆ getRef()

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

Definition at line 69 of file Reader.h.

70 {
71 const auto offset = feature_index_to_byte_offset(batch, ch, row, col);
72
73 const T *ptr = reinterpret_cast<const T *>(_ptr + offset);
74
75 return *ptr;
76 }
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References offset().

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


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