ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Dims.h File Reference
#include "Shape.h"
#include "Macro.h"

Go to the source code of this file.

Data Structures

struct  Dims< N >
 

Functions

Dims< 4 > convertShapeToDims (const Shape &shape)
 
int Offset (const Dims< 4 > &dims, int i0, int i1, int i2, int i3)
 
template<int N>
int ArraySize (const Dims< N > &array, int index)
 
template<int N>
int FlatSize (const Dims< N > &dims)
 
int RequiredBufferSizeForDims (const Dims< 4 > &dims)
 
template<int N>
int MatchingFlatSize (const Dims< N > &dims, const Dims< N > &check_dims_0)
 
template<int N>
int MatchingFlatSize (const Dims< N > &dims, const Dims< N > &check_dims_0, const Dims< N > &check_dims_1)
 
template<int N>
int MatchingFlatSize (const Dims< N > &dims, const Dims< N > &check_dims_0, const Dims< N > &check_dims_1, const Dims< N > &check_dims_2)
 
template<int N>
int MatchingFlatSize (const Dims< N > &dims, const Dims< N > &check_dims_0, const Dims< N > &check_dims_1, const Dims< N > &check_dims_2, const Dims< N > &check_dims_3)
 
template<int N>
bool IsPackedWithoutStrides (const Dims< N > &dims)
 

Function Documentation

◆ ArraySize()

template<int N>
int ArraySize ( const Dims< N > &  array,
int  index 
)

Definition at line 76 of file Dims.h.

77{
78 DCHECK(index >= 0 && index < N);
79 return array.sizes[index];
80}
#define DCHECK(condition)
Definition Macro.h:25
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
int sizes[N]
Definition Dims.h:27

References DCHECK, and Dims< N >::sizes.

Referenced by AveragePool(), BroadcastAdd(), BroadcastDiv(), BroadcastMul(), BroadcastSub(), Concatenation(), Conv(), optimized_ops::DepthwiseConv(), FullyConnected(), Im2col(), MatchingArraySize(), MatchingArraySize(), MatchingFlatSize(), MatchingFlatSize(), MatchingFlatSize(), MatchingFlatSize(), MaxPool(), and NdArrayDescsForElementwiseBroadcast().

◆ convertShapeToDims()

Dims< 4 > convertShapeToDims ( const Shape shape)
inline

Definition at line 31 of file Dims.h.

32{
33 Dims<4> dims;
34 for (int i = 0; i < 4; i++)
35 {
36 dims.sizes[i] = 1;
37 }
38
39 if (shape.dimensions.size() == 1)
40 {
41 dims.sizes[0] = (int)getSizeOfDimension(shape, 0);
42 }
43 else
44 {
45 for (int i = 0; i < 4; i++)
46 {
47 int src = (int)shape.dimensions.size() - i - 1;
48 if (src >= 0)
49 {
50 dims.sizes[i] = (int)getSizeOfDimension(shape, src);
51 }
52 }
53 }
54
55 dims.strides[0] = 1;
56 for (int i = 1; i < 4; i++)
57 {
58 dims.strides[i] = dims.strides[i - 1] * dims.sizes[i - 1];
59 }
60 return dims;
61}
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
Definition Dims.h:26
int strides[N]
Definition Dims.h:28
std::vector< uint32_t > dimensions
Definition Shape.h:30

References Shape::dimensions, getSizeOfDimension(), Dims< N >::sizes, and Dims< N >::strides.

Referenced by concatenationFloat32(), padGeneric(), and softmaxFloat32().

◆ FlatSize()

template<int N>
int FlatSize ( const Dims< N > &  dims)
inline

Definition at line 83 of file Dims.h.

84{
85 int flat_size = 1;
86 for (int i = 0; i < N; ++i)
87 {
88 flat_size *= dims.sizes[i];
89 }
90 return flat_size;
91}

References Dims< N >::sizes.

Referenced by MatchingFlatSize(), MatchingFlatSize(), and MatchingFlatSize().

◆ IsPackedWithoutStrides()

template<int N>
bool IsPackedWithoutStrides ( const Dims< N > &  dims)

Definition at line 155 of file Dims.h.

156{
157 int expected_stride = 1;
158 for (int d = 0; d < N; d++)
159 {
160 if (dims.strides[d] != expected_stride)
161 return false;
162 expected_stride *= dims.sizes[d];
163 }
164 return true;
165}

References Dims< N >::sizes, and Dims< N >::strides.

Referenced by Add(), Concatenation(), Div(), Im2col(), Mul(), and Sub().

◆ MatchingFlatSize() [1/4]

template<int N>
int MatchingFlatSize ( const Dims< N > &  dims,
const Dims< N > &  check_dims_0 
)
inline

◆ MatchingFlatSize() [2/4]

template<int N>
int MatchingFlatSize ( const Dims< N > &  dims,
const Dims< N > &  check_dims_0,
const Dims< N > &  check_dims_1 
)
inline

Definition at line 119 of file Dims.h.

121{
122 for (int i = 0; i < N; ++i)
123 {
124 DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i));
125 }
126 return MatchingFlatSize(dims, check_dims_1);
127}
int MatchingFlatSize(const Dims< N > &dims, const Dims< N > &check_dims_0)
Definition Dims.h:108

References ArraySize(), DCHECK_EQ, and MatchingFlatSize().

◆ MatchingFlatSize() [3/4]

template<int N>
int MatchingFlatSize ( const Dims< N > &  dims,
const Dims< N > &  check_dims_0,
const Dims< N > &  check_dims_1,
const Dims< N > &  check_dims_2 
)
inline

Definition at line 131 of file Dims.h.

133{
134 for (int i = 0; i < N; ++i)
135 {
136 DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i));
137 }
138 return FlatSize(dims, check_dims_1, check_dims_2);
139}

References ArraySize(), DCHECK_EQ, and FlatSize().

◆ MatchingFlatSize() [4/4]

template<int N>
int MatchingFlatSize ( const Dims< N > &  dims,
const Dims< N > &  check_dims_0,
const Dims< N > &  check_dims_1,
const Dims< N > &  check_dims_2,
const Dims< N > &  check_dims_3 
)
inline

Definition at line 143 of file Dims.h.

146{
147 for (int i = 0; i < N; ++i)
148 {
149 DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i));
150 }
151 return FlatSize(dims, check_dims_1, check_dims_2, check_dims_3);
152}

References ArraySize(), DCHECK_EQ, and FlatSize().

◆ Offset()

int Offset ( const Dims< 4 > &  dims,
int  i0,
int  i1,
int  i2,
int  i3 
)
inline

Definition at line 64 of file Dims.h.

65{
66 DCHECK(i0 >= 0 && i0 < dims.sizes[0]);
67 DCHECK(i1 >= 0 && i1 < dims.sizes[1]);
68 DCHECK(i2 >= 0 && i2 < dims.sizes[2]);
69 DCHECK(i3 >= 0 && i3 < dims.sizes[3]);
70 return i0 * dims.strides[0] + i1 * dims.strides[1] + i2 * dims.strides[2] + i3 * dims.strides[3];
71}

References DCHECK, Dims< N >::sizes, and Dims< N >::strides.

Referenced by AveragePool(), BroadcastAdd(), BroadcastDiv(), BroadcastMul(), tflite::reference_ops::BroadcastPow4DSlow(), tflite::reference_ops::BroadcastSelect4DSlow(), BroadcastSub(), ExtractPatchIntoBufferColumn(), tflite::reference_ops::LstmCell(), MaxPool(), tflite::reference_ops::Slice(), and tflite::reference_ops::SparseToDense().

◆ RequiredBufferSizeForDims()

int RequiredBufferSizeForDims ( const Dims< 4 > &  dims)
inline

Definition at line 94 of file Dims.h.

95{
96 int max_offset = 0;
97 for (int i = 0; i < 4; i++)
98 {
99 max_offset += (dims.sizes[i] - 1) * dims.strides[i];
100 }
101 return max_offset + 1;
102}

References Dims< N >::sizes, and Dims< N >::strides.

Referenced by MapAsVector().