read_value.hpp
1 //*****************************************************************************
2 // Copyright 2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/op/op.hpp"
20 #include "ngraph/op/util/variable.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v3
27  {
28  /// \brief ReadValue operation creates the variable with `variable_id` and returns value
29  /// of this variable.
30  class NGRAPH_API ReadValue : public Op
31  {
32  public:
33  static constexpr NodeTypeInfo type_info{"ReadValue", 3};
34  const NodeTypeInfo& get_type_info() const override { return type_info; }
35  ReadValue() = default;
36 
37  /// \brief Constructs a ReadValue operation.
38  ///
39  /// \param init_value Node that produces the input tensor.
40  /// \param variable_id identificator of the variable to create.
41  ReadValue(const Output<Node>& init_value, const std::string& variable_id);
42 
43  void validate_and_infer_types() override;
44 
45  std::shared_ptr<Node>
46  clone_with_new_inputs(const OutputVector& new_args) const override;
47 
48  bool visit_attributes(AttributeVisitor& visitor) override;
49 
50  std::string get_variable_id() { return m_variable_id; }
51  std::shared_ptr<ngraph::Variable> get_variable() { return m_variable; }
52  void set_variable_id(const std::string& variable_id)
53  {
54  m_variable_id = variable_id;
55  }
56  void set_variable(const std::shared_ptr<ngraph::Variable>& variable)
57  {
58  m_variable = variable;
59  }
60 
61  private:
62  std::string m_variable_id;
63  std::shared_ptr<ngraph::Variable> m_variable;
64  };
65  }
66  using v3::ReadValue;
67  }
68 }
ngraph::op::v3::ReadValue::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v3::ReadValue::ReadValue
ReadValue(const Output< Node > &init_value, const std::string &variable_id)
Constructs a ReadValue operation.
ngraph::op::v3::ReadValue
ReadValue operation creates the variable with variable_id and returns value of this variable.
Definition: read_value.hpp:31
ngraph::op::v3::ReadValue::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: read_value.hpp:34
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29