1 /**
2 * Copyright 2019 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 "backend/kernel_compiler/tbe/tbe_utils.h"
18
19 #include <dirent.h>
20 #include <string>
21 #include <map>
22 #include <set>
23 #include <list>
24 #include <functional>
25 #include <iostream>
26 #include <fstream>
27
28 #include "runtime/kernel.h"
29 #include "utils/utils.h"
30 #include "utils/ms_utils.h"
31 #include "utils/ms_context.h"
32 #include "ir/dtype/type.h"
33 #include "runtime/dev.h"
34 #include "runtime/device/ascend/lic_manager.h"
35 #include "backend/session/anf_runtime_algorithm.h"
36 #include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
37 #include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/tbe_json_creator.h"
38 #include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/single_tbe_json_creator.h"
39 #include "securec/include/securec.h"
40 #include "utils/json_operation_utils.h"
41 #include "mindspore/ccsrc/debug/common.h"
42
43 namespace mindspore {
44 namespace kernel {
45 namespace tbe {
46 constexpr auto kCceKernelMeta = "kernel_meta/";
47 constexpr auto kJsonSuffix = ".json";
48 constexpr auto kInfoSuffix = ".info";
49 constexpr auto kSOC_VERSION = "SOC_VERSION";
50 constexpr auto kBuildRes = "build_result";
51 constexpr auto kTUNE_BANK_PATH = "TUNE_BANK_PATH";
52 constexpr auto kTUNE_DUMP_PATH = "TUNE_DUMP_PATH";
53 constexpr auto kJRlTuneSwitch = "rl_tune_switch";
54 constexpr auto kJRlTuneList = "rl_tune_list";
55 constexpr auto kJOpTuneSwitch = "op_tune_switch";
56 constexpr auto kJOpTuneList = "op_tune_list";
57 constexpr auto kJPassList = "pass_list";
58 constexpr auto kRankID = "RANK_ID";
59 constexpr auto kCOMPILER_OP_LEVEL = "MS_COMPILER_OP_LEVEL";
60 constexpr auto kCOMPILER_CACHE_PATH = "MS_COMPILER_CACHE_PATH";
61
62 uintptr_t KernelManager::kernel_stub_gen_ = 0;
63 std::unordered_map<string, KernelMetaPtr> KernelManager::info_table_ = {};
64
GenLicInfo(nlohmann::json * lic_info_json)65 void TbeUtils::GenLicInfo(nlohmann::json *lic_info_json) {
66 MS_EXCEPTION_IF_NULL(lic_info_json);
67 (*lic_info_json)[kJRlTuneSwitch] = LicManager::GetInstance().GetRlTuneSwitch();
68 (*lic_info_json)[kJRlTuneList] = LicManager::GetInstance().GetRlTuneList();
69 (*lic_info_json)[kJOpTuneSwitch] = LicManager::GetInstance().GetOpTuneSwitch();
70 (*lic_info_json)[kJOpTuneList] = LicManager::GetInstance().GetOpTuneList();
71 (*lic_info_json)[kJPassList] = LicManager::GetInstance().GetPassSwitch();
72 }
73
GetBankPath()74 std::string TbeUtils::GetBankPath() {
75 // tune bank path
76 auto save_path = common::GetEnv(kTUNE_BANK_PATH);
77 char real_path[PATH_MAX] = {0};
78 if (!save_path.empty()) {
79 if (realpath(save_path.c_str(), real_path)) {
80 save_path = real_path;
81 return save_path;
82 }
83 MS_LOG(EXCEPTION) << "Invalid environment variable 'TUNE_BANK_PATH', the path is " << save_path
84 << ". Please check (1) whether the path exists, (2) whether the path has the access "
85 "permission, (3) whether the path is too long. ";
86 }
87 return "";
88 }
89
GetTuneDumpPath()90 std::string TbeUtils::GetTuneDumpPath() {
91 // tune dump path
92 auto save_path = common::GetEnv(kTUNE_DUMP_PATH);
93 char real_path[PATH_MAX] = {0};
94 if (!save_path.empty()) {
95 if (realpath(save_path.c_str(), real_path)) {
96 save_path = real_path;
97 return save_path;
98 }
99 MS_LOG(EXCEPTION) << "Invalid environment variable 'TUNE_DUMP_PATH', the path is " << save_path
100 << ". Please check (1) whether the path exists, (2) whether the path has the access "
101 "permission, (3) whether the path is too long. ";
102 }
103 return "";
104 }
105
GetOpDebugPath()106 std::string TbeUtils::GetOpDebugPath() {
107 static std::string debug_path = "";
108 if (debug_path != "") {
109 return debug_path;
110 }
111 auto old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
112 std::string config_path;
113 if (!Common::CommonFuncForConfigPath("./", common::GetEnv(kCOMPILER_CACHE_PATH), &config_path)) {
114 MS_LOG(EXCEPTION) << "Invalid environment variable 'MS_COMPILER_CACHE_PATH', the path is "
115 << common::GetEnv(kCOMPILER_CACHE_PATH)
116 << ". Please check (1) whether the path exists, (2) whether the path has the access "
117 "permission, (3) whether the path is too long. ";
118 }
119 if (config_path.empty()) {
120 MS_LOG(EXCEPTION) << "config path is empty.";
121 }
122 if (!old_build.empty()) {
123 if (config_path[config_path.length() - 1] == '/') {
124 debug_path = config_path;
125 } else {
126 debug_path = config_path + "/";
127 }
128 return debug_path;
129 } else {
130 std::string rank_id_str = common::GetEnv(kRankID);
131 if (rank_id_str.empty()) {
132 MS_LOG(DEBUG) << "Using the default value: 0";
133 rank_id_str = "0";
134 }
135 if (config_path[config_path.length() - 1] == '/') {
136 debug_path = config_path + "rank_" + rank_id_str + "/";
137 } else {
138 debug_path = config_path + "/" + "rank_" + rank_id_str + "/";
139 }
140 return debug_path;
141 }
142 }
143
GetOpDebugLevel()144 std::string GetOpDebugLevel() {
145 const std::set<std::string> exp = {"0", "1"};
146 std::string op_debug_level = "0";
147 auto env_level = common::GetEnv(kCOMPILER_OP_LEVEL);
148 if (!env_level.empty()) {
149 if (exp.find(env_level) == exp.end()) {
150 MS_LOG(WARNING) << "Invalid MS_COMPILER_OP_LEVEL env:" << env_level
151 << ", the value should be 0 or 1, now using the default value 0";
152 } else {
153 op_debug_level = env_level;
154 }
155 }
156 return op_debug_level;
157 }
158
GenSocInfo()159 nlohmann::json TbeUtils::GenSocInfo() {
160 static nlohmann::json soc_info_json;
161 if (!soc_info_json.empty()) {
162 return soc_info_json;
163 }
164 auto context_ptr = MsContext::GetInstance();
165 MS_EXCEPTION_IF_NULL(context_ptr);
166 std::list<int64_t> list;
167 soc_info_json["coreNum"] = "";
168 soc_info_json["coreType"] = "";
169 soc_info_json["op_impl_mode"] = "";
170 soc_info_json["vector_fp_ceiling"] = "";
171 soc_info_json["op_impl_mode_list"] = list;
172 soc_info_json["l2Mode"] = "2";
173 soc_info_json["l1Fusion"] = "false";
174 soc_info_json["l2Fusion"] = "false";
175 soc_info_json["op_bank_update"] = false;
176 soc_info_json["socVersion"] = GetSocVersion();
177 soc_info_json["offlineTune"] = CheckOfflineTune();
178 soc_info_json["op_debug_dir"] = GetOpDebugPath();
179 soc_info_json["op_debug_level"] = GetOpDebugLevel();
180 soc_info_json["autoTilingMode"] = context_ptr->get_param<std::string>(MS_CTX_TUNE_MODE);
181 soc_info_json["deviceId"] = std::to_string(context_ptr->get_param<uint32_t>(MS_CTX_DEVICE_ID));
182 std::string config_path;
183 if (!Common::CommonFuncForConfigPath("", common::GetEnv("OP_BANK_PATH"), &config_path)) {
184 MS_LOG(EXCEPTION) << "Invalid environment variable 'OP_BANK_PATH', the path is " << common::GetEnv("OP_BANK_PATH")
185 << ". Please check (1) whether the path exists, (2) whether the path has the access "
186 "permission, (3) whether the path is too long. ";
187 }
188 soc_info_json["op_bank_path"] = config_path;
189 if (!Common::CommonFuncForConfigPath("", common::GetEnv("MDL_BANK_PATH"), &config_path)) {
190 MS_LOG(EXCEPTION) << "Invalid environment variable 'MDL_BANK_PATH', the path is " << common::GetEnv("MDL_BANK_PATH")
191 << ". Please check (1) whether the path exists, (2) whether the path has the access "
192 "permission, (3) whether the path is too long. ";
193 }
194 soc_info_json["mdl_bank_path"] = config_path;
195 return soc_info_json;
196 }
197
SaveJsonInfo(const std::string & json_name,const std::string & info)198 void TbeUtils::SaveJsonInfo(const std::string &json_name, const std::string &info) {
199 auto config_path = TbeUtils::GetOpDebugPath();
200 std::string path = config_path + kCceKernelMeta + json_name + kInfoSuffix;
201 auto realpath = Common::CreatePrefixPath(path);
202 if (!realpath.has_value()) {
203 MS_LOG(WARNING) << "Get real path failed, invalid path: " << realpath.value();
204 return;
205 }
206 ChangeFileMode(realpath.value(), S_IWUSR);
207 std::ofstream file_write(realpath.value());
208 if (!file_write.is_open()) {
209 MS_LOG(WARNING) << "Create info file failed(" << realpath.value() << ").";
210 return;
211 }
212 file_write << info << std::endl;
213 file_write.close();
214 file_write.clear();
215 ChangeFileMode(realpath.value(), S_IRUSR);
216 }
217
LoadCache()218 void TbeUtils::LoadCache() {
219 static bool has_load = false;
220 if (!has_load) {
221 auto bin_map = KernelMeta::GetInstance();
222 auto config_path = TbeUtils::GetOpDebugPath();
223 auto path = config_path + kCceKernelMeta;
224 if (!bin_map->ReadIndex(path)) {
225 MS_LOG(INFO) << "Cache initialize failed[" << path << "]";
226 }
227 has_load = true;
228 }
229 }
230
SearchCache(const std::string & kernel_name,const bool is_akg)231 KernelPackPtr TbeUtils::SearchCache(const std::string &kernel_name, const bool is_akg) {
232 // search cache.
233 KernelMeta *bin_map = KernelMeta::GetInstance();
234 if (bin_map == nullptr) {
235 MS_LOG(INFO) << "kernel cache is invalid.";
236 return nullptr;
237 }
238 return bin_map->GetKernelPack(kernel_name, is_akg);
239 }
240
InsertCache(const std::string & kernel_name,const std::string & processor,const bool is_akg)241 KernelPackPtr TbeUtils::InsertCache(const std::string &kernel_name, const std::string &processor, const bool is_akg) {
242 MS_LOG(INFO) << "kernel name: " << kernel_name << ", processr:" << processor;
243 if (processor != kProcessorAiCore) {
244 MS_LOG(EXCEPTION) << "process type should be aicore, actually is: " << processor;
245 }
246 return SearchCache(kernel_name, is_akg);
247 }
248
BinaryRegister(const mindspore::kernel::FlexArray & kernel_buffer,void ** module,const string & magic,const bool dynamic_flag)249 int KernelManager::BinaryRegister(const mindspore::kernel::FlexArray &kernel_buffer, void **module, const string &magic,
250 const bool dynamic_flag) {
251 static std::map<string, uint32_t> magic_maps = {{"RT_DEV_BINARY_MAGIC_PLAIN", RT_DEV_BINARY_MAGIC_PLAIN},
252 {"RT_DEV_BINARY_MAGIC_PLAIN_AICPU", RT_DEV_BINARY_MAGIC_PLAIN_AICPU},
253 {"RT_DEV_BINARY_MAGIC_PLAIN_AIVEC", RT_DEV_BINARY_MAGIC_PLAIN_AIVEC},
254 {"RT_DEV_BINARY_MAGIC_ELF", RT_DEV_BINARY_MAGIC_ELF},
255 {"RT_DEV_BINARY_MAGIC_ELF_AICPU", RT_DEV_BINARY_MAGIC_ELF_AICPU},
256 {"RT_DEV_BINARY_MAGIC_ELF_AIVEC", RT_DEV_BINARY_MAGIC_ELF_AIVEC},
257 {"RT_DEV_BINARY_MAGIC_ELF_AICUBE", RT_DEV_BINARY_MAGIC_ELF_AICUBE}};
258 // object for device register.
259 rtDevBinary_t dev_bin;
260 dev_bin.data = kernel_buffer.contents;
261 auto iter = magic_maps.find(magic);
262 if (iter == magic_maps.end()) {
263 MS_LOG(INFO) << "Invalid magic number: " << magic;
264 return -1;
265 }
266 dev_bin.magic = iter->second;
267 dev_bin.length = kernel_buffer.len;
268 dev_bin.version = 0;
269 auto ret = dynamic_flag ? rtRegisterAllKernel(&dev_bin, module) : rtDevBinaryRegister(&dev_bin, module);
270 if (RT_ERROR_NONE != ret) {
271 MS_LOG(INFO) << "Call runtime rtDevBinaryRegister error.";
272 return -1;
273 }
274 return 0;
275 }
276
GenFuncStub(const mindspore::kernel::KernelPack & kernel_pack,bool force_reload,uint32_t * block_dim,const bool dynamic_flag,void ** handle,std::string * origin_key)277 uintptr_t KernelManager::GenFuncStub(const mindspore::kernel::KernelPack &kernel_pack, bool force_reload,
278 uint32_t *block_dim, const bool dynamic_flag, void **handle,
279 std::string *origin_key) {
280 MS_EXCEPTION_IF_NULL(block_dim);
281 auto kernel = kernel_pack.GetKernel();
282 if (kernel == nullptr) {
283 MS_LOG(EXCEPTION) << "Invalid kernel pack, json or kernel is nullptr.";
284 }
285 auto kernel_contents = kernel->contents;
286 if (kernel_contents == nullptr) {
287 MS_LOG(EXCEPTION) << "Invalid kernel context, json or kernel is nullptr.";
288 }
289 auto kernel_json_info = kernel_pack.kernel_json_info();
290
291 *block_dim = kernel_json_info.block_dim;
292 string func_name = kernel_json_info.kernel_name;
293 string magic = kernel_json_info.magic;
294
295 if (!force_reload) {
296 // use the cached object.
297 auto iter = info_table_.find(func_name);
298 if (iter != info_table_.end()) {
299 auto kernelmeta = iter->second;
300 *block_dim = kernelmeta->block_dim_;
301 if (!dynamic_flag) {
302 return kernelmeta->func_stub_;
303 }
304 }
305 }
306 void *module = nullptr;
307 if (BinaryRegister((*kernel_pack.GetKernel()), &module, magic, dynamic_flag) != 0) {
308 MS_LOG(INFO) << "Call runtime BinaryRegister error.";
309 if (module != nullptr) {
310 (void)rtDevBinaryUnRegister(module);
311 }
312 return 0;
313 }
314 if (dynamic_flag) {
315 *handle = module;
316 *origin_key = func_name;
317 return 1;
318 }
319 // to diff different funcs.
320 uintptr_t func_stub = ++kernel_stub_gen_;
321 if (RT_ERROR_NONE !=
322 rtFunctionRegister(module, reinterpret_cast<void *>(func_stub), func_name.c_str(), func_name.c_str(), 0)) {
323 MS_LOG(INFO) << "Call runtime rtFunctionRegister error.";
324 return 0;
325 }
326 // cache the registered kernelmeta.
327 info_table_[func_name] = std::make_shared<KernelMetaInfo>(KernelMetaInfo{func_stub, *block_dim});
328 return func_stub;
329 }
330
GetStubFuncName(const KernelPackPtr & kernel_pack)331 std::string KernelManager::GetStubFuncName(const KernelPackPtr &kernel_pack) {
332 MS_EXCEPTION_IF_NULL(kernel_pack);
333 auto kernel_json_info = kernel_pack->kernel_json_info();
334 return kernel_json_info.kernel_name;
335 }
336
GetInstance()337 KernelMeta *KernelMeta::GetInstance() {
338 static KernelMeta inst;
339 return &inst;
340 }
341
ReadIndex(const std::string & bin_dir)342 bool KernelMeta::ReadIndex(const std::string &bin_dir) {
343 DIR *dir = opendir(bin_dir.c_str());
344 if (dir == nullptr) {
345 auto ret = mkdir(bin_dir.c_str(), S_IRWXG | S_IRWXU);
346 if (ret != 0) {
347 MS_LOG(INFO) << "kernel dir: " << bin_dir << "not exist";
348 return false;
349 }
350 dir = opendir(bin_dir.c_str());
351 }
352 struct dirent *entry;
353 constexpr size_t SUFFIX_LENS = 5;
354 while ((entry = readdir(dir)) != nullptr) {
355 string bin_dir_tmp = bin_dir;
356 std::string cce_json = entry->d_name;
357 if (cce_json.length() <= SUFFIX_LENS) {
358 continue;
359 }
360 std::string suffix = cce_json.substr(cce_json.length() - SUFFIX_LENS);
361 if (suffix != kJsonSuffix) {
362 continue;
363 }
364 auto sp = cce_json.rfind('/');
365 if (sp != std::string::npos) {
366 continue;
367 }
368 sp = cce_json.rfind('.');
369 if (sp == std::string::npos) {
370 continue;
371 }
372 auto kernel_name = cce_json.substr(0, sp);
373 (void)bin_dir_tmp.append("/");
374 (void)bin_dir_tmp.append(cce_json);
375 kernel_index_map_[kernel_name] = bin_dir_tmp;
376 }
377 (void)closedir(dir);
378
379 return true;
380 }
381
GetCompileInfo(const AnfNodePtr & node,std::string * compile_info,bool * get_flag)382 void TbeUtils::GetCompileInfo(const AnfNodePtr &node, std::string *compile_info, bool *get_flag) {
383 MS_EXCEPTION_IF_NULL(node);
384 MS_LOG(INFO) << "Get compile info from json file start. [" << node->fullname_with_scope() << "]";
385 auto json_creator = std::make_shared<kernel::BuildTbeJsonCreator>();
386 MS_EXCEPTION_IF_NULL(json_creator);
387 nlohmann::json kernel_json;
388 if (!json_creator->GenJson(node, &kernel_json)) {
389 MS_LOG(WARNING) << "Gen kernel json failed [" << node->fullname_with_scope() << "]";
390 *get_flag = false;
391 return;
392 }
393 auto json_name = json_creator->GetJsonName();
394 auto config_path = TbeUtils::GetOpDebugPath();
395 std::string path = config_path + kCceKernelMeta + json_name + kJsonSuffix;
396 if (path.size() > PATH_MAX) {
397 MS_LOG(WARNING) << "File path: " << path << "is too long.";
398 *get_flag = false;
399 return;
400 }
401 nlohmann::json read_new_json;
402 std::ifstream file(path.c_str());
403 std::string ori_file = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
404 if (!ParseJson(ori_file, &read_new_json)) {
405 MS_LOG(EXCEPTION) << "Parse compile info error :" << ori_file;
406 }
407 auto build_res_str = GetJsonValue<std::string>(read_new_json, kBuildRes);
408 nlohmann::json build_res_json;
409 if (!ParseJson(build_res_str, &build_res_json)) {
410 MS_LOG(EXCEPTION) << "Parse build result for " << node->fullname_with_scope() << " error :" << build_res_str;
411 }
412 *compile_info = build_res_json.dump();
413 file.close();
414 file.clear();
415 MS_LOG(INFO) << "Get compile info from json file success :" << *compile_info;
416 }
417
SaveCompileInfo(const std::string & json_name,const std::string & build_res,bool * save_flag)418 void TbeUtils::SaveCompileInfo(const std::string &json_name, const std::string &build_res, bool *save_flag) {
419 MS_LOG(INFO) << "Save compile info to json file start. [" << json_name << "], value: " << build_res;
420 auto config_path = TbeUtils::GetOpDebugPath();
421 std::string path = config_path + kCceKernelMeta + json_name + kJsonSuffix;
422 if (path.size() > PATH_MAX) {
423 MS_LOG(WARNING) << "File path: " << path << "is too long.";
424 *save_flag = false;
425 return;
426 }
427 nlohmann::json save_new_json;
428 std::ifstream file(path.c_str());
429 std::string ori_file = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
430 if (!ParseJson(ori_file, &save_new_json)) {
431 MS_LOG(EXCEPTION) << "Parse compile info error.";
432 }
433 file.close();
434 file.clear();
435 save_new_json[kBuildRes] = build_res;
436 std::ofstream file_write;
437 file_write.open(path);
438 if (!file_write.is_open()) {
439 MS_LOG(WARNING) << "Create info file failed. [" << path << "]";
440 *save_flag = false;
441 return;
442 }
443 const int indent = 4;
444 auto info = save_new_json.dump(indent);
445 file_write << info << std::endl;
446 file_write.close();
447 file_write.clear();
448 MS_LOG(INFO) << "Save compile info to json file success";
449 }
450
CheckOfflineTune()451 bool TbeUtils::CheckOfflineTune() {
452 bool offline = false;
453 std::string offline_tune = common::GetEnv("ENABLE_TUNE_DUMP");
454 if (!offline_tune.empty()) {
455 for (size_t j = 0; j < offline_tune.length(); j++) {
456 offline_tune[j] = tolower(offline_tune[j]);
457 }
458 if (!(offline_tune == "true" || offline_tune == "false")) {
459 MS_LOG(ERROR) << "Invalid environment variable 'ENABLE_TUNE_DUMP', it should be 'true' or 'false', but got "
460 << offline_tune;
461 }
462 offline = (offline_tune == "true");
463 }
464 return offline;
465 }
466
GetSocVersion()467 std::string TbeUtils::GetSocVersion() {
468 // Get default soc version.
469 static std::string version;
470 if (version.empty()) {
471 const int kSocVersionLen = 50;
472 char soc_version[kSocVersionLen] = {0};
473 auto ret = rtGetSocVersion(soc_version, kSocVersionLen);
474 if (ret != RT_ERROR_NONE) {
475 MS_LOG(EXCEPTION) << "GetSocVersion failed.";
476 }
477 // Get soc version from env value.
478 const char *soc_version_env = nullptr;
479 std::string str_soc_version_env = common::GetEnv(kSOC_VERSION);
480 if (!str_soc_version_env.empty()) {
481 soc_version_env = common::SafeCStr(str_soc_version_env);
482 }
483 if (soc_version_env != nullptr) {
484 if (std::strcmp(soc_version, soc_version_env) != 0) {
485 MS_LOG(DEBUG) << "Detected the env SOC_VERSION, so the SocVersion will be changed to " << str_soc_version_env
486 << ".";
487 ret = rtSetSocVersion(soc_version_env);
488 if (ret != RT_ERROR_NONE) {
489 MS_LOG(EXCEPTION) << "SetSocVersion failed, errorno: " << ret;
490 }
491 version = soc_version_env;
492 return soc_version_env;
493 }
494 }
495 version = soc_version;
496 }
497 return version;
498 }
499
GetKernelPack(const std::string & kernel_name,const bool is_akg)500 KernelPackPtr KernelMeta::GetKernelPack(const std::string &kernel_name, const bool is_akg) {
501 KernelPackPtr ret = nullptr;
502 // 1. pack has been created
503 auto kernel_pack_iter = kernel_pack_map_.find(kernel_name);
504 if (kernel_pack_iter != kernel_pack_map_.end()) {
505 ret = kernel_pack_iter->second;
506 } else {
507 // 2. kernel file has been create, but pack does not been created.
508 auto config_path = TbeUtils::GetOpDebugPath();
509 std::string cce_json = is_akg ? ("./kernel_meta/" + kernel_name + kJsonSuffix)
510 : (config_path + kCceKernelMeta + kernel_name + kJsonSuffix);
511 ret = std::make_shared<KernelPack>();
512 if (!ret->LoadKernelMeta(cce_json)) {
513 MS_LOG(INFO) << "Read cache json and bin file failed[" << cce_json << "]";
514 return nullptr;
515 }
516 kernel_pack_map_[kernel_name] = ret;
517 auto iter = kernel_index_map_.find(kernel_name);
518 if (iter == kernel_index_map_.end()) {
519 MS_LOG(INFO) << "kernel name [" << kernel_name << "] has been created first.";
520 kernel_index_map_[kernel_name] = cce_json;
521 }
522 }
523 return ret;
524 }
525 } // namespace tbe
526 } // namespace kernel
527 } // namespace mindspore
528