ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::ruy Namespace Reference

Namespaces

namespace  ruy_support
 

Data Structures

class  Conv
 
struct  ConvParams
 
struct  FullyConnectedParams
 
struct  GemmParams
 
struct  MatrixParams
 
struct  PaddingValues
 
class  Shape
 
struct  UNUSED_ALL
 

Enumerations

enum class  FusedActivationFunctionType {
  kNone = 0 , kRelu6 = 1 , kRelu1 = 2 , kRelu = 3 ,
  kTanh = 4 , kSigmoid = 6
}
 
enum class  PaddingType { kNone = 0 , kSame = 1 , kValid = 2 }
 
enum class  Order { kColMajor , kRowMajor }
 
enum class  CachePolicy : std::uint8_t { kNeverCache , kCacheIfLargeSpeedup , kAlwaysCache }
 
enum class  QuantizationFlavor { kFloatingPoint , kIntegerWithUniformMultiplier , kIntegerWithPerRowMultiplier }
 

Functions

void FullyConnected (const FullyConnectedParams &params, const Shape &input_shape, const float *input_data, const Shape &weights_shape, const float *weights_data, const Shape &, const float *optional_bias_data, const Shape &output_shape, float *output_data, ::ruy::Context *ruy_context)
 
bool PortableIsZeroVector (const float *vector, int v_size)
 
int MatchingDim (const Shape &shape1, int index1, const Shape &shape2, int index2)
 
template<typename... Args>
int MatchingDim (const Shape &shape1, int index1, const Shape &shape2, int index2, Args... args)
 
Shape GetShape (const std::vector< int32_t > &data)
 
int Offset (const Shape &shape, int i0, int i1, int i2, int i3)
 
int Offset (const Shape &shape, int *index)
 
int FlatSizeSkipDim (const Shape &shape, int skip_dim)
 
template<typename... Ts>
bool checkMatching (const Shape &shape, Ts... check_shapes)
 
template<typename... Ts>
int MatchingFlatSize (const Shape &shape, Ts... check_shapes)
 
int MatchingFlatSizeSkipDim (const Shape &shape, int skip_dim, const Shape &check_shape_0)
 
int MatchingFlatSizeSkipDim (const Shape &shape, int skip_dim, const Shape &check_shape_0, const Shape &check_shape_1)
 
int MatchingElementsSize (const Shape &shape, const Shape &check_shape_0, const Shape &check_shape_1)
 
bool IsZeroVector (const float *vector, int v_size)
 
template<typename AccumScalar , typename DstScalar , QuantizationFlavor quantization_flavor>
void ValidateGemmParams (const GemmParams< AccumScalar, DstScalar, quantization_flavor > &params)
 
CachePolicy DefaultCachePolicy (bool is_constant_data)
 
template<typename T >
void ExtractPatchIntoBufferColumn (const Shape &input_shape, int w, int h, int b, int kheight, int kwidth, int stride_width, int stride_height, int pad_width, int pad_height, int in_width, int in_height, int in_depth, int single_buffer_length, int buffer_id, const T *in_data, T *conv_buffer_data, uint8_t zero_byte)
 
template<typename T >
void DilatedIm2col (const ConvParams &params, const Shape &input_shape, const T *input_data, const Shape &filter_shape, const Shape &output_shape, T *im2col_data, const int32_t *zero_bytes, const int zero_bytes_len)
 
template<typename T >
void DilatedIm2col (const ConvParams &params, uint8_t zero_byte, const Shape &input_shape, const T *input_data, const Shape &filter_shape, const Shape &output_shape, T *im2col_data)
 
template<typename T >
void Im2col (const ConvParams &params, int kheight, int kwidth, uint8_t zero_byte, const Shape &input_shape, const T *input_data, const Shape &output_shape, T *output_data)
 

Enumeration Type Documentation

◆ CachePolicy

enum class nnfw::ruy::CachePolicy : std::uint8_t
strong
Enumerator
kNeverCache 
kCacheIfLargeSpeedup 
kAlwaysCache 

Definition at line 110 of file Types.h.

111{
112 kNeverCache,
113 kCacheIfLargeSpeedup,
114 kAlwaysCache,
115};

◆ FusedActivationFunctionType

Enumerator
kNone 
kRelu6 
kRelu1 
kRelu 
kTanh 
kSigmoid 

Definition at line 33 of file Types.h.

34{
35 kNone = 0,
36 kRelu6 = 1,
37 kRelu1 = 2,
38 kRelu = 3,
39 kTanh = 4,
40 kSigmoid = 6,
41};

◆ Order

enum class nnfw::ruy::Order
strong
Enumerator
kColMajor 
kRowMajor 

Definition at line 104 of file Types.h.

105{
106 kColMajor,
107 kRowMajor
108};

◆ PaddingType

enum class nnfw::ruy::PaddingType
strong
Enumerator
kNone 
kSame 
kValid 

Definition at line 43 of file Types.h.

44{
45 kNone = 0,
46 kSame = 1,
47 kValid = 2,
48};

◆ QuantizationFlavor

enum class nnfw::ruy::QuantizationFlavor
strong
Enumerator
kFloatingPoint 
kIntegerWithUniformMultiplier 
kIntegerWithPerRowMultiplier 

Definition at line 159 of file Types.h.

160{
161 // Floating-point Gemm: the accumulators are not multiplied by any
162 // 'multiplier'.
163 kFloatingPoint,
164 // Quantized Gemm using a single multiplier for all accumulators.
165 kIntegerWithUniformMultiplier,
166 // Quantized Gemm using a separate multipliers for accumulators of each
167 // row of the destination matrix. This is what is called 'per-channel'
168 // in GemmParams. Here we use the more specific 'per-row' terminology
169 // to allow for the possibility of 'per-column' in the future, and to
170 // allow for that to be a separate code path in some back-end such as
171 // gemmlowp.
172 kIntegerWithPerRowMultiplier
173};

Function Documentation

◆ checkMatching()

template<typename... Ts>
bool nnfw::ruy::checkMatching ( const Shape shape,
Ts...  check_shapes 
)
inline

Definition at line 269 of file Shape.h.

270{
271 const Shape check_shapes_array[sizeof...(Ts)] = {std::forward<Ts>(check_shapes)...};
272 for (const auto &check_shape : check_shapes_array)
273 {
274 // Check matching of shapes except the case of that two shapes can be scalar
275 if (shape.DimensionsCount() > 1 || check_shape.DimensionsCount() > 1 || shape.FlatSize() != 1 ||
276 check_shape.FlatSize() != 1)
277 {
278 if (shape.DimensionsCount() != check_shape.DimensionsCount())
279 {
280 return false;
281 }
282 for (int i = 0; i < shape.DimensionsCount(); ++i)
283 {
284 if (shape.Dims(i) != check_shape.Dims(i))
285 {
286 return false;
287 }
288 }
289 }
290 }
291 return true;
292}
int FlatSize() const
Definition Shape.h:181
int32_t DimensionsCount() const
Definition Shape.h:91
int32_t Dims(int i) const
Definition Shape.h:92

References nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), and nnfw::ruy::Shape::FlatSize().

Referenced by MatchingFlatSize().

◆ DefaultCachePolicy()

CachePolicy nnfw::ruy::DefaultCachePolicy ( bool  is_constant_data)
inline

Definition at line 267 of file Types.h.

268{
269 return is_constant_data ? CachePolicy::kCacheIfLargeSpeedup : CachePolicy::kNeverCache;
270}

References kCacheIfLargeSpeedup, and kNeverCache.

Referenced by FullyConnected().

◆ DilatedIm2col() [1/2]

template<typename T >
void nnfw::ruy::DilatedIm2col ( const ConvParams params,
const Shape input_shape,
const T *  input_data,
const Shape filter_shape,
const Shape output_shape,
T *  im2col_data,
const int32_t *  zero_bytes,
const int  zero_bytes_len 
)

Definition at line 118 of file Utils.h.

121{
122 const int stride_width = params.stride_width;
123 const int stride_height = params.stride_height;
124 const int dilation_width_factor = params.dilation_width_factor;
125 const int dilation_height_factor = params.dilation_height_factor;
126 const int pad_width = params.padding_values.width;
127 const int pad_height = params.padding_values.height;
128 assert(input_shape.DimensionsCount() == 4);
129 assert(filter_shape.DimensionsCount() == 4);
130 assert(output_shape.DimensionsCount() == 4);
131
132 // For dilated convolution, the input pixels are not contiguous therefore we
133 // can't use the same optimizations as Im2Col(). Though note this code would
134 // work fine for the non-dilated case too (though likely a bit slower).
135 assert(dilation_width_factor != 1 || dilation_height_factor != 1);
136 assert(im2col_data);
137 const int batches = MatchingDim(input_shape, 0, output_shape, 0);
138 const int input_height = input_shape.Dims(1);
139 const int input_width = input_shape.Dims(2);
140 const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3);
141 const int filter_height = filter_shape.Dims(1);
142 const int filter_width = filter_shape.Dims(2);
143 const int output_height = output_shape.Dims(1);
144 const int output_width = output_shape.Dims(2);
145 MatchingDim(output_shape, 3, filter_shape, 0);
146
147 // Construct the MxN sized im2col matrix.
148 // The rows M, are sub-ordered B x H x W
149 const Shape row_shape({1, batches, output_height, output_width});
150 // The columns, N, are sub-ordered Kh x Kw x Din
151 const Shape col_shape({1, filter_height, filter_width, input_depth});
152 // Use dimensions M and N to construct dims for indexing directly into im2col
153 const Shape im2col_shape({1, 1, row_shape.FlatSize(), col_shape.FlatSize()});
154
155 // Loop through the output rows (B x H x W)
156 for (int batch = 0; batch < batches; ++batch)
157 {
158 const T zero_byte =
159 zero_bytes_len > 1 ? static_cast<T>(zero_bytes[batch]) : static_cast<T>(zero_bytes[0]);
160 for (int out_y = 0; out_y < output_height; ++out_y)
161 {
162 for (int out_x = 0; out_x < output_width; ++out_x)
163 {
164 // Each im2col row is an output pixel. Arrange the input data in this
165 // row in an order we can conveniently multiply with the filter data.
166 int row_offset = Offset(row_shape, 0, batch, out_y, out_x);
167 const int in_x_origin = (out_x * stride_width) - pad_width;
168 const int in_y_origin = (out_y * stride_height) - pad_height;
169 // Loop through all the pixels of the filter (Kh x Kw)
170 for (int filter_y = 0; filter_y < filter_height; ++filter_y)
171 {
172 const int in_y = in_y_origin + dilation_height_factor * filter_y;
173 if ((in_y >= 0) && (in_y < input_height))
174 {
175 // Filter row is within the input data.
176 // Loop through all the filter pixels in this row.
177 for (int filter_x = 0; filter_x < filter_width; ++filter_x)
178 {
179 const int in_x = in_x_origin + dilation_width_factor * filter_x;
180 int col_offset = Offset(col_shape, 0, filter_y, filter_x, 0);
181 T *dst = im2col_data + Offset(im2col_shape, 0, 0, row_offset, col_offset);
182 if ((in_x >= 0) && (in_x < input_width))
183 {
184 // Filter pixel is within the input, copy the input data.
185 T const *src = input_data + Offset(input_shape, batch, in_y, in_x, 0);
186 memcpy(dst, src, input_depth * sizeof(T));
187 }
188 else
189 {
190 // Filter pixel is outside the input, zero it out.
191 memset(dst, zero_byte, input_depth * sizeof(T));
192 }
193 }
194 }
195 else
196 {
197 // Filter row is outside the input, zero out the entire filter row.
198 int col_offset = Offset(col_shape, 0, filter_y, 0, 0);
199 T *dst = im2col_data + Offset(im2col_shape, 0, 0, row_offset, col_offset);
200 memset(dst, zero_byte, filter_width * input_depth * sizeof(T));
201 }
202 }
203 }
204 }
205 }
206}
int Offset(const Dims< 4 > &dims, int i0, int i1, int i2, int i3)
Definition Dims.h:64
const luci_interpreter::RuntimeShape output_shape
list input_data
Definition infer.py:29
Definition Shape.h:28
PaddingValues padding_values
Definition Types.h:59
int16_t dilation_height_factor
Definition Types.h:64
int16_t stride_width
Definition Types.h:61
int16_t dilation_width_factor
Definition Types.h:63
int16_t stride_height
Definition Types.h:62

References nnfw::ruy::ConvParams::dilation_height_factor, nnfw::ruy::ConvParams::dilation_width_factor, nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), nnfw::ruy::PaddingValues::height, MatchingDim(), Offset(), output_shape, nnfw::ruy::ConvParams::padding_values, nnfw::ruy::ConvParams::stride_height, nnfw::ruy::ConvParams::stride_width, and nnfw::ruy::PaddingValues::width.

◆ DilatedIm2col() [2/2]

template<typename T >
void nnfw::ruy::DilatedIm2col ( const ConvParams params,
uint8_t  zero_byte,
const Shape input_shape,
const T *  input_data,
const Shape filter_shape,
const Shape output_shape,
T *  im2col_data 
)

Definition at line 209 of file Utils.h.

212{
213 const int32_t zero_point = static_cast<int32_t>(zero_byte);
214 DilatedIm2col<T>(params, input_shape, input_data, filter_shape, output_shape, im2col_data,
215 &zero_point, 1);
216}

References output_shape.

◆ ExtractPatchIntoBufferColumn()

template<typename T >
void nnfw::ruy::ExtractPatchIntoBufferColumn ( const Shape input_shape,
int  w,
int  h,
int  b,
int  kheight,
int  kwidth,
int  stride_width,
int  stride_height,
int  pad_width,
int  pad_height,
int  in_width,
int  in_height,
int  in_depth,
int  single_buffer_length,
int  buffer_id,
const T *  in_data,
T *  conv_buffer_data,
uint8_t  zero_byte 
)
inline

Definition at line 31 of file Utils.h.

36{
37 assert(input_shape.DimensionsCount() == 4);
38 // This chunk of code reshapes all the inputs corresponding to
39 // output (b, h, w) to a column vector in conv_buffer(:, buffer_id).
40 const int kwidth_times_indepth = kwidth * in_depth;
41 const int inwidth_times_indepth = in_width * in_depth;
42 const int ih_ungated_start = h * stride_height - pad_height;
43 const int ih_ungated_end = (ih_ungated_start + kheight);
44 const int ih_end = std::min(ih_ungated_end, in_height);
45 const int iw_ungated_start = w * stride_width - pad_width;
46 const int iw_ungated_end = (iw_ungated_start + kwidth);
47 const int iw_end = std::min(iw_ungated_end, in_width);
48 // If the patch is off the edge of the input image, skip writing those rows
49 // and columns from the patch into the output array.
50 const int h_offset = std::max(0, -ih_ungated_start);
51 const int w_offset = std::max(0, -iw_ungated_start);
52 const int ih_start = std::max(0, ih_ungated_start);
53 const int iw_start = std::max(0, iw_ungated_start);
54 const int single_row_num = std::min(kwidth - w_offset, in_width - iw_start) * in_depth;
55 const int output_row_offset = (buffer_id * single_buffer_length);
56 int out_offset = output_row_offset + (h_offset * kwidth + w_offset) * in_depth;
57 int in_offset = Offset(input_shape, b, ih_start, iw_start, 0);
58
59 // Express all of the calculations as padding around the input patch.
60 const int top_padding = h_offset;
61 const int bottom_padding = (ih_ungated_end - ih_end);
62 const int left_padding = w_offset;
63 const int right_padding = (iw_ungated_end - iw_end);
64 assert(single_row_num == ((kwidth - (left_padding + right_padding)) * in_depth));
65
66 // Write out zeroes to the elements representing the top rows of the input
67 // patch that are off the edge of the input image.
68 if (top_padding > 0)
69 {
70 const int top_row_elements = (top_padding * kwidth * in_depth);
71 memset(conv_buffer_data + output_row_offset, zero_byte, (top_row_elements * sizeof(T)));
72 }
73
74 // If the patch is on the interior of the input image horizontally, just copy
75 // over the rows sequentially, otherwise add zero padding at the start or end.
76 if ((left_padding == 0) && (right_padding == 0))
77 {
78 for (int ih = ih_start; ih < ih_end; ++ih)
79 {
80 memcpy(conv_buffer_data + out_offset, in_data + in_offset, single_row_num * sizeof(T));
81 out_offset += kwidth_times_indepth;
82 in_offset += inwidth_times_indepth;
83 }
84 }
85 else
86 {
87 for (int ih = ih_start; ih < ih_end; ++ih)
88 {
89 if (left_padding > 0)
90 {
91 const int left_start = (out_offset - (left_padding * in_depth));
92 memset(conv_buffer_data + left_start, zero_byte, (left_padding * in_depth * sizeof(T)));
93 }
94 memcpy(conv_buffer_data + out_offset, in_data + in_offset, single_row_num * sizeof(T));
95 if (right_padding > 0)
96 {
97 const int right_start = (out_offset + single_row_num);
98 memset(conv_buffer_data + right_start, zero_byte, (right_padding * in_depth * sizeof(T)));
99 }
100 out_offset += kwidth_times_indepth;
101 in_offset += inwidth_times_indepth;
102 }
103 }
104
105 // If the bottom of the patch falls off the input image, pad the values
106 // representing those input rows with zeroes.
107 if (bottom_padding > 0)
108 {
109 const int bottom_row_elements = (bottom_padding * kwidth * in_depth);
110 const int bottom_start =
111 output_row_offset + ((top_padding + (ih_end - ih_start)) * kwidth * in_depth);
112 memset(conv_buffer_data + bottom_start, zero_byte, (bottom_row_elements * sizeof(T)));
113 }
114}

References nnfw::ruy::Shape::DimensionsCount(), and Offset().

Referenced by Im2col().

◆ FlatSizeSkipDim()

int nnfw::ruy::FlatSizeSkipDim ( const Shape shape,
int  skip_dim 
)
inline

Definition at line 254 of file Shape.h.

255{
256 const int dims_count = shape.DimensionsCount();
257 assert(skip_dim >= 0 && skip_dim < dims_count);
258 const auto *dims_data = shape.DimsData();
259 int flat_size = 1;
260 for (int i = 0; i < dims_count; ++i)
261 {
262 flat_size *= (i == skip_dim) ? 1 : dims_data[i];
263 }
264 return flat_size;
265}
int32_t * DimsData()
Definition Shape.h:112

References nnfw::ruy::Shape::DimensionsCount(), and nnfw::ruy::Shape::DimsData().

Referenced by FullyConnected(), and MatchingFlatSizeSkipDim().

◆ FullyConnected()

void nnfw::ruy::FullyConnected ( const FullyConnectedParams params,
const Shape input_shape,
const float *  input_data,
const Shape weights_shape,
const float *  weights_data,
const Shape ,
const float *  optional_bias_data,
const Shape output_shape,
float *  output_data,
::ruy::Context *  ruy_context 
)
inline

Definition at line 34 of file FullyConnected.h.

39{
40 const int dims_count = weights_shape.DimensionsCount();
41 const int input_rows = weights_shape.Dims(dims_count - 1);
42 MatrixParams<float> rhs_params;
43 rhs_params.order = Order::kColMajor;
44 rhs_params.rows = input_rows;
45 rhs_params.cols = input_shape.FlatSize() / input_rows;
47 assert(input_shape.FlatSize() == (rhs_params.rows * rhs_params.cols));
48 MatrixParams<float> lhs_params;
49 lhs_params.order = Order::kRowMajor;
50 lhs_params.cols = weights_shape.Dims(dims_count - 1);
51 lhs_params.rows = FlatSizeSkipDim(weights_shape, dims_count - 1);
53 MatrixParams<float> dst_params;
54 dst_params.order = Order::kColMajor;
55 dst_params.rows = output_shape.Dims(output_shape.DimensionsCount() - 1);
56 dst_params.cols = FlatSizeSkipDim(output_shape, output_shape.DimensionsCount() - 1);
57 GemmParams<float, float> gemm_params;
58 gemm_params.bias = optional_bias_data;
59 gemm_params.clamp_min = params.float_activation_min;
60 gemm_params.clamp_max = params.float_activation_max;
61
62 // Below code was copied from tflite::cpu_backend_gemm::detail::GemmImplUsingRuy
63 ::ruy::Matrix<float> ruy_lhs;
64 ::ruy::Matrix<float> ruy_rhs;
65 ::ruy::Matrix<float> ruy_dst;
66 // Note that cache is always enabled for input and weight tensors
67 ruy_support::MakeRuyMatrix(lhs_params, weights_data, &ruy_lhs, true);
68 ruy_support::MakeRuyMatrix(rhs_params, input_data, &ruy_rhs, true);
69 ruy_support::MakeRuyMatrix(dst_params, output_data, &ruy_dst);
70
71 ::ruy::MulParams<float, float> ruy_mul_params;
72 ruy_support::MakeRuyMulParams(gemm_params, &ruy_mul_params);
73
74 ::ruy::Mul(ruy_lhs, ruy_rhs, ruy_mul_params, ruy_context, &ruy_dst);
75}
CachePolicy DefaultCachePolicy(bool is_constant_data)
Definition Types.h:267
DstScalar clamp_max
Definition Types.h:222
DstScalar clamp_min
Definition Types.h:218
const AccumScalar * bias
Definition Types.h:216
CachePolicy cache_policy
Definition Types.h:141

References nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::bias, nnfw::ruy::MatrixParams< Scalar >::cache_policy, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_max, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_min, nnfw::ruy::MatrixParams< Scalar >::cols, DefaultCachePolicy(), nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), nnfw::ruy::Shape::FlatSize(), FlatSizeSkipDim(), nnfw::ruy::FullyConnectedParams::float_activation_max, nnfw::ruy::FullyConnectedParams::float_activation_min, kColMajor, kRowMajor, nnfw::ruy::FullyConnectedParams::lhs_cacheable, nnfw::ruy::ruy_support::MakeRuyMatrix(), nnfw::ruy::ruy_support::MakeRuyMulParams(), nnfw::ruy::MatrixParams< Scalar >::order, output_shape, nnfw::ruy::FullyConnectedParams::rhs_cacheable, and nnfw::ruy::MatrixParams< Scalar >::rows.

Referenced by onert::backend::ruy::ops::FullyConnectedLayer::fullyConnectedFloat32().

◆ GetShape()

Shape nnfw::ruy::GetShape ( const std::vector< int32_t > &  data)
inline

Definition at line 236 of file Shape.h.

236{ return Shape(data.size(), data.data()); }

◆ Im2col()

template<typename T >
void nnfw::ruy::Im2col ( const ConvParams params,
int  kheight,
int  kwidth,
uint8_t  zero_byte,
const Shape input_shape,
const T *  input_data,
const Shape output_shape,
T *  output_data 
)

Definition at line 219 of file Utils.h.

222{
223 const int stride_width = params.stride_width;
224 const int stride_height = params.stride_height;
225 const int pad_width = params.padding_values.width;
226 const int pad_height = params.padding_values.height;
227 assert(input_shape.DimensionsCount() == 4);
228 assert(output_shape.DimensionsCount() == 4);
229
230 const int batches = MatchingDim(input_shape, 0, output_shape, 0);
231 const int input_depth = input_shape.Dims(3);
232 const int input_width = input_shape.Dims(2);
233 const int input_height = input_shape.Dims(1);
234 const int output_depth = output_shape.Dims(3);
235 const int output_width = output_shape.Dims(2);
236 const int output_height = output_shape.Dims(1);
237
238 int buffer_id = 0;
239 // Loop over the output nodes.
240 for (int b = 0; b < batches; ++b)
241 {
242 for (int h = 0; h < output_height; ++h)
243 {
244 for (int w = 0; w < output_width; ++w)
245 {
246 ExtractPatchIntoBufferColumn(input_shape, w, h, b, kheight, kwidth, stride_width,
247 stride_height, pad_width, pad_height, input_width,
248 input_height, input_depth, output_depth, buffer_id, input_data,
249 output_data, zero_byte);
250 ++buffer_id;
251 }
252 }
253 }
254}
void ExtractPatchIntoBufferColumn(const Dims< 4 > &input_dims, int w, int h, int b, int kheight, int kwidth, int stride_width, int stride_height, int pad_width, int pad_height, int in_width, int in_height, int in_depth, int single_buffer_length, int buffer_id, const T *in_data, T *conv_buffer_data, uint8 byte_zero)

References nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), ExtractPatchIntoBufferColumn(), nnfw::ruy::PaddingValues::height, MatchingDim(), output_shape, nnfw::ruy::ConvParams::padding_values, nnfw::ruy::ConvParams::stride_height, nnfw::ruy::ConvParams::stride_width, and nnfw::ruy::PaddingValues::width.

◆ IsZeroVector()

bool nnfw::ruy::IsZeroVector ( const float *  vector,
int  v_size 
)
inline

Definition at line 29 of file TensorUtils.h.

30{
31 return NEON_OR_PORTABLE(IsZeroVector, vector, v_size);
32}
#define NEON_OR_PORTABLE(funcname,...)
Definition neon_check.h:47

References IsZeroVector(), and NEON_OR_PORTABLE.

Referenced by IsZeroVector(), and onert::backend::ruy::ops::FullyConnectedLayer::prepare().

◆ MatchingDim() [1/2]

int nnfw::ruy::MatchingDim ( const Shape shape1,
int  index1,
const Shape shape2,
int  index2 
)
inline

Definition at line 221 of file Shape.h.

223{
224 assert(shape1.Dims(index1) == shape2.Dims(index2));
225 return shape1.Dims(index1);
226}

References nnfw::ruy::Shape::Dims().

Referenced by DilatedIm2col(), Im2col(), and MatchingDim().

◆ MatchingDim() [2/2]

template<typename... Args>
int nnfw::ruy::MatchingDim ( const Shape shape1,
int  index1,
const Shape shape2,
int  index2,
Args...  args 
)

Definition at line 229 of file Shape.h.

231{
232 assert(shape1.Dims(index1) == shape2.Dims(index2));
233 return MatchingDim(shape1, index1, args...);
234}

References nnfw::ruy::Shape::Dims(), and MatchingDim().

◆ MatchingElementsSize()

int nnfw::ruy::MatchingElementsSize ( const Shape shape,
const Shape check_shape_0,
const Shape check_shape_1 
)
inline

Definition at line 334 of file Shape.h.

336{
337 const int size_1 = shape.FlatSize();
338 [[maybe_unused]] const int size_2 = check_shape_0.FlatSize();
339 [[maybe_unused]] const int size_3 = check_shape_1.FlatSize();
340 assert(size_1 == size_2);
341 assert(size_2 == size_3);
342 return size_1;
343}

References nnfw::ruy::Shape::FlatSize().

◆ MatchingFlatSize()

template<typename... Ts>
int nnfw::ruy::MatchingFlatSize ( const Shape shape,
Ts...  check_shapes 
)
inline

Definition at line 298 of file Shape.h.

299{
300 UNUSED_ALL{check_shapes...};
301 assert(checkMatching(shape, std::forward<Ts>(check_shapes)...));
302 return shape.FlatSize();
303}

References checkMatching(), and nnfw::ruy::Shape::FlatSize().

◆ MatchingFlatSizeSkipDim() [1/2]

int nnfw::ruy::MatchingFlatSizeSkipDim ( const Shape shape,
int  skip_dim,
const Shape check_shape_0 
)
inline

Definition at line 305 of file Shape.h.

307{
308 const int dims_count = shape.DimensionsCount();
309 for (int i = 0; i < dims_count; ++i)
310 {
311 if (i != skip_dim)
312 {
313 assert(shape.Dims(i) == check_shape_0.Dims(i));
314 }
315 }
316 return FlatSizeSkipDim(shape, skip_dim);
317}

References nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), and FlatSizeSkipDim().

Referenced by MatchingFlatSizeSkipDim().

◆ MatchingFlatSizeSkipDim() [2/2]

int nnfw::ruy::MatchingFlatSizeSkipDim ( const Shape shape,
int  skip_dim,
const Shape check_shape_0,
const Shape check_shape_1 
)
inline

Definition at line 319 of file Shape.h.

322{
323 const int dims_count = shape.DimensionsCount();
324 for (int i = 0; i < dims_count; ++i)
325 {
326 if (i != skip_dim)
327 {
328 assert(shape.Dims(i) == check_shape_0.Dims(i));
329 }
330 }
331 return MatchingFlatSizeSkipDim(shape, skip_dim, check_shape_1);
332}

References nnfw::ruy::Shape::DimensionsCount(), nnfw::ruy::Shape::Dims(), and MatchingFlatSizeSkipDim().

◆ Offset() [1/2]

int nnfw::ruy::Offset ( const Shape shape,
int *  index 
)
inline

Definition at line 249 of file Shape.h.

250{
251 return Offset(shape, index[0], index[1], index[2], index[3]);
252}

References Offset().

◆ Offset() [2/2]

int nnfw::ruy::Offset ( const Shape shape,
int  i0,
int  i1,
int  i2,
int  i3 
)
inline

Definition at line 238 of file Shape.h.

239{
240 assert(shape.DimensionsCount() == 4);
241 const int *dims_data = shape.DimsDataUpTo4D();
242 assert(i0 >= 0 && i0 < dims_data[0]);
243 assert(i1 >= 0 && i1 < dims_data[1]);
244 assert(i2 >= 0 && i2 < dims_data[2]);
245 assert(i3 >= 0 && i3 < dims_data[3]);
246 return ((i0 * dims_data[1] + i1) * dims_data[2] + i2) * dims_data[3] + i3;
247}
const int32_t * DimsDataUpTo4D() const
Definition Shape.h:115

References nnfw::ruy::Shape::DimensionsCount(), and nnfw::ruy::Shape::DimsDataUpTo4D().

Referenced by DilatedIm2col(), ExtractPatchIntoBufferColumn(), and Offset().

◆ PortableIsZeroVector()

bool nnfw::ruy::PortableIsZeroVector ( const float *  vector,
int  v_size 
)
inline

Definition at line 26 of file PortableTensorUtils.h.

27{
28 for (int i = 0; i < v_size; ++i)
29 {
30 if (*vector++ != 0.0f)
31 return false;
32 }
33 return true;
34}

◆ ValidateGemmParams()

template<typename AccumScalar , typename DstScalar , QuantizationFlavor quantization_flavor>
void nnfw::ruy::ValidateGemmParams ( const GemmParams< AccumScalar, DstScalar, quantization_flavor > &  params)

Definition at line 229 of file Types.h.

231{
232 // Guard consistency of the quantized multiplier fields.
233 if (quantization_flavor == QuantizationFlavor::kFloatingPoint)
234 {
235 assert(!params.multiplier_fixedpoint);
236 assert(!params.multiplier_exponent);
237 assert(!params.multiplier_fixedpoint_perchannel);
238 assert(!params.multiplier_exponent_perchannel);
239 }
240 else if (quantization_flavor == QuantizationFlavor::kIntegerWithUniformMultiplier &&
241 !std::is_same<DstScalar, int32_t>::value)
242 {
243 assert(params.multiplier_fixedpoint);
244 // Nothing to check about multiplier_exponent
245 assert(!params.multiplier_fixedpoint_perchannel);
246 assert(!params.multiplier_exponent_perchannel);
247 }
248 else if (quantization_flavor == QuantizationFlavor::kIntegerWithPerRowMultiplier &&
249 !std::is_same<DstScalar, int32_t>::value)
250 {
251 assert(!params.multiplier_fixedpoint);
252 assert(!params.multiplier_exponent);
254 assert(params.multiplier_exponent_perchannel);
255 }
256 else
257 {
258 // For the get raw accumulator case, we should make sure none of the
259 // quantization params are set.
260 assert(!params.multiplier_fixedpoint);
261 assert(!params.multiplier_exponent);
262 assert(!params.multiplier_fixedpoint_perchannel);
263 assert(!params.multiplier_exponent_perchannel);
264 }
265}
AccumScalar multiplier_fixedpoint
Definition Types.h:198
const int * multiplier_exponent_perchannel
Definition Types.h:214
const AccumScalar * multiplier_fixedpoint_perchannel
Definition Types.h:206

References kFloatingPoint, kIntegerWithPerRowMultiplier, and kIntegerWithUniformMultiplier.