• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 Huawei Technologies Co., Ltd
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 #include "kernel/kernel_mod_cache.h"
18 
19 #include <vector>
20 #include <unordered_set>
21 
22 namespace mindspore {
23 namespace kernel {
GetInstance()24 KernelModCache &KernelModCache::GetInstance() {
25   static KernelModCache instance;
26   return instance;
27 }
28 
GetKernelMod(const std::string & key)29 KernelModPtr KernelModCache::GetKernelMod(const std::string &key) {
30   auto iter = kernel_mod_cache_.find(key);
31   if (iter != kernel_mod_cache_.end()) {
32     return iter->second;
33   }
34   return nullptr;
35 }
36 
GetKernelModKey(const std::string & op_name,const std::string & device_name,const std::vector<KernelTensor * > & inputs)37 std::string KernelModCache::GetKernelModKey(const std::string &op_name, const std::string &device_name,
38                                             const std::vector<KernelTensor *> &inputs) {
39   std::string key = op_name;
40   key += "_";
41   key += device_name;
42   for (const auto &input : inputs) {
43     key += "_";
44     key += std::to_string(input->dtype_id());
45   }
46   return key;
47 }
ClearAllCache()48 void KernelModCache::ClearAllCache() { kernel_mod_cache_.clear(); }
ClearOpCache(const std::string & key)49 void KernelModCache::ClearOpCache(const std::string &key) { (void)kernel_mod_cache_.erase(key); }
50 }  // namespace kernel
51 }  // namespace mindspore
52