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 in_stride_y =
static_cast<int>(src->info()->strides_in_bytes().y());
63 const int in_stride_z =
static_cast<int>(src->info()->strides_in_bytes().z());
69 const int pool_limit_y = pool_pad_top -
idx_height;
70 const int pool_limit_x = pool_pad_left -
idx_width;
72 const int pool_start_y = std::max(0, window_src.z().start() + pool_limit_y);
73 const int pool_start_x = std::max(0, window_src.y().start() + pool_limit_x);
75 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());
76 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> 77 (src->info()->strides_in_bytes().z());
78 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> 79 (src->info()->strides_in_bytes().z());
80 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> 81 (src->info()->strides_in_bytes().z());
83 int x_off = window_start_x;
84 for(; x_off <= (window_end_x - window_step_x); x_off += window_step_x)
86 const auto in_x0_ptr =
reinterpret_cast<const float *
>(in.ptr() + in_x0_offset);
87 const auto in_x1_ptr =
reinterpret_cast<const float *
>(in.ptr() + in_x1_offset);
88 const auto in_x2_ptr =
reinterpret_cast<const float *
>(in.ptr() + in_x2_offset);
89 const auto in_x3_ptr =
reinterpret_cast<const float *
>(in.ptr() + in_x3_offset);
90 const auto v_x0 = vld1q_f32(in_x0_ptr + x_off);
91 const auto v_x1 = vld1q_f32(in_x1_ptr + x_off);
92 const auto v_x2 = vld1q_f32(in_x2_ptr + x_off);
93 const auto v_x3 = vld1q_f32(in_x3_ptr + x_off);
94 vres = vmaxq_f32(vmaxq_f32(v_x2, v_x3), vmaxq_f32(v_x0, v_x1));
96 vst1q_f32(reinterpret_cast<float *>(out.ptr()) + x_off, vres);
98 const uint32_t offset_base = offset_no_padding<float>(in.offset(), id, *src->info(),
pool_stride_x, pool_stride_y);
99 const uint32_t offset_x0 = (uint32_t)offset_base /
sizeof(
float) + x_off;
100 const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y /
sizeof(
float) - pad_right;
101 const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z /
sizeof(
float) - pad_right * src->info()->tensor_shape()[1];
102 const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y /
sizeof(
float) - pad_right;
103 const uint32x4_t voffset_x0 = { offset_x0, offset_x0 + 1, offset_x0 + 2, offset_x0 + 3 };
104 const uint32x4_t voffset_x1 = { offset_x1, offset_x1 + 1, offset_x1 + 2, offset_x1 + 3 };
105 const uint32x4_t voffset_x2 = { offset_x2, offset_x2 + 1, offset_x2 + 2, offset_x2 + 3 };
106 const uint32x4_t voffset_x3 = { offset_x3, offset_x3 + 1, offset_x3 + 2, offset_x3 + 3 };
107 const uint32x4_t tmp_indices0 = vbslq_u32(vcgeq_f32(v_x0, v_x1), voffset_x0, voffset_x1);
108 const uint32x4_t tmp_indices1 = vbslq_u32(vcgeq_f32(v_x2, v_x3), voffset_x2, voffset_x3);
109 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);
112 vst1q_u32(reinterpret_cast<uint32_t *>(indices.ptr()) + x_off, tmp_indices2);
116 for(; x_off < window_end_x; ++x_off)
118 const auto x0 = *(
reinterpret_cast<const float *
>(in.ptr() + in_x0_offset) + x_off);
119 const auto x1 = *(
reinterpret_cast<const float *
>(in.ptr() + in_x1_offset) + x_off);
120 const auto x2 = *(
reinterpret_cast<const float *
>(in.ptr() + in_x2_offset) + x_off);
121 const auto x3 = *(
reinterpret_cast<const float *
>(in.ptr() + in_x3_offset) + x_off);
122 res = std::max(std::max(x2, x3), std::max(x0, x1));
125 *(
reinterpret_cast<float *
>(out.ptr()) + x_off) = res;
127 const uint32_t offset_base = offset_no_padding<float>(in.offset(), id, *src->info(),
pool_stride_x, pool_stride_y);
128 const uint32_t offset_x0 = (uint32_t)offset_base /
sizeof(
float) + x_off;
129 const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y /
sizeof(
float) - pad_right;
130 const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z /
sizeof(
float) - pad_right * src->info()->tensor_shape()[1];
131 const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y /
sizeof(
float) - pad_right;
132 const uint32_t tmp_idx0 = (x0 >= x1) ? offset_x0 : offset_x1;
133 const uint32_t tmp_idx1 = (x2 >= x3) ? offset_x2 : offset_x3;
134 const uint32_t tmp_idx2 = (std::max(x0, x1) >= std::max(x2, x3)) ? tmp_idx0 : tmp_idx1;
137 *(
reinterpret_cast<uint32_t *
>(indices.ptr()) + x_off) = tmp_idx2;
148 pooling2_f32_maxpool_indices(src, dst0, dst1, pool_info, window_src, window);
152 const int window_start_x = window.
x().
start();
153 const int window_end_x = window.
x().
end();
154 const int window_step_x = 4;
156 Window window_out = window;
168 int pool_stride_x = 0;
169 int pool_stride_y = 0;
179 const int idx_height =
id.z() * pool_stride_y;
180 const int pool_limit_y = pool_pad_top -
idx_height;
181 const int pool_limit_x = pool_pad_left -
idx_width;
183 const int pool_start_y = std::max(0, window_src.
z().
start() + pool_limit_y);
184 const int pool_end_y = std::min(pool_size_y, window_src.
z().
end() + pool_limit_y);
185 const int pool_start_x = std::max(0, window_src.
y().
start() + pool_limit_x);
186 const int pool_end_x = std::min(pool_size_x, window_src.
y().
end() + pool_limit_x);
188 int x_off = window_start_x;
189 for(; x_off <= (window_end_x - window_step_x); x_off += window_step_x)
194 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,
196 const float32x4_t scale_v = vdupq_n_f32(scale);
199 vres = vdupq_n_f32(0.0f);
201 for(
int y = pool_start_y; y < pool_end_y; ++y)
203 for(
int x = pool_start_x; x < pool_end_x; ++x)
205 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> 211 vres = vmlaq_f32(vres, data, data);
215 vres = vaddq_f32(vres, data);
220 vres = vmulq_f32(vres, scale_v);
225 for(
int y = pool_start_y; y < pool_end_y; ++y)
227 for(
int x = pool_start_x; x < pool_end_x; ++x)
229 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> 231 vres = vmaxq_f32(vres, data);
239 float32x4_t l2_res = {
static_cast<float>(sqrt(vgetq_lane_f32(vres, 0))),
240 static_cast<float>(sqrt(vgetq_lane_f32(vres, 1))),
241 static_cast<float>(sqrt(vgetq_lane_f32(vres, 2))),
242 static_cast<float>(sqrt(vgetq_lane_f32(vres, 3)))
248 vst1q_f32(reinterpret_cast<float *>(out.
ptr()) + x_off, vres);
252 for(; x_off < window_end_x; ++x_off)
259 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,
262 for(
int y = pool_start_y; y < pool_end_y; ++y)
264 for(
int x = pool_start_x; x < pool_end_x; ++x)
266 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> 287 for(
int y = pool_start_y; y < pool_end_y; ++y)
289 for(
int x = pool_start_x; x < pool_end_x; ++x)
291 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> 293 res = std::max(res, data);
301 res = std::sqrt(res);
305 *(
reinterpret_cast<float *
>(out.
ptr()) + x_off) = res;
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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 Neon 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.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
T z() const
Alias to access the size of the third dimension.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Pooling Layer Information struct.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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...
T y() const
Alias to access the size of the second dimension.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
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.