registry.cc 1.8 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Z
zhupengyang 已提交
15
#include "lite/kernels/npu/bridges/registry.h"
Y
Yan Chunwei 已提交
16 17 18 19
#include <utility>

namespace paddle {
namespace lite {
20
namespace subgraph {
Y
Yan Chunwei 已提交
21

22 23 24
Registry& Registry::Instance() {
  static Registry x;
  return x;
Y
Yan Chunwei 已提交
25 26
}

27
void Registry::Insert(const std::string& op_type,
28
                      const TargetType& target,
29
                      const cvt_func_type& cvt_func_name) {
30 31
  int key = static_cast<int>(target);
  auto it = map_.find(key);
32
  if (it == map_.end()) {
33
    map_.insert(std::make_pair(key, std::map<std::string, cvt_func_type>()));
34
  }
35
  map_.at(key).insert(std::make_pair(op_type, cvt_func_name));
Y
Yan Chunwei 已提交
36 37
}

38
const cvt_func_type& Registry::Select(const std::string& op_type,
39 40 41
                                      const TargetType& target) const {
  int key = static_cast<int>(target);
  return map_.at(key).at(op_type);
Y
Yan Chunwei 已提交
42 43
}

44
bool Registry::Exists(const std::string& op_type,
45 46 47
                      const TargetType& target) const {
  int key = static_cast<int>(target);
  bool found = map_.find(key) != map_.end();
48
  if (found) {
49
    found = map_.at(static_cast<int>(key)).find(op_type) != map_.at(key).end();
50 51 52 53 54
  }
  return found;
}

}  // namespace subgraph
Y
Yan Chunwei 已提交
55 56
}  // namespace lite
}  // namespace paddle