result.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 
9 #include "ngraph/op/op.hpp"
10 
11 namespace ngraph
12 {
13  namespace op
14  {
15  namespace v0
16  {
17  class NGRAPH_API Result : public Op
18  {
19  public:
20  NGRAPH_RTTI_DECLARATION;
21 
22  /// \brief Allows a value to be used as a function result.
23  Result() = default;
24  /// \brief Allows a value to be used as a function result.
25  ///
26  /// \param arg Node that produces the input tensor.
27  Result(const Output<Node>& arg, bool needs_default_layout = false);
28 
29  bool visit_attributes(AttributeVisitor& visitor) override;
30  void validate_and_infer_types() override;
31 
32  virtual std::shared_ptr<Node>
33  clone_with_new_inputs(const OutputVector& new_args) const override;
34 
35  void set_needs_default_layout(bool val) { m_needs_default_layout = val; }
36  bool needs_default_layout() const { return m_needs_default_layout; }
37  bool evaluate(const HostTensorVector& outputs,
38  const HostTensorVector& inputs) const override;
39  bool has_evaluate() const override;
40  bool constant_fold(OutputVector& output_values,
41  const OutputVector& inputs_values) override;
42 
43  private:
44  bool m_needs_default_layout{false};
45  };
46  } // namespace v0
47 
48  using v0::Result;
49  } // namespace op
50  using ResultVector = std::vector<std::shared_ptr<op::Result>>;
51 
52  template <>
53  class NGRAPH_API AttributeAdapter<ResultVector> : public VisitorAdapter
54  {
55  public:
56  AttributeAdapter(ResultVector& ref);
57 
58  bool visit_attributes(AttributeVisitor& visitor) override;
59 
60  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<ResultVector>", 0};
61  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
62 
63  protected:
64  ResultVector& m_ref;
65  };
66 } // namespace ngraph
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:61
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Adapters will see visitor.
Definition: attribute_adapter.hpp:185
Root of all actual ops.
Definition: op.hpp:17
Definition: result.hpp:18
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....
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
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.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27