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

[Don't Review]Result tensor descriptor #26928

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
da0a322
Use pimpl in Tensor descriptor to hide implementation details from pu…
praasz Aug 7, 2024
9c3bf87
Use descriptor iface in ReverseShapeAndTypeInfer to update shapes
praasz Aug 7, 2024
6e50ee3
Don't use deprecated ctor for descriptor
praasz Aug 7, 2024
f53efb8
Export `TensorExtension::Hasher` and `TensorExtension::Equal`
praasz Aug 7, 2024
0a495a5
Update preprocess build of OutputInfo
praasz Aug 9, 2024
2b8d426
Fix preserve rt_info for Result
praasz Aug 9, 2024
e166772
Fix mo API tensor names test
praasz Aug 9, 2024
0c397ab
Update tensor descriptor compare in stateful to stateless tests
praasz Aug 19, 2024
bbdac8d
Update PPP output info dump
praasz Aug 20, 2024
2dd83db
Update check output name in mo_convert tests
praasz Aug 21, 2024
6035c91
Correct add tensor names to Result
praasz Aug 21, 2024
0c31ebe
Test use only Result names if exists
praasz Aug 22, 2024
f629e83
Update set result tensor names for v10
praasz Aug 23, 2024
76d58b1
Result tensor uses shared tensor names
praasz Aug 23, 2024
27cc72b
Use pimpl in Tensor descriptor to hide implementation details from pu…
praasz Aug 7, 2024
67dd4dc
Use descriptor iface in ReverseShapeAndTypeInfer to update shapes
praasz Aug 7, 2024
deb697d
Don't use deprecated ctor for descriptor
praasz Aug 7, 2024
0901acf
Export `TensorExtension::Hasher` and `TensorExtension::Equal`
praasz Aug 7, 2024
82f7fc2
Update preprocess build of OutputInfo
praasz Aug 9, 2024
5f20ff1
Fix preserve rt_info for Result
praasz Aug 9, 2024
af23baf
Fix mo API tensor names test
praasz Aug 9, 2024
7f7b335
Update tensor descriptor compare in stateful to stateless tests
praasz Aug 19, 2024
322170a
Update PPP output info dump
praasz Aug 20, 2024
50f3675
Update check output name in mo_convert tests
praasz Aug 21, 2024
0dde418
Correct add tensor names to Result
praasz Aug 21, 2024
3ba9369
Test use only Result names if exists
praasz Aug 22, 2024
1f876d6
Update set result tensor names for v10
praasz Aug 23, 2024
1b7eedf
Result tensor uses shared tensor names
praasz Aug 23, 2024
fa53642
Merge branch 'master' into feature/specific-tensor-descriptor-for-res…
praasz Sep 11, 2024
d8e3592
Merge branch 'feature/specific-tensor-descriptor-for-results' of gith…
praasz Sep 11, 2024
fa8c5a9
Move shared tensro descriptor to separate file
praasz Sep 13, 2024
2fcb0a9
Add missing includes
praasz Sep 13, 2024
b7e0d13
Update compare result tensor for stateful to stateless transformation…
praasz Sep 16, 2024
0b2e37b
Merge branch 'master' into feature/specific-tensor-descriptor-for-res…
praasz Sep 17, 2024
b004cf9
When Result tensor set will hide names from Result's input
praasz Sep 17, 2024
196c848
Add doxy comments
praasz Sep 17, 2024
c08d827
Apply review comments
praasz Oct 3, 2024
d8134e1
Test full result tensor name split
praasz Oct 7, 2024
eb3ced1
Update serialization
praasz Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

82 changes: 81 additions & 1 deletion src/core/dev_api/openvino/core/descriptor_tensor.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once

#include "openvino/core/descriptor/tensor.hpp"
#include <memory>
#include <unordered_set>

#include "openvino/core/partial_shape.hpp"
#include "openvino/core/type/element_type.hpp"

namespace ov {
namespace descriptor {

class Tensor;
class Input;
class Output;

// To change Tensor element type please change the Parameter type.
OPENVINO_API
void set_element_type(Tensor& tensor, const element::Type& elemenet_type);
Expand All @@ -15,6 +24,15 @@ void set_element_type(Tensor& tensor, const element::Type& elemenet_type);
OPENVINO_API
void set_tensor_type(Tensor& tensor, const element::Type& element_type, const PartialShape& pshape);

/**
* @brief Set destination tensor names as copy of all names from source tensor all tensor names.
*
* @param dst The tensor descriptor to set names.
* @param src The tensor descriptor as from which names will be copied.
*/
OPENVINO_API
void copy_tensor_names(Tensor& dst, const Tensor& src);

OPENVINO_DEPRECATED("get_ov_tensor_legacy_name() is deprecated. Please don't use this function.")
OPENVINO_API
std::string get_ov_tensor_legacy_name(const Tensor& tensor);
Expand All @@ -23,5 +41,67 @@ OPENVINO_DEPRECATED("set_ov_tensor_legacy_name() is deprecated. Please don't use
OPENVINO_API
void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name);

/** @brief Tensor descriptor interface. */
class OPENVINO_API ITensorDescriptor {
public:
virtual const element::Type& get_element_type() const = 0;
virtual const PartialShape& get_partial_shape() const = 0;
virtual const Shape& get_shape() const = 0;
virtual void set_type_shape(const element::Type& et, const PartialShape& shape) = 0;

virtual void set_names(const std::unordered_set<std::string>& names) = 0;
virtual void add_names(const std::unordered_set<std::string>& names) = 0;
virtual const std::unordered_set<std::string>& get_names() const = 0;
virtual const std::string& get_any_name() const = 0;
virtual void copy_names_to(Tensor& dst) const = 0;

virtual RTMap& rt_map() = 0;
virtual const RTMap& rt_map() const = 0;

// Legacy name compatibility API
OPENVINO_DEPRECATED("The legacy_name() is deprecated. Please don't use it")
virtual std::string& legacy_name() = 0;
OPENVINO_DEPRECATED("The legacy_name() is deprecated. Please don't use it")
virtual const std::string& legacy_name() const = 0;

virtual size_t pointer_hash() const noexcept = 0;

protected:
virtual ~ITensorDescriptor();
};

/** @brief The TensorExtension defines developer API for ov::descriptor::Tensor. */
struct OPENVINO_API TensorExtension {
/**
* @brief Get the tensor descriptor object
*
* @param tensor Tensor descriptor to access its implementation.
* @return Reference to Tensor description implementation.
*/
static const ITensorDescriptor& get_descriptor(const Tensor& tensor);
static std::shared_ptr<ITensorDescriptor>& get_descriptor_ptr(Tensor& tensor);

/**
* @brief The hasher of shared pointer Tensor descriptor.
*/
struct OPENVINO_API Hasher {
size_t operator()(const std::shared_ptr<Tensor>& tensor) const;
};

/**
* @brief The comparator of shared pointer Tensor descriptor.
*/
struct OPENVINO_API Equal {
bool operator()(const std::shared_ptr<Tensor>& lhs, const std::shared_ptr<Tensor>& rhs) const;
};
};

/**
* @brief Set input descriptor as shared tensor on output descriptor.
*
* @param output_descriptor Descriptor to set shared tensor.
* @param input_descriptor Input descriptor to set in output as shared tensor.
*/
OPENVINO_API void set_shared_tensor(Output& output_descriptor, const Input& input_descriptor);
} // namespace descriptor
} // namespace ov
13 changes: 1 addition & 12 deletions src/core/include/openvino/core/descriptor/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@

namespace ov {
class Node;
namespace op {
namespace v0 {
class Result;
} // namespace v0
} // namespace op

namespace descriptor {
class Output;

// Describes a tensor that is an input to an op, directly or indirectly via a tuple
class OPENVINO_API Input {
friend class ov::Node;
friend class ov::op::v0::Result;

public:
/// \param node The node that owns this input
Expand Down Expand Up @@ -111,12 +106,6 @@ class OPENVINO_API Input {
Input& operator=(const Input&) = default;

protected:
/// \return the tensor for the connected output
std::shared_ptr<const Tensor> get_tensor_ptr() const;

/// \return the tensor for the connected output
std::shared_ptr<Tensor> get_tensor_ptr();

// owner of an argument node (in lieu of m_arguments)
std::shared_ptr<Node> m_src_node;
Node* m_node; // The node we are an input for
Expand Down
104 changes: 54 additions & 50 deletions src/core/include/openvino/core/descriptor/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,103 +22,107 @@ namespace ov {
class Node;
/// \brief Alias for symbol tensor.
using TensorSymbol = std::vector<std::shared_ptr<Symbol>>;
/// \brief Alias for vector of symbol tensors.

/// \brief Alias for vector of symbol tensors.
using TensorSymbolVector = std::vector<TensorSymbol>;

namespace pass {
class ReverseShapeAndTypeInfer;
}
namespace descriptor {

class Tensor;
class ITensorDescriptor;

/// \brief Compile-time descriptor of a first-class value that is a tensor.
class OPENVINO_API Tensor {
public:
/// \brief Creates Tensor descriptor
/// \param element_type Element type
/// \param pshape Partial shape of tensor
/// \param names Tensor names (optional default empty).
Tensor(const element::Type& element_type,
const PartialShape& pshape,
const std::unordered_set<std::string>& names = {});

OPENVINO_DEPRECATED("This constructor is deprecated. Will be removed in 2026.0")
Tensor(const element::Type& element_type, const PartialShape& pshape, Node* node, size_t node_output_number);

Tensor(const Tensor&) = delete;
Tensor& operator=(const Tensor&) = delete;

/// \brief Gets any tensor name.
/// Throws if tensor has no names.
const std::string& get_any_name() const;

/// \brief Gets tensor names
const std::unordered_set<std::string>& get_names() const;

/// \brief Set new names.
/// \param names Names to set.
void set_names(const std::unordered_set<std::string>& names);

/// \brief Adds new names to tensor.
/// \param names new names to be added.
void add_names(const std::unordered_set<std::string>& names);

/// \brief sets lower bound value description
void set_lower_value(const ov::Tensor& value);

/// \brief sets upper bound value description
void set_upper_value(const ov::Tensor& value);

/// \brief sets value symbol description
void set_value_symbol(const TensorSymbol& value_symbol);

/// \brief unsets bound value descriptions
void invalidate_values();

const element::Type& get_element_type() const {
return m_element_type;
}
/// \brief Gets element type.
const element::Type& get_element_type() const;

/// \brief Gets shape.
/// Throw if Tensor's shape is not static.
const Shape& get_shape() const;
const PartialShape& get_partial_shape() const {
return m_partial_shape;
}

/// \brief Gets partial shape.
const PartialShape& get_partial_shape() const;

/// \brief gets lower bound value description
const ov::Tensor& get_lower_value() const {
return m_lower_value;
}
const ov::Tensor& get_lower_value() const;

/// \brief gets upper bound value description
const ov::Tensor& get_upper_value() const {
return m_upper_value;
}
const ov::Tensor& get_upper_value() const;

/// \brief gets symbol value description
TensorSymbol get_value_symbol() const {
return m_value_symbol;
}
TensorSymbol get_value_symbol() const;

/// \brief checks if lower and upper bound are set and point to the same Tensor
bool has_and_set_bound() const {
return m_upper_value && m_lower_value && m_upper_value.data() == m_lower_value.data();
}
bool has_and_set_bound() const;

/// \brief Get Tensor size in bytes.
/// \return Size in bytes.
size_t size() const;

RTMap& get_rt_info() {
return m_rt_info;
}
const RTMap& get_rt_info() const {
return m_rt_info;
}
/// \brief Gets runtime informations.
/// \return Runtime information map which can be modified.
RTMap& get_rt_info();

void clone_from(const Tensor& old);
/// \brief Gets runtime informations.
/// \return Read only runtime information map.
const RTMap& get_rt_info() const;

protected:
element::Type m_element_type;
/// \brief Clones Tensor from the other.
/// \param other Tensor used to clone its properties.
void clone_from(const Tensor& other);

PartialShape m_partial_shape;
protected:
ov::Tensor m_lower_value, m_upper_value;
TensorSymbol m_value_symbol;
std::string m_legacy_name;

std::unordered_set<std::string> m_names;
std::unordered_set<std::string>::const_iterator m_name_it;
RTMap m_rt_info;

friend OPENVINO_API std::string get_ov_tensor_legacy_name(const Tensor& tensor);
friend OPENVINO_API void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name);
friend OPENVINO_API void set_element_type(Tensor& tensor, const element::Type& elemenet_type);
friend OPENVINO_API void set_tensor_type(Tensor& tensor,
const element::Type& element_type,
const PartialShape& pshape);
friend class pass::ReverseShapeAndTypeInfer;
std::shared_ptr<ITensorDescriptor> m_impl;

private:
mutable std::atomic<bool> m_shape_changing{false};
mutable bool m_shape_changed{true};
mutable Shape m_shape;
// hidden extension API for Tensor descriptor
friend struct TensorExtension;
};

OPENVINO_API
std::ostream& operator<<(std::ostream&, const ov::descriptor::Tensor&);
} // namespace descriptor

} // namespace ov
7 changes: 7 additions & 0 deletions src/core/include/openvino/op/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace v0 {
/// \brief Result operation.
///
/// \ingroup ov_ops_cpp_api
///
/// The Result operator output is special output which share tensor with node connected to this node.
///
/// The Result's output names are visible as model outputs names.
/// When set/add Result's output tensor names they will treat as this result specific names which will be appended to
/// connect input tensor or transferred to new tensor connect Result to new input.
/// When Result has not specific names the names from connected input will be used.
class OPENVINO_API Result : public Op {
public:
OPENVINO_OP("Result", "opset1");
Expand Down
8 changes: 0 additions & 8 deletions src/core/src/descriptor/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ ov::descriptor::Tensor& ov::descriptor::Input::get_tensor() {
return m_output->get_tensor();
}

std::shared_ptr<const ov::descriptor::Tensor> ov::descriptor::Input::get_tensor_ptr() const {
return m_output->get_tensor_ptr();
}

std::shared_ptr<ov::descriptor::Tensor> ov::descriptor::Input::get_tensor_ptr() {
return m_output->get_tensor_ptr();
}

const ov::Shape& ov::descriptor::Input::get_shape() const {
return m_output->get_shape();
}
Expand Down
Loading
Loading