parameter.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 
21 namespace ngraph
22 {
23  class Function;
24  namespace op
25  {
26  namespace v0
27  {
28  /// \brief A function parameter.
29  ///
30  /// Parameters are nodes that represent the arguments that will be passed to
31  /// user-defined functions. Function creation requires a sequence of parameters.
32  /// Basic graph operations do not need parameters attached to a function.
33  class NGRAPH_API Parameter : public op::Op
34  {
35  public:
36  static constexpr NodeTypeInfo type_info{"Parameter", 0};
37  const NodeTypeInfo& get_type_info() const override { return type_info; }
38  /// \brief Constructions a tensor-typed parameter node.
39  Parameter() = default;
40  /// \brief Constructions a tensor-typed parameter node.
41  ///
42  /// \param element_type The element type of the parameter.
43  /// \param pshape The partial shape of the parameter.
44  Parameter(const ngraph::element::Type& element_type, const PartialShape& pshape);
45 
46  bool visit_attributes(AttributeVisitor& visitor) override;
47 
48  void validate_and_infer_types() override;
49 
50  virtual std::shared_ptr<Node>
51  clone_with_new_inputs(const OutputVector& new_args) const override;
52 
53  bool is_relevant_to_shapes() const;
54  void set_is_relevant_to_shapes(bool is_relevant);
55 
56  const PartialShape& get_partial_shape() const { return m_partial_shape; }
57  PartialShape& get_partial_shape() { return m_partial_shape; }
58  void set_partial_shape(const PartialShape& partial_shape)
59  {
60  m_partial_shape = partial_shape;
61  }
62  const element::Type& get_element_type() const { return m_element_type; }
63  void set_element_type(const element::Type& element_type)
64  {
65  m_element_type = element_type;
66  }
67 
68  protected:
69  PartialShape m_partial_shape;
70  element::Type m_element_type;
71  bool m_is_relevant_to_shapes;
72  };
73  }
74  using v0::Parameter;
75  }
76  using ParameterVector = std::vector<std::shared_ptr<op::Parameter>>;
77 
78  template <>
79  class NGRAPH_API AttributeAdapter<ParameterVector> : public VisitorAdapter
80  {
81  public:
82  AttributeAdapter(ParameterVector& ref);
83 
84  bool visit_attributes(AttributeVisitor& visitor) override;
85 
86  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<ParameterVector>", 0};
87  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
88  protected:
89  ParameterVector& m_ref;
90  };
91 }
const DiscreteTypeInfo & get_type_info() const override
type info enables identification of the value accessor, as well as is_type and as_type.
Definition: parameter.hpp:87
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:171
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
Adapters will see visitor.
Definition: attribute_adapter.hpp:194
Definition: element_type.hpp:61
Root of all actual ops.
Definition: op.hpp:29
A function parameter.
Definition: parameter.hpp:34
Parameter()=default
Constructions a tensor-typed parameter node.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
Parameter(const ngraph::element::Type &element_type, const PartialShape &pshape)
Constructions a tensor-typed parameter node.
const NodeTypeInfo & get_type_info() const override
Definition: parameter.hpp:37
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39