Skip to content

Commit 4a89ff5

Browse files
committed
feat: Provide a wrapper class to expose cpu::CpuPool2d
Resolves: MLINFSW-852 Signed-off-by: Zhibo Li <[email protected]> Change-Id: Ic9dc22094bc06b805634bb6601320d9c581e0e90 Signed-off-by: Zhibo Li <[email protected]> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/13392 Benchmark: Arm Jenkins <[email protected]> Tested-by: Arm Jenkins <[email protected]> Comments-Addressed: Arm Jenkins <[email protected]> Reviewed-by: Gunes Bayir <[email protected]>
1 parent 9e0ac71 commit 4a89ff5

File tree

8 files changed

+655
-0
lines changed

8 files changed

+655
-0
lines changed

Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ cc_library_static {
10051005
"src/runtime/experimental/operators/CpuGemmDirectConv2d.cpp",
10061006
"src/runtime/experimental/operators/CpuMeanStdDevNormalization.cpp",
10071007
"src/runtime/experimental/operators/CpuMul.cpp",
1008+
"src/runtime/experimental/operators/CpuPool2d.cpp",
10081009
"src/runtime/experimental/operators/CpuQuantize.cpp",
10091010
"src/runtime/experimental/operators/CpuSoftmax.cpp",
10101011
"src/runtime/experimental/operators/CpuSub.cpp",
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2017-2020, 2024-2025 Arm Limited.
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to
8+
* deal in the Software without restriction, including without limitation the
9+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
* sell copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#ifndef ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUPOOL2D_H
26+
#define ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUPOOL2D_H
27+
28+
#include "arm_compute/core/TensorInfo.h"
29+
#include "arm_compute/core/Types.h" // required for PoolingLayerInfo
30+
#include "arm_compute/runtime/NEON/INEOperator.h"
31+
32+
#include <memory>
33+
34+
namespace arm_compute
35+
{
36+
namespace experimental
37+
{
38+
namespace op
39+
{
40+
41+
/*
42+
* A shallow wrapper for arm_compute::cpu::CpuPool2d.
43+
* Any new features should be added to arm_compute::cpu::CpuPool2d,
44+
* and arm_compute::experimental::op::CpuPool2d should remain a shallow wrapper.
45+
* Note this is not thread safe therefore no thread safety tests provided.
46+
*/
47+
class CpuPool2d : public INEOperator
48+
{
49+
public:
50+
/** Constructor **/
51+
CpuPool2d();
52+
/** Prevent instances of this class from being copied (As this class contains pointers) **/
53+
CpuPool2d(const CpuPool2d &) = delete;
54+
/** Prevent copy assignment **/
55+
CpuPool2d &operator=(const CpuPool2d &) = delete;
56+
/** Default move constructor **/
57+
CpuPool2d(CpuPool2d &&) = default;
58+
/** Default move assignment **/
59+
CpuPool2d &operator=(CpuPool2d &&) = default;
60+
/** Default destructor **/
61+
~CpuPool2d() override;
62+
/** Set the src and dst tensors.
63+
*
64+
* Valid data layouts:
65+
* - NHWC
66+
* - NCHW
67+
*
68+
* Valid data type configurations:
69+
* |src |dst |
70+
* |:--------------|:--------------|
71+
* |QASYMM8 |QASYMM8 |
72+
* |QASYMM8_SIGNED |QASYMM8_SIGNED |
73+
* |F16 |F16 |
74+
* |F32 |F32 |
75+
*
76+
* @note F16 is supported for pool sizes 2 and 3 only
77+
* @note Source tensor is padded with -inf for MAX pooling and 0 otherwise
78+
* Cases where pooling region is completely outside input tensor are only supported for floating point data type
79+
*
80+
* @param[in, out] src Source tensor info. (Written to only when padding != 0) Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
81+
* @param[out] dst Destination tensor info. Data types supported: same as @p src.
82+
* @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
83+
* @param[out] indices (optional) The indices of the maximal values. Data type supported: U32.
84+
*/
85+
void
86+
configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices = nullptr);
87+
/** Static function to check if given info will lead to a valid configuration
88+
*
89+
* Similar to @ref CpuPool2d::configure()
90+
*/
91+
92+
static Status validate(const ITensorInfo *src,
93+
const ITensorInfo *dst,
94+
const PoolingLayerInfo &pool_info,
95+
const ITensorInfo *indices = nullptr);
96+
97+
// Inherited methods overridden:
98+
void run(ITensorPack &tensors) override;
99+
experimental::MemoryRequirements workspace() const override;
100+
101+
private:
102+
struct Impl;
103+
std::unique_ptr<Impl> impl_;
104+
};
105+
} // namespace op
106+
} //namespace experimental
107+
} // namespace arm_compute
108+
#endif // ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUPOOL2D_H

filelist.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@
16261626
"src/runtime/experimental/operators/CpuMul.cpp",
16271627
"src/runtime/experimental/operators/CpuQuantize.cpp",
16281628
"src/runtime/experimental/operators/CpuSoftmax.cpp",
1629+
"src/runtime/experimental/operators/CpuPool2d.cpp",
16291630
"src/runtime/experimental/operators/CpuSub.cpp",
16301631
"src/runtime/experimental/operators/CpuTranspose.cpp",
16311632
"src/runtime/experimental/operators/CpuWinogradConv2d.cpp"

src/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ filegroup(
994994
"runtime/experimental/operators/CpuGemmDirectConv2d.cpp",
995995
"runtime/experimental/operators/CpuMeanStdDevNormalization.cpp",
996996
"runtime/experimental/operators/CpuMul.cpp",
997+
"runtime/experimental/operators/CpuPool2d.cpp",
997998
"runtime/experimental/operators/CpuQuantize.cpp",
998999
"runtime/experimental/operators/CpuSoftmax.cpp",
9991000
"runtime/experimental/operators/CpuSub.cpp",

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ target_sources(
987987
runtime/experimental/operators/CpuGemmDirectConv2d.cpp
988988
runtime/experimental/operators/CpuMeanStdDevNormalization.cpp
989989
runtime/experimental/operators/CpuMul.cpp
990+
runtime/experimental/operators/CpuPool2d.cpp
990991
runtime/experimental/operators/CpuQuantize.cpp
991992
runtime/experimental/operators/CpuSoftmax.cpp
992993
runtime/experimental/operators/CpuSub.cpp
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025 Arm Limited.
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to
8+
* deal in the Software without restriction, including without limitation the
9+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
* sell copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include "arm_compute/runtime/experimental/operators/CpuPool2d.h"
26+
27+
#include "src/cpu/operators/CpuPool2d.h"
28+
29+
namespace arm_compute
30+
{
31+
namespace experimental
32+
{
33+
namespace op
34+
{
35+
36+
struct CpuPool2d::Impl
37+
{
38+
std::unique_ptr<arm_compute::cpu::CpuPool2d> op{nullptr};
39+
};
40+
41+
CpuPool2d::CpuPool2d() : impl_(std::make_unique<Impl>())
42+
{
43+
impl_->op = std::make_unique<cpu::CpuPool2d>();
44+
}
45+
46+
CpuPool2d::~CpuPool2d() = default;
47+
48+
void CpuPool2d::configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices)
49+
{
50+
impl_->op->configure(src, dst, pool_info, indices);
51+
}
52+
53+
Status CpuPool2d::validate(const ITensorInfo *src,
54+
const ITensorInfo *dst,
55+
const PoolingLayerInfo &pool_info,
56+
const ITensorInfo *indices)
57+
{
58+
return cpu::CpuPool2d::validate(src, dst, pool_info, indices);
59+
}
60+
61+
void CpuPool2d::run(ITensorPack &tensors)
62+
{
63+
impl_->op->run(tensors);
64+
}
65+
66+
experimental::MemoryRequirements CpuPool2d::workspace() const
67+
{
68+
return impl_->op->workspace();
69+
}
70+
71+
} //namespace op
72+
} //namespace experimental
73+
} //namespace arm_compute

0 commit comments

Comments
 (0)