Skip to content

Commit 515fe9c

Browse files
Vladislav-Denisovitikhono
authored andcommitted
[GoodFirstIssue][Core] Created AvgPoolBase (openvinotoolkit#23483)
### Details: - *Created `AvgPoolBase` class with the common functionality from `AvgPool-1` and `AvgPool-14`* ### Tickets: - *openvinotoolkit#23465
1 parent 94f85c5 commit 515fe9c

File tree

4 files changed

+219
-232
lines changed

4 files changed

+219
-232
lines changed

src/core/include/openvino/op/avg_pool.hpp

+11-76
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44

55
#pragma once
66

7-
#include "openvino/op/op.hpp"
8-
#include "openvino/op/util/attr_types.hpp"
7+
#include "openvino/op/util/avg_pool_base.hpp"
98

109
namespace ov {
1110
namespace op {
1211
namespace v1 {
1312
/// \brief Batched average pooling operation.
14-
///
15-
class OPENVINO_API AvgPool : public Op {
13+
/// \ingroup ov_ops_cpp_api
14+
class OPENVINO_API AvgPool : public util::AvgPoolBase {
1615
public:
17-
OPENVINO_OP("AvgPool", "opset1", op::Op);
16+
OPENVINO_OP("AvgPool", "opset1", util::AvgPoolBase);
1817

1918
/// \brief Constructs a batched average pooling operation.
2019
AvgPool() = default;
2120

22-
///
2321
/// \brief Constructs a batched average pooling operation.
2422
///
2523
/// \param arg The output producing the input data batch tensor.<br>
@@ -35,63 +33,31 @@ class OPENVINO_API AvgPool : public Op {
3533
/// \param rounding_type Whether to use ceiling or floor rounding type while
3634
/// computing output shape.
3735
/// \param auto_pad Padding type to use for additional padded dimensions
38-
///
3936
AvgPool(const Output<Node>& arg,
4037
const Strides& strides,
4138
const Shape& pads_begin,
4239
const Shape& pads_end,
4340
const Shape& kernel,
4441
bool exclude_pad,
45-
op::RoundingType rounding_type = op::RoundingType::FLOOR,
46-
const PadType& auto_pad = op::PadType::EXPLICIT);
42+
RoundingType rounding_type = RoundingType::FLOOR,
43+
const PadType& auto_pad = PadType::EXPLICIT);
4744

4845
void validate_and_infer_types() override;
49-
bool visit_attributes(AttributeVisitor& visitor) override;
5046

5147
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
52-
53-
/// \return The kernel shape.
54-
const Shape& get_kernel() const;
55-
void set_kernel(const Shape& kernel);
56-
/// \return The strides.
57-
const Strides& get_strides() const;
58-
void set_strides(const Strides& strides);
59-
/// \return The beginning of padding shape.
60-
const Shape& get_pads_begin() const;
61-
void set_pads_begin(const Shape& pads_begin);
62-
/// \return The end of padding shape.
63-
const Shape& get_pads_end() const;
64-
void set_pads_end(const Shape& pads_end);
65-
bool get_exclude_pad() const;
66-
void set_exclude_pad(bool exclude_pad);
67-
/// \return The pad type for pooling.
68-
const PadType& get_auto_pad() const;
69-
void set_auto_pad(const PadType& auto_pad);
70-
op::RoundingType get_rounding_type() const;
71-
void set_rounding_type(op::RoundingType rounding_type);
72-
73-
protected:
74-
Shape m_kernel;
75-
Strides m_strides;
76-
Shape m_pads_begin;
77-
Shape m_pads_end;
78-
bool m_exclude_pad{true};
79-
PadType m_auto_pad{PadType::EXPLICIT};
80-
op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
8148
};
8249
} // namespace v1
8350

8451
namespace v14 {
8552
/// \brief Batched average pooling operation.
86-
///
87-
class OPENVINO_API AvgPool : public Op {
53+
/// \ingroup ov_ops_cpp_api
54+
class OPENVINO_API AvgPool : public util::AvgPoolBase {
8855
public:
89-
OPENVINO_OP("AvgPool", "opset14", op::Op);
56+
OPENVINO_OP("AvgPool", "opset14", util::AvgPoolBase);
9057

9158
/// \brief Constructs a batched average pooling operation.
9259
AvgPool() = default;
9360

94-
///
9561
/// \brief Constructs a batched average pooling operation.
9662
///
9763
/// \param arg The output producing the input data batch tensor.<br>
@@ -107,49 +73,18 @@ class OPENVINO_API AvgPool : public Op {
10773
/// \param rounding_type Whether to use ceiling or floor rounding type while
10874
/// computing output shape.
10975
/// \param auto_pad Padding type to use for additional padded dimensions
110-
///
11176
AvgPool(const Output<Node>& arg,
11277
const Strides& strides,
11378
const Shape& pads_begin,
11479
const Shape& pads_end,
11580
const Shape& kernel,
11681
bool exclude_pad,
117-
op::RoundingType rounding_type = op::RoundingType::FLOOR,
118-
const PadType& auto_pad = op::PadType::EXPLICIT);
82+
RoundingType rounding_type = RoundingType::FLOOR,
83+
const PadType& auto_pad = PadType::EXPLICIT);
11984

12085
void validate_and_infer_types() override;
121-
bool visit_attributes(AttributeVisitor& visitor) override;
12286

12387
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
124-
125-
/// \return The kernel shape.
126-
const Shape& get_kernel() const;
127-
void set_kernel(const Shape& kernel);
128-
/// \return The strides.
129-
const Strides& get_strides() const;
130-
void set_strides(const Strides& strides);
131-
/// \return The beginning of padding shape.
132-
const Shape& get_pads_begin() const;
133-
void set_pads_begin(const Shape& pads_begin);
134-
/// \return The end of padding shape.
135-
const Shape& get_pads_end() const;
136-
void set_pads_end(const Shape& pads_end);
137-
bool get_exclude_pad() const;
138-
void set_exclude_pad(bool exclude_pad);
139-
/// \return The pad type for pooling.
140-
const PadType& get_auto_pad() const;
141-
void set_auto_pad(const PadType& auto_pad);
142-
op::RoundingType get_rounding_type() const;
143-
void set_rounding_type(op::RoundingType rounding_type);
144-
145-
protected:
146-
Shape m_kernel;
147-
Strides m_strides;
148-
Shape m_pads_begin;
149-
Shape m_pads_end;
150-
bool m_exclude_pad{true};
151-
PadType m_auto_pad{PadType::EXPLICIT};
152-
op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
15388
};
15489
} // namespace v14
15590
} // namespace op
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (C) 2018-2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include "openvino/op/op.hpp"
8+
#include "openvino/op/util/attr_types.hpp"
9+
10+
namespace ov {
11+
namespace op {
12+
namespace util {
13+
class OPENVINO_API AvgPoolBase : public Op {
14+
public:
15+
OPENVINO_OP("AvgPool", "util");
16+
AvgPoolBase() = default;
17+
18+
/// \brief Constructs a batched average pooling operation.
19+
///
20+
/// \param arg The output producing the input data batch tensor.<br>
21+
/// `[d1, dn]`
22+
/// \param strides The strides.<br> `[n]`
23+
/// \param pads_begin The beginning of padding shape.<br> `[n]`
24+
/// \param pads_end The end of padding shape.<br> `[n]`
25+
/// \param kernel The kernel shape.<br> `[n]`
26+
/// \param exclude_pad If false then averages include padding elements, each
27+
/// treated as the number zero. If true, padding
28+
/// elements
29+
/// are entirely ignored when computing averages.
30+
/// \param rounding_type Whether to use ceiling or floor rounding type while
31+
/// computing output shape.
32+
/// \param auto_pad Padding type to use for additional padded dimensions
33+
AvgPoolBase(const Output<Node>& arg,
34+
const Strides& strides,
35+
const Shape& pads_begin,
36+
const Shape& pads_end,
37+
const Shape& kernel,
38+
bool exclude_pad,
39+
RoundingType rounding_type = RoundingType::FLOOR,
40+
const PadType& auto_pad = PadType::EXPLICIT);
41+
42+
void validate_and_infer_types() override;
43+
bool visit_attributes(AttributeVisitor& visitor) override;
44+
45+
/// \return The kernel shape.
46+
const Shape& get_kernel() const;
47+
void set_kernel(const Shape& kernel);
48+
49+
/// \return The strides.
50+
const Strides& get_strides() const;
51+
void set_strides(const Strides& strides);
52+
53+
/// \return The beginning of padding shape.
54+
const Shape& get_pads_begin() const;
55+
void set_pads_begin(const Shape& pads_begin);
56+
57+
/// \return The end of padding shape.
58+
const Shape& get_pads_end() const;
59+
void set_pads_end(const Shape& pads_end);
60+
61+
/// \return Exclude zero-values in padding area.
62+
bool get_exclude_pad() const;
63+
void set_exclude_pad(bool exclude_pad);
64+
65+
/// \return The pad type for pooling.
66+
const PadType& get_auto_pad() const;
67+
void set_auto_pad(const PadType& auto_pad);
68+
69+
/// \return The ceiling mode being used for output shape computations
70+
RoundingType get_rounding_type() const;
71+
void set_rounding_type(RoundingType rounding_type);
72+
73+
protected:
74+
Shape m_kernel;
75+
Strides m_strides;
76+
Shape m_pads_begin;
77+
Shape m_pads_end;
78+
bool m_exclude_pad{true};
79+
PadType m_auto_pad{PadType::EXPLICIT};
80+
RoundingType m_rounding_type{RoundingType::FLOOR};
81+
};
82+
} // namespace util
83+
} // namespace op
84+
} // namespace ov

0 commit comments

Comments
 (0)