op_annotations.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 <vector>
20 
21 #include "ngraph/except.hpp"
22 #include "ngraph/ngraph_visibility.hpp"
23 
24 namespace ngraph
25 {
26  namespace op
27  {
28  namespace util
29  {
30  struct oi_pair
31  {
32  size_t output;
33  size_t input;
34  bool destructive;
35  };
36 
37  /// \brief Base class for annotations added to graph ops
38  class NGRAPH_API OpAnnotations
39  {
40  public:
41  virtual ~OpAnnotations() = default;
42 
43  void add_in_place_oi_pair(const struct oi_pair& oi)
44  {
45  for (auto e : m_in_place_oi_pairs)
46  {
47  if (e.input == oi.input || e.output == oi.output)
48  {
49  throw ngraph_error("In_place hint conflicts with an existing entry");
50  }
51  }
52  m_in_place_oi_pairs.emplace_back(oi);
53  }
54 
55  const std::vector<struct oi_pair>& get_in_place_oi_pairs() const
56  {
57  return m_in_place_oi_pairs;
58  }
59  bool is_cacheable() const { return m_cacheable; }
60  void set_cacheable(bool val) { m_cacheable = val; }
61  private:
62  // map of output-input pairs for which in-place computation is valid
63  std::vector<struct oi_pair> m_in_place_oi_pairs;
64 
65  bool m_cacheable = false;
66  };
67  }
68  }
69 }
Base error for ngraph runtime errors.
Definition: except.hpp:28
Base class for annotations added to graph ops.
Definition: op_annotations.hpp:39
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: op_annotations.hpp:31