op_annotations.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <vector>
8 
9 #include "ngraph/except.hpp"
10 #include "ngraph/ngraph_visibility.hpp"
11 
12 namespace ngraph
13 {
14  namespace op
15  {
16  namespace util
17  {
18  struct oi_pair
19  {
20  size_t output;
21  size_t input;
22  bool destructive;
23  };
24 
25  /// \brief Base class for annotations added to graph ops
26  class NGRAPH_API OpAnnotations
27  {
28  public:
29  virtual ~OpAnnotations() = default;
30 
31  void add_in_place_oi_pair(const struct oi_pair& oi)
32  {
33  for (auto e : m_in_place_oi_pairs)
34  {
35  if (e.input == oi.input || e.output == oi.output)
36  {
37  throw ngraph_error("In_place hint conflicts with an existing entry");
38  }
39  }
40  m_in_place_oi_pairs.emplace_back(oi);
41  }
42 
43  const std::vector<struct oi_pair>& get_in_place_oi_pairs() const
44  {
45  return m_in_place_oi_pairs;
46  }
47  bool is_cacheable() const { return m_cacheable; }
48  void set_cacheable(bool val) { m_cacheable = val; }
49 
50  private:
51  // map of output-input pairs for which in-place computation is valid
52  std::vector<struct oi_pair> m_in_place_oi_pairs;
53 
54  bool m_cacheable = false;
55  };
56  } // namespace util
57  } // namespace op
58 } // namespace ngraph
Base error for ngraph runtime errors.
Definition: except.hpp:16
Base class for annotations added to graph ops.
Definition: op_annotations.hpp:27
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: op_annotations.hpp:19