Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SegmentMax-16 reference implementation #28788

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

p-wysocki
Copy link
Contributor

@p-wysocki p-wysocki commented Feb 3, 2025

Details:

Related PRs:

Tickets:

Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
Signed-off-by: p-wysocki <[email protected]>
@p-wysocki p-wysocki requested review from a team as code owners February 3, 2025 15:32
@github-actions github-actions bot added category: Core OpenVINO Core (aka ngraph) category: IE Tests OpenVINO Test: plugins and common category: CPU OpenVINO CPU plugin category: TEMPLATE OpenVINO Template plugin category: CPP API OpenVINO CPP API bindings labels Feb 3, 2025
@@ -20,6 +20,12 @@ enum class PadMode { CONSTANT = 0, EDGE, REFLECT, SYMMETRIC };
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const PadMode& type);

/// \brief Fill modes for the `SegmentMax` operator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is specific for SegmentMax op only, then it should be placed in the op dedicated namespace and file.
Otherwise generalize the comment.

Copy link
Contributor

@mitruska mitruska Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a chance to extend it and reuse it with other ops in the future like SegmentMin

Suggested change
/// \brief Fill modes for the `SegmentMax` operator.
/// \brief Fill modes to set default value for operators like `SegmentMax`.

But if it's preferred to use a separate enums for such ops, it should be inside the SegmentMax class/namespace/file.

Comment on lines +24 to +25
const size_t inner_dim_size =
std::accumulate(data_shape.begin() + 1, data_shape.end(), 1, std::multiplies<size_t>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const size_t inner_dim_size =
std::accumulate(data_shape.begin() + 1, data_shape.end(), 1, std::multiplies<size_t>());
const auto inner_dim_size = shape_size(data_shape.begin() +1, data_shape.end());

Comment on lines +26 to +27
std::vector<std::vector<T>> max_values(num_segments,
std::vector<T>(inner_dim_size, std::numeric_limits<T>::lowest()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be input data copy avoided and set max values in the result tensor instead?

Copy link
Contributor

@mitruska mitruska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising. Let's merge the PR with op class first.

Comment on lines +16 to +19
template <typename T, typename T_idx>
void segment_max(const T* data,
const Shape& data_shape,
const T_idx* segment_ids,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid additional type specialization for int32 and int64 (in favour of smaller binary size) there is a common approach to upcast the i32 to i64, and use only i64 in the ref instead of T_idx.
But as this reference implementation is not used in the evaluate from the op class, it's not crucial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings category: CPU OpenVINO CPU plugin category: IE Tests OpenVINO Test: plugins and common category: TEMPLATE OpenVINO Template plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants