38 void pooling2_f32_maxpool_indices(
const ITensor *
src, ITensor *dst0, ITensor *dst1, PoolingLayerInfo &pool_info,
const Window &window_src,
const Window &window)
40 const int window_start_x = window.x().start();
41 const int window_end_x = window.x().end();
42 const int window_step_x = 4;
44 Window window_out = window;
45 window_out.set(
Window::DimX, Window::Dimension(0, 1, 1));
47 Iterator in(
src, window_src);
48 Iterator out(dst0, window_out);
49 Iterator indices(dst1, window_out);
51 const int pool_pad_top = pool_info.pad_stride_info.pad_top();
52 const int pool_pad_left = pool_info.pad_stride_info.pad_left();
55 int pool_stride_y = 0;
56 std::tie(
pool_stride_x, pool_stride_y) = pool_info.pad_stride_info.stride();
61 const int pad_right =
src->info()->padding().right;
62 const int pad_left =
src->info()->padding().left;
63 const int pad_horizontal = pad_right + pad_left;
64 const int in_stride_y = static_cast<int>(
src->info()->strides_in_bytes().y());
65 const int in_stride_z = static_cast<int>(
src->info()->strides_in_bytes().z());
71 const int pool_limit_y = pool_pad_top -
idx_height;
72 const int pool_limit_x = pool_pad_left -
idx_width;
74 const int pool_start_y = std::max(0, window_src.z().start() + pool_limit_y);
75 const int pool_start_x = std::max(0, window_src.y().start() + pool_limit_x);
77 const int in_x0_offset = (pool_start_x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (pool_start_y - pool_pad_top) * static_cast<int>(
src->info()->strides_in_bytes().z());
78 const int in_x1_offset = (pool_start_x + 1 - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (pool_start_y - pool_pad_top) * static_cast<int>
79 (
src->info()->strides_in_bytes().z());
80 const int in_x2_offset = (pool_start_x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (pool_start_y + 1 - pool_pad_top) * static_cast<int>
81 (
src->info()->strides_in_bytes().z());
82 const int in_x3_offset = (pool_start_x + 1 - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (pool_start_y + 1 - pool_pad_top) * static_cast<int>
83 (
src->info()->strides_in_bytes().z());
85 int x_off = window_start_x;
86 for(; x_off <= (window_end_x - window_step_x); x_off += window_step_x)
88 const auto in_x0_ptr = reinterpret_cast<const float *>(in.ptr() + in_x0_offset);
89 const auto in_x1_ptr = reinterpret_cast<const float *>(in.ptr() + in_x1_offset);
90 const auto in_x2_ptr = reinterpret_cast<const float *>(in.ptr() + in_x2_offset);
91 const auto in_x3_ptr = reinterpret_cast<const float *>(in.ptr() + in_x3_offset);
92 const auto v_x0 = vld1q_f32(in_x0_ptr + x_off);
93 const auto v_x1 = vld1q_f32(in_x1_ptr + x_off);
94 const auto v_x2 = vld1q_f32(in_x2_ptr + x_off);
95 const auto v_x3 = vld1q_f32(in_x3_ptr + x_off);
96 vres = vmaxq_f32(vmaxq_f32(v_x2, v_x3), vmaxq_f32(v_x0, v_x1));
98 vst1q_f32(reinterpret_cast<float *>(out.ptr()) + x_off, vres);
101 const uint32_t offset_x0 = (uint32_t)offset_base /
sizeof(
float) + x_off;
102 const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y /
sizeof(
float) - pad_horizontal;
103 const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z /
sizeof(
float) - pad_horizontal *
src->info()->tensor_shape()[1];
104 const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y /
sizeof(
float) - pad_horizontal;
105 const uint32x4_t voffset_x0 = { offset_x0, offset_x0 + 1, offset_x0 + 2, offset_x0 + 3 };
106 const uint32x4_t voffset_x1 = { offset_x1, offset_x1 + 1, offset_x1 + 2, offset_x1 + 3 };
107 const uint32x4_t voffset_x2 = { offset_x2, offset_x2 + 1, offset_x2 + 2, offset_x2 + 3 };
108 const uint32x4_t voffset_x3 = { offset_x3, offset_x3 + 1, offset_x3 + 2, offset_x3 + 3 };
109 const uint32x4_t tmp_indices0 = vbslq_u32(vcgeq_f32(v_x0, v_x1), voffset_x0, voffset_x1);
110 const uint32x4_t tmp_indices1 = vbslq_u32(vcgeq_f32(v_x2, v_x3), voffset_x2, voffset_x3);
111 const uint32x4_t tmp_indices2 = vbslq_u32(vcgeq_f32(vmaxq_f32(v_x0, v_x1), vmaxq_f32(v_x2, v_x3)), tmp_indices0, tmp_indices1);
114 vst1q_u32(reinterpret_cast<uint32_t *>(indices.ptr()) + x_off, tmp_indices2);
118 for(; x_off < window_end_x; ++x_off)
120 const auto x0 = *(reinterpret_cast<const float *>(in.ptr() + in_x0_offset) + x_off);
121 const auto x1 = *(reinterpret_cast<const float *>(in.ptr() + in_x1_offset) + x_off);
122 const auto x2 = *(reinterpret_cast<const float *>(in.ptr() + in_x2_offset) + x_off);
123 const auto x3 = *(reinterpret_cast<const float *>(in.ptr() + in_x3_offset) + x_off);
124 res = std::max(std::max(x2, x3), std::max(x0, x1));
127 *(reinterpret_cast<float *>(out.ptr()) + x_off) = res;
130 const uint32_t offset_x0 = (uint32_t)offset_base /
sizeof(
float) + x_off;
131 const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y /
sizeof(
float) - pad_horizontal;
132 const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z /
sizeof(
float) - pad_horizontal *
src->info()->tensor_shape()[1];
133 const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y /
sizeof(
float) - pad_horizontal;
134 const uint32_t tmp_idx0 = (x0 >= x1) ? offset_x0 : offset_x1;
135 const uint32_t tmp_idx1 = (x2 >= x3) ? offset_x2 : offset_x3;
136 const uint32_t tmp_idx2 = (std::max(x0, x1) >= std::max(x2, x3)) ? tmp_idx0 : tmp_idx1;
139 *(reinterpret_cast<uint32_t *>(indices.ptr()) + x_off) = tmp_idx2;
150 pooling2_f32_maxpool_indices(
src, dst0, dst1, pool_info, window_src, window);
154 const int window_start_x = window.
x().
start();
155 const int window_end_x = window.
x().
end();
156 const int window_step_x = 4;
158 Window window_out = window;
171 int pool_stride_y = 0;
173 const int upper_bound_w =
src->info()->dimension(1) + (pool_info.
exclude_padding ? 0 : pool_pad_right);
174 const int upper_bound_h =
src->info()->dimension(2) + (pool_info.
exclude_padding ? 0 : pool_pad_bottom);
181 const int idx_height =
id.z() * pool_stride_y;
182 const int pool_limit_y = pool_pad_top -
idx_height;
183 const int pool_limit_x = pool_pad_left -
idx_width;
185 const int pool_start_y = std::max(0, window_src.
z().
start() + pool_limit_y);
186 const int pool_end_y = std::min(pool_size_y, window_src.
z().
end() + pool_limit_y);
187 const int pool_start_x = std::max(0, window_src.
y().
start() + pool_limit_x);
188 const int pool_end_x = std::min(pool_size_x, window_src.
y().
end() + pool_limit_x);
190 int x_off = window_start_x;
191 for(; x_off <= (window_end_x - window_step_x); x_off += window_step_x)
196 const float scale =
calculate_avg_scale(pool_info.
exclude_padding,
DataLayout::NHWC,
id, pool_size_x, pool_size_y, upper_bound_w, upper_bound_h, pool_pad_left, pool_pad_top,
pool_stride_x,
198 const float32x4_t scale_v = vdupq_n_f32(
scale);
201 vres = vdupq_n_f32(0.0f);
203 for(
int y = pool_start_y; y < pool_end_y; ++y)
205 for(
int x = pool_start_x; x < pool_end_x; ++x)
207 const float32x4_t data = vld1q_f32(reinterpret_cast<const float *>(in.
ptr() + (x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (y - pool_pad_top) * static_cast<int>
208 (
src->info()->strides_in_bytes().z())) + x_off);
213 vres = vmlaq_f32(vres, data, data);
217 vres = vaddq_f32(vres, data);
222 vres = vmulq_f32(vres, scale_v);
227 for(
int y = pool_start_y; y < pool_end_y; ++y)
229 for(
int x = pool_start_x; x < pool_end_x; ++x)
231 const float32x4_t data = vld1q_f32(reinterpret_cast<const float *>(in.
ptr() + (x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (y - pool_pad_top) * static_cast<int>
232 (
src->info()->strides_in_bytes().z())) + x_off);
233 vres = vmaxq_f32(vres, data);
241 float32x4_t l2_res = { static_cast<float>(sqrt(vgetq_lane_f32(vres, 0))),
242 static_cast<float>(sqrt(vgetq_lane_f32(vres, 1))),
243 static_cast<float>(sqrt(vgetq_lane_f32(vres, 2))),
244 static_cast<float>(sqrt(vgetq_lane_f32(vres, 3)))
250 vst1q_f32(reinterpret_cast<float *>(out.
ptr()) + x_off, vres);
254 for(; x_off < window_end_x; ++x_off)
261 const float scale =
calculate_avg_scale(pool_info.
exclude_padding,
DataLayout::NHWC,
id, pool_size_x, pool_size_y, upper_bound_w, upper_bound_h, pool_pad_left, pool_pad_top,
pool_stride_x,
264 for(
int y = pool_start_y; y < pool_end_y; ++y)
266 for(
int x = pool_start_x; x < pool_end_x; ++x)
268 const float data = *(reinterpret_cast<const float *>(in.
ptr() + (x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (y - pool_pad_top) * static_cast<int>
269 (
src->info()->strides_in_bytes().z())) + x_off);
289 for(
int y = pool_start_y; y < pool_end_y; ++y)
291 for(
int x = pool_start_x; x < pool_end_x; ++x)
293 const float data = *(reinterpret_cast<const float *>(in.
ptr() + (x - pool_pad_left) * static_cast<int>(
src->info()->strides_in_bytes().y()) + (y - pool_pad_top) * static_cast<int>
294 (
src->info()->strides_in_bytes().z())) + x_off);
295 res = std::max(res, data);
303 res = std::sqrt(res);
307 *(reinterpret_cast<float *>(out.
ptr()) + x_off) = res;
void poolingMxN_fp32_neon_nhwc(const ITensor *src, ITensor *dst0, ITensor *dst1, PoolingLayerInfo &pool_info, const Window &window_src, const Window &window)
Describe one of the image's dimensions with a start, end and step.
unsigned int pad_top() const
Get the top padding.
constexpr const Dimension & z() const
Alias to access the third dimension of the window.
Interface for CPU tensor.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
size_t height
Height of the image region or rectangle.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Pooling Layer Information struct.
unsigned int pad_right() const
Get the right padding.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
float calculate_avg_scale(bool exclude_padding, DataLayout data_layout, const Coordinates &id, const int pool_size_x, const int pool_size_y, const int upper_bound_w, const int upper_bound_h, const int pad_x, const int pad_y, const int stride_x, const int stride_y)
PadStrideInfo pad_stride_info
size_t width
Width of the image region or rectangle.
Class for specifying the size of an image or rectangle.
Num samples, height, width, channels.
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
constexpr int end() const
Return the end of the dimension.
unsigned int pad_bottom() const
Get the bottom padding.
Iterator updated by execute_window_loop for each window element.
unsigned int pad_left() const
Get the left padding.
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.