已合并
fix: 根据当前架构动态设置UT中的路径和环境变量 #3710
Chang-an-HW创建于 6月25日
fix: 根据当前架构动态设置UT中的路径和环境变量 #3710
已合并
Chang-an-HW创建于 6月25日
2 个文件变更+41-24
@@ -362,14 +362,15 @@ void CreateBuiltInSplitAndUpgradedSo(std::vector<std::string> &paths) {
362 auto path_infos = CreateSceneInfo();362 auto path_infos = CreateSceneInfo();
363 auto opp_path = path_infos[1U];363 auto opp_path = path_infos[1U];
364 364 
365- std::string proto_path = opp_path + "built-in/op_proto/lib/linux/x86_64";365+ const std::string arch = GetCurArch();
366+ std::string proto_path = opp_path + "built-in/op_proto/lib/linux/" + arch;
366 system(("mkdir -p " + proto_path).c_str());367 system(("mkdir -p " + proto_path).c_str());
367 proto_path += "/a_rt.so";368 proto_path += "/a_rt.so";
368 paths.emplace_back(proto_path);369 paths.emplace_back(proto_path);
369 system(("touch " + proto_path).c_str());370 system(("touch " + proto_path).c_str());
370 system(("echo 'ops proto 123' > " + proto_path).c_str());371 system(("echo 'ops proto 123' > " + proto_path).c_str());
371 372 
372- std::string tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64";373+ std::string tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/" + arch;
373 system(("mkdir -p " + tiling_path).c_str());374 system(("mkdir -p " + tiling_path).c_str());
374 tiling_path += "/b_rt.so";375 tiling_path += "/b_rt.so";
375 paths.emplace_back(tiling_path);376 paths.emplace_back(tiling_path);
@@ -387,29 +388,30 @@ void CreateBuiltInSplitAndUpgradedSo(std::vector<std::string> &paths) {
387void CreateBuiltInSubPkgSo(std::vector<std::string> &paths) {388void CreateBuiltInSubPkgSo(std::vector<std::string> &paths) {
388 auto path_infos = CreateSceneInfo();389 auto path_infos = CreateSceneInfo();
389 auto opp_path = path_infos[1U];390 auto opp_path = path_infos[1U];
391+ const std::string arch = GetCurArch();
390 392 
391- std::string proto_path = opp_path + "built-in/op_proto/lib/linux/x86_64";393+ std::string proto_path = opp_path + "built-in/op_proto/lib/linux/" + arch;
392 system(("mkdir -p " + proto_path).c_str());394 system(("mkdir -p " + proto_path).c_str());
393 proto_path += "/a_rt.so";395 proto_path += "/a_rt.so";
394 paths.emplace_back(proto_path);396 paths.emplace_back(proto_path);
395 system(("touch " + proto_path).c_str());397 system(("touch " + proto_path).c_str());
396 system(("echo 'ops proto 123' > " + proto_path).c_str());398 system(("echo 'ops proto 123' > " + proto_path).c_str());
397 399 
398- std::string tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64";400+ std::string tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/" + arch;
399 system(("mkdir -p " + tiling_path).c_str());401 system(("mkdir -p " + tiling_path).c_str());
400 tiling_path += "/b_rt.so";402 tiling_path += "/b_rt.so";
401 paths.emplace_back(tiling_path);403 paths.emplace_back(tiling_path);
402 system(("touch " + tiling_path).c_str());404 system(("touch " + tiling_path).c_str());
403 system(("echo 'op tiling 456' > " + tiling_path).c_str());405 system(("echo 'op tiling 456' > " + tiling_path).c_str());
404 406 
405- proto_path = opp_path + "built-in/op_graph/lib/linux/x86_64";407+ proto_path = opp_path + "built-in/op_graph/lib/linux/" + arch;
406 system(("mkdir -p " + proto_path).c_str());408 system(("mkdir -p " + proto_path).c_str());
407 proto_path += "/libopgraph_math.so";409 proto_path += "/libopgraph_math.so";
408 paths.emplace_back(proto_path);410 paths.emplace_back(proto_path);
409 system(("touch " + proto_path).c_str());411 system(("touch " + proto_path).c_str());
410 system(("echo 'ops proto 123' > " + proto_path).c_str());412 system(("echo 'ops proto 123' > " + proto_path).c_str());
411 413 
412- tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_host/lib/linux/x86_64";414+ tiling_path = opp_path + "built-in/op_impl/ai_core/tbe/op_host/lib/linux/" + arch;
413 system(("mkdir -p " + tiling_path).c_str());415 system(("mkdir -p " + tiling_path).c_str());
414 tiling_path += "/libophost_math.so";416 tiling_path += "/libophost_math.so";
415 paths.emplace_back(tiling_path);417 paths.emplace_back(tiling_path);
@@ -66,8 +66,15 @@ const char *const kEnvNameCustom = "ASCEND_CUSTOM_OPP_PATH";
66const string kOpsProto = "libopsproto_rt2.0.so";66const string kOpsProto = "libopsproto_rt2.0.so";
67const string kOpMaster = "libopmaster_rt2.0.so";67const string kOpMaster = "libopmaster_rt2.0.so";
68const string kInner = "built-in";68const string kInner = "built-in";
69-const string kOpsProtoPath = "/op_proto/lib/linux/x86_64/";69+std::string GetCurArch() {
70-const string kOpMasterPath = "/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64/";70+#if defined(__aarch64__) || defined(__arm64__)
71+ return "aarch64";
72+#else
73+ return "x86_64";
74+#endif
75+}
76+const string kOpsProtoPath = "/op_proto/lib/linux/" + GetCurArch() + "/";
77+const string kOpMasterPath = "/op_impl/ai_core/tbe/op_tiling/lib/linux/" + GetCurArch() + "/";
71 78 
72constexpr const char *kPortableOpTypeForModelHelper = "ModelHelperPortableOpForUt";79constexpr const char *kPortableOpTypeForModelHelper = "ModelHelperPortableOpForUt";
73constexpr const char *kPortableOpEmptyTypeForModelHelper = "ModelHelperPortableOpEmptyForUt";80constexpr const char *kPortableOpEmptyTypeForModelHelper = "ModelHelperPortableOpEmptyForUt";
@@ -662,7 +669,7 @@ static GeRootModelPtr ConstructGeRootModel(bool is_dynamic_shape = true,
662 ge_root_model->subgraph_instance_name_to_model_["graph"] = ge_model;669 ge_root_model->subgraph_instance_name_to_model_["graph"] = ge_model;
663 ge_model->SetGraph(graph);670 ge_model->SetGraph(graph);
664 (void)ge::AttrUtils::SetStr(ge_model, ATTR_MODEL_HOST_ENV_OS, "linux");671 (void)ge::AttrUtils::SetStr(ge_model, ATTR_MODEL_HOST_ENV_OS, "linux");
665- (void)ge::AttrUtils::SetStr(ge_model, ATTR_MODEL_HOST_ENV_CPU, "x86_64");672+ (void)ge::AttrUtils::SetStr(ge_model, ATTR_MODEL_HOST_ENV_CPU, GetCurArch());
666 673 
667 GeModelPtr ge_model1 = std::make_shared<GeModel>();674 GeModelPtr ge_model1 = std::make_shared<GeModel>();
668 ge::ComputeGraphPtr graph1 = std::make_shared<ge::ComputeGraph>("graph1");675 ge::ComputeGraphPtr graph1 = std::make_shared<ge::ComputeGraph>("graph1");
@@ -919,7 +926,7 @@ TEST_F(UtestModelHelper, CheckOsCpuInfoAndOppVersion)
919 model_helper.file_header_ = file_header;926 model_helper.file_header_ = file_header;
920 927 
921 std::string host_env_os = "linux";928 std::string host_env_os = "linux";
922- std::string host_env_cpu = "x86_64";929+ std::string host_env_cpu = GetCurArch();
923 model_helper.model_ = std::make_shared<GeModel>();930 model_helper.model_ = std::make_shared<GeModel>();
924 ge::AttrUtils::SetStr(*(model_helper.model_.get()), "host_env_os", host_env_os);931 ge::AttrUtils::SetStr(*(model_helper.model_.get()), "host_env_os", host_env_os);
925 ge::AttrUtils::SetStr(*(model_helper.model_.get()), "host_env_cpu", host_env_cpu);932 ge::AttrUtils::SetStr(*(model_helper.model_.get()), "host_env_cpu", host_env_cpu);
@@ -965,7 +972,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmRootModel)
965 system(("touch " + inner_tiling_path).c_str());972 system(("touch " + inner_tiling_path).c_str());
966 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());973 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
967 974 
968- string cpu_info = "x86_64";975+ string cpu_info = GetCurArch();
969 string os_info = "linux";976 string os_info = "linux";
970 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);977 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);
971 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);978 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);
@@ -981,7 +988,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmRootModel)
981 988 
982 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, is_unknown_shape), SUCCESS);989 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, is_unknown_shape), SUCCESS);
983 990 
984- output_file += "_linux_x86_64.om";991+ output_file += "_linux_" + GetCurArch() + ".om";
985 system(("rm -rf " + path_vendors).c_str());992 system(("rm -rf " + path_vendors).c_str());
986 system(("rm -rf " + output_file).c_str());993 system(("rm -rf " + output_file).c_str());
987 system(("rm -rf " + opp_path + kInner).c_str());994 system(("rm -rf " + opp_path + kInner).c_str());
@@ -1051,7 +1058,7 @@ TEST_F(UtestModelHelper, RepackSoToOm)
1051 system(("touch " + inner_tiling_path).c_str());1058 system(("touch " + inner_tiling_path).c_str());
1052 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());1059 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
1053 1060 
1054- string cpu_info = "x86_64";1061+ string cpu_info = GetCurArch();
1055 string os_info = "linux";1062 string os_info = "linux";
1056 std::map<std::string, std::string> options_map;1063 std::map<std::string, std::string> options_map;
1057 options_map["ge.host_env_os"] = os_info;1064 options_map["ge.host_env_os"] = os_info;
@@ -1073,7 +1080,7 @@ TEST_F(UtestModelHelper, RepackSoToOm)
1073 ModelBufferData buffer;1080 ModelBufferData buffer;
1074 ASSERT_EQ(model_helper.LoadRootModel(model_data), SUCCESS);1081 ASSERT_EQ(model_helper.LoadRootModel(model_data), SUCCESS);
1075 EXPECT_EQ(model_helper.PackSoToModelData(model_data, output_file, buffer), SUCCESS);1082 EXPECT_EQ(model_helper.PackSoToModelData(model_data, output_file, buffer), SUCCESS);
1076- system("rm -rf outputfile_linux_x86_64.om");1083+ system(("rm -rf outputfile_linux_" + GetCurArch() + ".om").c_str());
1077 }1084 }
1078 1085 
1079 {1086 {
@@ -1245,7 +1252,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmModel)
1245 system(("touch " + inner_tiling_path).c_str());1252 system(("touch " + inner_tiling_path).c_str());
1246 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());1253 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
1247 1254 
1248- string cpu_info = "x86_64";1255+ string cpu_info = GetCurArch();
1249 string os_info = "linux";1256 string os_info = "linux";
1250 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);1257 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);
1251 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);1258 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);
@@ -1262,7 +1269,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmModel)
1262 1269 
1263 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, is_unknown_shape), SUCCESS);1270 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, is_unknown_shape), SUCCESS);
1264 1271 
1265- output_file += "_linux_x86_64.om";1272+ output_file += "_linux_" + GetCurArch() + ".om";
1266 system(("rm -rf " + path_vendors).c_str());1273 system(("rm -rf " + path_vendors).c_str());
1267 system(("rm -rf " + inner_proto_path).c_str());1274 system(("rm -rf " + inner_proto_path).c_str());
1268 system(("rm -rf " + output_file).c_str());1275 system(("rm -rf " + output_file).c_str());
@@ -2321,7 +2328,7 @@ TEST_F(UtestModelHelper, GetBinDataSuccess) {
2321 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());2328 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
2322 2329 
2323 ModelHelper model_helper;2330 ModelHelper model_helper;
2324- string cpu_info = "x86_64";2331+ string cpu_info = GetCurArch();
2325 string os_info = "linux";2332 string os_info = "linux";
2326 auto ret = model_helper.GetSoBinData(cpu_info, os_info);2333 auto ret = model_helper.GetSoBinData(cpu_info, os_info);
2327 EXPECT_EQ(ret, SUCCESS);2334 EXPECT_EQ(ret, SUCCESS);
@@ -2379,7 +2386,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmModel_CPU_OS_EMPTY)
2379 system(("touch " + inner_tiling_path).c_str());2386 system(("touch " + inner_tiling_path).c_str());
2380 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());2387 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
2381 2388 
2382- string cpu_info = "x86_64";2389+ string cpu_info = GetCurArch();
2383 string os_info = "linux";2390 string os_info = "linux";
2384 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);2391 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);
2385 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);2392 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);
@@ -2447,7 +2454,7 @@ TEST_F(UtestModelHelper, SoBinSaveToOmRootModelErrByFileNameTooLong)
2447 system(("touch " + inner_tiling_path).c_str());2454 system(("touch " + inner_tiling_path).c_str());
2448 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());2455 system(("echo 'op tiling:456 ' > " + inner_tiling_path).c_str());
2449 2456 
2450- string cpu_info = "x86_64";2457+ string cpu_info = GetCurArch();
2451 string os_info = "linux";2458 string os_info = "linux";
2452 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);2459 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);
2453 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);2460 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);
@@ -2502,7 +2509,7 @@ TEST_F(UtestModelHelper, GetSoBinData_fail)
2502 system(("echo 'compiler_version=6.4.T5.0.B121' > " + opp_path + "customize" + "/version.info").c_str());2509 system(("echo 'compiler_version=6.4.T5.0.B121' > " + opp_path + "customize" + "/version.info").c_str());
2503 mmSetEnv(kEnvNameCustom, (opp_path + "customize").c_str(), 1);2510 mmSetEnv(kEnvNameCustom, (opp_path + "customize").c_str(), 1);
2504 2511 
2505- string cpu_info = "x86_64";2512+ string cpu_info = GetCurArch();
2506 string os_info = "linux";2513 string os_info = "linux";
2507 ModelHelper model_helper;2514 ModelHelper model_helper;
2508 EXPECT_EQ(model_helper.GetSoBinData(cpu_info, os_info), PARAM_INVALID);2515 EXPECT_EQ(model_helper.GetSoBinData(cpu_info, os_info), PARAM_INVALID);
@@ -2558,7 +2565,7 @@ TEST_F(UtestModelHelper, GetSoBinData_upgraded_opp_success) {
2558 std::vector<std::string> paths;2565 std::vector<std::string> paths;
2559 gert::CreateBuiltInSplitAndUpgradedSo(paths);2566 gert::CreateBuiltInSplitAndUpgradedSo(paths);
2560 std::string os_info{"linux"};2567 std::string os_info{"linux"};
2561- std::string cpu_info{"x86_64"};2568+ std::string cpu_info{GetCurArch()};
2562 ModelHelper model_helper;2569 ModelHelper model_helper;
2563 EXPECT_EQ(model_helper.GetSoBinData(cpu_info, os_info), SUCCESS);2570 EXPECT_EQ(model_helper.GetSoBinData(cpu_info, os_info), SUCCESS);
2564 EXPECT_EQ(model_helper.op_so_store_.kernels_.size(), 4U);2571 EXPECT_EQ(model_helper.op_so_store_.kernels_.size(), 4U);
@@ -2620,14 +2627,14 @@ TEST_F(UtestModelHelper, SaveOpMasterDevice_WithSpaceRegistry_Success) {
2620 2627 
2621 std::map<std::string, std::string> options_map;2628 std::map<std::string, std::string> options_map;
2622 options_map["ge.host_env_os"] = "linux";2629 options_map["ge.host_env_os"] = "linux";
2623- options_map["ge.host_env_cpu"] = "x86_64";2630+ options_map["ge.host_env_cpu"] = GetCurArch();
2624 GetThreadLocalContext().SetGlobalOption(options_map);2631 GetThreadLocalContext().SetGlobalOption(options_map);
2625 std::string output_file = opp_path + "/output.om";2632 std::string output_file = opp_path + "/output.om";
2626 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, false), SUCCESS);2633 EXPECT_EQ(model_helper.SaveToOmRootModel(ge_root_model, output_file, model, false), SUCCESS);
2627 2634 
2628 ge::ModelParserBase base;2635 ge::ModelParserBase base;
2629 ge::ModelData model_data;2636 ge::ModelData model_data;
2630- EXPECT_EQ(base.LoadFromFile((opp_path + "output_linux_x86_64.om").c_str(), -1, model_data), SUCCESS);2637+ EXPECT_EQ(base.LoadFromFile((opp_path + "output_linux_" + GetCurArch() + ".om").c_str(), -1, model_data), SUCCESS);
2631 EXPECT_EQ(model_helper.LoadRootModel(model_data), SUCCESS);2638 EXPECT_EQ(model_helper.LoadRootModel(model_data), SUCCESS);
2632 if (model_data.model_data != nullptr) {2639 if (model_data.model_data != nullptr) {
2633 delete[] reinterpret_cast<char_t *>(model_data.model_data);2640 delete[] reinterpret_cast<char_t *>(model_data.model_data);
@@ -2719,9 +2726,17 @@ TEST_F(UtestModelHelper, SaveToOm_for_SubPkg_Opp) {
2719 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);2726 EXPECT_EQ(ge_root_model->CheckAndSetNeedSoInOM(), SUCCESS);
2720 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);2727 EXPECT_EQ(ge_root_model->GetSoInOmFlag(), 0x8000);
2721 FillModelTaskDef(ge_model);2728 FillModelTaskDef(ge_model);
2729+ std::string host_env_cpu;
2730+#if defined(__aarch64__) || defined(__arm64__)
2731+ host_env_cpu = "aarch64";
2732+#elif defined(__x86_64__) || defined(__amd64__)
2733+ host_env_cpu = "x86_64";
2734+#else
2735+ host_env_cpu = "x86_64";
2736+#endif
atomgit-bot
atomgit-botatomgit-bot6月25日
已过期

🔵 Low Priority

变更行 2722-2727:新增的 host_env_cpu 通过 #if / #elif 条件赋值,但没有 #else 分支。当编译平台未定义 __aarch64____arm64____x86_64____amd64__ 中任何一个宏时,host_env_cpu 保持为空字符串(std::string 默认构造值),随后在第 2730 行被写入 env_options["ge.host_env_cpu"]。这会导致测试在非主流架构上静默地使用空字符串作为 CPU 架构信息,可能使测试行为异常或产生难以诊断的失败。该测试原本硬编码 "x86_64" 至少保证了有值。

触发条件:在同时不定义上述四个宏任一者的平台上编译并运行该测试(例如某些 32 位 ARM 或 RISC-V 平台交叉编译场景)。实际触发概率低,因为当前支持的目标平台(Linux x86_64 / aarch64)均定义了相应宏。

建议:添加 #else 分支,为 host_env_cpu 提供默认值(建议回退到 "x86_64" 以兼容原有行为),或使用 #error 在编译期阻止不支持的架构。

改动建议
2736
+ std::string host_env_cpu;
2737
+ #if defined(__aarch64__) || defined(__arm64__)
2738
+ host_env_cpu = "aarch64";
2739
+ #elif defined(__x86_64__) || defined(__amd64__)
2740
+ host_env_cpu = "x86_64";
2741
+ #else
2742
+ host_env_cpu = "x86_64";
2736
2743
  #endif
已应用
likedislike
2722 std::map<string, string> env_options;2737 std::map<string, string> env_options;
2723 env_options["ge.host_env_os"] = "linux";2738 env_options["ge.host_env_os"] = "linux";
2724- env_options["ge.host_env_cpu"] = "x86_64";2739+ env_options["ge.host_env_cpu"] = host_env_cpu;
2725 (void)GetThreadLocalContext().SetGlobalOption(env_options);2740 (void)GetThreadLocalContext().SetGlobalOption(env_options);
2726 2741 
2727 ModelHelper model_helper;2742 ModelHelper model_helper;