26 case PoolingAlgorithm::Max:
28 return std::numeric_limits<float>::lowest();
30 case PoolingAlgorithm::Average:
31 case PoolingAlgorithm::L2:
42 using Accumulator = std::function<void(float & accu, float value)>;
48 case PoolingAlgorithm::Max:
50 return [](
float & accu,
float value) {
57 case PoolingAlgorithm::Average:
59 return [](
float & accu,
float value) {
64 case PoolingAlgorithm::L2:
66 return [](
float & accu,
float value) {
67 accu += (value*value);
78 using Executor = std::function<void(float & accumulated, float kernelSize)>;
84 case PoolingAlgorithm::Max:
86 return [](
float & ,
float ) {};
89 case PoolingAlgorithm::Average:
91 return [](
float & accumulated,
float kernelSize) {
92 accumulated /= kernelSize;
96 case PoolingAlgorithm::L2:
98 return [](
float & accumulated,
float kernelSize) {
99 accumulated = sqrtf(accumulated / kernelSize);
110 bool OnPaddingOnly(
int start,
int end,
int maxRange)
112 if (end <= 0 || start > maxRange)
123 bool ClampRange(
int & start,
int & end,
int maxRange)
125 if (start < 0 || end > maxRange)
127 start = std::min(std::max(start, 0), maxRange);
128 end = std::min(std::max(end, 0), maxRange);
137 int CalculateIndex(
int channels,
int depth,
int height,
int width,
138 int n,
int c,
int z,
int y,
int x,
144 int outputIndex = n * depth * height * width * channels +
145 z * height * width * channels +
146 y * width * channels +
153 int outputIndex = n * channels * depth * height * width +
154 c * depth * height * width +
212 float defaultInitializer = DefaultInitializer(params.
m_PoolType);
213 Accumulator accumulate = GetAccumulator(params.
m_PoolType);
214 Executor execute = GetExecutor(params.
m_PoolType);
226 for (
int n = 0; n < batchSize; n++)
228 for (
int c = 0; c < channels; c++)
230 for (
int zOutput = 0; zOutput < depthOutput; zOutput++)
233 int dstart = (zOutput * strideZ) - padFront;
234 int dend = dstart + poolDepth;
237 dend = std::min(dend, depthInput + padBack);
239 int depth = dend - dstart;
240 bool dclamped = ClampRange(dstart, dend, depthInput);
241 int depthClamped = dend - dstart;
243 for (
int yOutput = 0; yOutput < heightOutput; yOutput++)
245 int hstart = (yOutput * strideY) - padTop;
246 int hend = hstart + poolHeight;
249 hend = std::min(hend, heightInput + padBottom);
251 int height = hend - hstart;
252 bool hclamped = ClampRange(hstart, hend, heightInput);
253 int heightClamped = hend - hstart;
255 for (
int xOutput = 0; xOutput < widthOutput; xOutput++)
257 int wstart = (xOutput * strideX) - padLeft;
258 int wend = wstart + poolWidth;
261 wend = std::min(wend, widthInput + padRight);
263 int width = wend - wstart;
264 bool wclamped = ClampRange(wstart, wend, widthInput);
265 int widthClamped = wend - wstart;
267 float result = defaultInitializer;
275 if (OnPaddingOnly(dstart, dend, depthInput) ||
276 OnPaddingOnly(hstart, hend, heightInput) ||
277 OnPaddingOnly(wstart, wend, widthInput))
281 int outputIndex = CalculateIndex(channels, depthOutput, heightOutput, widthOutput,
282 n, c, zOutput, yOutput, xOutput, dataLayout);
284 rOutputEncoder[
static_cast<unsigned int>(outputIndex)];
285 rOutputEncoder.
Set(result);
290 bool clamped = (dclamped | hclamped | wclamped);
299 for (
auto zInput = dstart; zInput < dend; zInput++)
301 for (
auto yInput = hstart; yInput < hend; yInput++)
303 for (
auto xInput = wstart; xInput < wend; xInput++)
306 int inputIndex = CalculateIndex(channels, depthInput, heightInput, widthInput,
307 n, c, zInput, yInput, xInput, dataLayout);
309 accumulate(result, decodedInputVec[static_cast<unsigned int>(inputIndex)]);
314 execute(result, poolAreaSize);
316 int outputIndex = CalculateIndex(channels, depthOutput, heightOutput, widthOutput,
317 n, c, zOutput, yOutput, xOutput, dataLayout);
319 rOutputEncoder[
static_cast<unsigned int>(outputIndex)];
320 rOutputEncoder.
Set(result);
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
unsigned int GetWidthIndex() const
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
const TensorShape & GetShape() const
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_PoolDepth
Pooling depth value.
virtual std::vector< float > DecodeTensor(const TensorShape &tensorShape, bool isDepthwise=false)=0
virtual void Set(IType right)=0
uint32_t m_PadRight
Padding right value in the width dimension.
unsigned int GetDepthIndex() const
Copyright (c) 2021 ARM Limited and Contributors.
DataLayout m_DataLayout
The data layout to be used (NCDHW, NDHWC).
uint32_t m_PadFront
Padding front value in the depth dimension.
uint32_t m_PoolHeight
Pooling height value.
unsigned int GetHeightIndex() const
uint32_t m_PadBack
Padding back value in the depth dimension.
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
uint32_t m_PadBottom
Padding bottom value in the height dimension.
armnn::DataLayout GetDataLayout() const
A Pooling3dDescriptor for the Pooling3dLayer.
uint32_t m_StrideZ
Stride value when proceeding through input for the depth dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void Pooling3d(Decoder< float > &rInputDecoder, Encoder< float > &rOutputEncoder, const TensorInfo &inputInfo, const TensorInfo &outputInfo, const Pooling3dDescriptor ¶ms)
Computes the Pooling3d operation.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
unsigned int GetChannelsIndex() const