result.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 <memory>
20 
21 #include "ngraph/op/op.hpp"
22 
23 namespace ngraph
24 {
25  namespace op
26  {
27  namespace v0
28  {
29  class NGRAPH_API Result : public Op
30  {
31  public:
32  static constexpr NodeTypeInfo type_info{"Result", 0};
33  const NodeTypeInfo& get_type_info() const override { return type_info; }
34  /// \brief Allows a value to be used as a function result.
35  Result() = default;
36  /// \brief Allows a value to be used as a function result.
37  ///
38  /// \param arg Node that produces the input tensor.
39  Result(const Output<Node>& arg, bool needs_default_layout = false);
40 
41  bool visit_attributes(AttributeVisitor& visitor) override;
42  void validate_and_infer_types() override;
43 
44  virtual std::shared_ptr<Node>
45  clone_with_new_inputs(const OutputVector& new_args) const override;
46 
47  void set_needs_default_layout(bool val) { m_needs_default_layout = val; }
48  bool needs_default_layout() const { return m_needs_default_layout; }
49  bool evaluate(const HostTensorVector& outputs,
50  const HostTensorVector& inputs) const override;
51  bool constant_fold(OutputVector& output_values,
52  const OutputVector& inputs_values) override;
53 
54  private:
55  bool m_needs_default_layout{false};
56  };
57  }
58 
59  using v0::Result;
60  }
61  using ResultVector = std::vector<std::shared_ptr<op::Result>>;
62 
63  template <>
64  class NGRAPH_API AttributeAdapter<ResultVector> : public VisitorAdapter
65  {
66  public:
67  AttributeAdapter(ResultVector& ref);
68 
69  bool visit_attributes(AttributeVisitor& visitor) override;
70 
71  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<ResultVector>", 0};
72  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
73  protected:
74  ResultVector& m_ref;
75  };
76 }
const DiscreteTypeInfo & get_type_info() const override
type info enables identification of the value accessor, as well as is_type and as_type.
Definition: result.hpp:72
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
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Adapters will see visitor.
Definition: attribute_adapter.hpp:194
Root of all actual ops.
Definition: op.hpp:29
Definition: result.hpp:30
Result(const Output< Node > &arg, bool needs_default_layout=false)
Allows a value to be used as a function result.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
Result()=default
Allows a value to be used as a function result.
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
const NodeTypeInfo & get_type_info() const override
Definition: result.hpp:33
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39