[core]Shape and Node util functions size optimization (#20206)
* Refactor shape_size util to reduce bin size * Make `check_new_args_count` non-template function * Use as not template check_new_args_count in multi-nominal
This commit is contained in:
parent
387bfdebef
commit
e8d80f9b0d
@ -554,21 +554,17 @@ OPENVINO_API void NodeValidationFailure::create(const CheckLocInfo& check_loc_in
|
||||
NODE_VALIDATION_CHECK(std::make_pair(static_cast<const ::ov::Node*>((node)), &(input_shapes)), __VA_ARGS__)
|
||||
|
||||
namespace ov {
|
||||
template <typename T>
|
||||
void check_new_args_count(const Node* node, T new_args) {
|
||||
NODE_VALIDATION_CHECK(node,
|
||||
new_args.size() == node->input_values().size(),
|
||||
"clone_with_new_inputs() expected ",
|
||||
node->input_values().size(),
|
||||
" argument",
|
||||
(node->input_values().size() == 1 ? "" : "s"),
|
||||
" but got ",
|
||||
new_args.size());
|
||||
}
|
||||
|
||||
} // namespace ov
|
||||
/**
|
||||
* @brief Check new arguments size if match node inputs count.
|
||||
*
|
||||
* This check is required in cloning ov::Node.
|
||||
*
|
||||
* @param node Pointer to node.
|
||||
* @param new_args Vector with new outputs to check.
|
||||
*/
|
||||
void OPENVINO_API check_new_args_count(const Node* const node, const OutputVector& new_args);
|
||||
|
||||
namespace ov {
|
||||
/// \brief Visits a reference to a node that has been registered with the visitor.
|
||||
template <>
|
||||
class OPENVINO_API AttributeAdapter<std::shared_ptr<ov::Node>> : public VisitorAdapter {
|
||||
|
@ -42,19 +42,6 @@ public:
|
||||
OPENVINO_API std::string to_string() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Number of elements in spanned by a shape
|
||||
* @ingroup ov_model_cpp_api
|
||||
*/
|
||||
template <typename SHAPE_TYPE>
|
||||
size_t shape_size(const SHAPE_TYPE& shape) {
|
||||
size_t size = 1;
|
||||
for (auto d : shape) {
|
||||
size *= d;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of elements in a subset of dimensions of a shape.
|
||||
* Returns a product of dimensions in a range [start_dim;end_dim)
|
||||
@ -72,6 +59,15 @@ size_t shape_size(ForwardIt start_dim, const ForwardIt end_dim) {
|
||||
std::multiplies<typename std::iterator_traits<ForwardIt>::value_type>());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Number of elements in spanned by a shape
|
||||
* @ingroup ov_model_cpp_api
|
||||
*/
|
||||
template <typename SHAPE_TYPE>
|
||||
size_t shape_size(const SHAPE_TYPE& shape) {
|
||||
return shape_size(shape.begin(), shape.end());
|
||||
}
|
||||
|
||||
/// Row-major strides for a shape
|
||||
template <typename SHAPE_TYPE>
|
||||
std::vector<size_t> row_major_strides(const SHAPE_TYPE& shape) {
|
||||
|
@ -844,6 +844,17 @@ bool ov::Node::visit_attributes(AttributeVisitor&) {
|
||||
}
|
||||
|
||||
namespace ov {
|
||||
void check_new_args_count(const Node* const node, const OutputVector& new_args) {
|
||||
NODE_VALIDATION_CHECK(node,
|
||||
new_args.size() == node->input_values().size(),
|
||||
"clone_with_new_inputs() expected ",
|
||||
node->input_values().size(),
|
||||
" argument",
|
||||
(node->input_values().size() == 1 ? "" : "s"),
|
||||
" but got ",
|
||||
new_args.size());
|
||||
}
|
||||
|
||||
AttributeAdapter<std::shared_ptr<Node>>::AttributeAdapter(std::shared_ptr<Node>& value) : m_ref(value) {}
|
||||
|
||||
bool AttributeAdapter<std::shared_ptr<Node>>::visit_attributes(AttributeVisitor& visitor) {
|
||||
|
@ -6,11 +6,9 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "bound_evaluate.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "multinomial_shape_inference.hpp"
|
||||
#include "openvino/core/attribute_visitor.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/util/op_types.hpp"
|
||||
#include "openvino/reference/multinomial.hpp"
|
||||
|
||||
@ -60,7 +58,7 @@ void op::v13::Multinomial::validate_and_infer_types() {
|
||||
|
||||
std::shared_ptr<Node> op::v13::Multinomial::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
OV_OP_SCOPE(v13_Multinomial_clone_with_new_inputs);
|
||||
check_new_args_count<OutputVector>(this, new_args);
|
||||
check_new_args_count(this, new_args);
|
||||
|
||||
return std::make_shared<op::v13::Multinomial>(new_args.at(0),
|
||||
new_args.at(1),
|
||||
|
Loading…
Reference in New Issue
Block a user