Skip to content

Commit

Permalink
[GoodFirstIssue][Core] Created AvgPoolBase (openvinotoolkit#23483)
Browse files Browse the repository at this point in the history
### Details:
- *Created `AvgPoolBase` class with the common functionality from
`AvgPool-1` and `AvgPool-14`*

### Tickets:
 - *openvinotoolkit#23465
  • Loading branch information
Vladislav-Denisov authored and itikhono committed Mar 28, 2024
1 parent 94f85c5 commit 515fe9c
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 232 deletions.
87 changes: 11 additions & 76 deletions src/core/include/openvino/op/avg_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@

#pragma once

#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
#include "openvino/op/util/avg_pool_base.hpp"

namespace ov {
namespace op {
namespace v1 {
/// \brief Batched average pooling operation.
///
class OPENVINO_API AvgPool : public Op {
/// \ingroup ov_ops_cpp_api
class OPENVINO_API AvgPool : public util::AvgPoolBase {
public:
OPENVINO_OP("AvgPool", "opset1", op::Op);
OPENVINO_OP("AvgPool", "opset1", util::AvgPoolBase);

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

///
/// \brief Constructs a batched average pooling operation.
///
/// \param arg The output producing the input data batch tensor.<br>
Expand All @@ -35,63 +33,31 @@ class OPENVINO_API AvgPool : public Op {
/// \param rounding_type Whether to use ceiling or floor rounding type while
/// computing output shape.
/// \param auto_pad Padding type to use for additional padded dimensions
///
AvgPool(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
bool exclude_pad,
op::RoundingType rounding_type = op::RoundingType::FLOOR,
const PadType& auto_pad = op::PadType::EXPLICIT);
RoundingType rounding_type = RoundingType::FLOOR,
const PadType& auto_pad = PadType::EXPLICIT);

void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

/// \return The kernel shape.
const Shape& get_kernel() const;
void set_kernel(const Shape& kernel);
/// \return The strides.
const Strides& get_strides() const;
void set_strides(const Strides& strides);
/// \return The beginning of padding shape.
const Shape& get_pads_begin() const;
void set_pads_begin(const Shape& pads_begin);
/// \return The end of padding shape.
const Shape& get_pads_end() const;
void set_pads_end(const Shape& pads_end);
bool get_exclude_pad() const;
void set_exclude_pad(bool exclude_pad);
/// \return The pad type for pooling.
const PadType& get_auto_pad() const;
void set_auto_pad(const PadType& auto_pad);
op::RoundingType get_rounding_type() const;
void set_rounding_type(op::RoundingType rounding_type);

protected:
Shape m_kernel;
Strides m_strides;
Shape m_pads_begin;
Shape m_pads_end;
bool m_exclude_pad{true};
PadType m_auto_pad{PadType::EXPLICIT};
op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
};
} // namespace v1

namespace v14 {
/// \brief Batched average pooling operation.
///
class OPENVINO_API AvgPool : public Op {
/// \ingroup ov_ops_cpp_api
class OPENVINO_API AvgPool : public util::AvgPoolBase {
public:
OPENVINO_OP("AvgPool", "opset14", op::Op);
OPENVINO_OP("AvgPool", "opset14", util::AvgPoolBase);

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

///
/// \brief Constructs a batched average pooling operation.
///
/// \param arg The output producing the input data batch tensor.<br>
Expand All @@ -107,49 +73,18 @@ class OPENVINO_API AvgPool : public Op {
/// \param rounding_type Whether to use ceiling or floor rounding type while
/// computing output shape.
/// \param auto_pad Padding type to use for additional padded dimensions
///
AvgPool(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
bool exclude_pad,
op::RoundingType rounding_type = op::RoundingType::FLOOR,
const PadType& auto_pad = op::PadType::EXPLICIT);
RoundingType rounding_type = RoundingType::FLOOR,
const PadType& auto_pad = PadType::EXPLICIT);

void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

/// \return The kernel shape.
const Shape& get_kernel() const;
void set_kernel(const Shape& kernel);
/// \return The strides.
const Strides& get_strides() const;
void set_strides(const Strides& strides);
/// \return The beginning of padding shape.
const Shape& get_pads_begin() const;
void set_pads_begin(const Shape& pads_begin);
/// \return The end of padding shape.
const Shape& get_pads_end() const;
void set_pads_end(const Shape& pads_end);
bool get_exclude_pad() const;
void set_exclude_pad(bool exclude_pad);
/// \return The pad type for pooling.
const PadType& get_auto_pad() const;
void set_auto_pad(const PadType& auto_pad);
op::RoundingType get_rounding_type() const;
void set_rounding_type(op::RoundingType rounding_type);

protected:
Shape m_kernel;
Strides m_strides;
Shape m_pads_begin;
Shape m_pads_end;
bool m_exclude_pad{true};
PadType m_auto_pad{PadType::EXPLICIT};
op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
};
} // namespace v14
} // namespace op
Expand Down
84 changes: 84 additions & 0 deletions src/core/include/openvino/op/util/avg_pool_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"

namespace ov {
namespace op {
namespace util {
class OPENVINO_API AvgPoolBase : public Op {
public:
OPENVINO_OP("AvgPool", "util");
AvgPoolBase() = default;

/// \brief Constructs a batched average pooling operation.
///
/// \param arg The output producing the input data batch tensor.<br>
/// `[d1, dn]`
/// \param strides The strides.<br> `[n]`
/// \param pads_begin The beginning of padding shape.<br> `[n]`
/// \param pads_end The end of padding shape.<br> `[n]`
/// \param kernel The kernel shape.<br> `[n]`
/// \param exclude_pad If false then averages include padding elements, each
/// treated as the number zero. If true, padding
/// elements
/// are entirely ignored when computing averages.
/// \param rounding_type Whether to use ceiling or floor rounding type while
/// computing output shape.
/// \param auto_pad Padding type to use for additional padded dimensions
AvgPoolBase(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
bool exclude_pad,
RoundingType rounding_type = RoundingType::FLOOR,
const PadType& auto_pad = PadType::EXPLICIT);

void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;

/// \return The kernel shape.
const Shape& get_kernel() const;
void set_kernel(const Shape& kernel);

/// \return The strides.
const Strides& get_strides() const;
void set_strides(const Strides& strides);

/// \return The beginning of padding shape.
const Shape& get_pads_begin() const;
void set_pads_begin(const Shape& pads_begin);

/// \return The end of padding shape.
const Shape& get_pads_end() const;
void set_pads_end(const Shape& pads_end);

/// \return Exclude zero-values in padding area.
bool get_exclude_pad() const;
void set_exclude_pad(bool exclude_pad);

/// \return The pad type for pooling.
const PadType& get_auto_pad() const;
void set_auto_pad(const PadType& auto_pad);

/// \return The ceiling mode being used for output shape computations
RoundingType get_rounding_type() const;
void set_rounding_type(RoundingType rounding_type);

protected:
Shape m_kernel;
Strides m_strides;
Shape m_pads_begin;
Shape m_pads_end;
bool m_exclude_pad{true};
PadType m_auto_pad{PadType::EXPLICIT};
RoundingType m_rounding_type{RoundingType::FLOOR};
};
} // namespace util
} // namespace op
} // namespace ov
Loading

0 comments on commit 515fe9c

Please sign in to comment.