tensor.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <memory>
8 #include <vector>
9 
10 #include "ngraph/descriptor/tensor.hpp"
11 #include "ngraph/shape.hpp"
12 #include "ngraph/strides.hpp"
13 #include "ngraph/type/element_type.hpp"
14 
15 namespace ngraph
16 {
17  namespace runtime
18  {
19  class NGRAPH_API Tensor
20  {
21  protected:
22  Tensor(const std::shared_ptr<ngraph::descriptor::Tensor>& descriptor)
23  : m_descriptor(descriptor)
24  , m_stale(true)
25  {
26  }
27 
28  public:
29  virtual ~Tensor() {}
30  Tensor& operator=(const Tensor&) = default;
31 
32  /// \brief Get tensor shape
33  /// \return const reference to a Shape
34  virtual const ngraph::Shape& get_shape() const;
35 
36  /// \brief Get tensor partial shape
37  /// \return const reference to a PartialShape
39 
40  /// \brief Get tensor element type
41  /// \return element::Type
42  virtual const element::Type& get_element_type() const;
43 
44  /// \brief Get number of elements in the tensor
45  /// \return number of elements in the tensor
46  virtual size_t get_element_count() const;
47 
48  /// \brief Get the size in bytes of the tensor
49  /// \return number of bytes in tensor's allocation
50  virtual size_t get_size_in_bytes() const;
51 
52  /// \brief Get tensor's unique name
53  /// \return tensor's name
54  NGRAPH_DEPRECATED("Only output ports have names")
55  const std::string& get_name() const;
56 
57  /// \brief Get the stale value of the tensor. A tensor is stale if its data is
58  /// changed.
59  /// \return true if there is new data in this tensor
60  NGRAPH_DEPRECATED("This method is deprecated and will be removed in 2022.1 release")
61  bool get_stale() const;
62 
63  /// \brief Set the stale value of the tensor. A tensor is stale if its data is
64  /// changed.
65  NGRAPH_DEPRECATED("This method is deprecated and will be removed in 2022.1 release")
66  void set_stale(bool val);
67 
68  /// \brief Write bytes directly into the tensor
69  /// \param p Pointer to source of data
70  /// \param n Number of bytes to write, must be integral number of elements.
71  virtual void write(const void* p, size_t n) = 0;
72 
73  /// \brief Read bytes directly from the tensor
74  /// \param p Pointer to destination for data
75  /// \param n Number of bytes to read, must be integral number of elements.
76  virtual void read(void* p, size_t n) const = 0;
77 
78  /// \brief check tensor for new data, call may block.
79  /// backends may use this to ensure tensor is updated (eg: lazy eval).
80  NGRAPH_DEPRECATED("This method is deprecated and will be removed in 2022.1 release")
81  virtual void wait_for_read_ready() {}
82  /// \brief notify tensor of new data, call may block.
83  /// backends may use this as indication of new data in tensor.
84  NGRAPH_DEPRECATED("This method is deprecated and will be removed in 2022.1 release")
85  virtual void wait_for_write_ready() {}
86 
87  protected:
88  std::shared_ptr<ngraph::descriptor::Tensor> m_descriptor;
89  bool m_stale;
90  };
91  } // namespace runtime
92 } // namespace ngraph
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: element_type.hpp:51
Definition: tensor.hpp:20
const ngraph::PartialShape & get_partial_shape() const
Get tensor partial shape.
virtual size_t get_size_in_bytes() const
Get the size in bytes of the tensor.
virtual const element::Type & get_element_type() const
Get tensor element type.
virtual size_t get_element_count() const
Get number of elements in the tensor.
virtual const ngraph::Shape & get_shape() const
Get tensor shape.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16