output.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <unordered_set>
11 #include <vector>
12 
13 #include "ngraph/descriptor/input.hpp"
14 #include "ngraph/descriptor/tensor.hpp"
15 #include "ngraph/node_output.hpp"
16 
17 namespace ngraph
18 {
19  // The forward declaration of Node is needed here because Node has a deque of
20  // Outputs, and Output is an incomplete type at this point. STL containers of
21  // incomplete type have undefined behavior according to the C++11 standard, and
22  // in practice including node.hpp here was causing compilation errors on some
23  // systems (namely macOS).
24  class Node;
25 
26  class Variant;
27 
28  namespace descriptor
29  {
30  // Describes an output tensor of an op
31  class NGRAPH_API Output
32  {
33  public:
34  Output()
35  : m_node(nullptr)
36  , m_index(0)
37  , m_tensor(nullptr)
38  , m_inputs()
39  {
40  }
41 
42  /// \param node Node that owns this output.
43  /// \param index Position of the output tensor in all output tensors
44  /// \param tensor The tensor where the value will be written
45  Output(Node* node, size_t index, const std::shared_ptr<Tensor>& tensor);
46 
47  std::shared_ptr<Node> get_node() const;
48  size_t get_index() const { return m_index; }
49  ngraph::Output<Node> get_output() const;
50  std::shared_ptr<Tensor> get_tensor_ptr() const { return m_tensor; }
51  void set_tensor_ptr(const std::shared_ptr<Tensor>& tensor) { m_tensor = tensor; }
52  void add_input(Input* input);
53  void remove_input(Input* input);
54  const std::vector<Input*>& get_inputs() const { return m_inputs; }
55  Tensor& get_tensor() const;
56 
57  using RTMap = std::map<std::string, std::shared_ptr<Variant>>;
58 
59  RTMap& get_rt_info() { return m_rt_info; }
60  const RTMap& get_rt_info() const { return m_rt_info; }
61  /// \return the shape of the output
62  const Shape& get_shape() const;
63 
64  /// \return the partial shape of the output
66 
67  /// \return the element type of the output
69 
70  Output(const Output&) = default;
71  Output(Output&&) = default;
72  Output& operator=(const Output&) = default;
73 
74  protected:
75  Node* m_node;
76  size_t m_index;
77  std::shared_ptr<Tensor> m_tensor;
78  RTMap m_rt_info;
79  std::vector<Input*> m_inputs;
80  };
81  } // namespace descriptor
82 } // namespace ngraph
Definition: node.hpp:127
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:34
Shape for a tensor.
Definition: shape.hpp:19
Definition: output.hpp:32
Output(Node *node, size_t index, const std::shared_ptr< Tensor > &tensor)
const PartialShape & get_partial_shape() const
const Shape & get_shape() const
const element::Type & get_element_type() const
Definition: element_type.hpp:51
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16