40 std::string
read_file(
const std::string &filename,
bool binary)
45 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
49 fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
50 std::ios_base::openmode
mode = std::ios::in;
54 mode |= std::ios::binary;
57 fs.open(filename,
mode);
62 out.reserve(fs.tellg());
64 fs.seekg(0, std::ios::beg);
66 out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>());
67 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
69 catch (
const std::ifstream::failure &e)
80 static std::map<Channel, const std::string> channels_map = {{
Channel::UNKNOWN,
"UNKNOWN"},
93 return channels_map[channel];
98 static std::map<BorderMode, const std::string> border_mode_map = {
104 return border_mode_map[border_mode];
109 static std::map<NormType, const std::string> norm_type_map = {
115 return norm_type_map[
type];
120 static std::map<PoolingType, const std::string> pool_type_map = {
126 return pool_type_map[
type];
131 if (
info.is_global_pooling ||
info.exclude_padding ||
info.pool_size.x() == 0 ||
info.pool_size.y() == 0)
135 const auto ps =
info.pad_stride_info;
136 const auto pool_le_padding_x =
info.pool_size.x() <= std::max({ps.pad_left(), ps.pad_right()});
137 const auto pool_le_padding_y =
info.pool_size.y() <= std::max({ps.pad_top(), ps.pad_bottom()});
138 return pool_le_padding_x || pool_le_padding_y;
143 if (
info.is_global_pooling ||
info.pool_size.x() == 0 ||
info.pool_size.y() == 0 ||
info.pool_size.z() == 0)
147 const auto ps =
info.padding;
148 const auto pool_le_padding_x =
info.pool_size.x() <= std::max({ps.left, ps.right});
149 const auto pool_le_padding_y =
info.pool_size.y() <= std::max({ps.top, ps.bottom});
150 const auto pool_le_padding_z =
info.pool_size.z() <= std::max({ps.front, ps.back});
151 return pool_le_padding_x || pool_le_padding_y || pool_le_padding_z;
156 static std::map<GEMMLowpOutputStageType, const std::string> output_stage_map = {
167 std::stringstream
ss;
168 std::string converted_string;
175 ss << uint32_t(value.
get<uint8_t>());
176 converted_string =
ss.str();
182 ss << int32_t(value.
get<int8_t>());
183 converted_string =
ss.str();
187 ss << value.
get<uint16_t>();
188 converted_string =
ss.str();
192 ss << value.
get<int16_t>();
193 converted_string =
ss.str();
196 ss << value.
get<uint32_t>();
197 converted_string =
ss.str();
200 ss << value.
get<int32_t>();
201 converted_string =
ss.str();
207 static_assert(
sizeof(
half) == 2,
"Half must be 16 bit");
209 converted_string =
ss.str();
215 return converted_string;
225 const auto &strides =
conv_info.stride();
227 "Stride values should be greater than or equal to 1.");
233 const unsigned int kernel_width = weights_shape[
width_idx];
234 const unsigned int kernel_height = weights_shape[
height_idx];
238 const unsigned int out_width = ((in_width - is_ceil) + strides.first - 1) / strides.first + is_ceil;
239 const unsigned int out_height = ((in_height - is_ceil) + strides.second - 1) / strides.second + is_ceil;
242 const int real_weight_width = (kernel_width - 1) * dilation.
x() + 1;
243 const int real_weight_height = (kernel_height - 1) * dilation.
y() + 1;
246 const int pad_width = std::max(0,
static_cast<int>((out_width - 1) * strides.first + real_weight_width - in_width));
247 const int pad_height =
248 std::max(0,
static_cast<int>((out_height - 1) * strides.second + real_weight_height - in_height));
251 const unsigned int pad_left = pad_width / 2;
252 const unsigned int pad_top = pad_height / 2;
253 const unsigned int pad_right = pad_width - pad_left;
254 const unsigned int pad_bottom = pad_height - pad_top;
256 PadStrideInfo same_info(strides.first, strides.second, pad_left, pad_right, pad_top, pad_bottom, rounding_type);
259 const auto out_dims =
scaled_dimensions(in_width, in_height, kernel_width, kernel_height, same_info, dilation);
267 unsigned int in_height,
268 unsigned int kernel_width,
269 unsigned int kernel_height,
272 const unsigned int pad_left = pad_stride_info.
pad_left();
273 const unsigned int pad_top = pad_stride_info.
pad_top();
274 const unsigned int pad_right = pad_stride_info.
pad_right();
275 const unsigned int pad_bottom = pad_stride_info.
pad_bottom();
276 const unsigned int stride_x = pad_stride_info.
stride().first;
277 const unsigned int stride_y = pad_stride_info.
stride().second;
282 const int w = stride_x * (in_width - 1) + kernel_width - (pad_left + pad_right);
283 const int h = stride_y * (in_height - 1) + kernel_height - (pad_top + pad_bottom);
285 return std::make_pair<unsigned int, unsigned int>(
w, h);
295 const int dilation_x = dilation.
x();
296 const int dilation_y = dilation.
y();
297 const int pad_left = pad_stride_info.
pad_left();
298 const int pad_top = pad_stride_info.
pad_top();
299 const int pad_right = pad_stride_info.
pad_right();
300 const int pad_bottom = pad_stride_info.
pad_bottom();
301 const int stride_x = pad_stride_info.
stride().first;
302 const int stride_y = pad_stride_info.
stride().second;
305 switch (pad_stride_info.
round())
308 w =
static_cast<int>(std::floor(
309 (
static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) +
311 h =
static_cast<int>(
312 std::floor((
static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) /
317 w =
static_cast<int>(std::ceil(
318 (
static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) +
320 h =
static_cast<int>(
321 std::ceil((
static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) /
331 return std::make_pair(
static_cast<unsigned int>(
w),
static_cast<unsigned int>(h));
335 int width,
int height,
int kernel_width,
int kernel_height,
const PadStrideInfo &pad_stride_info)
337 const int pad_left = pad_stride_info.
pad_left();
338 const int pad_top = pad_stride_info.
pad_top();
339 const int pad_right = pad_stride_info.
pad_right();
340 const int pad_bottom = pad_stride_info.
pad_bottom();
341 const int stride_x = pad_stride_info.
stride().first;
342 const int stride_y = pad_stride_info.
stride().second;
345 switch (pad_stride_info.
round())
348 w =
static_cast<int>(
349 std::floor((
static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
350 h =
static_cast<int>(
351 std::floor((
static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
354 w =
static_cast<int>(
355 std::ceil((
static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
356 h =
static_cast<int>(
357 std::ceil((
static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
363 return std::make_pair(
static_cast<int>(
w),
static_cast<int>(h));
380 const int stride_x = pool3d_info.
stride.
x();
381 const int stride_y = pool3d_info.
stride.
y();
382 const int stride_z = pool3d_info.
stride.
z();
390 w =
static_cast<int>(
391 std::floor((
static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
392 h =
static_cast<int>(
393 std::floor((
static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
394 d =
static_cast<int>(
395 std::floor((
static_cast<float>(depth + pad_front + pad_back - kernel_depth) / stride_z) + 1));
398 w =
static_cast<int>(
399 std::ceil((
static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
400 h =
static_cast<int>(
401 std::ceil((
static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
402 d =
static_cast<int>(
403 std::ceil((
static_cast<float>(depth + pad_front + pad_back - kernel_depth) / stride_z) + 1));
409 return std::make_tuple(
static_cast<int>(
w),
static_cast<int>(h),
static_cast<int>(d));
416 const bool is_first_dim = (axis == 0);
418 return !is_first_dim || (is_quantized_type && !is_min_max);
453 const int32_t min_activation =
act_info.activation() != ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU
454 ? std::min(oq_info.
offset, type_max_value)
456 const int32_t max_activation =
457 act_info.activation() == ActivationLayerInfo::ActivationFunction::RELU ? type_max_value : a_int;
459 return std::make_pair(min_activation, max_activation);
462 std::unordered_map<const ITensorInfo *, PaddingSize>
get_padding_info(std::initializer_list<const ITensor *> tensors)
464 std::unordered_map<const ITensorInfo *, PaddingSize> res;
477 std::unordered_map<const ITensorInfo *, PaddingSize>
get_padding_info(std::initializer_list<const ITensorInfo *> infos)
479 std::unordered_map<const ITensorInfo *, PaddingSize> res;
485 res.insert({
info,
info->padding()});
494 return std::find_if(padding_map.begin(), padding_map.end(),
495 [](
const std::pair<const ITensorInfo *, PaddingSize> &padding_info)
496 { return (padding_info.first->padding() != padding_info.second); }) != padding_map.end();
499 #ifdef ARM_COMPUTE_ASSERTS_ENABLED
500 void print_consecutive_elements(std::ostream &s,
505 const std::string &element_delim)
511 print_consecutive_elements_impl<uint8_t>(s, ptr, n, stream_width, element_delim);
517 print_consecutive_elements_impl<int8_t>(s,
reinterpret_cast<const int8_t *
>(ptr), n, stream_width,
522 print_consecutive_elements_impl<uint16_t>(s,
reinterpret_cast<const uint16_t *
>(ptr), n, stream_width,
527 print_consecutive_elements_impl<int16_t>(s,
reinterpret_cast<const int16_t *
>(ptr), n, stream_width,
531 print_consecutive_elements_impl<uint32_t>(s,
reinterpret_cast<const uint32_t *
>(ptr), n, stream_width,
535 print_consecutive_elements_impl<int32_t>(s,
reinterpret_cast<const int32_t *
>(ptr), n, stream_width,
539 print_consecutive_elements_impl<uint64_t>(s,
reinterpret_cast<const uint64_t *
>(ptr), n, stream_width,
543 print_consecutive_elements_impl<int64_t>(s,
reinterpret_cast<const int64_t *
>(ptr), n, stream_width,
547 print_consecutive_elements_impl<bfloat16>(s,
reinterpret_cast<const bfloat16 *
>(ptr), n, stream_width,
551 print_consecutive_elements_impl<half>(s,
reinterpret_cast<const half *
>(ptr), n, stream_width,
555 print_consecutive_elements_impl<float>(s,
reinterpret_cast<const float *
>(ptr), n, stream_width,
563 int max_consecutive_elements_display_width(std::ostream &s,
DataType dt,
const uint8_t *ptr,
unsigned int n)
569 return max_consecutive_elements_display_width_impl<uint8_t>(s, ptr, n);
574 return max_consecutive_elements_display_width_impl<int8_t>(s,
reinterpret_cast<const int8_t *
>(ptr), n);
577 return max_consecutive_elements_display_width_impl<uint16_t>(s,
reinterpret_cast<const uint16_t *
>(ptr), n);
580 return max_consecutive_elements_display_width_impl<int16_t>(s,
reinterpret_cast<const int16_t *
>(ptr), n);
582 return max_consecutive_elements_display_width_impl<uint32_t>(s,
reinterpret_cast<const uint32_t *
>(ptr), n);
584 return max_consecutive_elements_display_width_impl<int32_t>(s,
reinterpret_cast<const int32_t *
>(ptr), n);
586 return max_consecutive_elements_display_width_impl<uint64_t>(s,
reinterpret_cast<const uint64_t *
>(ptr), n);
588 return max_consecutive_elements_display_width_impl<int64_t>(s,
reinterpret_cast<const int64_t *
>(ptr), n);
590 return max_consecutive_elements_display_width_impl<bfloat16>(s,
reinterpret_cast<const bfloat16 *
>(ptr), n);
592 return max_consecutive_elements_display_width_impl<half>(s,
reinterpret_cast<const half *
>(ptr), n);
594 return max_consecutive_elements_display_width_impl<float>(s,
reinterpret_cast<const float *
>(ptr), n);