• 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 #ifndef MINDSPORE_CCSRC_KERNEL_KERNEL_MOD_CACHE_H_
17 #define MINDSPORE_CCSRC_KERNEL_KERNEL_MOD_CACHE_H_
18 
19 #include <utility>
20 #include <vector>
21 #include <memory>
22 #include <map>
23 #include <string>
24 #include <unordered_map>
25 #include "kernel/kernel.h"
26 #include "include/backend/visible.h"
27 
28 namespace mindspore {
29 namespace kernel {
30 class BACKEND_EXPORT KernelModCache {
31  public:
32   static KernelModCache &GetInstance();
33 
34   std::string GetKernelModKey(const std::string &op_name, const std::string &device_name,
35                               const std::vector<KernelTensor *> &inputs);
36   KernelModPtr GetKernelMod(const std::string &key);
SetCache(const std::string & key,const KernelModPtr & kernel_mod)37   void SetCache(const std::string &key, const KernelModPtr &kernel_mod) { kernel_mod_cache_[key] = kernel_mod; }
38   void ClearAllCache();
39   void ClearOpCache(const std::string &key);
40 
41  private:
KernelModCache()42   KernelModCache() {}
43   ~KernelModCache() = default;
44   DISABLE_COPY_AND_ASSIGN(KernelModCache);
45   mindspore::HashMap<std::string, KernelModPtr> kernel_mod_cache_;
46 };
47 
48 }  // namespace kernel
49 }  // namespace mindspore
50 #endif  // MINDSPORE_CCSRC_KERNEL_KERNEL_MOD_CACHE_H_
51