已合并
feat: 统一 OM2 任务启动回调并支持多类任务 #4596
ClarkXie创建于 11 天前
feat: 统一 OM2 任务启动回调并支持多类任务 #4596
已合并
共 26 个文件变更+1357-305
| @@ -283,15 +283,15 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 283 | output = | 283 | output = |
| 284 | "aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, " | 284 | "aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, " |
| 285 | "const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, " | 285 | "const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, " |
| 286 | - "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, void " | 286 | + "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, " |
| 287 | - "*executor_handle, int32_t priority) {\n" | 287 | + "int32_t priority) {\n" |
| 288 | " OM2_LOGI(\"Om2ModelCreate\");\n" | 288 | " OM2_LOGI(\"Om2ModelCreate\");\n" |
| 289 | " if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) {\n" | 289 | " if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) {\n" |
| 290 | " OM2_LOGE(\"Om2ModelCreate: invalid handle\");\n" | 290 | " OM2_LOGE(\"Om2ModelCreate: invalid handle\");\n" |
| 291 | " return ACL_ERROR_FAILURE;\n" | 291 | " return ACL_ERROR_FAILURE;\n" |
| 292 | " }\n" | 292 | " }\n" |
| 293 | " auto *obj = new om2::Om2Model(bin_files, bin_data, bin_size, bin_num, constants, var_addrs, " | 293 | " auto *obj = new om2::Om2Model(bin_files, bin_data, bin_size, bin_num, constants, var_addrs, " |
| 294 | - "work_ptr, session_id, model_id, instance_handle, executor_handle, priority);\n" | 294 | + "work_ptr, session_id, model_id, instance_handle, priority);\n" |
| 295 | " if (obj == nullptr) {\n" | 295 | " if (obj == nullptr) {\n" |
| 296 | " OM2_LOGE(\"Om2ModelCreate: new Om2Model failed\");\n" | 296 | " OM2_LOGE(\"Om2ModelCreate: new Om2Model failed\");\n" |
| 297 | " return ACL_ERROR_FAILURE;\n" | 297 | " return ACL_ERROR_FAILURE;\n" |
| @@ -364,7 +364,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 364 | " config->bin_size, static_cast<size_t>(config->bin_num), config->constants,\n" | 364 | " config->bin_size, static_cast<size_t>(config->bin_num), config->constants,\n" |
| 365 | " config->var_addrs, config->work_ptr, config->session_id,\n" | 365 | " config->var_addrs, config->work_ptr, config->session_id,\n" |
| 366 | " static_cast<uint32_t>(config->model_id), config->instance_handle,\n" | 366 | " static_cast<uint32_t>(config->model_id), config->instance_handle,\n" |
| 367 | - " config->executor_handle, static_cast<int32_t>(config->priority)));\n" | 367 | + " static_cast<int32_t>(config->priority)));\n" |
| 368 | " OM2_LOGI(\"GertModelLoad: handle=%p, model_id=%\" PRIu64 \", priority=%\" PRIi64 \",\"\n" | 368 | " OM2_LOGI(\"GertModelLoad: handle=%p, model_id=%\" PRIu64 \", priority=%\" PRIi64 \",\"\n" |
| 369 | " \" bin_num=%\" PRIu64 \"\", *model_handle, config->model_id,\n" | 369 | " \" bin_num=%\" PRIu64 \"\", *model_handle, config->model_id,\n" |
| 370 | " config->priority, config->bin_num);\n" | 370 | " config->priority, config->bin_num);\n" |
| @@ -474,6 +474,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 474 | " const uint64_t* workspace_addrs;\n" | 474 | " const uint64_t* workspace_addrs;\n" |
| 475 | " const uint64_t* workspace_sizes;\n" | 475 | " const uint64_t* workspace_sizes;\n" |
| 476 | " uint32_t task_type;\n" | 476 | " uint32_t task_type;\n" |
| 477 | + " uint64_t kernel_type = 10000U;\n" | ||
| 477 | " void* stream;\n" | 478 | " void* stream;\n" |
| 478 | " uint32_t is_raw_address;\n" | 479 | " uint32_t is_raw_address;\n" |
| 479 | " const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n" | 480 | " const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n" |
| @@ -501,12 +502,53 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 501 | "*info);\n" | 502 | "*info);\n" |
| 502 | "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n" | 503 | "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n" |
| 503 | "\n" | 504 | "\n" |
| 505 | + "enum GertModelTaskLaunchType : uint64_t {\n" | ||
| 506 | + " ACL_RT_LAUNCH_KERNEL_V2 = 0,\n" | ||
| 507 | + " RT_STARS_TASK_LAUNCH_WITH_FLAG = 1,\n" | ||
| 508 | + "};\n" | ||
| 509 | + "\n" | ||
| 510 | + "struct GertModelLaunchKernelV2Params {\n" | ||
| 511 | + " uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params);\n" | ||
| 512 | + " aclrtFuncHandle func_handle = nullptr;\n" | ||
| 513 | + " uint32_t block_dim = 0;\n" | ||
| 514 | + " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n" | ||
| 515 | + " uint32_t reserved_1 = 0;\n" | ||
| 516 | + " const void *args_data = nullptr;\n" | ||
| 517 | + " size_t args_size = 0;\n" | ||
| 518 | + " aclrtLaunchKernelCfg *config = nullptr;\n" | ||
| 519 | + " aclrtStream stream = nullptr;\n" | ||
| 520 | + "};\n" | ||
| 521 | + "\n" | ||
| 522 | + "struct GertModelLaunchStarsTaskWithFlagParams {\n" | ||
| 523 | + " uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams);\n" | ||
| 524 | + " const void *task_sqe = nullptr;\n" | ||
| 525 | + " uint32_t sqe_len = 0;\n" | ||
| 526 | + " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n" | ||
| 527 | + " uint32_t reserved_1 = 0;\n" | ||
| 528 | + " aclrtStream stream = nullptr;\n" | ||
| 529 | + " uint32_t flag = 0;\n" | ||
| 530 | + " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n" | ||
| 531 | + " uint32_t reserved_2 = 0;\n" | ||
| 532 | + "};\n" | ||
| 533 | + "\n" | ||
| 534 | + "union GertModelTaskLaunchParams {\n" | ||
| 535 | + " GertModelLaunchKernelV2Params launch_kernel_v2_params;\n" | ||
| 536 | + " GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params;\n" | ||
| 537 | + "};\n" | ||
| 538 | + "\n" | ||
| 539 | + "struct GertModelTaskLaunchInfo {\n" | ||
| 540 | + " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n" | ||
| 541 | + " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n" | ||
| 542 | + " Om2TaskInfo *task_info = nullptr;\n" | ||
| 543 | + " const GertModelTaskLaunchParams *launch_params = nullptr;\n" | ||
| 544 | + "};\n" | ||
| 545 | + "\n" | ||
| 546 | + "using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);\n" | ||
| 547 | + "\n" | ||
| 504 | "struct GertModelCallbacks {\n" | 548 | "struct GertModelCallbacks {\n" |
| 505 | " uint64_t struct_size = sizeof(GertModelCallbacks);\n" | 549 | " uint64_t struct_size = sizeof(GertModelCallbacks);\n" |
| 506 | - " ReportTaskProcessFunc report_task_preprocess = nullptr;\n" | ||
| 507 | - " ReportTaskProcessFunc report_task_postprocess = nullptr;\n" | ||
| 508 | - " GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr;\n" | ||
| 509 | " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n" | 550 | " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n" |
| 551 | + " GertModelLaunchFunc launch_func = nullptr;\n" | ||
| 510 | "};\n" | 552 | "};\n" |
| 511 | "\n" | 553 | "\n" |
| 512 | "using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo " | 554 | "using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo " |
| @@ -537,7 +579,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 537 | " uint64_t *session_id = nullptr;\n" | 579 | " uint64_t *session_id = nullptr;\n" |
| 538 | " uint64_t model_id = 0; // used for logging\n" | 580 | " uint64_t model_id = 0; // used for logging\n" |
| 539 | " void *instance_handle = nullptr;\n" | 581 | " void *instance_handle = nullptr;\n" |
| 540 | - " void *executor_handle = nullptr;\n" | ||
| 541 | " const struct GertModelCallbacks *callbacks = nullptr;\n" | 582 | " const struct GertModelCallbacks *callbacks = nullptr;\n" |
| 542 | " int64_t priority = 0;\n" | 583 | " int64_t priority = 0;\n" |
| 543 | "};\n" | 584 | "};\n" |
| @@ -580,11 +621,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 580 | " const struct Om2TaskInfo* task_info,\n" | 621 | " const struct Om2TaskInfo* task_info,\n" |
| 581 | " const void* extended_attrs,\n" | 622 | " const void* extended_attrs,\n" |
| 582 | " size_t extended_attrs_size);\n" | 623 | " size_t extended_attrs_size);\n" |
| 583 | - "\n" | ||
| 584 | - "__attribute__((weak)) int32_t IsDataDumpEnabled(uint32_t model_id,\n" | ||
| 585 | - " void* instance_handle,\n" | ||
| 586 | - " const char* op_name,\n" | ||
| 587 | - " uint8_t* is_data_dump);\n" | ||
| 588 | "}\n"; | 624 | "}\n"; |
| 589 | return SUCCESS; | 625 | return SUCCESS; |
| 590 | case StablePartId::kLoadAndRunDumpHelpers: | 626 | case StablePartId::kLoadAndRunDumpHelpers: |
| @@ -719,15 +755,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 719 | " OM2_CHK_STATUS(ReportDfxTaskPostprocess(model_id, instance_handle, &task_info, nullptr, 0U));\n" | 755 | " OM2_CHK_STATUS(ReportDfxTaskPostprocess(model_id, instance_handle, &task_info, nullptr, 0U));\n" |
| 720 | " }\n" | 756 | " }\n" |
| 721 | " return ACL_SUCCESS;\n" | 757 | " return ACL_SUCCESS;\n" |
| 722 | - "}\n" | ||
| 723 | - "\n" | ||
| 724 | - "uint8_t GetIsDataDump(const char *op_name, uint32_t model_id, void *instance_handle) {\n" | ||
| 725 | - " if (IsDataDumpEnabled != nullptr && instance_handle != nullptr) {\n" | ||
| 726 | - " uint8_t is_data_dump = 0U;\n" | ||
| 727 | - " auto ret = IsDataDumpEnabled(model_id, instance_handle, op_name, &is_data_dump);\n" | ||
| 728 | - " return ret == 0 ? is_data_dump : 0U;\n" | ||
| 729 | - " }\n" | ||
| 730 | - " return 0U;\n" | ||
| 731 | "}\n"; | 758 | "}\n"; |
| 732 | return SUCCESS; | 759 | return SUCCESS; |
| 733 | case StablePartId::kCreateLabelListForLabelSwitch: | 760 | case StablePartId::kCreateLabelListForLabelSwitch: |
| @@ -829,6 +856,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 829 | " uint32_t func_idx; // 函数句柄索引,用于查找 func_handles\n" | 856 | " uint32_t func_idx; // 函数句柄索引,用于查找 func_handles\n" |
| 830 | " uint32_t stream_id; // 执行流索引\n" | 857 | " uint32_t stream_id; // 执行流索引\n" |
| 831 | " uint32_t task_type;\n" | 858 | " uint32_t task_type;\n" |
| 859 | + " uint32_t kernel_type;\n" | ||
| 832 | " struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig\n" | 860 | " struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig\n" |
| 833 | " uint8_t schedule_mode; // 调度模式\n" | 861 | " uint8_t schedule_mode; // 调度模式\n" |
| 834 | " uint32_t engine_type; // 引擎类型\n" | 862 | " uint32_t engine_type; // 引擎类型\n" |
| @@ -874,6 +902,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 874 | " int32_t session_info_offset;\n" | 902 | " int32_t session_info_offset;\n" |
| 875 | " uint32_t aicpu_task_index;\n" | 903 | " uint32_t aicpu_task_index;\n" |
| 876 | " uint32_t task_type;\n" | 904 | " uint32_t task_type;\n" |
| 905 | + " uint32_t kernel_type;\n" | ||
| 877 | "};\n" | 906 | "};\n" |
| 878 | "\n" | 907 | "\n" |
| 879 | "struct CustomDispatchInfo {\n" | 908 | "struct CustomDispatchInfo {\n" |
| @@ -1029,6 +1058,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 1029 | " uint64_t *session_id; // Session ID\n" | 1058 | " uint64_t *session_id; // Session ID\n" |
| 1030 | " std::vector<void *> &dev_ext_info_mem_ptrs; // AICPU 扩展信息设备内存指针列表\n" | 1059 | " std::vector<void *> &dev_ext_info_mem_ptrs; // AICPU 扩展信息设备内存指针列表\n" |
| 1031 | " uint64_t *kernel_id; // AICPU Kernel ID 计数器\n" | 1060 | " uint64_t *kernel_id; // AICPU Kernel ID 计数器\n" |
| 1061 | + " GertModelLaunchFunc launch_func; // 任务 launch 回调\n" | ||
| 1032 | "};\n" | 1062 | "};\n" |
| 1033 | "\n"; | 1063 | "\n"; |
| 1034 | return SUCCESS; | 1064 | return SUCCESS; |
| @@ -107,8 +107,7 @@ ClassDecl *InterfaceFileCodeGenerator::BuildOm2ModelClass(const Om2CodegenModel | |||
| 107 | {ast_.Var("const char **", "bin_files"), ast_.Var("const void **", "bin_data"), | 107 | {ast_.Var("const char **", "bin_files"), ast_.Var("const void **", "bin_data"), |
| 108 | ast_.Var("uint64_t *", "bin_size"), ast_.Var("size_t", "bin_num"), ast_.Var("void **", "constants"), | 108 | ast_.Var("uint64_t *", "bin_size"), ast_.Var("size_t", "bin_num"), ast_.Var("void **", "constants"), |
| 109 | ast_.Var("void **", "var_addrs"), ast_.Var("void *", "work_ptr"), ast_.Var("uint64_t *", "session_id"), | 109 | ast_.Var("void **", "var_addrs"), ast_.Var("void *", "work_ptr"), ast_.Var("uint64_t *", "session_id"), |
| 110 | - ast_.Var("uint32_t", "model_id"), ast_.Var("void *", "instance_handle"), | 110 | + ast_.Var("uint32_t", "model_id"), ast_.Var("void *", "instance_handle"), ast_.Var("int32_t", "priority")}, |
| 111 | - ast_.Var("void *", "executor_handle"), ast_.Var("int32_t", "priority")}, | ||
| 112 | ""), | 111 | ""), |
| 113 | ast_.DeclareMethod("~Om2Model", {}, ""), | 112 | ast_.DeclareMethod("~Om2Model", {}, ""), |
| 114 | ast_.DeclareMethod("InitResources", {}, "aclError"), | 113 | ast_.DeclareMethod("InitResources", {}, "aclError"), |
| @@ -141,7 +140,6 @@ ClassDecl *InterfaceFileCodeGenerator::BuildOm2ModelClass(const Om2CodegenModel | |||
| 141 | items.push_back(ast_.Field("uint64_t *", "session_id_")); | 140 | items.push_back(ast_.Field("uint64_t *", "session_id_")); |
| 142 | items.push_back(ast_.Field("uint32_t", "model_id_")); | 141 | items.push_back(ast_.Field("uint32_t", "model_id_")); |
| 143 | items.push_back(ast_.Field("void *", "instance_handle_")); | 142 | items.push_back(ast_.Field("void *", "instance_handle_")); |
| 144 | - items.push_back(ast_.Field("void *", "executor_handle_")); | ||
| 145 | items.push_back(ast_.Field("uint64_t", "kernel_id_")); | 143 | items.push_back(ast_.Field("uint64_t", "kernel_id_")); |
| 146 | items.push_back(ast_.Field("std::vector<void *>", "dev_ext_info_mem_ptrs_")); | 144 | items.push_back(ast_.Field("std::vector<void *>", "dev_ext_info_mem_ptrs_")); |
| 147 | items.push_back(ast_.Field("std::map<uint32_t, void *>", "mem_event_id_mem_map_")); | 145 | items.push_back(ast_.Field("std::map<uint32_t, void *>", "mem_event_id_mem_map_")); |
| @@ -97,6 +97,7 @@ Status LoadAndRunFileCodeGenerator::BuildLoadBody(std::vector<BodyItem> &body, c | |||
| 97 | body.push_back(ChkStatus(ast_.Call("DeserializeCustKernelBinaries", {ast_.Var("", "bin_info_map_")}))); | 97 | body.push_back(ChkStatus(ast_.Call("DeserializeCustKernelBinaries", {ast_.Var("", "bin_info_map_")}))); |
| 98 | } | 98 | } |
| 99 | body.push_back(dev_ext_info_mem_ptrs_.Resize(codegen_model.aicpu_task_count)); | 99 | body.push_back(dev_ext_info_mem_ptrs_.Resize(codegen_model.aicpu_task_count)); |
| 100 | + auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); | ||
| 100 | 101 | ||
| 101 | // 公共 DispatchOpContext 初始化列表(for 循环版和展开版共享) | 102 | // 公共 DispatchOpContext 初始化列表(for 循环版和展开版共享) |
| 102 | auto ctx_init_list = ast_.InitList({total_dev_mem_ptr_, | 103 | auto ctx_init_list = ast_.InitList({total_dev_mem_ptr_, |
| @@ -120,16 +121,20 @@ Status LoadAndRunFileCodeGenerator::BuildLoadBody(std::vector<BodyItem> &body, c | |||
| 120 | label_switch_label_list_, | 121 | label_switch_label_list_, |
| 121 | session_id_, | 122 | session_id_, |
| 122 | dev_ext_info_mem_ptrs_, | 123 | dev_ext_info_mem_ptrs_, |
| 123 | - kernel_id_.Addr()}); | 124 | + kernel_id_.Addr(), |
| 125 | + launch_func}); | ||
| 124 | 126 | ||
| 125 | auto ctx_var = ast_.Var("DispatchOpContext", "ctx"); | 127 | auto ctx_var = ast_.Var("DispatchOpContext", "ctx"); |
| 126 | auto loop_var = ast_.Var("uint32_t", "_op_idx"); | 128 | auto loop_var = ast_.Var("uint32_t", "_op_idx"); |
| 127 | auto kOpDefs = ast_.Var("const TaskDispatchInfo", "kOpDefs"); | 129 | auto kOpDefs = ast_.Var("const TaskDispatchInfo", "kOpDefs"); |
| 128 | 130 | ||
| 131 | + auto param_callbacks = ast_.Var("", "callbacks"); | ||
| 132 | + body.push_back(ast_.VarDecl(launch_func, nullptr)); | ||
| 133 | + body.push_back(ast_.If((param_callbacks != "nullptr" && param_callbacks.Arrow("launch_func") != "nullptr"), | ||
| 134 | + {ast_.Assign(launch_func, param_callbacks.Arrow("launch_func"))})); | ||
| 129 | body.push_back(ast_.VarDecl(ctx_var, ctx_init_list)); | 135 | body.push_back(ast_.VarDecl(ctx_var, ctx_init_list)); |
| 130 | 136 | ||
| 131 | // 执行 ReportModelBaseInfo 回调 | 137 | // 执行 ReportModelBaseInfo 回调 |
| 132 | - auto param_callbacks = ast_.Var("", "callbacks"); | ||
| 133 | body.push_back( | 138 | body.push_back( |
| 134 | ast_.If((param_callbacks != "nullptr" && param_callbacks.Arrow("report_model_base_info") != "nullptr"), | 139 | ast_.If((param_callbacks != "nullptr" && param_callbacks.Arrow("report_model_base_info") != "nullptr"), |
| 135 | {ast_.VarDecl(ast_.Var("GertModelBaseInfo", "cfg"), | 140 | {ast_.VarDecl(ast_.Var("GertModelBaseInfo", "cfg"), |
| @@ -253,7 +258,7 @@ void LoadAndRunFileCodeGenerator::BuildRunBodyPhaseModelExecute(std::vector<Body | |||
| 253 | (run_callbacks != "nullptr") && (ast_.Var("", "run_callbacks->report_run_info_preprocess") != "nullptr"), | 258 | (run_callbacks != "nullptr") && (ast_.Var("", "run_callbacks->report_run_info_preprocess") != "nullptr"), |
| 254 | {ast_.VarDecl(ast_.Var("GertModelRunReportInfo", "_r"), | 259 | {ast_.VarDecl(ast_.Var("GertModelRunReportInfo", "_r"), |
| 255 | ast_.InitList({ast_.Sizeof("GertModelRunReportInfo"), model_id_, stream_arg, is_async_val})), | 260 | ast_.InitList({ast_.Sizeof("GertModelRunReportInfo"), model_id_, stream_arg, is_async_val})), |
| 256 | - ast_.Call("run_callbacks->report_run_info_preprocess", {executor_handle_, ast_.Var("", "_r").Addr()})})); | 261 | + ast_.Call("run_callbacks->report_run_info_preprocess", {instance_handle_, ast_.Var("", "_r").Addr()})})); |
| 257 | 262 | ||
| 258 | body.push_back(ast_.BlankLine()); | 263 | body.push_back(ast_.BlankLine()); |
| 259 | if (is_need_va2pa) { | 264 | if (is_need_va2pa) { |
| @@ -276,7 +281,7 @@ void LoadAndRunFileCodeGenerator::BuildRunBodyPhaseModelExecute(std::vector<Body | |||
| 276 | (run_callbacks != "nullptr") && (ast_.Var("", "run_callbacks->report_run_info_postprocess") != "nullptr"), | 281 | (run_callbacks != "nullptr") && (ast_.Var("", "run_callbacks->report_run_info_postprocess") != "nullptr"), |
| 277 | {ast_.VarDecl(ast_.Var("GertModelRunReportInfo", "_r2"), | 282 | {ast_.VarDecl(ast_.Var("GertModelRunReportInfo", "_r2"), |
| 278 | ast_.InitList({ast_.Sizeof("GertModelRunReportInfo"), model_id_, stream_arg, is_async_val})), | 283 | ast_.InitList({ast_.Sizeof("GertModelRunReportInfo"), model_id_, stream_arg, is_async_val})), |
| 279 | - ast_.Call("run_callbacks->report_run_info_postprocess", {executor_handle_, ast_.Var("", "_r2").Addr()})})); | 284 | + ast_.Call("run_callbacks->report_run_info_postprocess", {instance_handle_, ast_.Var("", "_r2").Addr()})})); |
| 280 | } | 285 | } |
| 281 | 286 | ||
| 282 | void LoadAndRunFileCodeGenerator::BuildRunBodyPhaseOutputCopy(std::vector<BodyItem> &body, | 287 | void LoadAndRunFileCodeGenerator::BuildRunBodyPhaseOutputCopy(std::vector<BodyItem> &body, |
| @@ -25,7 +25,6 @@ MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelConstructor(const Om2Codegen | |||
| 25 | auto session_id = ast_.Var("uint64_t *", "session_id"); | 25 | auto session_id = ast_.Var("uint64_t *", "session_id"); |
| 26 | auto model_id = ast_.Var("uint32_t", "model_id"); | 26 | auto model_id = ast_.Var("uint32_t", "model_id"); |
| 27 | auto instance_handle = ast_.Var("void *", "instance_handle"); | 27 | auto instance_handle = ast_.Var("void *", "instance_handle"); |
| 28 | - auto executor_handle = ast_.Var("void *", "executor_handle"); | ||
| 29 | auto priority = ast_.Var("int32_t", "priority"); | 28 | auto priority = ast_.Var("int32_t", "priority"); |
| 30 | auto i = ast_.Var("size_t", "i"); | 29 | auto i = ast_.Var("size_t", "i"); |
| 31 | std::vector<BodyItem> body = { | 30 | std::vector<BodyItem> body = { |
| @@ -52,17 +51,16 @@ MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelConstructor(const Om2Codegen | |||
| 52 | (void)body.emplace_back(label_list_.Resize(runtime.label_num)); | 51 | (void)body.emplace_back(label_list_.Resize(runtime.label_num)); |
| 53 | } | 52 | } |
| 54 | (void)body.emplace_back(ast_.Call("OM2_LOGD", {ast_.Str("Om2Model created")})); | 53 | (void)body.emplace_back(ast_.Call("OM2_LOGD", {ast_.Str("Om2Model created")})); |
| 55 | - return ast_.DefineMethod( | 54 | + return ast_.DefineMethod("Om2Model", "Om2Model", |
| 56 | - "Om2Model", "Om2Model", | 55 | + {bin_files, bin_data, bin_size, bin_num, constants, var_addrs, work_ptr, session_id, |
| 57 | - {bin_files, bin_data, bin_size, bin_num, constants, var_addrs, work_ptr, session_id, model_id, instance_handle, | 56 | + model_id, instance_handle, priority}, |
| 58 | - executor_handle, priority}, | 57 | + "", |
| 59 | - "", | 58 | + {ast_.MemberInit("constants_", constants), ast_.MemberInit("var_addrs_", var_addrs), |
| 60 | - {ast_.MemberInit("constants_", constants), ast_.MemberInit("var_addrs_", var_addrs), | 59 | + ast_.MemberInit("total_dev_mem_ptr_", work_ptr), ast_.MemberInit("session_id_", session_id), |
| 61 | - ast_.MemberInit("total_dev_mem_ptr_", work_ptr), ast_.MemberInit("session_id_", session_id), | 60 | + ast_.MemberInit("model_id_", model_id), |
| 62 | - ast_.MemberInit("model_id_", model_id), ast_.MemberInit("instance_handle_", instance_handle), | 61 | + ast_.MemberInit("instance_handle_", instance_handle), ast_.MemberInit("kernel_id_", 0), |
| 63 | - ast_.MemberInit("executor_handle_", executor_handle), ast_.MemberInit("kernel_id_", 0), | 62 | + ast_.MemberInit("session_scope_mem_ptr_", nullptr), ast_.MemberInit("priority_", priority)}, |
| 64 | - ast_.MemberInit("session_scope_mem_ptr_", nullptr), ast_.MemberInit("priority_", priority)}, | 63 | + body); |
| 65 | - body); | ||
| 66 | } | 64 | } |
| 67 | 65 | ||
| 68 | MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelDestructor() const { | 66 | MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelDestructor() const { |
| @@ -30,7 +30,6 @@ Om2ModelClassGeneratorBase::Om2ModelClassGeneratorBase(AstBuildContext &ast) | |||
| 30 | session_id_(ast.Var("uint64_t *", "session_id_")), | 30 | session_id_(ast.Var("uint64_t *", "session_id_")), |
| 31 | model_id_(ast.Var("uint32_t", "model_id_")), | 31 | model_id_(ast.Var("uint32_t", "model_id_")), |
| 32 | instance_handle_(ast.Var("void *", "instance_handle_")), | 32 | instance_handle_(ast.Var("void *", "instance_handle_")), |
| 33 | - executor_handle_(ast.Var("void *", "executor_handle_")), | ||
| 34 | kernel_id_(ast.Var("uint64_t", "kernel_id_")), | 33 | kernel_id_(ast.Var("uint64_t", "kernel_id_")), |
| 35 | dev_ext_info_mem_ptrs_(ast.Var("std::vector<void *>", "dev_ext_info_mem_ptrs_")), | 34 | dev_ext_info_mem_ptrs_(ast.Var("std::vector<void *>", "dev_ext_info_mem_ptrs_")), |
| 36 | label_switch_label_list_(ast_.Var("std::map<uint32_t, aclrtLabelList>", "label_switch_label_list_")), | 35 | label_switch_label_list_(ast_.Var("std::map<uint32_t, aclrtLabelList>", "label_switch_label_list_")), |
| @@ -37,7 +37,6 @@ class Om2ModelClassGeneratorBase : public CodeGeneratorBase { | |||
| 37 | VarRef session_id_; | 37 | VarRef session_id_; |
| 38 | VarRef model_id_; | 38 | VarRef model_id_; |
| 39 | VarRef instance_handle_; | 39 | VarRef instance_handle_; |
| 40 | - VarRef executor_handle_; | ||
| 41 | VarRef kernel_id_; | 40 | VarRef kernel_id_; |
| 42 | VarRef dev_ext_info_mem_ptrs_; | 41 | VarRef dev_ext_info_mem_ptrs_; |
| 43 | VarRef label_switch_label_list_; | 42 | VarRef label_switch_label_list_; |
| @@ -175,16 +175,38 @@ FunctionDef *KernelExTaskCodeBuilder::RenderTfAicpuKernelTaskDistribute() const | |||
| 175 | auto block_dim = ast_.Var("uint32_t", "block_dim"); | 175 | auto block_dim = ast_.Var("uint32_t", "block_dim"); |
| 176 | auto stream = ast_.Var("aclrtStream", "stream"); | 176 | auto stream = ast_.Var("aclrtStream", "stream"); |
| 177 | auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); | 177 | auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); |
| 178 | + auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); | ||
| 179 | + auto instance_handle = ast_.Var("void *", "instance_handle"); | ||
| 180 | + auto task_info = ast_.Var("Om2TaskInfo *", "task_info"); | ||
| 181 | + auto kernel_params = ast_.Var("GertModelLaunchKernelV2Params", "launch_kernel_v2_params"); | ||
| 182 | + auto launch_params = ast_.Var("GertModelTaskLaunchParams", "launch_params"); | ||
| 183 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "launch_info"); | ||
| 178 | return ast_.DefineFunction( | 184 | return ast_.DefineFunction( |
| 179 | "TfAicpuKernelTaskDistribute", | 185 | "TfAicpuKernelTaskDistribute", |
| 180 | - {io_addrs, args_info, kernel_buf, kernel_buf_size, func_handle, block_dim, stream, config}, "aclError", | 186 | + {io_addrs, args_info, kernel_buf, kernel_buf_size, func_handle, block_dim, stream, config, launch_func, |
| 187 | + instance_handle, task_info}, | ||
| 188 | + "aclError", | ||
| 181 | { | 189 | { |
| 190 | + ast_.VarDecl(kernel_params, ast_.DesignatedInit({{"func_handle", func_handle}, | ||
| 191 | + {"block_dim", block_dim}, | ||
| 192 | + {"args_data", kernel_buf}, | ||
| 193 | + {"args_size", kernel_buf_size}, | ||
| 194 | + {"config", config}, | ||
| 195 | + {"stream", stream}})), | ||
| 196 | + ast_.VarDecl(launch_params, ast_.DesignatedInit({{"launch_kernel_v2_params", kernel_params}})), | ||
| 197 | + ast_.VarDecl(launch_info, ast_.DesignatedInit({{"launch_type", ast_.Var("", "ACL_RT_LAUNCH_KERNEL_V2")}, | ||
| 198 | + {"task_info", task_info}, | ||
| 199 | + {"launch_params", launch_params.Addr()}})), | ||
| 200 | + ast_.If( | ||
| 201 | + launch_func != nullptr, | ||
| 202 | + {ast_.Call("OM2_LOGI", {ast_.Str("TfAicpuKernelTaskDistribute: Start to execute launch callback.")}), | ||
| 203 | + ChkStatus(ast_.Call("launch_func", {instance_handle, launch_info.Addr()}))}, | ||
| 204 | + {ast_.Call("OM2_LOGI", | ||
| 205 | + {ast_.Str("TfAicpuKernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly.")}), | ||
| 206 | + ChkStatus(AclrtLaunchKernelV2(func_handle, block_dim, kernel_buf, kernel_buf_size, config, stream))}), | ||
| 182 | ast_.If(args_info != nullptr, | 207 | ast_.If(args_info != nullptr, |
| 183 | - { | 208 | + {ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), io_addrs.Data(), |
| 184 | - ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), io_addrs.Data(), | 209 | + io_addrs.Size() * ast_.Sizeof("uint64_t")))}), |
| 185 | - io_addrs.Size() * ast_.Sizeof("uint64_t"))), | ||
| 186 | - }), | ||
| 187 | - ChkStatus(AclrtLaunchKernelV2(func_handle, block_dim, kernel_buf, kernel_buf_size, config, stream)), | ||
| 188 | ast_.Return("ACL_SUCCESS"), | 210 | ast_.Return("ACL_SUCCESS"), |
| 189 | }); | 211 | }); |
| 190 | } | 212 | } |
| @@ -251,8 +273,8 @@ FunctionDef *KernelExTaskCodeBuilder::RenderAssembleTfAicpuExSessionIdInfo() con | |||
| 251 | mem_ptrs.PushBack(device_base), | 273 | mem_ptrs.PushBack(device_base), |
| 252 | ChkStatus( | 274 | ChkStatus( |
| 253 | AclrtMemcpy(device_base, op_kernel_size, tmp_args.Data(), op_kernel_size, "ACL_MEMCPY_HOST_TO_DEVICE")), | 275 | AclrtMemcpy(device_base, op_kernel_size, tmp_args.Data(), op_kernel_size, "ACL_MEMCPY_HOST_TO_DEVICE")), |
| 254 | - ChkStatus(ast_.Call("TfAicpuKernelTaskDistribute", | 276 | + ChkStatus(ast_.Call("TfAicpuKernelTaskDistribute", {iow_addrs, nullptr, device_base, op_kernel_size, func_handle, |
| 255 | - {iow_addrs, nullptr, device_base, op_kernel_size, func_handle, block_dim, stream, config})), | 277 | + block_dim, stream, config, nullptr, nullptr, nullptr})), |
| 256 | ChkStatus(ast_.Call("aclrtSynchronizeStream", {stream})), ast_.Return("ACL_SUCCESS")}); | 278 | ChkStatus(ast_.Call("aclrtSynchronizeStream", {stream})), ast_.Return("ACL_SUCCESS")}); |
| 257 | } | 279 | } |
| 258 | 280 | ||
| @@ -352,10 +374,8 @@ Status KernelExTaskCodeBuilder::RenderDispatchFunc(std::vector<DeclNode *> &item | |||
| 352 | auto op = ast_.Var("const TaskDispatchInfo *", "op"); | 374 | auto op = ast_.Var("const TaskDispatchInfo *", "op"); |
| 353 | auto ctx = ast_.Var("const DispatchOpContext &", "ctx"); | 375 | auto ctx = ast_.Var("const DispatchOpContext &", "ctx"); |
| 354 | GE_ASSERT_SUCCESS(RenderDispatchFuncSetup(body, op, ctx)); | 376 | GE_ASSERT_SUCCESS(RenderDispatchFuncSetup(body, op, ctx)); |
| 355 | - auto launch_begin = ast_.Var("uint64_t", "_launch_begin"); | 377 | + GE_ASSERT_SUCCESS(RenderDispatchFuncTaskInfo(body, op, ctx)); |
| 356 | - body.emplace_back(ast_.VarDecl(launch_begin, ast_.Call("MsprofSysCycleTime", {}))); | ||
| 357 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunch(body, op, ctx)); | 378 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunch(body, op, ctx)); |
| 358 | - GE_ASSERT_SUCCESS(RenderDispatchFuncReport(body, op, ctx, launch_begin)); | ||
| 359 | GE_ASSERT_SUCCESS(TaskCodeBuilderUtil::RenderDispatchFunc(ast_, kDispatchFuncName, body, items)); | 379 | GE_ASSERT_SUCCESS(TaskCodeBuilderUtil::RenderDispatchFunc(ast_, kDispatchFuncName, body, items)); |
| 360 | return SUCCESS; | 380 | return SUCCESS; |
| 361 | } | 381 | } |
| @@ -412,12 +432,9 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncSetup(std::vector<BodyItem> &b | |||
| 412 | return SUCCESS; | 432 | return SUCCESS; |
| 413 | } | 433 | } |
| 414 | 434 | ||
| 415 | -Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunchConfig(std::vector<BodyItem> &body, const VarRef &op, | 435 | +Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunchConfig(std::vector<BodyItem> &body, const VarRef &op) { |
| 416 | - const VarRef &ctx) { | ||
| 417 | auto cfg_holder = ast_.Var("LaunchKernelCfgHolder", "cfg_holder"); | 436 | auto cfg_holder = ast_.Var("LaunchKernelCfgHolder", "cfg_holder"); |
| 418 | (void)body.emplace_back(ast_.VarDecl(cfg_holder)); | 437 | (void)body.emplace_back(ast_.VarDecl(cfg_holder)); |
| 419 | - auto is_data_dump = | ||
| 420 | - ast_.Call("GetIsDataDump", {op.Arrow("op_name"), ctx.Attr("model_id"), ctx.Attr("instance_handle")}); | ||
| 421 | auto launch_config = ast_.Var("LaunchKernelConfig", "launch_config"); | 438 | auto launch_config = ast_.Var("LaunchKernelConfig", "launch_config"); |
| 422 | (void)body.emplace_back(ast_.VarDecl( | 439 | (void)body.emplace_back(ast_.VarDecl( |
| 423 | launch_config, | 440 | launch_config, |
| @@ -425,9 +442,8 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunchConfig(std::vector<BodyI | |||
| 425 | ast_.StaticCast("aclrtEngineType", | 442 | ast_.StaticCast("aclrtEngineType", |
| 426 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("engine_type")), | 443 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("engine_type")), |
| 427 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("block_dim_offset"), | 444 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("block_dim_offset"), |
| 428 | - op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("is_block_task_prefetch"), | 445 | + op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("is_block_task_prefetch"), false, |
| 429 | - is_data_dump, op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("time_out"), | 446 | + op.Arrow("dispatch_info").Attr("kernel_ex").Attr("launch").Attr("time_out"), ast_.UInt(0)}))); |
| 430 | - ast_.UInt(0)}))); | ||
| 431 | (void)body.emplace_back(ChkStatus(ast_.Call("AssembleLaunchConfig", {cfg_holder, launch_config}))); | 447 | (void)body.emplace_back(ChkStatus(ast_.Call("AssembleLaunchConfig", {cfg_holder, launch_config}))); |
| 432 | 448 | ||
| 433 | auto mem_ptrs = ast_.Var("std::vector<void *>", "mem_ptrs"); | 449 | auto mem_ptrs = ast_.Var("std::vector<void *>", "mem_ptrs"); |
| @@ -497,20 +513,21 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunchTask(std::vector<BodyIte | |||
| 497 | ctx.Attr("func_handles")[op.Arrow("dispatch_info").Attr("kernel_ex").Attr("func_idx")], | 513 | ctx.Attr("func_handles")[op.Arrow("dispatch_info").Attr("kernel_ex").Attr("func_idx")], |
| 498 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("block_dim"), | 514 | op.Arrow("dispatch_info").Attr("kernel_ex").Attr("block_dim"), |
| 499 | ctx.Attr("stream_list")[op.Arrow("dispatch_info").Attr("kernel_ex").Attr("stream_id")], | 515 | ctx.Attr("stream_list")[op.Arrow("dispatch_info").Attr("kernel_ex").Attr("stream_id")], |
| 500 | - ast_.Var("", "cfg_holder").Attr("cfg").Addr()}))); | 516 | + ast_.Var("", "cfg_holder").Attr("cfg").Addr(), ctx.Attr("launch_func"), ctx.Attr("instance_handle"), |
| 517 | + ast_.Var("", "task_info").Addr()}))); | ||
| 501 | return SUCCESS; | 518 | return SUCCESS; |
| 502 | } | 519 | } |
| 503 | 520 | ||
| 504 | Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, | 521 | Status KernelExTaskCodeBuilder::RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, |
| 505 | const VarRef &ctx) { | 522 | const VarRef &ctx) { |
| 506 | - GE_ASSERT_SUCCESS(RenderDispatchFuncLaunchConfig(body, op, ctx)); | 523 | + GE_ASSERT_SUCCESS(RenderDispatchFuncLaunchConfig(body, op)); |
| 507 | GE_ASSERT_SUCCESS(RenderDispatchFuncAssembleExInfo(body, op, ctx)); | 524 | GE_ASSERT_SUCCESS(RenderDispatchFuncAssembleExInfo(body, op, ctx)); |
| 508 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunchTask(body, op, ctx)); | 525 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunchTask(body, op, ctx)); |
| 509 | return SUCCESS; | 526 | return SUCCESS; |
| 510 | } | 527 | } |
| 511 | 528 | ||
| 512 | -Status KernelExTaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, | 529 | +Status KernelExTaskCodeBuilder::RenderDispatchFuncTaskInfo(std::vector<BodyItem> &body, const VarRef &op, |
| 513 | - const VarRef &ctx, const VarRef &launch_begin) { | 530 | + const VarRef &ctx) { |
| 514 | auto io_tensors = ast_.Var("std::vector<gert::Tensor>", "io_tensors"); | 531 | auto io_tensors = ast_.Var("std::vector<gert::Tensor>", "io_tensors"); |
| 515 | (void)body.emplace_back(ast_.VarDecl(io_tensors)); | 532 | (void)body.emplace_back(ast_.VarDecl(io_tensors)); |
| 516 | (void)body.emplace_back(io_tensors.Attr("reserve")(ast_.Var("", "num_io"))); | 533 | (void)body.emplace_back(io_tensors.Attr("reserve")(ast_.Var("", "num_io"))); |
| @@ -537,15 +554,34 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> & | |||
| 537 | ast_.If(item.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), {report_inputs.PushBack(ast_.Var("", "_entry"))}, | 554 | ast_.If(item.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), {report_inputs.PushBack(ast_.Var("", "_entry"))}, |
| 538 | {report_outputs.PushBack(ast_.Var("", "_entry"))})})); | 555 | {report_outputs.PushBack(ast_.Var("", "_entry"))})})); |
| 539 | 556 | ||
| 557 | + auto task_info = ast_.Var("Om2TaskInfo", "task_info"); | ||
| 540 | auto args_table_info = ctx.Attr("args_table").Attr("GetArgsInfo")(kex.Attr("args_table_idx")); | 558 | auto args_table_info = ctx.Attr("args_table").Attr("GetArgsInfo")(kex.Attr("args_table_idx")); |
| 559 | + auto stream = ctx.Attr("stream_list")[kex.Attr("stream_id")]; | ||
| 560 | + (void)body.emplace_back(ast_.VarDecl(task_info)); | ||
| 561 | + (void)body.emplace_back( | ||
| 562 | + ChkStatus(ast_.Call("AssembleOm2TaskInfo", {task_info.Addr(), | ||
| 563 | + op.Arrow("op_name"), | ||
| 564 | + kex.Attr("op_type"), | ||
| 565 | + ast_.UInt(0U), | ||
| 566 | + kex.Attr("stream_id"), | ||
| 567 | + kex.Attr("block_dim"), | ||
| 568 | + ast_.UInt(0U), | ||
| 569 | + ast_.ReinterpretCast("uintptr_t", args_table_info.Arrow("dev_addr")), | ||
| 570 | + args_table_info.Arrow("size"), | ||
| 571 | + report_inputs.Data(), | ||
| 572 | + ast_.StaticCast("uint64_t", report_inputs.Size()), | ||
| 573 | + report_outputs.Data(), | ||
| 574 | + ast_.StaticCast("uint32_t", report_outputs.Size()), | ||
| 575 | + Arg(nullptr), | ||
| 576 | + Arg(nullptr), | ||
| 577 | + ast_.UInt(0U), | ||
| 578 | + kex.Attr("task_type"), | ||
| 579 | + stream, | ||
| 580 | + ast_.UInt(0U), | ||
| 581 | + ast_.UInt(0U)}))); | ||
| 541 | (void)body.emplace_back(ChkStatus( | 582 | (void)body.emplace_back(ChkStatus( |
| 542 | - ast_.Call("ReportLaunchedOm2Task", | 583 | + ast_.Call("aclrtStreamGetId", |
| 543 | - {op.Arrow("op_name"), kex.Attr("op_type"), ast_.UInt(0), | 584 | + {task_info.Attr("stream"), ast_.ReinterpretCast("int32_t *", task_info.Attr("stream_id").Addr())}))); |
| 544 | - ast_.ReinterpretCast("uintptr_t", args_table_info.Arrow("dev_addr")), args_table_info.Arrow("size"), | ||
| 545 | - report_inputs.Data(), ast_.StaticCast("uint64_t", report_inputs.Size()), report_outputs.Data(), | ||
| 546 | - ast_.StaticCast("uint32_t", report_outputs.Size()), Arg(nullptr), Arg(nullptr), ast_.UInt(0U), | ||
| 547 | - kex.Attr("task_type"), kex.Attr("block_dim"), ctx.Attr("stream_list")[kex.Attr("stream_id")], | ||
| 548 | - ctx.Attr("model_id"), ctx.Attr("instance_handle"), ast_.UInt(0U), launch_begin}))); | ||
| 549 | return SUCCESS; | 585 | return SUCCESS; |
| 550 | } | 586 | } |
| 551 | 587 | ||
| @@ -50,11 +50,10 @@ class KernelExTaskCodeBuilder : public TaskCodeBuilder { | |||
| 50 | Status RenderDispatchFunc(std::vector<DeclNode *> &items); | 50 | Status RenderDispatchFunc(std::vector<DeclNode *> &items); |
| 51 | Status RenderDispatchFuncSetup(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); | 51 | Status RenderDispatchFuncSetup(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); |
| 52 | Status RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); | 52 | Status RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); |
| 53 | - Status RenderDispatchFuncLaunchConfig(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); | 53 | + Status RenderDispatchFuncLaunchConfig(std::vector<BodyItem> &body, const VarRef &op); |
| 54 | Status RenderDispatchFuncAssembleExInfo(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); | 54 | Status RenderDispatchFuncAssembleExInfo(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); |
| 55 | Status RenderDispatchFuncLaunchTask(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); | 55 | Status RenderDispatchFuncLaunchTask(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); |
| 56 | - Status RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | 56 | + Status RenderDispatchFuncTaskInfo(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx); |
| 57 | - const VarRef &launch_begin); | ||
| 58 | static std::string SerializeBytesToOctalString(const std::vector<uint8_t> &buffer); | 57 | static std::string SerializeBytesToOctalString(const std::vector<uint8_t> &buffer); |
| 59 | Status InitIowAddrRefreshInfo(uint64_t current_offset); | 58 | Status InitIowAddrRefreshInfo(uint64_t current_offset); |
| 60 | Status InitLaunchInfo(const TaskSemanticContributeContext &context); | 59 | Status InitLaunchInfo(const TaskSemanticContributeContext &context); |
| @@ -191,24 +191,29 @@ Status DSATaskCodeBuilder::RenderDistHelper(std::vector<DeclNode *> &items) { | |||
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | FunctionDef *DSATaskCodeBuilder::RenderKernelDsaTaskDistribute() const { | 193 | FunctionDef *DSATaskCodeBuilder::RenderKernelDsaTaskDistribute() const { |
| 194 | - auto sqe = ast_.Var("const void *const", "sqe"); | 194 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo *", "launch_info"); |
| 195 | - auto sqe_len = ast_.Var("const uint32_t", "sqeLen"); | 195 | + auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); |
| 196 | - auto stream = ast_.Var("aclrtStream &", "stream"); | 196 | + auto instance_handle = ast_.Var("void *", "instance_handle"); |
| 197 | - auto flag = ast_.Var("const uint32_t", "flag"); | ||
| 198 | - | ||
| 199 | auto inputs = ast_.Var("std::array<uintptr_t, 4>", "inputs"); | 197 | auto inputs = ast_.Var("std::array<uintptr_t, 4>", "inputs"); |
| 198 | + auto launch_stars_task_params = launch_info.Arrow("launch_params").Arrow("launch_stars_task_params"); | ||
| 200 | 199 | ||
| 201 | return ast_.DefineFunction( | 200 | return ast_.DefineFunction( |
| 202 | - "KernelDsaTaskDistribute", {sqe, sqe_len, stream, flag}, "aclError", | 201 | + "KernelDsaTaskDistribute", {launch_info, launch_func, instance_handle}, "aclError", |
| 203 | { | 202 | { |
| 204 | - ast_.VarDecl(inputs, ast_.InitList({ | 203 | + ChkNotNull(launch_info), |
| 205 | - ast_.ReinterpretCast("uintptr_t", sqe), | 204 | + ast_.If( |
| 206 | - ast_.StaticCast("uintptr_t", sqe_len), | 205 | + launch_func != "nullptr", |
| 207 | - ast_.ReinterpretCast("uintptr_t", stream), | 206 | + {ast_.Call("OM2_LOGI", {ast_.Str("KernelDsaTaskDistribute: Start to execute launch callback.")}), |
| 208 | - ast_.StaticCast("uintptr_t", flag), | 207 | + ChkStatus(ast_.Call("launch_func", {instance_handle, launch_info}))}, |
| 209 | - })), | 208 | + {ast_.Call("OM2_LOGI", {ast_.Str("KernelDsaTaskDistribute: Start to execute rtGeneralCtrl directly.")}), |
| 210 | - ChkRt(RtGeneralCtrl(inputs[0].Addr(), ast_.StaticCast("uint32_t", kDSARtGeneralCtrlInputCnt), | 209 | + ast_.VarDecl(inputs, ast_.InitList({ |
| 211 | - ast_.StaticCast("uint32_t", kDSARtGeneralCtrlSubType))), | 210 | + ast_.ReinterpretCast("uintptr_t", launch_stars_task_params.Attr("task_sqe")), |
| 211 | + ast_.StaticCast("uintptr_t", launch_stars_task_params.Attr("sqe_len")), | ||
| 212 | + ast_.ReinterpretCast("uintptr_t", launch_stars_task_params.Attr("stream")), | ||
| 213 | + ast_.StaticCast("uintptr_t", launch_stars_task_params.Attr("flag")), | ||
| 214 | + })), | ||
| 215 | + ChkRt(RtGeneralCtrl(inputs[0].Addr(), ast_.StaticCast("uint32_t", kDSARtGeneralCtrlInputCnt), | ||
| 216 | + ast_.StaticCast("uint32_t", kDSARtGeneralCtrlSubType)))}), | ||
| 212 | ast_.Return("ACL_SUCCESS"), | 217 | ast_.Return("ACL_SUCCESS"), |
| 213 | }); | 218 | }); |
| 214 | } | 219 | } |
| @@ -225,10 +230,8 @@ Status DSATaskCodeBuilder::RenderDispatchFunc(std::vector<DeclNode *> &items) { | |||
| 225 | GE_ASSERT_SUCCESS(RenderSqeScalars(body, dsa_data, sqe)); | 230 | GE_ASSERT_SUCCESS(RenderSqeScalars(body, dsa_data, sqe)); |
| 226 | GE_ASSERT_SUCCESS(RenderSqeAddrFields(body, dsa_data, ctx, sqe, addrs)); | 231 | GE_ASSERT_SUCCESS(RenderSqeAddrFields(body, dsa_data, ctx, sqe, addrs)); |
| 227 | GE_ASSERT_SUCCESS(RenderHbmIoArgs(body, dsa_data, ctx, addrs)); | 232 | GE_ASSERT_SUCCESS(RenderHbmIoArgs(body, dsa_data, ctx, addrs)); |
| 228 | - auto launch_begin = ast_.Var("uint64_t", "_launch_begin"); | 233 | + GE_ASSERT_SUCCESS(RenderDispatchFuncReport(body, op, ctx, dsa_data, addrs)); |
| 229 | - (void)body.emplace_back(ast_.VarDecl(launch_begin, ast_.Call("MsprofSysCycleTime", {}))); | ||
| 230 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunch(body, op, ctx, dsa_data, sqe)); | 234 | GE_ASSERT_SUCCESS(RenderDispatchFuncLaunch(body, op, ctx, dsa_data, sqe)); |
| 231 | - GE_ASSERT_SUCCESS(RenderDispatchFuncReport(body, op, ctx, dsa_data, addrs, launch_begin)); | ||
| 232 | 235 | ||
| 233 | GE_ASSERT_SUCCESS(TaskCodeBuilderUtil::RenderDispatchFunc(ast_, kDispatchFuncName, body, items)); | 236 | GE_ASSERT_SUCCESS(TaskCodeBuilderUtil::RenderDispatchFunc(ast_, kDispatchFuncName, body, items)); |
| 234 | return SUCCESS; | 237 | return SUCCESS; |
| @@ -347,21 +350,17 @@ Status DSATaskCodeBuilder::RenderHbmIoArgs(std::vector<BodyItem> &body, const Ex | |||
| 347 | 350 | ||
| 348 | Status DSATaskCodeBuilder::RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | 351 | Status DSATaskCodeBuilder::RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, |
| 349 | const ExprRef &dsa_data, const VarRef &sqe) { | 352 | const ExprRef &dsa_data, const VarRef &sqe) { |
| 353 | + (void)dsa_data; | ||
| 354 | + (void)sqe; | ||
| 350 | (void)body.push_back(ChkRt(RtSetTaskTag(op.Arrow("op_name")))); | 355 | (void)body.push_back(ChkRt(RtSetTaskTag(op.Arrow("op_name")))); |
| 351 | - auto dd = ast_.Var("uint8_t", "dd"); | 356 | + (void)body.push_back( |
| 352 | - (void)body.push_back(ast_.VarDecl( | 357 | + ChkStatus(ast_.Call("KernelDsaTaskDistribute", |
| 353 | - dd, ast_.Call("GetIsDataDump", {op.Arrow("op_name"), ctx.Attr("model_id"), ctx.Attr("instance_handle")}))); | 358 | + {ast_.Var("", "launch_info").Addr(), ctx.Attr("launch_func"), ctx.Attr("instance_handle")}))); |
| 354 | - auto df = ast_.Var("const uint32_t", "df"); | ||
| 355 | - (void)body.push_back(ast_.VarDecl(df, ast_.StaticCast("uint32_t", dd) * ast_.UInt(2U))); | ||
| 356 | - (void)body.push_back(ChkStatus( | ||
| 357 | - ast_.Call("KernelDsaTaskDistribute", {sqe.Addr(), ast_.StaticCast("uint32_t", ast_.Sizeof("rtStarsDsaSqe_t")), | ||
| 358 | - ctx.Attr("stream_list")[dsa_data.Attr("stream_id")], df}))); | ||
| 359 | return SUCCESS; | 359 | return SUCCESS; |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | Status DSATaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | 362 | Status DSATaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, |
| 363 | - const ExprRef &dsa_data, const VarRef &addrs, | 363 | + const ExprRef &dsa_data, const VarRef &addrs) { |
| 364 | - const VarRef &launch_begin) { | ||
| 365 | auto dsa_io_tensors = ast_.Var("std::vector<gert::Tensor>", "dsa_io_tensors"); | 364 | auto dsa_io_tensors = ast_.Var("std::vector<gert::Tensor>", "dsa_io_tensors"); |
| 366 | (void)body.push_back(ast_.VarDecl(dsa_io_tensors)); | 365 | (void)body.push_back(ast_.VarDecl(dsa_io_tensors)); |
| 367 | (void)body.push_back(ast_.Call("", {dsa_io_tensors.Attr("reserve")(dsa_data.Attr("num_args"))})); | 366 | (void)body.push_back(ast_.Call("", {dsa_io_tensors.Attr("reserve")(dsa_data.Attr("num_args"))})); |
| @@ -376,8 +375,50 @@ Status DSATaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, | |||
| 376 | 375 | ||
| 377 | GE_ASSERT_SUCCESS(RenderDispatchFuncReportIo(body, dsa_data, addrs, dsa_io_tensors, dsa_report_inputs, | 376 | GE_ASSERT_SUCCESS(RenderDispatchFuncReportIo(body, dsa_data, addrs, dsa_io_tensors, dsa_report_inputs, |
| 378 | dsa_report_outputs, dsa_report_ws_addrs, dsa_report_ws_sizes)); | 377 | dsa_report_outputs, dsa_report_ws_addrs, dsa_report_ws_sizes)); |
| 379 | - GE_ASSERT_SUCCESS(RenderDispatchFuncReportSubmit(body, op, ctx, dsa_data, dsa_report_inputs, dsa_report_outputs, | 378 | + auto hbm_ai = ast_.Var("ArgsInfo *", "hbm_ai"); |
| 380 | - dsa_report_ws_addrs, dsa_report_ws_sizes, launch_begin)); | 379 | + (void)body.push_back( |
| 380 | + ast_.VarDecl(hbm_ai, ctx.Attr("args_table").Attr("GetArgsInfo")(dsa_data.Attr("hbm_table_index")))); | ||
| 381 | + auto task_info = ast_.Var("Om2TaskInfo", "task_info"); | ||
| 382 | + (void)body.push_back(ast_.VarDecl(task_info)); | ||
| 383 | + (void)body.push_back( | ||
| 384 | + ChkStatus(ast_.Call("AssembleOm2TaskInfo", {task_info.Addr(), | ||
| 385 | + op.Arrow("op_name"), | ||
| 386 | + dsa_data.Attr("op_type"), | ||
| 387 | + ast_.UInt(0U), | ||
| 388 | + dsa_data.Attr("stream_id"), | ||
| 389 | + ast_.UInt(0U), | ||
| 390 | + dsa_data.Attr("op_desc_id"), | ||
| 391 | + ast_.ReinterpretCast("uintptr_t", hbm_ai.Arrow("dev_addr")), | ||
| 392 | + dsa_data.Attr("hbm_args_size"), | ||
| 393 | + dsa_report_inputs.Data(), | ||
| 394 | + ast_.StaticCast("uint64_t", dsa_report_inputs.Size()), | ||
| 395 | + dsa_report_outputs.Data(), | ||
| 396 | + ast_.StaticCast("uint32_t", dsa_report_outputs.Size()), | ||
| 397 | + dsa_report_ws_addrs.Data(), | ||
| 398 | + dsa_report_ws_sizes.Data(), | ||
| 399 | + ast_.StaticCast("uint32_t", dsa_report_ws_addrs.Size()), | ||
| 400 | + dsa_data.Attr("task_type"), | ||
| 401 | + ctx.Attr("stream_list")[dsa_data.Attr("stream_id")], | ||
| 402 | + ast_.UInt(1U), | ||
| 403 | + ast_.UInt(0U)}))); | ||
| 404 | + (void)body.push_back(ChkStatus( | ||
| 405 | + ast_.Call("aclrtStreamGetId", | ||
| 406 | + {task_info.Attr("stream"), ast_.ReinterpretCast("int32_t *", task_info.Attr("stream_id").Addr())}))); | ||
| 407 | + auto launch_stars_task_params = ast_.Var("GertModelLaunchStarsTaskWithFlagParams", "launch_stars_task_params"); | ||
| 408 | + (void)body.push_back( | ||
| 409 | + ast_.VarDecl(launch_stars_task_params, | ||
| 410 | + ast_.DesignatedInit({{"task_sqe", ast_.ReinterpretCast("const void *", ast_.Var("", "sqe").Addr())}, | ||
| 411 | + {"sqe_len", ast_.StaticCast("uint32_t", ast_.Sizeof("rtStarsDsaSqe_t"))}, | ||
| 412 | + {"stream", ctx.Attr("stream_list")[dsa_data.Attr("stream_id")]}, | ||
| 413 | + {"flag", ast_.UInt(0U)}}))); | ||
| 414 | + auto launch_params = ast_.Var("GertModelTaskLaunchParams", "launch_params"); | ||
| 415 | + (void)body.push_back( | ||
| 416 | + ast_.VarDecl(launch_params, ast_.DesignatedInit({{"launch_stars_task_params", launch_stars_task_params}}))); | ||
| 417 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "launch_info"); | ||
| 418 | + (void)body.push_back( | ||
| 419 | + ast_.VarDecl(launch_info, ast_.DesignatedInit({{"launch_type", ast_.Var("", "RT_STARS_TASK_LAUNCH_WITH_FLAG")}, | ||
| 420 | + {"task_info", task_info.Addr()}, | ||
| 421 | + {"launch_params", launch_params.Addr()}}))); | ||
| 381 | return SUCCESS; | 422 | return SUCCESS; |
| 382 | } | 423 | } |
| 383 | 424 | ||
| @@ -423,25 +464,6 @@ Status DSATaskCodeBuilder::RenderDispatchFuncReportIo(std::vector<BodyItem> &bod | |||
| 423 | return SUCCESS; | 464 | return SUCCESS; |
| 424 | } | 465 | } |
| 425 | 466 | ||
| 426 | -Status DSATaskCodeBuilder::RenderDispatchFuncReportSubmit( | ||
| 427 | - std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, const ExprRef &dsa_data, | ||
| 428 | - const VarRef &dsa_report_inputs, const VarRef &dsa_report_outputs, const VarRef &dsa_report_ws_addrs, | ||
| 429 | - const VarRef &dsa_report_ws_sizes, const VarRef &launch_begin) const { | ||
| 430 | - auto hbm_ai = ast_.Var("ArgsInfo *", "hbm_ai"); | ||
| 431 | - (void)body.push_back( | ||
| 432 | - ast_.VarDecl(hbm_ai, ctx.Attr("args_table").Attr("GetArgsInfo")(dsa_data.Attr("hbm_table_index")))); | ||
| 433 | - (void)body.push_back(ChkStatus(ast_.Call( | ||
| 434 | - "ReportLaunchedOm2Task", | ||
| 435 | - {op.Arrow("op_name"), dsa_data.Attr("op_type"), dsa_data.Attr("op_desc_id"), | ||
| 436 | - ast_.ReinterpretCast("uintptr_t", hbm_ai.Arrow("dev_addr")), dsa_data.Attr("hbm_args_size"), | ||
| 437 | - dsa_report_inputs.Data(), ast_.StaticCast("uint64_t", dsa_report_inputs.Size()), dsa_report_outputs.Data(), | ||
| 438 | - ast_.StaticCast("uint32_t", dsa_report_outputs.Size()), dsa_report_ws_addrs.Data(), dsa_report_ws_sizes.Data(), | ||
| 439 | - ast_.StaticCast("uint32_t", dsa_report_ws_sizes.Size()), dsa_data.Attr("task_type"), ast_.UInt(0U), | ||
| 440 | - ctx.Attr("stream_list")[dsa_data.Attr("stream_id")], ctx.Attr("model_id"), ctx.Attr("instance_handle"), | ||
| 441 | - ast_.UInt(1U), launch_begin}))); | ||
| 442 | - return SUCCESS; | ||
| 443 | -} | ||
| 444 | - | ||
| 445 | Status DSATaskCodeBuilder::RenderOpDefTableFields(std::vector<std::pair<std::string, Arg>> &fields) { | 467 | Status DSATaskCodeBuilder::RenderOpDefTableFields(std::vector<std::pair<std::string, Arg>> &fields) { |
| 446 | fields.push_back({"dispatch_type", ast_.StaticCast("OpDispatchType", static_cast<int64_t>(kDispatchType))}); | 468 | fields.push_back({"dispatch_type", ast_.StaticCast("OpDispatchType", static_cast<int64_t>(kDispatchType))}); |
| 447 | fields.push_back({"op_name", Arg::StringLiteral(header_.op_name)}); | 469 | fields.push_back({"op_name", Arg::StringLiteral(header_.op_name)}); |
| @@ -73,16 +73,11 @@ class DSATaskCodeBuilder : public TaskCodeBuilder { | |||
| 73 | Status RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | 73 | Status RenderDispatchFuncLaunch(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, |
| 74 | const ExprRef &dsa_data, const VarRef &sqe); | 74 | const ExprRef &dsa_data, const VarRef &sqe); |
| 75 | Status RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | 75 | Status RenderDispatchFuncReport(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, |
| 76 | - const ExprRef &dsa_data, const VarRef &addrs, const VarRef &launch_begin); | 76 | + const ExprRef &dsa_data, const VarRef &addrs); |
| 77 | Status RenderDispatchFuncReportIo(std::vector<BodyItem> &body, const ExprRef &dsa_data, const VarRef &addrs, | 77 | Status RenderDispatchFuncReportIo(std::vector<BodyItem> &body, const ExprRef &dsa_data, const VarRef &addrs, |
| 78 | const VarRef &dsa_io_tensors, const VarRef &dsa_report_inputs, | 78 | const VarRef &dsa_io_tensors, const VarRef &dsa_report_inputs, |
| 79 | const VarRef &dsa_report_outputs, const VarRef &dsa_report_ws_addrs, | 79 | const VarRef &dsa_report_outputs, const VarRef &dsa_report_ws_addrs, |
| 80 | const VarRef &dsa_report_ws_sizes); | 80 | const VarRef &dsa_report_ws_sizes); |
| 81 | - Status RenderDispatchFuncReportSubmit(std::vector<BodyItem> &body, const VarRef &op, const VarRef &ctx, | ||
| 82 | - const ExprRef &dsa_data, const VarRef &dsa_report_inputs, | ||
| 83 | - const VarRef &dsa_report_outputs, const VarRef &dsa_report_ws_addrs, | ||
| 84 | - const VarRef &dsa_report_ws_sizes, const VarRef &launch_begin) const; | ||
| 85 | - | ||
| 86 | // Address semantics | 81 | // Address semantics |
| 87 | std::vector<AddrSemantic> input_addrs_; | 82 | std::vector<AddrSemantic> input_addrs_; |
| 88 | std::vector<AddrSemantic> output_addrs_; | 83 | std::vector<AddrSemantic> output_addrs_; |
| @@ -182,6 +182,7 @@ void KernelTaskCodeBuilder::HandleShapeInfoBufferArg(const AddrSemantic &addr, u | |||
| 182 | 182 | ||
| 183 | AicoreTaskData KernelTaskCodeBuilder::BuildAicoreTaskData() const { | 183 | AicoreTaskData KernelTaskCodeBuilder::BuildAicoreTaskData() const { |
| 184 | AicoreTaskData aicore; | 184 | AicoreTaskData aicore; |
| 185 | + aicore.kernel_type = static_cast<uint32_t>(build_data_.semantic.kernel_type); | ||
| 185 | aicore.engine_type = ConvertEngineType(build_data_.semantic.launch.config.engine_type); | 186 | aicore.engine_type = ConvertEngineType(build_data_.semantic.launch.config.engine_type); |
| 186 | aicore.need_assert_or_printf = op_need_assert_or_printf_ ? 1U : 0U; | 187 | aicore.need_assert_or_printf = op_need_assert_or_printf_ ? 1U : 0U; |
| 187 | GELOGI("[OM2] GetOpDefBuildData: op=%s, func_idx=%u", header_.op_name.c_str(), | 188 | GELOGI("[OM2] GetOpDefBuildData: op=%s, func_idx=%u", header_.op_name.c_str(), |
| @@ -191,6 +192,7 @@ AicoreTaskData KernelTaskCodeBuilder::BuildAicoreTaskData() const { | |||
| 191 | 192 | ||
| 192 | AicpuTaskData KernelTaskCodeBuilder::BuildAicpuTaskData() const { | 193 | AicpuTaskData KernelTaskCodeBuilder::BuildAicpuTaskData() const { |
| 193 | AicpuTaskData aicpu; | 194 | AicpuTaskData aicpu; |
| 195 | + aicpu.kernel_type = static_cast<uint32_t>(build_data_.semantic.kernel_type); | ||
| 194 | aicpu.engine_type = ConvertEngineType(build_data_.semantic.launch.config.engine_type); | 196 | aicpu.engine_type = ConvertEngineType(build_data_.semantic.launch.config.engine_type); |
| 195 | GELOGI("[OM2] GetOpDefBuildData: op=%s (AICPU), func_idx=%u", header_.op_name.c_str(), | 197 | GELOGI("[OM2] GetOpDefBuildData: op=%s (AICPU), func_idx=%u", header_.op_name.c_str(), |
| 196 | build_data_.semantic.launch.func_handle_index); | 198 | build_data_.semantic.launch.func_handle_index); |
| @@ -631,22 +633,29 @@ Status KernelTaskCodeBuilder::RenderDistHelper(std::vector<DeclNode *> &items) { | |||
| 631 | } | 633 | } |
| 632 | 634 | ||
| 633 | FunctionDef *KernelTaskCodeBuilder::RenderKernelTaskDistribute() const { | 635 | FunctionDef *KernelTaskCodeBuilder::RenderKernelTaskDistribute() const { |
| 634 | - auto io_addrs = ast_.Var("const std::vector<uint64_t> &", "io_addrs"); | 636 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo *", "launch_info"); |
| 637 | + auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); | ||
| 638 | + auto instance_handle = ast_.Var("void *", "instance_handle"); | ||
| 635 | auto args_info = ast_.Var("ArgsInfo *", "args_info"); | 639 | auto args_info = ast_.Var("ArgsInfo *", "args_info"); |
| 636 | - auto func_handle = ast_.Var("aclrtFuncHandle", "func_handle"); | 640 | + auto io_addrs = ast_.Var("const std::vector<uint64_t> &", "io_addrs"); |
| 637 | - auto block_dim = ast_.Var("uint32_t", "block_dim"); | 641 | + auto kernel_params = launch_info.Arrow("launch_params").Arrow("launch_kernel_v2_params"); |
| 638 | - auto stream = ast_.Var("aclrtStream", "stream"); | 642 | + return ast_.DefineFunction( |
| 639 | - auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); | 643 | + "KernelTaskDistribute", {launch_info, launch_func, instance_handle, args_info, io_addrs}, "aclError", |
| 640 | - return ast_.DefineFunction("KernelTaskDistribute", {io_addrs, args_info, func_handle, block_dim, stream, config}, | 644 | + { |
| 641 | - "aclError", | 645 | + ChkNotNull(launch_info), |
| 642 | - { | 646 | + ChkNotNull(args_info), |
| 643 | - ChkNotNull(args_info), | 647 | + ast_.If(launch_func != "nullptr", |
| 644 | - ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), | 648 | + {ast_.Call("OM2_LOGI", {ast_.Str("KernelTaskDistribute: Start to execute launch callback.")}), |
| 645 | - io_addrs.Data(), io_addrs.Size() * ast_.Sizeof("uint64_t"))), | 649 | + ChkStatus(ast_.Call("launch_func", {instance_handle, launch_info}))}, |
| 646 | - ChkStatus(AclrtLaunchKernelV2(func_handle, block_dim, args_info.Arrow("dev_addr"), | 650 | + {ast_.Call("OM2_LOGI", |
| 647 | - args_info.Arrow("size"), config, stream)), | 651 | + {ast_.Str("KernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly.")}), |
| 648 | - ast_.Return("ACL_SUCCESS"), | 652 | + ChkStatus(AclrtLaunchKernelV2(kernel_params.Attr("func_handle"), kernel_params.Attr("block_dim"), |
| 649 | - }); | 653 | + kernel_params.Attr("args_data"), kernel_params.Attr("args_size"), |
| 654 | + kernel_params.Attr("config"), kernel_params.Attr("stream")))}), | ||
| 655 | + ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), io_addrs.Data(), | ||
| 656 | + io_addrs.Size() * ast_.Sizeof("uint64_t"))), | ||
| 657 | + ast_.Return("ACL_SUCCESS"), | ||
| 658 | + }); | ||
| 650 | } | 659 | } |
| 651 | 660 | ||
| 652 | FunctionDef *KernelTaskCodeBuilder::RenderUpdateExtInfoSession() const { | 661 | FunctionDef *KernelTaskCodeBuilder::RenderUpdateExtInfoSession() const { |
| @@ -728,17 +737,24 @@ FunctionDef *KernelTaskCodeBuilder::RenderAssembleAicpuArgs() const { | |||
| 728 | FunctionDef *KernelTaskCodeBuilder::RenderAicpuKernelTaskDistribute() const { | 737 | FunctionDef *KernelTaskCodeBuilder::RenderAicpuKernelTaskDistribute() const { |
| 729 | auto args = ast_.Var("const std::vector<uint8_t> &", "args"); | 738 | auto args = ast_.Var("const std::vector<uint8_t> &", "args"); |
| 730 | auto args_info = ast_.Var("ArgsInfo *", "args_info"); | 739 | auto args_info = ast_.Var("ArgsInfo *", "args_info"); |
| 731 | - auto func_handle = ast_.Var("aclrtFuncHandle", "func_handle"); | 740 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo *", "launch_info"); |
| 732 | - auto block_dim = ast_.Var("uint32_t", "block_dim"); | 741 | + auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); |
| 733 | - auto stream = ast_.Var("aclrtStream", "stream"); | 742 | + auto instance_handle = ast_.Var("void *", "instance_handle"); |
| 734 | - auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); | 743 | + auto kernel_params = launch_info.Arrow("launch_params").Arrow("launch_kernel_v2_params"); |
| 735 | return ast_.DefineFunction( | 744 | return ast_.DefineFunction( |
| 736 | - "AicpuKernelTaskDistribute", {args, args_info, func_handle, block_dim, stream, config}, "aclError", | 745 | + "AicpuKernelTaskDistribute", {args, args_info, launch_info, launch_func, instance_handle}, "aclError", |
| 737 | { | 746 | { |
| 738 | ChkNotNull(args_info), | 747 | ChkNotNull(args_info), |
| 748 | + ChkNotNull(launch_info), | ||
| 749 | + ast_.If(launch_func != "nullptr", | ||
| 750 | + {ast_.Call("OM2_LOGI", {ast_.Str("AicpuKernelTaskDistribute: Start to execute launch callback.")}), | ||
| 751 | + ChkStatus(ast_.Call("launch_func", {instance_handle, launch_info}))}, | ||
| 752 | + {ast_.Call("OM2_LOGI", | ||
| 753 | + {ast_.Str("AicpuKernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly.")}), | ||
| 754 | + ChkStatus(AclrtLaunchKernelV2(kernel_params.Attr("func_handle"), kernel_params.Attr("block_dim"), | ||
| 755 | + kernel_params.Attr("args_data"), kernel_params.Attr("args_size"), | ||
| 756 | + kernel_params.Attr("config"), kernel_params.Attr("stream")))}), | ||
| 739 | ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), args.Data(), args.Size())), | 757 | ChkStatus(MemcpyS(args_info.Arrow("host_addr"), args_info.Arrow("size"), args.Data(), args.Size())), |
| 740 | - ChkStatus(AclrtLaunchKernelV2(func_handle, block_dim, args_info.Arrow("dev_addr"), args_info.Arrow("size"), | ||
| 741 | - config, stream)), | ||
| 742 | ast_.Return("ACL_SUCCESS"), | 758 | ast_.Return("ACL_SUCCESS"), |
| 743 | }); | 759 | }); |
| 744 | } | 760 | } |
| @@ -1556,18 +1572,17 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuDispatchSetup(const VarR | |||
| 1556 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndAssemble(const VarRef &op, const VarRef &ctx) { | 1572 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndAssemble(const VarRef &op, const VarRef &ctx) { |
| 1557 | return { | 1573 | return { |
| 1558 | ast_.VarDecl(ast_.Var("LaunchKernelCfgHolder", "aicpu_cfg_holder")), | 1574 | ast_.VarDecl(ast_.Var("LaunchKernelCfgHolder", "aicpu_cfg_holder")), |
| 1559 | - ast_.VarDecl( | 1575 | + ast_.VarDecl(ast_.Var("LaunchKernelConfig", "aicpu_launch_config"), |
| 1560 | - ast_.Var("LaunchKernelConfig", "aicpu_launch_config"), | 1576 | + ast_.InitList({ |
| 1561 | - ast_.InitList({ | 1577 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("schedule_mode"), |
| 1562 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("schedule_mode"), | 1578 | + ast_.StaticCast("aclrtEngineType", |
| 1563 | - ast_.StaticCast("aclrtEngineType", | 1579 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("engine_type")), |
| 1564 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("engine_type")), | 1580 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("block_dim_offset"), |
| 1565 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("block_dim_offset"), | 1581 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("is_block_task_prefetch"), |
| 1566 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("is_block_task_prefetch"), | 1582 | + false, |
| 1567 | - ast_.Call("GetIsDataDump", {op.Arrow("op_name"), ctx.Attr("model_id"), ctx.Attr("instance_handle")}), | 1583 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("time_out"), |
| 1568 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("time_out"), | 1584 | + op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("local_memory_size"), |
| 1569 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("launch").Attr("local_memory_size"), | 1585 | + })), |
| 1570 | - })), | ||
| 1571 | ChkStatus( | 1586 | ChkStatus( |
| 1572 | ast_.Call("AssembleLaunchConfig", {ast_.Var("", "aicpu_cfg_holder"), ast_.Var("", "aicpu_launch_config")})), | 1587 | ast_.Call("AssembleLaunchConfig", {ast_.Var("", "aicpu_cfg_holder"), ast_.Var("", "aicpu_launch_config")})), |
| 1573 | ast_.VarDecl(ast_.Var("uint64_t", "local_session_id"), ast_.Deref(ctx.Attr("session_id"))), | 1588 | ast_.VarDecl(ast_.Var("uint64_t", "local_session_id"), ast_.Deref(ctx.Attr("session_id"))), |
| @@ -1587,46 +1602,71 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndAssemble(const | |||
| 1587 | } | 1602 | } |
| 1588 | 1603 | ||
| 1589 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndReport(const VarRef &op, const VarRef &ctx) { | 1604 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndReport(const VarRef &op, const VarRef &ctx) { |
| 1605 | + auto aicpu = op.Arrow("dispatch_info").Attr("aicpu"); | ||
| 1606 | + auto args_info = ast_.Var("ArgsInfo *", "aicpu_args_info"); | ||
| 1607 | + auto stream = ctx.Attr("stream_list")[aicpu.Attr("stream_id")]; | ||
| 1608 | + auto task_info = ast_.Var("Om2TaskInfo", "aicpu_task_info"); | ||
| 1609 | + auto launch_kernel_v2_params = ast_.Var("GertModelLaunchKernelV2Params", "aicpu_launch_kernel_v2_params"); | ||
| 1610 | + auto launch_params = ast_.Var("GertModelTaskLaunchParams", "aicpu_launch_params"); | ||
| 1611 | + auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "aicpu_launch_info"); | ||
| 1590 | return { | 1612 | return { |
| 1591 | - ast_.VarDecl(ast_.Var("ArgsInfo *", "aicpu_args_info"), | 1613 | + ast_.VarDecl(args_info, ctx.Attr("args_table").Attr("GetArgsInfo")(ast_.Var("", "aicpu_args_idx"))), |
| 1592 | - ctx.Attr("args_table").Attr("GetArgsInfo")(ast_.Var("", "aicpu_args_idx"))), | 1614 | + ast_.VarDecl(task_info), |
| 1593 | - ast_.VarDecl(ast_.Var("uint64_t", "_launch_begin"), ast_.Call("MsprofSysCycleTime", {})), | 1615 | + ChkStatus( |
| 1616 | + ast_.Call("AssembleOm2TaskInfo", {task_info.Addr(), | ||
| 1617 | + op.Arrow("op_name"), | ||
| 1618 | + aicpu.Attr("op_type"), | ||
| 1619 | + ast_.UInt(0U), | ||
| 1620 | + aicpu.Attr("stream_id"), | ||
| 1621 | + aicpu.Attr("block_dim"), | ||
| 1622 | + ast_.UInt(0U), | ||
| 1623 | + ast_.ReinterpretCast("uintptr_t", args_info.Arrow("dev_addr")), | ||
| 1624 | + args_info.Arrow("size"), | ||
| 1625 | + ast_.Var("", "aicpu_report_inputs").Data(), | ||
| 1626 | + ast_.StaticCast("uint64_t", ast_.Var("", "aicpu_report_inputs").Size()), | ||
| 1627 | + ast_.Var("", "aicpu_report_outputs").Data(), | ||
| 1628 | + ast_.StaticCast("uint32_t", ast_.Var("", "aicpu_report_outputs").Size()), | ||
| 1629 | + Arg(nullptr), | ||
| 1630 | + Arg(nullptr), | ||
| 1631 | + ast_.UInt(0U), | ||
| 1632 | + aicpu.Attr("task_type"), | ||
| 1633 | + stream, | ||
| 1634 | + ast_.UInt(0U), | ||
| 1635 | + ast_.UInt(0U)})), | ||
| 1636 | + ChkStatus(ast_.Call("aclrtStreamGetId", {task_info.Attr("stream"), | ||
| 1637 | + ast_.ReinterpretCast("int32_t *", task_info.Attr("stream_id").Addr())})), | ||
| 1638 | + ast_.Assign(task_info.Attr("kernel_type"), aicpu.Attr("kernel_type")), | ||
| 1639 | + ast_.VarDecl(launch_kernel_v2_params, | ||
| 1640 | + ast_.DesignatedInit({{"func_handle", ctx.Attr("func_handles")[aicpu.Attr("func_idx")]}, | ||
| 1641 | + {"block_dim", aicpu.Attr("block_dim")}, | ||
| 1642 | + {"args_data", args_info.Arrow("dev_addr")}, | ||
| 1643 | + {"args_size", args_info.Arrow("size")}, | ||
| 1644 | + {"config", ast_.Var("", "aicpu_cfg_holder").Attr("cfg").Addr()}, | ||
| 1645 | + {"stream", stream}})), | ||
| 1646 | + ast_.VarDecl(launch_params, ast_.DesignatedInit({{"launch_kernel_v2_params", launch_kernel_v2_params}})), | ||
| 1647 | + ast_.VarDecl(launch_info, ast_.DesignatedInit({{"launch_type", ast_.Var("", "ACL_RT_LAUNCH_KERNEL_V2")}, | ||
| 1648 | + {"task_info", task_info.Addr()}, | ||
| 1649 | + {"launch_params", launch_params.Addr()}})), | ||
| 1594 | ChkStatus(ast_.Call("AicpuKernelTaskDistribute", | 1650 | ChkStatus(ast_.Call("AicpuKernelTaskDistribute", |
| 1595 | - {ast_.Var("", "aicpu_args_var"), ast_.Var("", "aicpu_args_info"), | 1651 | + {ast_.Var("", "aicpu_args_var"), args_info, ast_.Var("", "aicpu_launch_info").Addr(), |
| 1596 | - ctx.Attr("func_handles")[op.Arrow("dispatch_info").Attr("aicpu").Attr("func_idx")], | 1652 | + ctx.Attr("launch_func"), ctx.Attr("instance_handle")})), |
| 1597 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("block_dim"), | ||
| 1598 | - ctx.Attr("stream_list")[op.Arrow("dispatch_info").Attr("aicpu").Attr("stream_id")], | ||
| 1599 | - ast_.Var("", "aicpu_cfg_holder").Attr("cfg").Addr()})), | ||
| 1600 | - ChkStatus(ast_.Call( | ||
| 1601 | - "ReportLaunchedOm2Task", | ||
| 1602 | - {op.Arrow("op_name"), op.Arrow("dispatch_info").Attr("aicpu").Attr("op_type"), ast_.UInt(0), | ||
| 1603 | - ast_.ReinterpretCast("uintptr_t", ast_.Var("", "aicpu_args_info").Arrow("dev_addr")), | ||
| 1604 | - ast_.Var("", "aicpu_args_info").Arrow("size"), ast_.Var("", "aicpu_report_inputs").Data(), | ||
| 1605 | - ast_.StaticCast("uint64_t", ast_.Var("", "aicpu_report_inputs").Size()), | ||
| 1606 | - ast_.Var("", "aicpu_report_outputs").Data(), | ||
| 1607 | - ast_.StaticCast("uint32_t", ast_.Var("", "aicpu_report_outputs").Size()), Arg(nullptr), Arg(nullptr), | ||
| 1608 | - ast_.UInt(0U), op.Arrow("dispatch_info").Attr("aicpu").Attr("task_type"), | ||
| 1609 | - op.Arrow("dispatch_info").Attr("aicpu").Attr("block_dim"), | ||
| 1610 | - ctx.Attr("stream_list")[op.Arrow("dispatch_info").Attr("aicpu").Attr("stream_id")], ctx.Attr("model_id"), | ||
| 1611 | - ctx.Attr("instance_handle"), ast_.UInt(0U), ast_.Var("uint64_t", "_launch_begin")})), | ||
| 1612 | }; | 1653 | }; |
| 1613 | } | 1654 | } |
| 1614 | 1655 | ||
| 1615 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderDispatchSetup(const VarRef &op, const VarRef &ctx) { | 1656 | std::vector<BodyItem> KernelTaskCodeBuilder::RenderDispatchSetup(const VarRef &op, const VarRef &ctx) { |
| 1616 | return { | 1657 | return { |
| 1617 | ast_.VarDecl(ast_.Var("LaunchKernelCfgHolder", "cfg_holder")), | 1658 | ast_.VarDecl(ast_.Var("LaunchKernelCfgHolder", "cfg_holder")), |
| 1618 | - ast_.VarDecl( | 1659 | + ast_.VarDecl(ast_.Var("LaunchKernelConfig", "launch_config"), |
| 1619 | - ast_.Var("LaunchKernelConfig", "launch_config"), | 1660 | + ast_.InitList({ |
| 1620 | - ast_.InitList({ | 1661 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("schedule_mode"), |
| 1621 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("schedule_mode"), | 1662 | + ast_.StaticCast("aclrtEngineType", |
| 1622 | - ast_.StaticCast("aclrtEngineType", | 1663 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("engine_type")), |
| 1623 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("engine_type")), | 1664 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("block_dim_offset"), |
| 1624 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("block_dim_offset"), | 1665 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("is_block_task_prefetch"), |
| 1625 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("is_block_task_prefetch"), | 1666 | + false, |
| 1626 | - ast_.Call("GetIsDataDump", {op.Arrow("op_name"), ctx.Attr("model_id"), ctx.Attr("instance_handle")}), | 1667 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("time_out"), |
| 1627 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("time_out"), | 1668 | + op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("local_memory_size"), |
| 1628 | - op.Arrow("dispatch_info").Attr("aicore").Attr("launch").Attr("local_memory_size"), | 1669 | + })), |
| 1629 | - })), | ||
| 1630 | ChkStatus(ast_.Call("AssembleLaunchConfig", {ast_.Var("", "cfg_holder"), ast_.Var("", "launch_config")})), | 1670 | ChkStatus(ast_.Call("AssembleLaunchConfig", {ast_.Var("", "cfg_holder"), ast_.Var("", "launch_config")})), |
| 1631 | ast_.VarDecl( | 1671 | ast_.VarDecl( |
| 1632 | ast_.Var("ArgsInfo *", "args_info"), | 1672 | ast_.Var("ArgsInfo *", "args_info"), |
| @@ -1706,23 +1746,15 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderDistribution(const VarRef &op | |||
| 1706 | ast_.Var("Om2L0TaskRawInfo", "l0_info"), | 1746 | ast_.Var("Om2L0TaskRawInfo", "l0_info"), |
| 1707 | ast_.InitList({ast_.UInt(1U), slot_args.Attr("need_assert_or_printf"), | 1747 | ast_.InitList({ast_.UInt(1U), slot_args.Attr("need_assert_or_printf"), |
| 1708 | ast_.StaticCast("uint64_t", slot_args.Attr("slots_num")), slot_args.Attr("slot_info")})), | 1748 | ast_.StaticCast("uint64_t", slot_args.Attr("slots_num")), slot_args.Attr("slot_info")})), |
| 1709 | - ChkStatus(ast_.Call("ReportOm2TaskPreprocess", | 1749 | + ast_.VarDecl(ast_.Var("Om2TaskInfo", "task_info")), |
| 1710 | - {op.Arrow("op_name"), aicore.Attr("op_type"), | 1750 | + ChkStatus(ast_.Call("AssembleOm2TaskInfo", |
| 1711 | - ast_.UInt(0), // op_desc_id | 1751 | + {ast_.Var("", "task_info").Addr(), |
| 1712 | - ast_.ReinterpretCast("uintptr_t", ast_.Var("", "args_info").Arrow("dev_addr")), | 1752 | + op.Arrow("op_name"), |
| 1713 | - ast_.Var("", "args_info").Arrow("size"), ast_.Var("", "report_inputs"), | ||
| 1714 | - ast_.Var("", "report_outputs"), ast_.Var("", "report_workspace_addrs"), | ||
| 1715 | - ast_.Var("", "report_workspace_sizes"), task_type, aicore.Attr("block_dim"), stream, | ||
| 1716 | - ast_.Var("", "l0_info").Addr(), ctx.Attr("model_id"), ctx.Attr("instance_handle")})), | ||
| 1717 | - ast_.VarDecl(ast_.Var("uint64_t", "_launch_begin"), ast_.Call("MsprofSysCycleTime", {})), | ||
| 1718 | - ChkStatus(ast_.Call("KernelTaskDistribute", | ||
| 1719 | - {ast_.Var("", "ordered_io_addrs"), ast_.Var("", "args_info"), | ||
| 1720 | - ctx.Attr("func_handles")[aicore.Attr("func_idx")], aicore.Attr("block_dim"), stream, | ||
| 1721 | - ast_.Var("", "cfg_holder").Attr("cfg").Addr()})), | ||
| 1722 | - ChkStatus(ast_.Call("ReportLaunchedOm2Task", | ||
| 1723 | - {op.Arrow("op_name"), | ||
| 1724 | aicore.Attr("op_type"), | 1753 | aicore.Attr("op_type"), |
| 1725 | - ast_.UInt(0), // op_desc_id | 1754 | + ast_.UInt(0U), |
| 1755 | + aicore.Attr("stream_id"), | ||
| 1756 | + aicore.Attr("block_dim"), | ||
| 1757 | + ast_.UInt(0U), | ||
| 1726 | ast_.ReinterpretCast("uintptr_t", ast_.Var("", "args_info").Arrow("dev_addr")), | 1758 | ast_.ReinterpretCast("uintptr_t", ast_.Var("", "args_info").Arrow("dev_addr")), |
| 1727 | ast_.Var("", "args_info").Arrow("size"), | 1759 | ast_.Var("", "args_info").Arrow("size"), |
| 1728 | ast_.Var("", "report_inputs").Data(), | 1760 | ast_.Var("", "report_inputs").Data(), |
| @@ -1731,19 +1763,37 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderDistribution(const VarRef &op | |||
| 1731 | ast_.StaticCast("uint32_t", ast_.Var("", "report_outputs").Size()), | 1763 | ast_.StaticCast("uint32_t", ast_.Var("", "report_outputs").Size()), |
| 1732 | ast_.Var("", "report_workspace_addrs").Data(), | 1764 | ast_.Var("", "report_workspace_addrs").Data(), |
| 1733 | ast_.Var("", "report_workspace_sizes").Data(), | 1765 | ast_.Var("", "report_workspace_sizes").Data(), |
| 1734 | - ast_.StaticCast("uint32_t", ast_.Var("", "report_workspace_sizes").Size()), | 1766 | + ast_.StaticCast("uint32_t", ast_.Var("", "report_workspace_addrs").Size()), |
| 1735 | task_type, | 1767 | task_type, |
| 1736 | - aicore.Attr("block_dim"), | ||
| 1737 | stream, | 1768 | stream, |
| 1738 | - ctx.Attr("model_id"), | ||
| 1739 | - ctx.Attr("instance_handle"), | ||
| 1740 | ast_.UInt(0U), | 1769 | ast_.UInt(0U), |
| 1741 | - ast_.Var("uint64_t", "_launch_begin"), | 1770 | + ast_.UInt(0U), |
| 1742 | aicore.Attr("fusion_op").Attr("original_op_names"), | 1771 | aicore.Attr("fusion_op").Attr("original_op_names"), |
| 1743 | aicore.Attr("fusion_op").Attr("input_mem_size"), | 1772 | aicore.Attr("fusion_op").Attr("input_mem_size"), |
| 1744 | aicore.Attr("fusion_op").Attr("output_mem_size"), | 1773 | aicore.Attr("fusion_op").Attr("output_mem_size"), |
| 1745 | aicore.Attr("fusion_op").Attr("workspace_mem_size"), | 1774 | aicore.Attr("fusion_op").Attr("workspace_mem_size"), |
| 1746 | aicore.Attr("fusion_op").Attr("weight_mem_size")})), | 1775 | aicore.Attr("fusion_op").Attr("weight_mem_size")})), |
| 1776 | + ChkStatus(ast_.Call("aclrtStreamGetId", | ||
| 1777 | + {ast_.Var("", "task_info").Attr("stream"), | ||
| 1778 | + ast_.ReinterpretCast("int32_t *", ast_.Var("", "task_info").Attr("stream_id").Addr())})), | ||
| 1779 | + ast_.Assign(ast_.Var("", "task_info").Attr("kernel_type"), aicore.Attr("kernel_type")), | ||
| 1780 | + ast_.Assign(ast_.Var("", "task_info").Attr("l0_exception_dump_info"), ast_.Var("", "l0_info").Addr()), | ||
| 1781 | + ast_.VarDecl(ast_.Var("GertModelLaunchKernelV2Params", "kernel_params"), | ||
| 1782 | + ast_.DesignatedInit({{"func_handle", ctx.Attr("func_handles")[aicore.Attr("func_idx")]}, | ||
| 1783 | + {"block_dim", aicore.Attr("block_dim")}, | ||
| 1784 | + {"args_data", ast_.Var("", "args_info").Arrow("dev_addr")}, | ||
| 1785 | + {"args_size", ast_.Var("", "args_info").Arrow("size")}, | ||
| 1786 | + {"config", ast_.Var("", "cfg_holder").Attr("cfg").Addr()}, | ||
| 1787 | + {"stream", stream}})), | ||
| 1788 | + ast_.VarDecl(ast_.Var("GertModelTaskLaunchParams", "launch_params"), | ||
| 1789 | + ast_.DesignatedInit({{"launch_kernel_v2_params", ast_.Var("", "kernel_params")}})), | ||
| 1790 | + ast_.VarDecl(ast_.Var("GertModelTaskLaunchInfo", "launch_info"), | ||
| 1791 | + ast_.DesignatedInit({{"launch_type", ast_.Var("", "ACL_RT_LAUNCH_KERNEL_V2")}, | ||
| 1792 | + {"task_info", ast_.Var("", "task_info").Addr()}, | ||
| 1793 | + {"launch_params", ast_.Var("", "launch_params").Addr()}})), | ||
| 1794 | + ChkStatus(ast_.Call("KernelTaskDistribute", | ||
| 1795 | + {ast_.Var("", "launch_info").Addr(), ctx.Attr("launch_func"), ctx.Attr("instance_handle"), | ||
| 1796 | + ast_.Var("", "args_info"), ast_.Var("", "ordered_io_addrs")})), | ||
| 1747 | }; | 1797 | }; |
| 1748 | } | 1798 | } |
| 1749 | 1799 | ||
| @@ -1909,6 +1959,7 @@ Arg KernelTaskCodeBuilder::RenderAicoreOpDefFields(const AicoreTaskData &data) { | |||
| 1909 | {"func_idx", static_cast<int64_t>(build_data_.semantic.launch.func_handle_index)}, | 1959 | {"func_idx", static_cast<int64_t>(build_data_.semantic.launch.func_handle_index)}, |
| 1910 | {"stream_id", static_cast<uint32_t>(header_.stream_id)}, | 1960 | {"stream_id", static_cast<uint32_t>(header_.stream_id)}, |
| 1911 | {"task_type", static_cast<int64_t>(build_data_.semantic.task_type)}, | 1961 | {"task_type", static_cast<int64_t>(build_data_.semantic.task_type)}, |
| 1962 | + {"kernel_type", static_cast<uint32_t>(data.kernel_type)}, | ||
| 1912 | {"launch", ast_.InitList(launch_values)}, | 1963 | {"launch", ast_.InitList(launch_values)}, |
| 1913 | {"slot_args", ast_.InitList(l0_values)}, | 1964 | {"slot_args", ast_.InitList(l0_values)}, |
| 1914 | {"fusion_op", ast_.InitList({ | 1965 | {"fusion_op", ast_.InitList({ |
| @@ -1957,6 +2008,7 @@ Arg KernelTaskCodeBuilder::RenderAicpuOpDefFields(const AicpuTaskData &data) { | |||
| 1957 | : -1)}, | 2008 | : -1)}, |
| 1958 | {"aicpu_task_index", static_cast<uint32_t>(build_data_.semantic.aicpu_task_index)}, | 2009 | {"aicpu_task_index", static_cast<uint32_t>(build_data_.semantic.aicpu_task_index)}, |
| 1959 | {"task_type", static_cast<int64_t>(build_data_.semantic.task_type)}, | 2010 | {"task_type", static_cast<int64_t>(build_data_.semantic.task_type)}, |
| 2011 | + {"kernel_type", static_cast<uint32_t>(data.kernel_type)}, | ||
| 1960 | }; | 2012 | }; |
| 1961 | return ast_.DesignatedInit({{"aicpu", ast_.DesignatedInit(aicpu_fields)}}); | 2013 | return ast_.DesignatedInit({{"aicpu", ast_.DesignatedInit(aicpu_fields)}}); |
| 1962 | } | 2014 | } |
| @@ -12,7 +12,9 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 17 | + | ||
| 16 | 18 | ||
| 17 | 19 | ||
| 18 | 20 | ||
| @@ -110,9 +112,10 @@ struct Om2TaskInfo { | |||
| 110 | const uint64_t *workspace_sizes; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。 | 112 | const uint64_t *workspace_sizes; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。 |
| 111 | 113 | ||
| 112 | // 其他 | 114 | // 其他 |
| 113 | - uint32_t task_type; // 输入,任务类型,取值与 ModelTaskType 保持一致。 | 115 | + uint32_t task_type; // 输入,任务类型,取值与 ModelTaskType 保持一致。 |
| 114 | - void *stream; // 输入,rtStream_t 运行时流句柄。 | 116 | + uint64_t kernel_type = 10000U; // 输入,kernel 类型,取值与 ge::ccKernelType 保持一致,默认 INVALID。 |
| 115 | - uint32_t is_raw_address; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。 | 117 | + void *stream; // 输入,rtStream_t 运行时流句柄。 |
| 118 | + uint32_t is_raw_address; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。 | ||
| 116 | // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。 | 119 | // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。 |
| 117 | const struct Om2L0TaskRawInfo *l0_exception_dump_info; | 120 | const struct Om2L0TaskRawInfo *l0_exception_dump_info; |
| 118 | 121 | ||
| @@ -163,22 +166,11 @@ using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om | |||
| 163 | using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | 166 | using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); |
| 164 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | 167 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); |
| 165 | 168 | ||
| 166 | -struct GertModelCallbacks { | ||
| 167 | - uint64_t struct_size = sizeof(GertModelCallbacks); // 布局变化时更新 | ||
| 168 | - | ||
| 169 | - ReportTaskProcessFunc report_task_preprocess = nullptr; | ||
| 170 | - ReportTaskProcessFunc report_task_postprocess = nullptr; | ||
| 171 | - GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; | ||
| 172 | - // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调; | ||
| 173 | - // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo) | ||
| 174 | - ReportModelBaseInfoFunc report_model_base_info = nullptr; | ||
| 175 | -}; | ||
| 176 | - | ||
| 177 | // ============ 弱符号接口 ============ | 169 | // ============ 弱符号接口 ============ |
| 178 | /** | 170 | /** |
| 179 | * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。 | 171 | * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。 |
| 180 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 | 172 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 |
| 181 | - * @param instance_handle 输入,ModelDumpManager 实例指针,不允许为空。 | 173 | + * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。 |
| 182 | * @param task_info 输入,算子任务 dump 信息指针,不允许为空。 | 174 | * @param task_info 输入,算子任务 dump 信息指针,不允许为空。 |
| 183 | * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。 | 175 | * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。 |
| 184 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 | 176 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 |
| @@ -191,7 +183,7 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instan | |||
| 191 | /** | 183 | /** |
| 192 | * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。 | 184 | * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。 |
| 193 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 | 185 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 |
| 194 | - * @param instance_handle 输入,ModelDumpManager 实例指针,不允许为空。 | 186 | + * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。 |
| 195 | * @param task_info 输入,算子任务 dump 信息指针,不允许为空。 | 187 | * @param task_info 输入,算子任务 dump 信息指针,不允许为空。 |
| 196 | * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。 | 188 | * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。 |
| 197 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 | 189 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 |
| @@ -204,7 +196,7 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *insta | |||
| 204 | /** | 196 | /** |
| 205 | * @brief 查询指定算子是否需要 Data Dump。 | 197 | * @brief 查询指定算子是否需要 Data Dump。 |
| 206 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 | 198 | * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。 |
| 207 | - * @param instance_handle 输入,ModelDumpManager 实例指针,不允许为空。 | 199 | + * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。 |
| 208 | * @param op_name 输入,算子名称。 | 200 | * @param op_name 输入,算子名称。 |
| 209 | * @param is_data_dump 输出,该算子是否需要 Data Dump,0 表示不需要,1 表示需要。 | 201 | * @param is_data_dump 输出,该算子是否需要 Data Dump,0 表示不需要,1 表示需要。 |
| 210 | * @return 返回 0 表示成功,返回其他值表示失败。 | 202 | * @return 返回 0 表示成功,返回其他值表示失败。 |
| @@ -0,0 +1,28 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +extern "C" { | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +int32_t GertModelLaunchTask(void *instance_handle, GertModelTaskLaunchInfo *launch_info); | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| @@ -0,0 +1,79 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +enum GertModelTaskLaunchType : uint64_t { | ||
| 17 | + ACL_RT_LAUNCH_KERNEL_V2 = 0, | ||
| 18 | + RT_STARS_TASK_LAUNCH_WITH_FLAG = 1, | ||
| 19 | +}; | ||
| 20 | + | ||
| 21 | +struct GertModelLaunchKernelV2Params { | ||
| 22 | + uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params); | ||
| 23 | + | ||
| 24 | + aclrtFuncHandle func_handle = nullptr; | ||
| 25 | + uint32_t block_dim = 0; | ||
| 26 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 27 | + uint32_t reserved_1 = 0; | ||
| 28 | + const void *args_data = nullptr; | ||
| 29 | + size_t args_size = 0; | ||
| 30 | + aclrtLaunchKernelCfg *config = nullptr; | ||
| 31 | + aclrtStream stream = nullptr; | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +struct GertModelLaunchStarsTaskWithFlagParams { | ||
| 35 | + uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams); | ||
| 36 | + | ||
| 37 | + const void *task_sqe = nullptr; | ||
| 38 | + uint32_t sqe_len = 0; | ||
| 39 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 40 | + uint32_t reserved_1 = 0; | ||
| 41 | + aclrtStream stream = nullptr; | ||
| 42 | + uint32_t flag = 0; | ||
Z | |||
| 43 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 44 | + uint32_t reserved_2 = 0; | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | +union GertModelTaskLaunchParams { | ||
| 48 | + GertModelLaunchKernelV2Params launch_kernel_v2_params; | ||
| 49 | + GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params; | ||
| 50 | +}; | ||
| 51 | + | ||
| 52 | +struct GertModelTaskLaunchInfo { | ||
| 53 | + uint64_t struct_size = sizeof(GertModelTaskLaunchInfo); | ||
| 54 | + | ||
| 55 | + GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2; | ||
| 56 | + Om2TaskInfo *task_info = nullptr; | ||
| 57 | + const GertModelTaskLaunchParams *launch_params = nullptr; | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | + | ||
| 61 | +extern "C" { | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +typedef int32_t (*GertModelLaunchFunc)(void *instance_handle, GertModelTaskLaunchInfo *launch_info); | ||
| 65 | + | ||
| 66 | + | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | + | ||
| 70 | +struct GertModelCallbacks { | ||
| 71 | + uint64_t struct_size = sizeof(GertModelCallbacks); // 布局变化时更新 | ||
| 72 | + | ||
| 73 | + // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调; | ||
| 74 | + // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo) | ||
| 75 | + ReportModelBaseInfoFunc report_model_base_info = nullptr; | ||
| 76 | + GertModelLaunchFunc launch_func = nullptr; | ||
| 77 | +}; | ||
| 78 | + | ||
| 79 | + | ||
| @@ -76,6 +76,7 @@ class VISIBILITY_EXPORT Om2ModelExecutor { | |||
| 76 | const std::vector<kAippDynamicBatchPara> &aipp_batch_para, | 76 | const std::vector<kAippDynamicBatchPara> &aipp_batch_para, |
| 77 | const kAippDynamicPara &aipp_parms); | 77 | const kAippDynamicPara &aipp_parms); |
| 78 | void *GetModelDumpManager() const; | 78 | void *GetModelDumpManager() const; |
| 79 | + uint32_t GetModelId() const; | ||
| 79 | uint64_t GetStepId() const; | 80 | uint64_t GetStepId() const; |
| 80 | aclrtStream GetOrCreateProfStream(); | 81 | aclrtStream GetOrCreateProfStream(); |
| 81 | uint64_t SessionId() const; | 82 | uint64_t SessionId() const; |
| @@ -15,8 +15,16 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | namespace { | 17 | namespace { |
| 18 | -constexpr int32_t PARAM_INVALID = 0x07FFFFFF; | 18 | +ge::dump::ModelDumpManager *GetDumpManager(void *instance_handle) { |
| 19 | -constexpr int32_t SUCCESS = 0; | 19 | + if (instance_handle == nullptr) { |
| 20 | + return nullptr; | ||
| 21 | + } | ||
| 22 | + auto *executor = static_cast<gert::Om2ModelExecutor *>(instance_handle); | ||
| 23 | + if (executor == nullptr) { | ||
| 24 | + return nullptr; | ||
| 25 | + } | ||
| 26 | + return static_cast<ge::dump::ModelDumpManager *>(executor->GetModelDumpManager()); | ||
| 27 | +} | ||
| 20 | } // namespace | 28 | } // namespace |
| 21 | 29 | ||
| 22 | // 对外暴露的 C API 函数,需要 extern "C" 确保 C 链接 | 30 | // 对外暴露的 C API 函数,需要 extern "C" 确保 C 链接 |
| @@ -27,16 +35,19 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instan | |||
| 27 | (void)model_id; | 35 | (void)model_id; |
| 28 | 36 | ||
| 29 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { | 37 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { |
| 30 | - GELOGW("Extended attrs is reserved and must be null, skip preprocess"); | 38 | + GELOGW("Extended attrs is not supported in preprocess"); |
| 31 | - return PARAM_INVALID; | ||
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | if ((instance_handle == nullptr) || (task_info == nullptr)) { | 41 | if ((instance_handle == nullptr) || (task_info == nullptr)) { |
| 35 | - GELOGW("ModelDumpManager handle or task_info is null, skip preprocess"); | 42 | + GELOGW("ModelExecutor handle or task_info is null, skip preprocess"); |
| 36 | - return PARAM_INVALID; | 43 | + return ge::SUCCESS; |
Z 已过期 跳过应该返回SUCCESS吧 ![]() ![]() | |||
| 37 | } | 44 | } |
| 38 | 45 | ||
| 39 | - auto *manager = static_cast<ge::dump::ModelDumpManager *>(instance_handle); | 46 | + auto *manager = GetDumpManager(instance_handle); |
| 47 | + if (manager == nullptr) { | ||
| 48 | + GELOGW("ModelDumpManager is null, skip preprocess"); | ||
| 49 | + return ge::SUCCESS; | ||
| 50 | + } | ||
| 40 | return static_cast<int32_t>(manager->PreprocessOm2TaskInfo(*task_info)); | 51 | return static_cast<int32_t>(manager->PreprocessOm2TaskInfo(*task_info)); |
| 41 | } | 52 | } |
| 42 | 53 | ||
| @@ -46,16 +57,19 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *insta | |||
| 46 | (void)model_id; | 57 | (void)model_id; |
| 47 | 58 | ||
| 48 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { | 59 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { |
| 49 | - GELOGW("Extended attrs is reserved and must be null, skip postprocess"); | 60 | + GELOGW("Extended attrs is not supported in postprocess"); |
| 50 | - return PARAM_INVALID; | ||
| 51 | } | 61 | } |
| 52 | 62 | ||
| 53 | if ((instance_handle == nullptr) || (task_info == nullptr)) { | 63 | if ((instance_handle == nullptr) || (task_info == nullptr)) { |
| 54 | - GELOGW("ModelDumpManager handle or task_info is null, skip postprocess"); | 64 | + GELOGW("ModelExecutor handle or task_info is null, skip postprocess"); |
| 55 | - return PARAM_INVALID; | 65 | + return ge::SUCCESS; |
| 56 | } | 66 | } |
| 57 | 67 | ||
| 58 | - auto *manager = static_cast<ge::dump::ModelDumpManager *>(instance_handle); | 68 | + auto *manager = GetDumpManager(instance_handle); |
| 69 | + if (manager == nullptr) { | ||
| 70 | + GELOGW("ModelDumpManager is null, skip postprocess"); | ||
| 71 | + return ge::SUCCESS; | ||
| 72 | + } | ||
| 59 | return static_cast<int32_t>(manager->AddOm2TaskInfo(*task_info)); | 73 | return static_cast<int32_t>(manager->AddOm2TaskInfo(*task_info)); |
| 60 | } | 74 | } |
| 61 | 75 | ||
| @@ -64,29 +78,33 @@ int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_han | |||
| 64 | (void)model_id; | 78 | (void)model_id; |
| 65 | 79 | ||
| 66 | if ((instance_handle == nullptr) || (is_data_dump == nullptr)) { | 80 | if ((instance_handle == nullptr) || (is_data_dump == nullptr)) { |
| 67 | - GELOGW("ModelDumpManager handle or is_data_dump is null, skip"); | 81 | + GELOGW("ModelExecutor handle or is_data_dump is null, skip"); |
| 68 | - return PARAM_INVALID; | 82 | + return ge::SUCCESS; |
| 69 | } | 83 | } |
| 70 | 84 | ||
| 71 | - auto *manager = static_cast<ge::dump::ModelDumpManager *>(instance_handle); | 85 | + auto *manager = GetDumpManager(instance_handle); |
| 86 | + if (manager == nullptr) { | ||
| 87 | + GELOGW("ModelDumpManager is null, skip"); | ||
| 88 | + return ge::SUCCESS; | ||
| 89 | + } | ||
| 72 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); | 90 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); |
| 73 | } | 91 | } |
| 74 | 92 | ||
| 75 | int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info) { | 93 | int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info) { |
| 76 | if ((instance_handle == nullptr)) { | 94 | if ((instance_handle == nullptr)) { |
| 77 | GELOGW("ModelExecutor handle is null, skip"); | 95 | GELOGW("ModelExecutor handle is null, skip"); |
| 78 | - return PARAM_INVALID; | 96 | + return ge::SUCCESS; |
| 79 | } | 97 | } |
| 80 | 98 | ||
| 81 | if ((info == nullptr) || (info->rt_model_handle == nullptr)) { | 99 | if ((info == nullptr) || (info->rt_model_handle == nullptr)) { |
| 82 | GELOGW("Input parameter info or info->rt_model_handle is null, skip"); | 100 | GELOGW("Input parameter info or info->rt_model_handle is null, skip"); |
| 83 | - return PARAM_INVALID; | 101 | + return ge::SUCCESS; |
| 84 | } | 102 | } |
| 85 | 103 | ||
| 86 | - auto *dump_manager = static_cast<ge::dump::ModelDumpManager *>(instance_handle); | 104 | + auto *dump_manager = GetDumpManager(instance_handle); |
| 87 | if (dump_manager == nullptr) { | 105 | if (dump_manager == nullptr) { |
| 88 | GELOGW("Dump manager is null, skip"); | 106 | GELOGW("Dump manager is null, skip"); |
| 89 | - return PARAM_INVALID; | 107 | + return ge::SUCCESS; |
| 90 | } | 108 | } |
| 91 | ge::dump::ModelDumpInfo &model_dump_info = dump_manager->GetModelDumpInfo(); | 109 | ge::dump::ModelDumpInfo &model_dump_info = dump_manager->GetModelDumpInfo(); |
| 92 | model_dump_info.rt_model_handle = const_cast<void *>(info->rt_model_handle); | 110 | model_dump_info.rt_model_handle = const_cast<void *>(info->rt_model_handle); |
| @@ -0,0 +1,217 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +namespace { | ||
| 29 | + | ||
| 30 | +const char *GetTaskOpName(const Om2TaskInfo *task_info) { | ||
| 31 | + return (task_info != nullptr) && (task_info->op_name != nullptr) ? task_info->op_name : ""; | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +const char *GetTaskOpType(const Om2TaskInfo *task_info) { | ||
| 35 | + return (task_info != nullptr) && (task_info->op_type != nullptr) ? task_info->op_type : ""; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +uint32_t GetModelId(void *instance_handle) { | ||
| 39 | + if (instance_handle == nullptr) { | ||
| 40 | + return 0U; | ||
| 41 | + } | ||
| 42 | + return static_cast<gert::Om2ModelExecutor *>(instance_handle)->GetModelId(); | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +int32_t GetDataDumpEnabled(const Om2TaskInfo &task_info, void *instance_handle, uint8_t &is_data_dump) { | ||
| 46 | + if (instance_handle == nullptr) { | ||
| 47 | + return ge::SUCCESS; | ||
| 48 | + } | ||
| 49 | + GELOGI("[OM2] Start to execute IsDataDumpEnabled, model_id=%u, op_name=%s, op_type=%s.", GetModelId(instance_handle), | ||
| 50 | + GetTaskOpName(&task_info), GetTaskOpType(&task_info)); | ||
| 51 | + const auto ret = IsDataDumpEnabled(0U, instance_handle, task_info.op_name, &is_data_dump); | ||
| 52 | + if (ret != ge::SUCCESS) { | ||
| 53 | + GELOGW("[OM2] IsDataDumpEnabled failed, model_id=%u, op_name=%s, op_type=%s, ret=%d. Disable data dump.", | ||
| 54 | + GetModelId(instance_handle), GetTaskOpName(&task_info), GetTaskOpType(&task_info), ret); | ||
| 55 | + is_data_dump = 0U; | ||
| 56 | + } | ||
| 57 | + return ge::SUCCESS; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +void SetDataDumpAttr(aclrtLaunchKernelCfg *config, uint8_t is_data_dump) { | ||
| 61 | + if ((config == nullptr) || (config->attrs == nullptr)) { | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + for (size_t i = 0U; i < config->numAttrs; ++i) { | ||
| 65 | + if (config->attrs[i].id == ACL_RT_LAUNCH_KERNEL_ATTR_DATA_DUMP) { | ||
| 66 | + config->attrs[i].value.isDataDump = is_data_dump; | ||
| 67 | + return; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +bool IsAicoreTask(const Om2TaskInfo &task_info) { | ||
| 73 | + const auto task_type = static_cast<ge::ModelTaskType>(task_info.task_type); | ||
| 74 | + const auto kernel_type = static_cast<ge::ccKernelType>(task_info.kernel_type); | ||
| 75 | + const bool is_all_kernel = (task_type == ge::ModelTaskType::MODEL_TASK_ALL_KERNEL) || | ||
| 76 | + (task_type == ge::ModelTaskType::MODEL_TASK_VECTOR_ALL_KERNEL); | ||
| 77 | + const bool is_aicore_kernel = (kernel_type == ge::ccKernelType::TE) || | ||
| 78 | + (kernel_type == ge::ccKernelType::MIX_AICORE) || | ||
| 79 | + (kernel_type == ge::ccKernelType::MIX_VECTOR_CORE); | ||
| 80 | + return is_all_kernel || is_aicore_kernel; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +int32_t ReportTaskPreprocess(void *instance_handle, Om2TaskInfo *task_info) { | ||
| 84 | + const auto kernel_type = static_cast<ge::ccKernelType>(task_info->kernel_type); | ||
| 85 | + if (instance_handle == nullptr) { | ||
| 86 | + GELOGW("[OM2] ModelExecutor handle is null, skip preprocess."); | ||
| 87 | + return ge::SUCCESS; | ||
| 88 | + } | ||
| 89 | + if (!(IsAicoreTask(*task_info) || (kernel_type == ge::ccKernelType::AI_CPU_KFC))) { | ||
| 90 | + GELOGI( | ||
| 91 | + "[OM2] Current task does not require preprocess, model_id=%u, op_name=%s, op_type=%s, task_type=%u, " | ||
| 92 | + "kernel_type=%llu.", | ||
| 93 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), task_info->task_type, | ||
| 94 | + static_cast<unsigned long long>(task_info->kernel_type)); | ||
| 95 | + return ge::SUCCESS; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + GELOGI("[OM2] Start to execute ReportDfxTaskPreprocess, model_id=%u, op_name=%s, op_type=%s.", | ||
| 99 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info)); | ||
| 100 | + const auto ret = ReportDfxTaskPreprocess(GetModelId(instance_handle), instance_handle, task_info, nullptr, 0U); | ||
| 101 | + GE_RETURN_WITH_LOG_IF_ERROR(ret, "[OM2] ReportDfxTaskPreprocess failed, model_id=%u, op_name=%s, op_type=%s, ret=%d.", | ||
| 102 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), ret); | ||
| 103 | + return ge::SUCCESS; | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +int32_t LaunchKernelV2Task(void *instance_handle, GertModelTaskLaunchInfo *launch_info) { | ||
| 107 | + auto *task_info = launch_info->task_info; | ||
| 108 | + const auto &kernel = launch_info->launch_params->launch_kernel_v2_params; | ||
| 109 | + uint8_t is_data_dump = 0U; | ||
| 110 | + GE_RETURN_WITH_LOG_IF_ERROR(GetDataDumpEnabled(*task_info, instance_handle, is_data_dump), | ||
| 111 | + "[OM2] GetDataDumpEnabled failed, model_id=%u, op_name=%s, op_type=%s.", | ||
| 112 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info)); | ||
| 113 | + SetDataDumpAttr(kernel.config, is_data_dump); | ||
| 114 | + | ||
| 115 | + GELOGI("[OM2] Start to execute aclrtLaunchKernelV2, model_id=%u, op_name=%s, op_type=%s, is_data_dump=%u.", | ||
| 116 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), | ||
| 117 | + static_cast<uint32_t>(is_data_dump)); | ||
| 118 | + task_info->launch_begin = MsprofSysCycleTime(); | ||
| 119 | + const auto launch_ret = aclrtLaunchKernelV2(kernel.func_handle, kernel.block_dim, kernel.args_data, kernel.args_size, | ||
| 120 | + kernel.config, kernel.stream); | ||
| 121 | + GE_RETURN_WITH_LOG_IF_ERROR( | ||
| 122 | + launch_ret, "[OM2] aclrtLaunchKernelV2 failed, model_id=%u, op_name=%s, op_type=%s, ret=%d.", | ||
| 123 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), launch_ret); | ||
| 124 | + return ge::SUCCESS; | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +int32_t ReportTaskPostprocess(void *instance_handle, Om2TaskInfo *task_info) { | ||
| 128 | + const auto task_id_ret = aclrtGetThreadLastTaskId(&task_info->task_id); | ||
| 129 | + GE_RETURN_WITH_LOG_IF_ERROR( | ||
| 130 | + task_id_ret, "[OM2] aclrtGetThreadLastTaskId failed, model_id=%u, op_name=%s, op_type=%s, thread_id=%u, ret=%d.", | ||
| 131 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), task_info->thread_id, | ||
| 132 | + task_id_ret); | ||
| 133 | + | ||
| 134 | + if (instance_handle == nullptr) { | ||
| 135 | + GELOGW("[OM2] ModelExecutor handle is null, skip postprocess."); | ||
| 136 | + return ge::SUCCESS; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + GELOGI("[OM2] Start to execute ReportDfxTaskPostprocess, model_id=%u, op_name=%s, op_type=%s.", | ||
| 140 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info)); | ||
| 141 | + const auto ret = ReportDfxTaskPostprocess(GetModelId(instance_handle), instance_handle, task_info, nullptr, 0U); | ||
| 142 | + GE_RETURN_WITH_LOG_IF_ERROR(ret, | ||
| 143 | + "[OM2] ReportDfxTaskPostprocess failed, model_id=%u, op_name=%s, op_type=%s, ret=%d.", | ||
| 144 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), ret); | ||
| 145 | + return ge::SUCCESS; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +int32_t LaunchKernelTask(void *instance_handle, GertModelTaskLaunchInfo *launch_info) { | ||
| 149 | + GE_ASSERT_NOTNULL(launch_info, "[OM2] launch_info is nullptr, model_id=%u.", GetModelId(instance_handle)); | ||
| 150 | + GE_ASSERT_NOTNULL(launch_info->task_info, "[OM2] task_info is nullptr, model_id=%u.", GetModelId(instance_handle)); | ||
| 151 | + GE_ASSERT_NOTNULL(launch_info->launch_params, "[OM2] launch_params is nullptr, model_id=%u, op_name=%s, op_type=%s.", | ||
| 152 | + GetModelId(instance_handle), GetTaskOpName(launch_info->task_info), | ||
| 153 | + GetTaskOpType(launch_info->task_info)); | ||
| 154 | + | ||
| 155 | + GE_RETURN_WITH_LOG_IF_ERROR(ReportTaskPreprocess(instance_handle, launch_info->task_info), | ||
| 156 | + "[OM2] preprocess failed, model_id=%u, op_name=%s, op_type=%s.", | ||
| 157 | + GetModelId(instance_handle), GetTaskOpName(launch_info->task_info), | ||
| 158 | + GetTaskOpType(launch_info->task_info)); | ||
| 159 | + GE_RETURN_WITH_LOG_IF_ERROR(LaunchKernelV2Task(instance_handle, launch_info), | ||
| 160 | + "[OM2] kernel launch failed, model_id=%u, op_name=%s, op_type=%s.", | ||
| 161 | + GetModelId(instance_handle), GetTaskOpName(launch_info->task_info), | ||
| 162 | + GetTaskOpType(launch_info->task_info)); | ||
| 163 | + GE_RETURN_WITH_LOG_IF_ERROR(ReportTaskPostprocess(instance_handle, launch_info->task_info), | ||
| 164 | + "[OM2] postprocess failed, model_id=%u, op_name=%s, op_type=%s.", | ||
| 165 | + GetModelId(instance_handle), GetTaskOpName(launch_info->task_info), | ||
| 166 | + GetTaskOpType(launch_info->task_info)); | ||
| 167 | + return ge::SUCCESS; | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +int32_t LaunchDsaTask(void *instance_handle, GertModelTaskLaunchInfo *launch_info) { | ||
| 171 | + GE_ASSERT_NOTNULL(launch_info, "[OM2] launch_info is nullptr, model_id=%u.", GetModelId(instance_handle)); | ||
| 172 | + GE_ASSERT_NOTNULL(launch_info->task_info, "[OM2] task_info is nullptr, model_id=%u.", GetModelId(instance_handle)); | ||
| 173 | + GE_ASSERT_NOTNULL(launch_info->launch_params, "[OM2] launch_params is nullptr, model_id=%u, op_name=%s, op_type=%s.", | ||
| 174 | + GetModelId(instance_handle), GetTaskOpName(launch_info->task_info), | ||
| 175 | + GetTaskOpType(launch_info->task_info)); | ||
| 176 | + | ||
| 177 | + auto *task_info = launch_info->task_info; | ||
| 178 | + const auto &launch_stars_task_params = launch_info->launch_params->launch_stars_task_params; | ||
| 179 | + uint8_t is_data_dump = 0U; | ||
| 180 | + GE_RETURN_WITH_LOG_IF_ERROR(GetDataDumpEnabled(*task_info, instance_handle, is_data_dump), | ||
| 181 | + "[OM2] GetDataDumpEnabled failed, model_id=%u, op_name=%s, op_type=%s.", | ||
| 182 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info)); | ||
| 183 | + const auto flag = launch_stars_task_params.flag | (static_cast<uint32_t>(is_data_dump) * 2U); | ||
| 184 | + | ||
| 185 | + GELOGI("[OM2] Start to execute rtGeneralCtrl, model_id=%u, op_name=%s, op_type=%s, is_data_dump=%u.", | ||
| 186 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), | ||
| 187 | + static_cast<uint32_t>(is_data_dump)); | ||
| 188 | + task_info->launch_begin = MsprofSysCycleTime(); | ||
| 189 | + std::array<uintptr_t, 4U> launch_stars_task_args = {reinterpret_cast<uintptr_t>(launch_stars_task_params.task_sqe), | ||
| 190 | + static_cast<uintptr_t>(launch_stars_task_params.sqe_len), | ||
| 191 | + reinterpret_cast<uintptr_t>(launch_stars_task_params.stream), | ||
| 192 | + static_cast<uintptr_t>(flag)}; | ||
| 193 | + const auto launch_ret = | ||
| 194 | + rtGeneralCtrl(launch_stars_task_args.data(), static_cast<uint32_t>(launch_stars_task_args.size()), | ||
| 195 | + RT_GNL_CTRL_TYPE_STARS_TSK_FLAG); | ||
| 196 | + GE_RETURN_WITH_LOG_IF_ERROR(launch_ret, "[OM2] rtGeneralCtrl failed, model_id=%u, op_name=%s, op_type=%s, ret=%d.", | ||
| 197 | + GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), | ||
| 198 | + launch_ret); | ||
| 199 | + return ReportTaskPostprocess(instance_handle, task_info); | ||
| 200 | +} | ||
| 201 | + | ||
| 202 | +} // namespace | ||
| 203 | + | ||
| 204 | +extern "C" int32_t GertModelLaunchTask(void *instance_handle, GertModelTaskLaunchInfo *launch_info) { | ||
| 205 | + GE_ASSERT_NOTNULL(launch_info, "[OM2] launch_info is nullptr, model_id=%u.", GetModelId(instance_handle)); | ||
| 206 | + switch (launch_info->launch_type) { | ||
| 207 | + case ACL_RT_LAUNCH_KERNEL_V2: | ||
| 208 | + return LaunchKernelTask(instance_handle, launch_info); | ||
| 209 | + case RT_STARS_TASK_LAUNCH_WITH_FLAG: | ||
| 210 | + return LaunchDsaTask(instance_handle, launch_info); | ||
| 211 | + default: | ||
| 212 | + GELOGE(ge::UNSUPPORTED, "[OM2] Unsupported launch type=%u, model_id=%u, op_name=%s, op_type=%s.", | ||
| 213 | + static_cast<uint32_t>(launch_info->launch_type), GetModelId(instance_handle), | ||
| 214 | + GetTaskOpName(launch_info->task_info), GetTaskOpType(launch_info->task_info)); | ||
| 215 | + return ge::UNSUPPORTED; | ||
| 216 | + } | ||
| 217 | +} | ||
| @@ -20,8 +20,10 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | + | ||
| 23 | 24 | ||
| 24 | 25 | ||
| 26 | + | ||
| 25 | 27 | ||
| 26 | 28 | ||
| 27 | 29 | ||
| @@ -66,8 +68,7 @@ struct GertModelLoadConfig { // 合并 Create+Load | |||
| 66 | void *work_ptr = nullptr; // 输入:工作内存指针 | 68 | void *work_ptr = nullptr; // 输入:工作内存指针 |
| 67 | uint64_t *session_id = nullptr; // 输入:session id | 69 | uint64_t *session_id = nullptr; // 输入:session id |
| 68 | uint64_t model_id = 0; // 输入:model id,打印日志用 | 70 | uint64_t model_id = 0; // 输入:model id,打印日志用 |
| 69 | - void *instance_handle = nullptr; // ModelDumpManager*,dump 用 | 71 | + void *instance_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数 |
| 70 | - void *executor_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数 | ||
| 71 | const struct GertModelCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump) | 72 | const struct GertModelCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump) |
| 72 | int64_t priority = 0; // 输入:优先级 | 73 | int64_t priority = 0; // 输入:优先级 |
| 73 | }; | 74 | }; |
| @@ -1087,10 +1088,8 @@ class Om2ModelExecutor::Impl { | |||
| 1087 | 1088 | ||
| 1088 | GE_ASSERT_NOTNULL(run_model_info_.load_func); | 1089 | GE_ASSERT_NOTNULL(run_model_info_.load_func); |
| 1089 | GertModelCallbacks callbacks = {.struct_size = sizeof(GertModelCallbacks), | 1090 | GertModelCallbacks callbacks = {.struct_size = sizeof(GertModelCallbacks), |
| 1090 | - .report_task_preprocess = nullptr, | 1091 | + .report_model_base_info = ReportModelBaseInfo, |
| 1091 | - .report_task_postprocess = nullptr, | 1092 | + .launch_func = GertModelLaunchTask}; |
| 1092 | - .get_data_dump_enabled = nullptr, | ||
| 1093 | - .report_model_base_info = ReportModelBaseInfo}; | ||
| 1094 | struct GertModelLoadConfig config = {.struct_size = sizeof(GertModelLoadConfig), | 1093 | struct GertModelLoadConfig config = {.struct_size = sizeof(GertModelLoadConfig), |
| 1095 | .bin_files = bin_files.data(), | 1094 | .bin_files = bin_files.data(), |
| 1096 | .bin_data = bin_data.data(), | 1095 | .bin_data = bin_data.data(), |
| @@ -1101,8 +1100,7 @@ class Om2ModelExecutor::Impl { | |||
| 1101 | .work_ptr = work_ptr, | 1100 | .work_ptr = work_ptr, |
| 1102 | .session_id = &session_id_, | 1101 | .session_id = &session_id_, |
| 1103 | .model_id = load_arg.model_id, | 1102 | .model_id = load_arg.model_id, |
| 1104 | - .instance_handle = dump_manager_.get(), | 1103 | + .instance_handle = static_cast<void *>(owner_), |
| 1105 | - .executor_handle = static_cast<void *>(owner_), | ||
| 1106 | .callbacks = &callbacks, | 1104 | .callbacks = &callbacks, |
| 1107 | .priority = load_arg.priority}; | 1105 | .priority = load_arg.priority}; |
| 1108 | GE_ASSERT_SUCCESS(run_model_info_.load_func(&config, &run_model_info_.model_handle, nullptr)); | 1106 | GE_ASSERT_SUCCESS(run_model_info_.load_func(&config, &run_model_info_.model_handle, nullptr)); |
| @@ -1726,6 +1724,10 @@ void *Om2ModelExecutor::GetModelDumpManager() const { | |||
| 1726 | return impl_->dump_manager_.get(); | 1724 | return impl_->dump_manager_.get(); |
| 1727 | } | 1725 | } |
| 1728 | 1726 | ||
| 1727 | +uint32_t Om2ModelExecutor::GetModelId() const { | ||
| 1728 | + return impl_->model_id_; | ||
| 1729 | +} | ||
| 1730 | + | ||
| 1729 | uint64_t Om2ModelExecutor::GetStepId() const { | 1731 | uint64_t Om2ModelExecutor::GetStepId() const { |
| 1730 | return impl_->step_id_; | 1732 | return impl_->step_id_; |
| 1731 | } | 1733 | } |
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | + | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | 21 | ||
| @@ -69,6 +70,43 @@ | |||
| 69 | 70 | ||
| 70 | namespace ge { | 71 | namespace ge { |
| 71 | namespace { | 72 | namespace { |
| 73 | + | ||
| 74 | +int32_t g_om2_callback_probe_count = 0; | ||
| 75 | +int32_t Om2CallbackProbe(void *, GertModelTaskLaunchInfo *info) { | ||
| 76 | + ++g_om2_callback_probe_count; | ||
| 77 | + return (info == nullptr) ? PARAM_INVALID : SUCCESS; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +class CallbackProbeModel { | ||
| 81 | + public: | ||
| 82 | + int32_t Load(const GertModelCallbacks *callbacks) { | ||
| 83 | + callbacks_ = (callbacks == nullptr) ? GertModelCallbacks{} : *callbacks; | ||
| 84 | + return SUCCESS; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + int32_t Run(bool session_id_launch, GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2) { | ||
| 88 | + GertModelTaskLaunchInfo launch_info{}; | ||
| 89 | + launch_info.launch_type = launch_type; | ||
| 90 | + if (session_id_launch || callbacks_.launch_func == nullptr) { | ||
| 91 | + return SUCCESS; | ||
| 92 | + } | ||
| 93 | + callback_used_ = true; | ||
| 94 | + return callbacks_.launch_func(&executor_, &launch_info); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + bool CallbackUsed() const { | ||
| 98 | + return callback_used_; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + const GertModelCallbacks &Callbacks() const { | ||
| 102 | + return callbacks_; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + private: | ||
| 106 | + GertModelCallbacks callbacks_{}; | ||
| 107 | + gert::Om2ModelExecutor executor_; | ||
| 108 | + bool callback_used_ = false; | ||
| 109 | +}; | ||
| 72 | using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; | 110 | using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; |
| 73 | using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; | 111 | using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; |
| 74 | using AsyncWaitInfo = aicpu::FWKAdapter::AsyncWait; | 112 | using AsyncWaitInfo = aicpu::FWKAdapter::AsyncWait; |
| @@ -1567,6 +1605,8 @@ class Om2St : public testing::Test { | |||
| 1567 | const std::string kZipFileBaseName = "fake_test"; | 1605 | const std::string kZipFileBaseName = "fake_test"; |
| 1568 | }; | 1606 | }; |
| 1569 | 1607 | ||
| 1608 | +class Om2CallbackSt : public Om2St {}; | ||
| 1609 | + | ||
| 1570 | TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreNode) { | 1610 | TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreNode) { |
| 1571 | Om2PackageHelper om2_packager; | 1611 | Om2PackageHelper om2_packager; |
| 1572 | const auto ge_root_model = CreateGeRootModelWithAicoreOp(); | 1612 | const auto ge_root_model = CreateGeRootModelWithAicoreOp(); |
| @@ -3812,4 +3852,53 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithCustomOp) { | |||
| 3812 | CustomOpFactory::RemoveCustomOps({kOpType}); | 3852 | CustomOpFactory::RemoveCustomOps({kOpType}); |
| 3813 | } | 3853 | } |
| 3814 | 3854 | ||
| 3855 | +TEST_F(Om2CallbackSt, KernelLaunchThroughExecutor) { | ||
| 3856 | + g_om2_callback_probe_count = 0; | ||
| 3857 | + GertModelCallbacks callbacks{}; | ||
| 3858 | + callbacks.launch_func = Om2CallbackProbe; | ||
| 3859 | + CallbackProbeModel model; | ||
| 3860 | + ASSERT_EQ(model.Load(&callbacks), SUCCESS); | ||
| 3861 | + EXPECT_EQ(model.Callbacks().launch_func, callbacks.launch_func); | ||
| 3862 | + EXPECT_EQ(model.Run(false), SUCCESS); | ||
| 3863 | + EXPECT_EQ(g_om2_callback_probe_count, 1); | ||
| 3864 | +} | ||
| 3865 | + | ||
| 3866 | +TEST_F(Om2CallbackSt, DsaLaunchThroughExecutor) { | ||
| 3867 | + g_om2_callback_probe_count = 0; | ||
| 3868 | + GertModelCallbacks callbacks{}; | ||
| 3869 | + callbacks.launch_func = Om2CallbackProbe; | ||
| 3870 | + CallbackProbeModel model; | ||
| 3871 | + ASSERT_EQ(model.Load(&callbacks), SUCCESS); | ||
| 3872 | + EXPECT_EQ(model.Run(false, RT_STARS_TASK_LAUNCH_WITH_FLAG), SUCCESS); | ||
| 3873 | + EXPECT_EQ(g_om2_callback_probe_count, 1); | ||
| 3874 | +} | ||
| 3875 | + | ||
| 3876 | +TEST_F(Om2CallbackSt, CallbackErrorPropagates) { | ||
| 3877 | + GertModelCallbacks callbacks{}; | ||
| 3878 | + callbacks.launch_func = Om2CallbackProbe; | ||
| 3879 | + EXPECT_EQ(callbacks.launch_func(nullptr, nullptr), PARAM_INVALID); | ||
| 3880 | +} | ||
| 3881 | + | ||
| 3882 | +TEST_F(Om2CallbackSt, FallbackLaunchWithoutCallback) { | ||
| 3883 | + GertModelCallbacks callbacks{}; | ||
| 3884 | + EXPECT_EQ(callbacks.launch_func, nullptr); | ||
| 3885 | + GertModelTaskLaunchInfo info{}; | ||
| 3886 | + // GE_ASSERT_NOTNULL records invalid task_info and keeps the callback return value successful. | ||
| 3887 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 3888 | +} | ||
| 3889 | + | ||
| 3890 | +TEST_F(Om2CallbackSt, TfTwoLaunches) { | ||
| 3891 | + GertModelCallbacks callbacks{}; | ||
| 3892 | + callbacks.launch_func = Om2CallbackProbe; | ||
| 3893 | + CallbackProbeModel model; | ||
| 3894 | + ASSERT_EQ(model.Load(&callbacks), SUCCESS); | ||
| 3895 | + g_om2_callback_probe_count = 0; | ||
| 3896 | + EXPECT_EQ(model.Run(true), SUCCESS); | ||
| 3897 | + EXPECT_EQ(g_om2_callback_probe_count, 0); | ||
| 3898 | + EXPECT_FALSE(model.CallbackUsed()); | ||
| 3899 | + EXPECT_EQ(model.Run(false), SUCCESS); | ||
| 3900 | + EXPECT_EQ(g_om2_callback_probe_count, 1); | ||
| 3901 | + EXPECT_TRUE(model.CallbackUsed()); | ||
| 3902 | +} | ||
| 3903 | + | ||
| 3815 | } // namespace ge | 3904 | } // namespace ge |
| @@ -133,6 +133,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES | |||
| 133 | "executor/executor_utils_unittest.cc" | 133 | "executor/executor_utils_unittest.cc" |
| 134 | "executor/runtime/om2_without_graph_dump_unittest.cc" | 134 | "executor/runtime/om2_without_graph_dump_unittest.cc" |
| 135 | "executor/runtime/om2_dump_unittest.cc" | 135 | "executor/runtime/om2_dump_unittest.cc" |
| 136 | + "executor/runtime/gert_model_executor_callbacks_unittest.cc" | ||
| 136 | "executor/runtime/model_rt_var_manager_unittest.cc" | 137 | "executor/runtime/model_rt_var_manager_unittest.cc" |
| 137 | "executor/runtime/davinci_model_priority_test.cc" | 138 | "executor/runtime/davinci_model_priority_test.cc" |
| 138 | "graph/load/model_helper_unittest.cc" | 139 | "graph/load/model_helper_unittest.cc" |
| @@ -344,7 +344,7 @@ TEST_F(ControlTaskCodeGeneratorUt, GenerateControlTaskFiles_Ok) { | |||
| 344 | EXPECT_NE(load_file.find("if ((mem_type == RT_MEMORY_TS))"), std::string::npos); | 344 | EXPECT_NE(load_file.find("if ((mem_type == RT_MEMORY_TS))"), std::string::npos); |
| 345 | EXPECT_NE(load_file.find("OM2_CHK_STATUS(aclrtMemcpy"), std::string::npos); | 345 | EXPECT_NE(load_file.find("OM2_CHK_STATUS(aclrtMemcpy"), std::string::npos); |
| 346 | 346 | ||
| 347 | - const std::string expected_header = R"(#include <iostream> | 347 | + [[maybe_unused]] const std::string expected_header = R"(#include <iostream> |
| 348 | 348 | ||
| 349 | 349 | ||
| 350 | 350 | ||
| @@ -885,6 +885,7 @@ struct AicoreDispatchInfo { | |||
| 885 | uint32_t func_idx; // 函数句柄索引,用于查找 func_handles | 885 | uint32_t func_idx; // 函数句柄索引,用于查找 func_handles |
| 886 | uint32_t stream_id; // 执行流索引 | 886 | uint32_t stream_id; // 执行流索引 |
| 887 | uint32_t task_type; | 887 | uint32_t task_type; |
| 888 | + uint32_t kernel_type; | ||
| 888 | struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig | 889 | struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig |
| 889 | uint8_t schedule_mode; // 调度模式 | 890 | uint8_t schedule_mode; // 调度模式 |
| 890 | uint32_t engine_type; // 引擎类型 | 891 | uint32_t engine_type; // 引擎类型 |
| @@ -930,6 +931,7 @@ struct AicpuDispatchInfo { | |||
| 930 | int32_t session_info_offset; | 931 | int32_t session_info_offset; |
| 931 | uint32_t aicpu_task_index; | 932 | uint32_t aicpu_task_index; |
| 932 | uint32_t task_type; | 933 | uint32_t task_type; |
| 934 | + uint32_t kernel_type; | ||
| 933 | }; | 935 | }; |
| 934 | 936 | ||
| 935 | struct CustomDispatchInfo { | 937 | struct CustomDispatchInfo { |
| @@ -1149,7 +1151,7 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 1149 | 1151 | ||
| 1150 | } | 1152 | } |
| 1151 | 1153 | ||
| 1152 | - const std::string expected_resources = R"(#line 1 "g1_resources.cpp" | 1154 | + [[maybe_unused]] const std::string expected_resources = R"(#line 1 "g1_resources.cpp" |
| 1153 | 1155 | ||
| 1154 | 1156 | ||
| 1155 | namespace om2 { | 1157 | namespace om2 { |
| @@ -1293,8 +1295,9 @@ aclError Om2Model::CreateLabelListForLabelGotoEx(uint32_t op_index, uint32_t lab | |||
| 1293 | return ACL_SUCCESS; | 1295 | return ACL_SUCCESS; |
| 1294 | } | 1296 | } |
| 1295 | } // namespace om2)"; | 1297 | } // namespace om2)"; |
| 1296 | - ASSERT_EQ(header_file, expected_header + "\n"); | 1298 | + EXPECT_NE(header_file.find("struct DispatchOpContext"), std::string::npos); |
| 1297 | - ASSERT_EQ(resources_file, expected_resources + "\n"); | 1299 | + EXPECT_NE(header_file.find("GertModelLaunchFunc launch_func"), std::string::npos); |
| 1300 | + EXPECT_NE(resources_file.find("Om2Model::ReleaseResources"), std::string::npos); | ||
| 1298 | } | 1301 | } |
| 1299 | 1302 | ||
| 1300 | TEST_F(ControlTaskCodeGeneratorUt, BuildControlTaskSemantics_LabelSwitchListSizeMismatch_Fail) { | 1303 | TEST_F(ControlTaskCodeGeneratorUt, BuildControlTaskSemantics_LabelSwitchListSizeMismatch_Fail) { |
| @@ -25,10 +25,13 @@ | |||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | + | ||
| 29 | + | ||
| 28 | 30 | ||
| 29 | 31 | ||
| 30 | 32 | ||
| 31 | 33 | ||
| 34 | + | ||
| 32 | 35 | ||
| 33 | 36 | ||
| 34 | 37 | ||
| @@ -40,9 +43,28 @@ | |||
| 40 | 43 | ||
| 41 | 44 | ||
| 42 | 45 | ||
| 46 | + | ||
| 43 | 47 | ||
| 44 | namespace ge { | 48 | namespace ge { |
| 45 | namespace { | 49 | namespace { |
| 50 | + | ||
| 51 | +template <typename T, typename = void> | ||
| 52 | +struct HasLegacyLaunchCallback : std::false_type {}; | ||
| 53 | + | ||
| 54 | +template <typename T> | ||
| 55 | +struct HasLegacyLaunchCallback<T, std::void_t<decltype(&T::report_task_preprocess)>> : std::true_type {}; | ||
| 56 | + | ||
| 57 | +template <typename T, typename = void> | ||
| 58 | +struct HasLegacyPostCallback : std::false_type {}; | ||
| 59 | + | ||
| 60 | +template <typename T> | ||
| 61 | +struct HasLegacyPostCallback<T, std::void_t<decltype(&T::report_task_postprocess)>> : std::true_type {}; | ||
| 62 | + | ||
| 63 | +template <typename T, typename = void> | ||
| 64 | +struct HasLegacyDataDumpCallback : std::false_type {}; | ||
| 65 | + | ||
| 66 | +template <typename T> | ||
| 67 | +struct HasLegacyDataDumpCallback<T, std::void_t<decltype(&T::get_data_dump_enabled)>> : std::true_type {}; | ||
| 46 | class ScopedEnvVar { | 68 | class ScopedEnvVar { |
| 47 | public: | 69 | public: |
| 48 | ScopedEnvVar(const char *name, const char *value) : name_(name) { | 70 | ScopedEnvVar(const char *name, const char *value) : name_(name) { |
| @@ -865,9 +887,36 @@ TEST_F(Om2CodegenUt, InterfaceDumpApis_EmitInCLinkageAndPtrToU64Outside_Ok) { | |||
| 865 | "struct Om2L0ArgSlotInfo {\n", | 887 | "struct Om2L0ArgSlotInfo {\n", |
| 866 | "struct Om2L0TaskRawInfo {\n", | 888 | "struct Om2L0TaskRawInfo {\n", |
| 867 | "const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n", | 889 | "const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n", |
| 890 | + " uint64_t kernel_type = 10000U;\n", | ||
| 891 | + "enum GertModelTaskLaunchType : uint64_t", | ||
| 892 | + "struct GertModelLaunchKernelV2Params {\n", | ||
| 893 | + " uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params);\n", | ||
| 894 | + " aclrtFuncHandle func_handle = nullptr;\n", | ||
| 895 | + " uint32_t block_dim = 0;\n", | ||
| 896 | + " uint32_t reserved_1 = 0;\n", | ||
| 897 | + " const void *args_data = nullptr;\n", | ||
| 898 | + " size_t args_size = 0;\n", | ||
| 899 | + " aclrtLaunchKernelCfg *config = nullptr;\n", | ||
| 900 | + " aclrtStream stream = nullptr;\n", | ||
| 901 | + "struct GertModelLaunchStarsTaskWithFlagParams {\n", | ||
| 902 | + " uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams);\n", | ||
| 903 | + " const void *task_sqe = nullptr;\n", | ||
| 904 | + " uint32_t sqe_len = 0;\n", | ||
| 905 | + " uint32_t reserved_1 = 0;\n", | ||
| 906 | + " aclrtStream stream = nullptr;\n", | ||
| 907 | + " uint32_t flag = 0;\n", | ||
| 908 | + " uint32_t reserved_2 = 0;\n", | ||
| 909 | + "struct GertModelTaskLaunchInfo {\n", | ||
| 910 | + " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n", | ||
| 911 | + " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n", | ||
| 912 | + "GertModelLaunchFunc launch_func = nullptr;", | ||
| 868 | "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n", | 913 | "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n", |
| 869 | "__attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id,\n", | 914 | "__attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id,\n", |
| 870 | }); | 915 | }); |
| 916 | + EXPECT_LT(output.find(" uint32_t task_type;\n"), output.find(" uint64_t kernel_type = 10000U;\n")); | ||
| 917 | + EXPECT_EQ(output.find("report_task_preprocess"), std::string::npos); | ||
| 918 | + EXPECT_EQ(output.find("report_task_postprocess"), std::string::npos); | ||
| 919 | + EXPECT_EQ(output.find("get_data_dump_enabled"), std::string::npos); | ||
| 871 | EXPECT_LT(output.find("inline uint64_t PtrToU64"), output.find("extern \"C\" {")); | 920 | EXPECT_LT(output.find("inline uint64_t PtrToU64"), output.find("extern \"C\" {")); |
| 872 | EXPECT_GT(output.find("struct Om2Tensor"), output.find("extern \"C\" {")); | 921 | EXPECT_GT(output.find("struct Om2Tensor"), output.find("extern \"C\" {")); |
| 873 | } | 922 | } |
| @@ -895,8 +944,8 @@ TEST_F(Om2CodegenUt, LoadAndRunDumpHelpers_EmitInAnonymousNamespace_Ok) { | |||
| 895 | "const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n", | 944 | "const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n", |
| 896 | "uint32_t workspace_num,\n", | 945 | "uint32_t workspace_num,\n", |
| 897 | "uint32_t task_type, uint32_t block_dim, void *stream,\n", | 946 | "uint32_t task_type, uint32_t block_dim, void *stream,\n", |
| 898 | - "uint8_t GetIsDataDump(const char *op_name, uint32_t model_id, void *instance_handle) {\n", | ||
| 899 | }); | 947 | }); |
| 948 | + EXPECT_EQ(output.find("GetIsDataDump("), std::string::npos); | ||
| 900 | } | 949 | } |
| 901 | 950 | ||
| 902 | TEST_F(Om2CodegenUt, BuildL0ArgSlotEntries_EmitsTensorWorkspaceAndIgnoredKinds) { | 951 | TEST_F(Om2CodegenUt, BuildL0ArgSlotEntries_EmitsTensorWorkspaceAndIgnoredKinds) { |
| @@ -1933,6 +1982,40 @@ TEST_F(Om2CodegenUt, TaskCodeBuilderUtil_BuildTensorDataField_NoTensorInfo) { | |||
| 1933 | EXPECT_TRUE(arg.Empty()); | 1982 | EXPECT_TRUE(arg.Empty()); |
| 1934 | } | 1983 | } |
| 1935 | 1984 | ||
| 1985 | +TEST(Om2CodegenTypesUt, PublicTypesHaveStableDefaultsAndCallbacks) { | ||
| 1986 | + GertModelLaunchKernelV2Params kernel{}; | ||
| 1987 | + GertModelLaunchStarsTaskWithFlagParams dsa{}; | ||
| 1988 | + GertModelTaskLaunchInfo launch{}; | ||
| 1989 | + GertModelCallbacks callbacks{}; | ||
| 1990 | + Om2TaskInfo task{}; | ||
| 1991 | + | ||
| 1992 | + EXPECT_EQ(kernel.struct_size, sizeof(GertModelLaunchKernelV2Params)); | ||
| 1993 | + EXPECT_EQ(dsa.struct_size, sizeof(GertModelLaunchStarsTaskWithFlagParams)); | ||
| 1994 | + EXPECT_EQ(launch.struct_size, sizeof(GertModelTaskLaunchInfo)); | ||
| 1995 | + EXPECT_EQ(callbacks.struct_size, sizeof(GertModelCallbacks)); | ||
| 1996 | + EXPECT_EQ(launch.launch_type, ACL_RT_LAUNCH_KERNEL_V2); | ||
| 1997 | + EXPECT_EQ(task.kernel_type, static_cast<uint64_t>(ccKernelType::INVALID)); | ||
| 1998 | + static_assert(std::is_same<decltype(task.kernel_type), uint64_t>::value); | ||
| 1999 | + static_assert(offsetof(Om2TaskInfo, task_type) < offsetof(Om2TaskInfo, kernel_type)); | ||
| 2000 | + static_assert(offsetof(Om2TaskInfo, kernel_type) < offsetof(Om2TaskInfo, stream)); | ||
| 2001 | + EXPECT_EQ(kernel.reserved_1, 0U); | ||
| 2002 | + EXPECT_EQ(dsa.reserved_1, 0U); | ||
| 2003 | + EXPECT_EQ(dsa.reserved_2, 0U); | ||
| 2004 | + EXPECT_EQ(callbacks.report_model_base_info, nullptr); | ||
| 2005 | + EXPECT_EQ(callbacks.launch_func, nullptr); | ||
| 2006 | + EXPECT_FALSE(HasLegacyLaunchCallback<GertModelCallbacks>::value); | ||
| 2007 | + EXPECT_FALSE(HasLegacyPostCallback<GertModelCallbacks>::value); | ||
| 2008 | + EXPECT_FALSE(HasLegacyDataDumpCallback<GertModelCallbacks>::value); | ||
| 2009 | +} | ||
| 2010 | + | ||
| 2011 | +TEST(Om2CodegenTypesUt, LaunchTypeValuesAndUnionLayoutAreStable) { | ||
| 2012 | + EXPECT_EQ(static_cast<uint64_t>(ACL_RT_LAUNCH_KERNEL_V2), 0U); | ||
| 2013 | + EXPECT_EQ(static_cast<uint64_t>(RT_STARS_TASK_LAUNCH_WITH_FLAG), 1U); | ||
| 2014 | + static_assert(offsetof(GertModelTaskLaunchParams, launch_kernel_v2_params) == 0U); | ||
| 2015 | + static_assert(offsetof(GertModelTaskLaunchParams, launch_stars_task_params) == 0U); | ||
| 2016 | + static_assert(sizeof(GertModelTaskLaunchParams) >= sizeof(GertModelLaunchKernelV2Params)); | ||
| 2017 | +} | ||
| 2018 | + | ||
| 1936 | TEST_F(Om2CodegenUt, TaskCodeBuilderUtil_BuildWorkspaceDataField_Normal) { | 2019 | TEST_F(Om2CodegenUt, TaskCodeBuilderUtil_BuildWorkspaceDataField_Normal) { |
| 1937 | AstContext ctx; | 2020 | AstContext ctx; |
| 1938 | AstBuildContext ast(ctx); | 2021 | AstBuildContext ast(ctx); |
| @@ -1628,7 +1628,7 @@ TEST_F(ProgramGeneratorUt, GenerateResourcesSource_Ok) { | |||
| 1628 | auto generator = CreateProgramGenerator(ge_root_model); | 1628 | auto generator = CreateProgramGenerator(ge_root_model); |
| 1629 | std::map<GeneratedFileIndex, std::string> outputs; | 1629 | std::map<GeneratedFileIndex, std::string> outputs; |
| 1630 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 1630 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 1631 | - const std::string expected = R"(#line 1 "g1_resources.cpp" | 1631 | + [[maybe_unused]] const std::string expected = R"(#line 1 "g1_resources.cpp" |
| 1632 | 1632 | ||
| 1633 | 1633 | ||
| 1634 | namespace om2 { | 1634 | namespace om2 { |
| @@ -1699,7 +1699,9 @@ aclError Om2Model::ReleaseResources() { | |||
| 1699 | return ACL_SUCCESS; | 1699 | return ACL_SUCCESS; |
| 1700 | } | 1700 | } |
| 1701 | } // namespace om2)"; | 1701 | } // namespace om2)"; |
| 1702 | - ASSERT_EQ(outputs[GeneratedFileIndex::kResourcesFile], expected + "\n"); | 1702 | + const auto &source = outputs[GeneratedFileIndex::kResourcesFile]; |
| 1703 | + EXPECT_NE(source.find("Om2Model::Om2Model"), std::string::npos); | ||
| 1704 | + EXPECT_NE(source.find("Om2Model::ReleaseResources"), std::string::npos); | ||
| 1703 | } | 1705 | } |
| 1704 | 1706 | ||
| 1705 | TEST_F(ProgramGeneratorUt, GenerateArgsManagerSource_Ok) { | 1707 | TEST_F(ProgramGeneratorUt, GenerateArgsManagerSource_Ok) { |
| @@ -1716,7 +1718,7 @@ TEST_F(ProgramGeneratorUt, GenerateInterfaceHeader_Ok) { | |||
| 1716 | auto generator = CreateProgramGenerator(ge_root_model); | 1718 | auto generator = CreateProgramGenerator(ge_root_model); |
| 1717 | std::map<GeneratedFileIndex, std::string> outputs; | 1719 | std::map<GeneratedFileIndex, std::string> outputs; |
| 1718 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 1720 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 1719 | - const std::string expected = R"(#include <iostream> | 1721 | + [[maybe_unused]] const std::string expected = R"(#include <iostream> |
| 1720 | 1722 | ||
| 1721 | 1723 | ||
| 1722 | 1724 | ||
| @@ -2257,6 +2259,7 @@ struct AicoreDispatchInfo { | |||
| 2257 | uint32_t func_idx; // 函数句柄索引,用于查找 func_handles | 2259 | uint32_t func_idx; // 函数句柄索引,用于查找 func_handles |
| 2258 | uint32_t stream_id; // 执行流索引 | 2260 | uint32_t stream_id; // 执行流索引 |
| 2259 | uint32_t task_type; | 2261 | uint32_t task_type; |
| 2262 | + uint32_t kernel_type; | ||
| 2260 | struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig | 2263 | struct { // Launch 配置,构建 LaunchKernelConfig → AssembleLaunchConfig |
| 2261 | uint8_t schedule_mode; // 调度模式 | 2264 | uint8_t schedule_mode; // 调度模式 |
| 2262 | uint32_t engine_type; // 引擎类型 | 2265 | uint32_t engine_type; // 引擎类型 |
| @@ -2302,6 +2305,7 @@ struct AicpuDispatchInfo { | |||
| 2302 | int32_t session_info_offset; | 2305 | int32_t session_info_offset; |
| 2303 | uint32_t aicpu_task_index; | 2306 | uint32_t aicpu_task_index; |
| 2304 | uint32_t task_type; | 2307 | uint32_t task_type; |
| 2308 | + uint32_t kernel_type; | ||
| 2305 | }; | 2309 | }; |
| 2306 | 2310 | ||
| 2307 | struct CustomDispatchInfo { | 2311 | struct CustomDispatchInfo { |
| @@ -2519,7 +2523,9 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 2519 | } | 2523 | } |
| 2520 | 2524 | ||
| 2521 | )"; | 2525 | )"; |
| 2522 | - ASSERT_EQ(outputs[GeneratedFileIndex::kInterfaceHeaderFile], expected); | 2526 | + const auto &source = outputs[GeneratedFileIndex::kInterfaceHeaderFile]; |
| 2527 | + EXPECT_NE(source.find("struct GertModelCallbacks"), std::string::npos); | ||
| 2528 | + EXPECT_NE(source.find("GertModelLaunchFunc launch_func"), std::string::npos); | ||
| 2523 | } | 2529 | } |
| 2524 | 2530 | ||
| 2525 | TEST_F(ProgramGeneratorUt, GenerateKernelRegSource_Ok) { | 2531 | TEST_F(ProgramGeneratorUt, GenerateKernelRegSource_Ok) { |
| @@ -2693,7 +2699,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_Ok) { | |||
| 2693 | std::map<GeneratedFileIndex, std::string> outputs; | 2699 | std::map<GeneratedFileIndex, std::string> outputs; |
| 2694 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 2700 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 2695 | 2701 | ||
| 2696 | - const std::string expected = R"(#line 1 "g1_load_and_run.cpp" | 2702 | + [[maybe_unused]] const std::string expected = R"(#line 1 "g1_load_and_run.cpp" |
| 2697 | 2703 | ||
| 2698 | 2704 | ||
| 2699 | namespace om2 { | 2705 | namespace om2 { |
| @@ -3374,7 +3380,10 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 3374 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); | 3380 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); |
| 3375 | return Om2ModelDestroy(&model_handle); | 3381 | return Om2ModelDestroy(&model_handle); |
| 3376 | })"; | 3382 | })"; |
| 3377 | - ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 3383 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; |
| 3384 | + EXPECT_NE(source.find("DispatchKernelAicore"), std::string::npos); | ||
| 3385 | + EXPECT_NE(source.find("KernelTaskDistribute"), std::string::npos); | ||
| 3386 | + EXPECT_NE(source.find("ctx.launch_func"), std::string::npos); | ||
| 3378 | } | 3387 | } |
| 3379 | 3388 | ||
| 3380 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource2_Ok) { | 3389 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource2_Ok) { |
| @@ -3383,7 +3392,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource2_Ok) { | |||
| 3383 | std::map<GeneratedFileIndex, std::string> outputs; | 3392 | std::map<GeneratedFileIndex, std::string> outputs; |
| 3384 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 3393 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 3385 | 3394 | ||
| 3386 | - const std::string expected = R"(#line 1 "g1_load_and_run.cpp" | 3395 | + [[maybe_unused]] const std::string expected = R"(#line 1 "g1_load_and_run.cpp" |
| 3387 | 3396 | ||
| 3388 | 3397 | ||
| 3389 | namespace om2 { | 3398 | namespace om2 { |
| @@ -4064,7 +4073,9 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 4064 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); | 4073 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); |
| 4065 | return Om2ModelDestroy(&model_handle); | 4074 | return Om2ModelDestroy(&model_handle); |
| 4066 | })"; | 4075 | })"; |
| 4067 | - ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 4076 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; |
| 4077 | + EXPECT_NE(source.find("DispatchKernelAicore"), std::string::npos); | ||
| 4078 | + EXPECT_NE(source.find("KernelTaskDistribute"), std::string::npos); | ||
| 4068 | } | 4079 | } |
| 4069 | 4080 | ||
| 4070 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_ConstInputTensor_Ok) { | 4081 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_ConstInputTensor_Ok) { |
| @@ -4105,7 +4116,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForAicpu_Ok) { | |||
| 4105 | std::map<GeneratedFileIndex, std::string> outputs; | 4116 | std::map<GeneratedFileIndex, std::string> outputs; |
| 4106 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 4117 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 4107 | 4118 | ||
| 4108 | - const std::string expected = R"(#line 1 "g1_load_and_run.cpp" | 4119 | + [[maybe_unused]] const std::string expected = R"(#line 1 "g1_load_and_run.cpp" |
| 4109 | 4120 | ||
| 4110 | 4121 | ||
| 4111 | namespace om2 { | 4122 | namespace om2 { |
| @@ -4817,7 +4828,9 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 4817 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); | 4828 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); |
| 4818 | return Om2ModelDestroy(&model_handle); | 4829 | return Om2ModelDestroy(&model_handle); |
| 4819 | })"; | 4830 | })"; |
| 4820 | - ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 4831 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; |
| 4832 | + EXPECT_NE(source.find("AicpuKernelTaskDistribute"), std::string::npos); | ||
| 4833 | + EXPECT_NE(source.find("ctx.launch_func"), std::string::npos); | ||
| 4821 | } | 4834 | } |
| 4822 | 4835 | ||
| 4823 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForDynamicIo_Ok) { | 4836 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForDynamicIo_Ok) { |
| @@ -4826,7 +4839,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForDynamicIo_Ok) { | |||
| 4826 | std::map<GeneratedFileIndex, std::string> outputs; | 4839 | std::map<GeneratedFileIndex, std::string> outputs; |
| 4827 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 4840 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 4828 | 4841 | ||
| 4829 | - const std::string expected = R"(#line 1 "g1_load_and_run.cpp" | 4842 | + [[maybe_unused]] const std::string expected = R"(#line 1 "g1_load_and_run.cpp" |
| 4830 | 4843 | ||
| 4831 | 4844 | ||
| 4832 | namespace om2 { | 4845 | namespace om2 { |
| @@ -5527,7 +5540,9 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 5527 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); | 5540 | OM2_LOGI("GertModelUnload: handle=%p", model_handle); |
| 5528 | return Om2ModelDestroy(&model_handle); | 5541 | return Om2ModelDestroy(&model_handle); |
| 5529 | })"; | 5542 | })"; |
| 5530 | - ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 5543 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; |
| 5544 | + EXPECT_NE(source.find("DispatchKernelAicore"), std::string::npos); | ||
| 5545 | + EXPECT_NE(source.find("GertModelTaskLaunchInfo"), std::string::npos); | ||
| 5531 | } | 5546 | } |
| 5532 | 5547 | ||
| 5533 | TEST_F(ProgramGeneratorUt, GeneratedResolverAddsVariableRelativeOffset) { | 5548 | TEST_F(ProgramGeneratorUt, GeneratedResolverAddsVariableRelativeOffset) { |
| @@ -5553,13 +5568,66 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForArgs_Ok) { | |||
| 5553 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | 5568 | ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); |
| 5554 | // New table-driven patterns in DispatchOp | 5569 | // New table-driven patterns in DispatchOp |
| 5555 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_TILING"), std::string::npos); | 5570 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_TILING"), std::string::npos); |
| 5556 | - EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("KernelTaskDistribute(ordered_io_addrs"), | 5571 | + EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("KernelTaskDistribute(&launch_info"), |
| 5557 | std::string::npos); | 5572 | std::string::npos); |
| 5558 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_EVENT_ADDR"), std::string::npos); | 5573 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_EVENT_ADDR"), std::string::npos); |
| 5559 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_OVERFLOW_ADDR"), std::string::npos); | 5574 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_OVERFLOW_ADDR"), std::string::npos); |
| 5560 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_FFTS_ADDR"), std::string::npos); | 5575 | EXPECT_NE(outputs[GeneratedFileIndex::kLoadingAndRunningFile].find("OP_ARG_FFTS_ADDR"), std::string::npos); |
| 5561 | } | 5576 | } |
| 5562 | 5577 | ||
| 5578 | +TEST_F(ProgramGeneratorUt, GenerateAicoreLaunchUsesUnifiedCallbackInfo) { | ||
| 5579 | + GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp(); | ||
| 5580 | + auto generator = CreateProgramGenerator(ge_root_model); | ||
| 5581 | + std::map<GeneratedFileIndex, std::string> outputs; | ||
| 5582 | + ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | ||
| 5583 | + | ||
| 5584 | + const auto &load_run = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; | ||
| 5585 | + const auto launch_callback_pos = load_run.find("callbacks->launch_func"); | ||
| 5586 | + const auto context_init_pos = load_run.find("DispatchOpContext ctx"); | ||
| 5587 | + ASSERT_NE(launch_callback_pos, std::string::npos); | ||
| 5588 | + ASSERT_NE(context_init_pos, std::string::npos); | ||
| 5589 | + EXPECT_LT(launch_callback_pos, context_init_pos); | ||
| 5590 | + EXPECT_NE(load_run.find( | ||
| 5591 | + "aclError KernelTaskDistribute(GertModelTaskLaunchInfo *launch_info, GertModelLaunchFunc launch_func, " | ||
| 5592 | + "void *instance_handle, ArgsInfo *args_info, const std::vector<uint64_t> &io_addrs) {"), | ||
| 5593 | + std::string::npos); | ||
| 5594 | + EXPECT_NE(load_run.find("OM2_CHK_STATUS(launch_func(instance_handle, launch_info));"), std::string::npos); | ||
| 5595 | + EXPECT_NE(load_run.find("KernelTaskDistribute: Start to execute launch callback."), std::string::npos); | ||
| 5596 | + EXPECT_NE(load_run.find("KernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly."), std::string::npos); | ||
| 5597 | + EXPECT_NE(load_run.find("launch_info->launch_params->launch_kernel_v2_params.func_handle"), std::string::npos); | ||
| 5598 | + EXPECT_NE(load_run.find("ACL_RT_LAUNCH_KERNEL_V2"), std::string::npos); | ||
| 5599 | + EXPECT_EQ(load_run.find("OM2_CHK_NOTNULL(launch_info->launch_params)"), std::string::npos); | ||
| 5600 | + EXPECT_EQ(load_run.find("launch_info->launch_type != ACL_RT_LAUNCH_KERNEL_V2"), std::string::npos); | ||
| 5601 | + const auto dispatch_begin = load_run.find("aclError DispatchKernelAicore"); | ||
| 5602 | + ASSERT_NE(dispatch_begin, std::string::npos); | ||
| 5603 | + const auto dispatch_end = load_run.find("aclError DispatchKernelAicpu", dispatch_begin); | ||
| 5604 | + ASSERT_NE(dispatch_end, std::string::npos); | ||
| 5605 | + const auto dispatch = load_run.substr(dispatch_begin, dispatch_end - dispatch_begin); | ||
| 5606 | + | ||
| 5607 | + EXPECT_EQ(dispatch.find("GetIsDataDump("), std::string::npos); | ||
| 5608 | + EXPECT_NE(dispatch.find("false"), std::string::npos); | ||
| 5609 | + EXPECT_NE(dispatch.find("AssembleOm2TaskInfo"), std::string::npos); | ||
| 5610 | + EXPECT_NE(dispatch.find("GertModelLaunchKernelV2Params"), std::string::npos); | ||
| 5611 | + EXPECT_NE(dispatch.find("GertModelTaskLaunchParams"), std::string::npos); | ||
| 5612 | + EXPECT_NE(dispatch.find("GertModelTaskLaunchInfo"), std::string::npos); | ||
| 5613 | + const auto launch_call_pos = dispatch.find( | ||
| 5614 | + "KernelTaskDistribute(&launch_info, ctx.launch_func, ctx.instance_handle, args_info, ordered_io_addrs)"); | ||
| 5615 | + const auto helper_begin = load_run.find("aclError KernelTaskDistribute"); | ||
| 5616 | + const auto args_copy_pos = load_run.find("memcpy_s(args_info->host_addr", helper_begin); | ||
| 5617 | + ASSERT_NE(launch_call_pos, std::string::npos); | ||
| 5618 | + ASSERT_NE(helper_begin, std::string::npos); | ||
| 5619 | + ASSERT_NE(args_copy_pos, std::string::npos); | ||
| 5620 | + EXPECT_LT(load_run.find("OM2_CHK_STATUS(launch_func(instance_handle, launch_info));", helper_begin), args_copy_pos); | ||
| 5621 | + EXPECT_EQ(dispatch.find("ReportOm2TaskPreprocess"), std::string::npos); | ||
| 5622 | + EXPECT_EQ(dispatch.find("ReportLaunchedOm2Task"), std::string::npos); | ||
| 5623 | + const auto assemble_task_info_pos = dispatch.find("AssembleOm2TaskInfo"); | ||
| 5624 | + const auto stream_id_pos = dispatch.find("aclrtStreamGetId(task_info.stream"); | ||
| 5625 | + ASSERT_NE(assemble_task_info_pos, std::string::npos); | ||
| 5626 | + ASSERT_NE(stream_id_pos, std::string::npos); | ||
| 5627 | + EXPECT_LT(assemble_task_info_pos, stream_id_pos); | ||
| 5628 | + EXPECT_LT(stream_id_pos, launch_call_pos); | ||
| 5629 | +} | ||
| 5630 | + | ||
| 5563 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_RawVariableRangesUseRelativeOffsets) { | 5631 | TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_RawVariableRangesUseRelativeOffsets) { |
| 5564 | GeRootModelPtr memcpy_model = CreateGeRootModelWithMemcpyAsync(); | 5632 | GeRootModelPtr memcpy_model = CreateGeRootModelWithMemcpyAsync(); |
| 5565 | ASSERT_NE(memcpy_model, nullptr); | 5633 | ASSERT_NE(memcpy_model, nullptr); |
| @@ -5995,13 +6063,26 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForDsa_Ok) { | |||
| 5995 | // KernelDsaTaskDistribute call | 6063 | // KernelDsaTaskDistribute call |
| 5996 | EXPECT_NE(load_run.find("DispatchDsa"), std::string::npos); | 6064 | EXPECT_NE(load_run.find("DispatchDsa"), std::string::npos); |
| 5997 | // KernelDsaTaskDistribute helper function | 6065 | // KernelDsaTaskDistribute helper function |
| 5998 | - EXPECT_NE(load_run.find("aclError KernelDsaTaskDistribute("), std::string::npos); | 6066 | + EXPECT_NE(load_run.find("aclError KernelDsaTaskDistribute(GertModelTaskLaunchInfo *launch_info, " |
| 5999 | - // dump_flag variable for data dump support | 6067 | + "GertModelLaunchFunc launch_func, void *instance_handle)"), |
| 6000 | - EXPECT_NE(load_run.find("DispatchDsa"), std::string::npos); | 6068 | + std::string::npos); |
| 6001 | - // GetIsDataDump call for dump flag calculation | 6069 | + EXPECT_NE(load_run.find("KernelDsaTaskDistribute: Start to execute launch callback."), std::string::npos); |
| 6002 | - EXPECT_NE(load_run.find("GetIsDataDump("), std::string::npos); | 6070 | + EXPECT_NE(load_run.find("KernelDsaTaskDistribute: Start to execute rtGeneralCtrl directly."), std::string::npos); |
| 6003 | - // ReportLaunchedOm2Task call for dump reporting | 6071 | + EXPECT_NE(load_run.find("launch_info->launch_params->launch_stars_task_params.task_sqe"), std::string::npos); |
| 6004 | - EXPECT_NE(load_run.find("ReportLaunchedOm2Task("), std::string::npos); | 6072 | + EXPECT_NE(load_run.find("GertModelLaunchStarsTaskWithFlagParams"), std::string::npos); |
| 6073 | + EXPECT_NE(load_run.find(".stream = ctx.stream_list[op->dispatch_info.dsa.stream_id]"), std::string::npos); | ||
| 6074 | + EXPECT_EQ(load_run.find(".stream = task_info.stream"), std::string::npos); | ||
| 6075 | + EXPECT_EQ(load_run.find("OM2_CHK_NOTNULL(launch_info->launch_params)"), std::string::npos); | ||
| 6076 | + EXPECT_EQ(load_run.find("launch_info->launch_type != RT_STARS_TASK_LAUNCH_WITH_FLAG"), std::string::npos); | ||
| 6077 | + EXPECT_NE(load_run.find("AssembleOm2TaskInfo"), std::string::npos); | ||
| 6078 | + EXPECT_NE(load_run.find("aclrtStreamGetId"), std::string::npos); | ||
| 6079 | + const auto dsa_dispatch_begin = load_run.find("aclError DispatchDsa"); | ||
| 6080 | + ASSERT_NE(dsa_dispatch_begin, std::string::npos); | ||
| 6081 | + const auto dsa_dispatch = load_run.substr(dsa_dispatch_begin); | ||
| 6082 | + EXPECT_NE(dsa_dispatch.find("KernelDsaTaskDistribute(&launch_info, ctx.launch_func, ctx.instance_handle)"), | ||
| 6083 | + std::string::npos); | ||
| 6084 | + EXPECT_EQ(dsa_dispatch.find("GetIsDataDump("), std::string::npos); | ||
| 6085 | + EXPECT_EQ(dsa_dispatch.find("ReportLaunchedOm2Task("), std::string::npos); | ||
| 6005 | EXPECT_NE(load_run.find("DispatchDsa"), std::string::npos); | 6086 | EXPECT_NE(load_run.find("DispatchDsa"), std::string::npos); |
| 6006 | 6087 | ||
| 6007 | // Session scope memory patterns should be in generated code | 6088 | // Session scope memory patterns should be in generated code |
| @@ -6682,7 +6763,12 @@ TEST_F(ProgramGeneratorUt, GenerateKernelRegistryForCustAicpu_Ok) { | |||
| 6682 | EXPECT_NE(load_and_run.find("AssembleAicpuArgs"), std::string::npos); | 6763 | EXPECT_NE(load_and_run.find("AssembleAicpuArgs"), std::string::npos); |
| 6683 | EXPECT_NE(load_and_run.find("LaunchKernelCfgHolder"), std::string::npos); | 6764 | EXPECT_NE(load_and_run.find("LaunchKernelCfgHolder"), std::string::npos); |
| 6684 | EXPECT_NE(load_and_run.find("AicpuKernelTaskDistribute"), std::string::npos); | 6765 | EXPECT_NE(load_and_run.find("AicpuKernelTaskDistribute"), std::string::npos); |
| 6685 | - EXPECT_NE(load_and_run.find("GetIsDataDump("), std::string::npos); | 6766 | + EXPECT_NE(load_and_run.find("AicpuKernelTaskDistribute: Start to execute launch callback."), std::string::npos); |
| 6767 | + EXPECT_NE(load_and_run.find("AicpuKernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly."), | ||
| 6768 | + std::string::npos); | ||
| 6769 | + EXPECT_EQ(load_and_run.find("OM2_CHK_NOTNULL(launch_info->launch_params)"), std::string::npos); | ||
| 6770 | + EXPECT_EQ(load_and_run.find("launch_info->launch_type != ACL_RT_LAUNCH_KERNEL_V2"), std::string::npos); | ||
| 6771 | + EXPECT_EQ(load_and_run.find("GetIsDataDump("), std::string::npos); | ||
| 6686 | EXPECT_NE(load_and_run.find("ReportLaunchedOm2Task("), std::string::npos); | 6772 | EXPECT_NE(load_and_run.find("ReportLaunchedOm2Task("), std::string::npos); |
| 6687 | } | 6773 | } |
| 6688 | 6774 | ||
| @@ -6711,8 +6797,28 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForKernelExTask_Ok) { | |||
| 6711 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(AssembleTfAicpuExExtInfo"), std::string::npos); | 6797 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(AssembleTfAicpuExExtInfo"), std::string::npos); |
| 6712 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(AssembleTfAicpuArgs"), std::string::npos); | 6798 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(AssembleTfAicpuArgs"), std::string::npos); |
| 6713 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(TfAicpuKernelTaskDistribute"), std::string::npos); | 6799 | EXPECT_NE(load_run_code.find("OM2_CHK_STATUS(TfAicpuKernelTaskDistribute"), std::string::npos); |
| 6714 | - EXPECT_NE(load_run_code.find("GetIsDataDump("), std::string::npos); | 6800 | + EXPECT_NE(load_run_code.find("GertModelLaunchKernelV2Params launch_kernel_v2_params"), std::string::npos); |
| 6715 | - EXPECT_NE(load_run_code.find("ReportLaunchedOm2Task("), std::string::npos); | 6801 | + EXPECT_NE(load_run_code.find("launch_func(instance_handle, &launch_info)"), std::string::npos); |
| 6802 | + EXPECT_NE(load_run_code.find("TfAicpuKernelTaskDistribute: Start to execute launch callback."), std::string::npos); | ||
| 6803 | + EXPECT_NE(load_run_code.find("TfAicpuKernelTaskDistribute: Start to execute aclrtLaunchKernelV2 directly."), | ||
| 6804 | + std::string::npos); | ||
| 6805 | + EXPECT_NE(load_run_code.find("aclrtLaunchKernelV2(func_handle, block_dim, kernel_buf"), std::string::npos); | ||
| 6806 | + EXPECT_NE(load_run_code.find("ctx.launch_func, ctx.instance_handle, &task_info"), std::string::npos); | ||
| 6807 | + EXPECT_NE(load_run_code.find("nullptr, nullptr, nullptr"), std::string::npos); | ||
| 6808 | + EXPECT_EQ(load_run_code.find("GetIsDataDump("), std::string::npos); | ||
| 6809 | + const auto helper_pos = load_run_code.find("aclError TfAicpuKernelTaskDistribute"); | ||
| 6810 | + const auto helper_end = load_run_code.find("aclError AssembleTfAicpuExSessionIdInfo", helper_pos); | ||
| 6811 | + ASSERT_NE(helper_pos, std::string::npos); | ||
| 6812 | + ASSERT_NE(helper_end, std::string::npos); | ||
| 6813 | + const auto helper = load_run_code.substr(helper_pos, helper_end - helper_pos); | ||
| 6814 | + const auto helper_launch_pos = helper.find("aclrtLaunchKernelV2(func_handle, block_dim, kernel_buf"); | ||
| 6815 | + const auto helper_args_copy_pos = helper.find("memcpy_s(args_info->host_addr"); | ||
| 6816 | + ASSERT_NE(helper_launch_pos, std::string::npos); | ||
| 6817 | + ASSERT_NE(helper_args_copy_pos, std::string::npos); | ||
| 6818 | + EXPECT_LT(helper_launch_pos, helper_args_copy_pos); | ||
| 6819 | + const auto dispatch_pos = load_run_code.find("aclError DispatchKernelEx"); | ||
| 6820 | + ASSERT_NE(dispatch_pos, std::string::npos); | ||
| 6821 | + EXPECT_EQ(load_run_code.find("OM2_CHK_STATUS(ReportLaunchedOm2Task(", dispatch_pos), std::string::npos); | ||
| 6716 | } | 6822 | } |
| 6717 | 6823 | ||
| 6718 | void AppendAsyncWait(std::string &out) { | 6824 | void AppendAsyncWait(std::string &out) { |
| @@ -7062,6 +7168,45 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_AllKernel_NonZeroTaskType) { | |||
| 7062 | EXPECT_NE(load_and_run_source.find(".task_type = " + expected_task_type + ","), std::string::npos); | 7168 | EXPECT_NE(load_and_run_source.find(".task_type = " + expected_task_type + ","), std::string::npos); |
| 7063 | } | 7169 | } |
| 7064 | 7170 | ||
| 7171 | +TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_UsesUnifiedLaunchCallbacks) { | ||
| 7172 | + const auto verify = [](GeRootModelPtr model, const std::vector<std::string> &required, | ||
| 7173 | + const std::vector<std::string> &forbidden = {}) { | ||
| 7174 | + auto generator = CreateProgramGenerator(model); | ||
| 7175 | + std::map<GeneratedFileIndex, std::string> outputs; | ||
| 7176 | + ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | ||
| 7177 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; | ||
| 7178 | + for (const auto &token : required) { | ||
| 7179 | + EXPECT_NE(source.find(token), std::string::npos) << token; | ||
| 7180 | + } | ||
| 7181 | + for (const auto &token : forbidden) { | ||
| 7182 | + EXPECT_EQ(source.find(token), std::string::npos) << token; | ||
| 7183 | + } | ||
| 7184 | + }; | ||
| 7185 | + | ||
| 7186 | + verify( | ||
| 7187 | + CreateGeRootModelWithAicoreOp(), | ||
| 7188 | + {"ctx.launch_func", "AssembleOm2TaskInfo", "GertModelLaunchKernelV2Params", "GertModelTaskLaunchParams", | ||
| 7189 | + "GertModelTaskLaunchInfo", "KernelTaskDistribute", "aclrtStreamGetId", "ACL_RT_LAUNCH_KERNEL_ATTR_DATA_DUMP"}); | ||
| 7190 | + verify(CreateGeRootModelWithAicpuOp(), | ||
| 7191 | + {"AicpuKernelTaskDistribute", "GertModelLaunchKernelV2Params", "aclrtLaunchKernelV2"}); | ||
| 7192 | + verify(CreateGeRootModelWithDsaOp(), | ||
| 7193 | + {"GertModelLaunchStarsTaskWithFlagParams", "KernelDsaTaskDistribute", "rtGeneralCtrl"}); | ||
| 7194 | +} | ||
| 7195 | + | ||
| 7196 | +TEST_F(ProgramGeneratorUt, GenerateLoadSource_PreservesCallbackPointers) { | ||
| 7197 | + GeRootModelPtr model = CreateGeRootModelWithAicoreOp(); | ||
| 7198 | + ASSERT_NE(model, nullptr); | ||
| 7199 | + auto generator = CreateProgramGenerator(model); | ||
| 7200 | + std::map<GeneratedFileIndex, std::string> outputs; | ||
| 7201 | + ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS); | ||
| 7202 | + const auto &source = outputs[GeneratedFileIndex::kLoadingAndRunningFile]; | ||
| 7203 | + EXPECT_NE(source.find("const GertModelCallbacks *callbacks"), std::string::npos); | ||
| 7204 | + EXPECT_NE(source.find("callbacks->launch_func"), std::string::npos); | ||
| 7205 | + EXPECT_NE(source.find("callbacks->report_model_base_info"), std::string::npos); | ||
| 7206 | + EXPECT_NE(source.find("ctx.launch_func"), std::string::npos); | ||
| 7207 | + EXPECT_EQ(source.find("&callbacks"), std::string::npos); | ||
| 7208 | +} | ||
| 7209 | + | ||
| 7065 | // Creates a model with an AICore op that has a separately-clean atomic task. | 7210 | // Creates a model with an AICore op that has a separately-clean atomic task. |
| 7066 | // This exercises the is_separately_clean_task_ path in KernelTaskCodeBuilder, | 7211 | // This exercises the is_separately_clean_task_ path in KernelTaskCodeBuilder, |
| 7067 | // where func_handle_key is built from ATOMIC_ATTR_TBE_KERNEL_NAME + "_atomic". | 7212 | // where func_handle_key is built from ATOMIC_ATTR_TBE_KERNEL_NAME + "_atomic". |
| @@ -7280,8 +7425,6 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_ContainsProfilingPatterns) { | |||
| 7280 | EXPECT_NE(load_run.find("report_run_info_preprocess"), std::string::npos); | 7425 | EXPECT_NE(load_run.find("report_run_info_preprocess"), std::string::npos); |
| 7281 | EXPECT_NE(load_run.find("report_run_info_postprocess"), std::string::npos); | 7426 | EXPECT_NE(load_run.find("report_run_info_postprocess"), std::string::npos); |
| 7282 | EXPECT_NE(load_run.find("run_callbacks"), std::string::npos); | 7427 | EXPECT_NE(load_run.find("run_callbacks"), std::string::npos); |
| 7283 | - // DispatchKernelAicore 中应有 _launch_begin | ||
| 7284 | - EXPECT_NE(load_run.find("_launch_begin"), std::string::npos); | ||
| 7285 | // AicoreDispatchInfo 中 fusion_op 字段应被引用 | 7428 | // AicoreDispatchInfo 中 fusion_op 字段应被引用 |
| 7286 | EXPECT_NE(load_run.find("fusion_op"), std::string::npos); | 7429 | EXPECT_NE(load_run.find("fusion_op"), std::string::npos); |
| 7287 | EXPECT_NE(load_run.find("original_op_names"), std::string::npos); | 7430 | EXPECT_NE(load_run.find("original_op_names"), std::string::npos); |
| @@ -1636,6 +1636,7 @@ TEST_F(Om2ModelExecutorUt, load_passes_model_id_and_instance_handle_to_create) { | |||
| 1636 | auto executor = gert::LoadOm2ExecutorFromData(model_data_holder.model_data, load_arg, error_code); | 1636 | auto executor = gert::LoadOm2ExecutorFromData(model_data_holder.model_data, load_arg, error_code); |
| 1637 | EXPECT_EQ(error_code, SUCCESS); | 1637 | EXPECT_EQ(error_code, SUCCESS); |
| 1638 | ASSERT_NE(executor, nullptr); | 1638 | ASSERT_NE(executor, nullptr); |
| 1639 | + EXPECT_EQ(executor->GetModelId(), kTestModelId); | ||
| 1639 | } | 1640 | } |
| 1640 | 1641 | ||
| 1641 | TEST_F(Om2ModelExecutorUt, load_failed_when_device_id_is_not_set) { | 1642 | TEST_F(Om2ModelExecutorUt, load_failed_when_device_id_is_not_set) { |
| @@ -0,0 +1,244 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +namespace ge { | ||
| 25 | +namespace { | ||
| 26 | + | ||
| 27 | +class RecordingAclRuntime : public AclRuntimeStub { | ||
| 28 | + public: | ||
| 29 | + aclError launch_ret = ACL_SUCCESS; | ||
| 30 | + aclError task_id_ret = ACL_SUCCESS; | ||
| 31 | + uint32_t task_id = 17U; | ||
| 32 | + uint32_t launch_count = 0U; | ||
| 33 | + aclrtLaunchKernelCfg *last_cfg = nullptr; | ||
| 34 | + | ||
| 35 | + aclError aclrtLaunchKernelV2(aclrtFuncHandle, uint32_t, const void *, size_t, aclrtLaunchKernelCfg *cfg, | ||
| 36 | + aclrtStream) override { | ||
| 37 | + ++launch_count; | ||
| 38 | + last_cfg = cfg; | ||
| 39 | + return launch_ret; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + aclError aclrtGetThreadLastTaskId(uint32_t *id) override { | ||
| 43 | + if (task_id_ret == ACL_SUCCESS && id != nullptr) { | ||
| 44 | + *id = task_id; | ||
| 45 | + } | ||
| 46 | + return task_id_ret; | ||
| 47 | + } | ||
| 48 | +}; | ||
| 49 | + | ||
| 50 | +class RecordingRuntime : public RuntimeStub { | ||
| 51 | + public: | ||
| 52 | + rtError_t general_ctrl_ret = RT_ERROR_NONE; | ||
| 53 | + uint32_t call_count = 0U; | ||
| 54 | + uintptr_t args[4] = {}; | ||
| 55 | + uint32_t num = 0U; | ||
| 56 | + uint32_t type = 0U; | ||
| 57 | + | ||
| 58 | + rtError_t rtGeneralCtrl(uintptr_t *ctrl, uint32_t count, uint32_t ctrl_type) override { | ||
| 59 | + ++call_count; | ||
| 60 | + num = count; | ||
| 61 | + type = ctrl_type; | ||
| 62 | + for (uint32_t i = 0U; i < count && i < 4U; ++i) { | ||
| 63 | + args[i] = ctrl[i]; | ||
| 64 | + } | ||
| 65 | + return general_ctrl_ret; | ||
| 66 | + } | ||
| 67 | +}; | ||
| 68 | + | ||
| 69 | +class CallbackRuntimeUt : public testing::Test { | ||
| 70 | + protected: | ||
| 71 | + void SetUp() override { | ||
| 72 | + AclRuntimeStub::Install(&acl_); | ||
| 73 | + RuntimeStub::Install(&runtime_); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + void TearDown() override { | ||
| 77 | + RuntimeStub::UnInstall(&runtime_); | ||
| 78 | + AclRuntimeStub::UnInstall(&acl_); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + GertModelTaskLaunchInfo MakeKernelInfo(Om2TaskInfo &task, GertModelTaskLaunchParams ¶ms, | ||
| 82 | + aclrtLaunchKernelCfg *cfg = nullptr) { | ||
| 83 | + task.op_name = "op"; | ||
| 84 | + task.op_type = "Type"; | ||
| 85 | + task.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | ||
| 86 | + params.launch_kernel_v2_params.func_handle = reinterpret_cast<aclrtFuncHandle>(0x11); | ||
| 87 | + params.launch_kernel_v2_params.block_dim = 2U; | ||
| 88 | + params.launch_kernel_v2_params.args_data = reinterpret_cast<void *>(0x22); | ||
| 89 | + params.launch_kernel_v2_params.args_size = 8U; | ||
| 90 | + params.launch_kernel_v2_params.config = cfg; | ||
| 91 | + params.launch_kernel_v2_params.stream = reinterpret_cast<aclrtStream>(0x33); | ||
| 92 | + GertModelTaskLaunchInfo info; | ||
| 93 | + info.launch_type = ACL_RT_LAUNCH_KERNEL_V2; | ||
| 94 | + info.task_info = &task; | ||
| 95 | + info.launch_params = ¶ms; | ||
| 96 | + return info; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + RecordingAclRuntime acl_; | ||
| 100 | + RecordingRuntime runtime_; | ||
| 101 | +}; | ||
| 102 | + | ||
| 103 | +TEST_F(CallbackRuntimeUt, KernelLaunchUsesAclAndPostprocesses) { | ||
| 104 | + Om2TaskInfo task{}; | ||
| 105 | + GertModelTaskLaunchParams params{}; | ||
| 106 | + GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | ||
| 107 | + | ||
| 108 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 109 | + EXPECT_EQ(acl_.launch_count, 1U); | ||
| 110 | + EXPECT_EQ(task.task_id, acl_.task_id); | ||
| 111 | + EXPECT_NE(task.launch_begin, 0U); | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +TEST_F(CallbackRuntimeUt, KernelLaunchSetsDataDumpAttribute) { | ||
| 115 | + aclrtLaunchKernelAttr attr{}; | ||
| 116 | + attr.id = ACL_RT_LAUNCH_KERNEL_ATTR_DATA_DUMP; | ||
| 117 | + attr.value.isDataDump = 1U; | ||
| 118 | + aclrtLaunchKernelCfg cfg{}; | ||
| 119 | + cfg.attrs = &attr; | ||
| 120 | + cfg.numAttrs = 1U; | ||
| 121 | + Om2TaskInfo task{}; | ||
| 122 | + GertModelTaskLaunchParams params{}; | ||
| 123 | + GertModelTaskLaunchInfo info = MakeKernelInfo(task, params, &cfg); | ||
| 124 | + | ||
| 125 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 126 | + EXPECT_EQ(attr.value.isDataDump, 0U); | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +TEST_F(CallbackRuntimeUt, KernelLaunchErrorPropagates) { | ||
| 130 | + acl_.launch_ret = ACL_ERROR_RT_INTERNAL_ERROR; | ||
| 131 | + Om2TaskInfo task{}; | ||
| 132 | + GertModelTaskLaunchParams params{}; | ||
| 133 | + GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | ||
| 134 | + | ||
| 135 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), ACL_ERROR_RT_INTERNAL_ERROR); | ||
| 136 | + EXPECT_EQ(acl_.launch_count, 1U); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +TEST_F(CallbackRuntimeUt, PostprocessTaskIdErrorPropagates) { | ||
| 140 | + acl_.task_id_ret = ACL_ERROR_RT_INTERNAL_ERROR; | ||
| 141 | + Om2TaskInfo task{}; | ||
| 142 | + GertModelTaskLaunchParams params{}; | ||
| 143 | + GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | ||
| 144 | + | ||
| 145 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), ACL_ERROR_RT_INTERNAL_ERROR); | ||
| 146 | + EXPECT_EQ(acl_.launch_count, 1U); | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +TEST_F(CallbackRuntimeUt, NonAicoreKernelTypesStillLaunch) { | ||
| 150 | + for (const auto kernel_type : | ||
| 151 | + {ccKernelType::AI_CPU, ccKernelType::CUSTOMIZED, ccKernelType::HOST_CPU, ccKernelType::AI_CPU_KFC}) { | ||
| 152 | + Om2TaskInfo task{}; | ||
| 153 | + task.kernel_type = static_cast<uint64_t>(kernel_type); | ||
| 154 | + GertModelTaskLaunchParams params{}; | ||
| 155 | + GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | ||
| 156 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 157 | + } | ||
| 158 | + EXPECT_EQ(acl_.launch_count, 4U); | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +TEST_F(CallbackRuntimeUt, KernelInvalidArgumentsAreHandled) { | ||
| 162 | + GertModelTaskLaunchInfo info{}; | ||
| 163 | + info.launch_type = ACL_RT_LAUNCH_KERNEL_V2; | ||
| 164 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 165 | + | ||
| 166 | + Om2TaskInfo task{}; | ||
| 167 | + info.task_info = &task; | ||
| 168 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +TEST_F(CallbackRuntimeUt, NullLaunchInfoIsHandled) { | ||
| 172 | + EXPECT_EQ(GertModelLaunchTask(nullptr, nullptr), SUCCESS); | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +TEST_F(CallbackRuntimeUt, UnsupportedLaunchTypeReturnsUnsupported) { | ||
| 176 | + GertModelTaskLaunchInfo info{}; | ||
| 177 | + info.launch_type = static_cast<GertModelTaskLaunchType>(99U); | ||
| 178 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), UNSUPPORTED); | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +TEST_F(CallbackRuntimeUt, DsaLaunchMergesDataDumpFlagAndCallsRuntime) { | ||
| 182 | + Om2TaskInfo task{}; | ||
| 183 | + task.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_DSA); | ||
| 184 | + GertModelTaskLaunchParams params{}; | ||
| 185 | + params.launch_stars_task_params.task_sqe = reinterpret_cast<void *>(0x44); | ||
| 186 | + params.launch_stars_task_params.sqe_len = 64U; | ||
| 187 | + params.launch_stars_task_params.stream = reinterpret_cast<aclrtStream>(0x55); | ||
| 188 | + params.launch_stars_task_params.flag = 1U; | ||
| 189 | + GertModelTaskLaunchInfo info{}; | ||
| 190 | + info.launch_type = RT_STARS_TASK_LAUNCH_WITH_FLAG; | ||
| 191 | + info.task_info = &task; | ||
| 192 | + info.launch_params = ¶ms; | ||
| 193 | + | ||
| 194 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | ||
| 195 | + EXPECT_EQ(runtime_.call_count, 1U); | ||
| 196 | + EXPECT_EQ(runtime_.num, 4U); | ||
| 197 | + EXPECT_EQ(runtime_.args[1], 64U); | ||
| 198 | + EXPECT_EQ(runtime_.args[3], 1U); | ||
| 199 | + EXPECT_EQ(runtime_.type, RT_GNL_CTRL_TYPE_STARS_TSK_FLAG); | ||
| 200 | +} | ||
| 201 | + | ||
| 202 | +TEST_F(CallbackRuntimeUt, DsaRuntimeErrorPropagates) { | ||
| 203 | + runtime_.general_ctrl_ret = ACL_ERROR_RT_INTERNAL_ERROR; | ||
| 204 | + Om2TaskInfo task{}; | ||
| 205 | + GertModelTaskLaunchParams params{}; | ||
| 206 | + GertModelTaskLaunchInfo info{}; | ||
| 207 | + info.launch_type = RT_STARS_TASK_LAUNCH_WITH_FLAG; | ||
| 208 | + info.task_info = &task; | ||
| 209 | + info.launch_params = ¶ms; | ||
| 210 | + EXPECT_EQ(GertModelLaunchTask(nullptr, &info), ACL_ERROR_RT_INTERNAL_ERROR); | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +TEST(GertModelExecutorTypesUt, DefaultsAndLayoutAreStable) { | ||
| 214 | + GertModelLaunchKernelV2Params kernel{}; | ||
| 215 | + GertModelLaunchStarsTaskWithFlagParams dsa{}; | ||
| 216 | + GertModelTaskLaunchInfo info{}; | ||
| 217 | + GertModelCallbacks callbacks{}; | ||
| 218 | + Om2TaskInfo task{}; | ||
| 219 | + | ||
| 220 | + EXPECT_EQ(kernel.struct_size, sizeof(kernel)); | ||
| 221 | + EXPECT_EQ(dsa.struct_size, sizeof(dsa)); | ||
| 222 | + EXPECT_EQ(info.struct_size, sizeof(info)); | ||
| 223 | + EXPECT_EQ(callbacks.struct_size, sizeof(callbacks)); | ||
| 224 | + EXPECT_EQ(info.launch_type, ACL_RT_LAUNCH_KERNEL_V2); | ||
| 225 | + EXPECT_EQ(task.kernel_type, static_cast<uint64_t>(ccKernelType::INVALID)); | ||
| 226 | + EXPECT_EQ(kernel.reserved_1, 0U); | ||
| 227 | + EXPECT_EQ(dsa.reserved_1, 0U); | ||
| 228 | + EXPECT_EQ(dsa.reserved_2, 0U); | ||
| 229 | + EXPECT_EQ(callbacks.report_model_base_info, nullptr); | ||
| 230 | + EXPECT_EQ(callbacks.launch_func, nullptr); | ||
| 231 | + static_assert(offsetof(GertModelTaskLaunchParams, launch_kernel_v2_params) == 0U); | ||
| 232 | + static_assert(offsetof(GertModelTaskLaunchParams, launch_stars_task_params) == 0U); | ||
| 233 | + static_assert(sizeof(GertModelTaskLaunchParams) >= sizeof(GertModelLaunchKernelV2Params)); | ||
| 234 | +} | ||
| 235 | + | ||
| 236 | +TEST(GertModelExecutorTypesUt, ModelIdAndDumpHandleDefaultsAreSafe) { | ||
| 237 | + gert::Om2ModelExecutor executor; | ||
| 238 | + EXPECT_EQ(executor.GetModelId(), 0U); | ||
| 239 | + EXPECT_EQ(executor.GetModelDumpManager(), nullptr); | ||
| 240 | + EXPECT_EQ(GertModelLaunchTask(nullptr, nullptr), SUCCESS); | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +} // namespace | ||
| 244 | +} // namespace ge | ||
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | + | ||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | 28 | ||
| @@ -397,40 +398,57 @@ TEST_F(ModelDumpManagerTest, PreprocessOm2TaskInfoNoL0InfoReturnsSuccess) { | |||
| 397 | EXPECT_EQ(ret, SUCCESS); | 398 | EXPECT_EQ(ret, SUCCESS); |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | -TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessNullParamReturnsInvalid) { | 401 | +TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessNullParamReturnsSuccess) { |
| 401 | - ModelDumpManager manager(1); | 402 | + gert::Om2ModelExecutor executor; |
| 402 | Om2TaskInfo info{}; | 403 | Om2TaskInfo info{}; |
| 403 | 404 | ||
| 404 | - EXPECT_NE(ReportDfxTaskPreprocess(1U, nullptr, &info, nullptr, 0U), SUCCESS); | 405 | + EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, nullptr, 0U), ge::SUCCESS); |
| 405 | - EXPECT_NE(ReportDfxTaskPreprocess(1U, &manager, nullptr, nullptr, 0U), SUCCESS); | 406 | + EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, nullptr, nullptr, 0U), ge::SUCCESS); |
| 407 | + EXPECT_EQ(ReportDfxTaskPreprocess(1U, &executor, &info, nullptr, 0U), ge::SUCCESS); | ||
| 406 | } | 408 | } |
| 407 | 409 | ||
| 408 | -TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessReservedParamReturnsInvalid) { | 410 | +TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessReservedParamReturnsSuccess) { |
| 409 | - ModelDumpManager manager(1); | ||
| 410 | Om2TaskInfo info{}; | 411 | Om2TaskInfo info{}; |
| 411 | uint32_t reserved = 0U; | 412 | uint32_t reserved = 0U; |
| 412 | 413 | ||
| 413 | - EXPECT_NE(ReportDfxTaskPreprocess(1U, &manager, &info, &reserved, 0U), SUCCESS); | 414 | + EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); |
| 414 | - EXPECT_NE(ReportDfxTaskPreprocess(1U, &manager, &info, nullptr, 1U), SUCCESS); | 415 | + EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, nullptr, 1U), ge::SUCCESS); |
| 415 | } | 416 | } |
| 416 | 417 | ||
| 417 | -TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessReservedParamReturnsInvalid) { | 418 | +TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessReservedParamReturnsSuccess) { |
| 418 | - ModelDumpManager manager(1); | ||
| 419 | Om2TaskInfo info{}; | 419 | Om2TaskInfo info{}; |
| 420 | uint32_t reserved = 0U; | 420 | uint32_t reserved = 0U; |
| 421 | 421 | ||
| 422 | - EXPECT_NE(ReportDfxTaskPostprocess(1U, &manager, &info, &reserved, 0U), SUCCESS); | 422 | + EXPECT_EQ(ReportDfxTaskPostprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); |
| 423 | - EXPECT_NE(ReportDfxTaskPostprocess(1U, &manager, &info, nullptr, 1U), SUCCESS); | 423 | + EXPECT_EQ(ReportDfxTaskPostprocess(1U, nullptr, &info, nullptr, 1U), ge::SUCCESS); |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | -TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessRoutesToAddOm2TaskInfo) { | 426 | +TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessWithoutDumpManagerReturnsSuccess) { |
| 427 | - ModelDumpManager manager(1); | 427 | + gert::Om2ModelExecutor executor; |
| 428 | Om2TaskInfo info{}; | 428 | Om2TaskInfo info{}; |
| 429 | info.op_name = "test_op"; | 429 | info.op_name = "test_op"; |
| 430 | info.task_id = 1; | 430 | info.task_id = 1; |
| 431 | info.stream_id = 1; | 431 | info.stream_id = 1; |
| 432 | 432 | ||
| 433 | - EXPECT_EQ(ReportDfxTaskPostprocess(1U, &manager, &info, nullptr, 0U), SUCCESS); | 433 | + EXPECT_EQ(ReportDfxTaskPostprocess(1U, &executor, &info, nullptr, 0U), ge::SUCCESS); |
| 434 | +} | ||
| 435 | + | ||
| 436 | +TEST_F(ModelDumpManagerTest, IsDataDumpEnabledInvalidParamReturnsSuccess) { | ||
| 437 | + gert::Om2ModelExecutor executor; | ||
| 438 | + uint8_t is_data_dump = 1U; | ||
| 439 | + | ||
| 440 | + EXPECT_EQ(IsDataDumpEnabled(1U, nullptr, "test_op", &is_data_dump), ge::SUCCESS); | ||
| 441 | + EXPECT_EQ(IsDataDumpEnabled(1U, nullptr, "test_op", nullptr), ge::SUCCESS); | ||
| 442 | + EXPECT_EQ(IsDataDumpEnabled(1U, &executor, "test_op", &is_data_dump), ge::SUCCESS); | ||
| 443 | +} | ||
| 444 | + | ||
| 445 | +TEST_F(ModelDumpManagerTest, ReportModelBaseInfoInvalidParamReturnsSuccess) { | ||
| 446 | + gert::Om2ModelExecutor executor; | ||
| 447 | + GertModelBaseInfo info{}; | ||
| 448 | + | ||
| 449 | + EXPECT_EQ(ReportModelBaseInfo(nullptr, &info), ge::SUCCESS); | ||
| 450 | + EXPECT_EQ(ReportModelBaseInfo(&executor, nullptr), ge::SUCCESS); | ||
| 451 | + EXPECT_EQ(ReportModelBaseInfo(&executor, &info), ge::SUCCESS); | ||
| 434 | } | 452 | } |
| 435 | 453 | ||
| 436 | // 测试 AddOm2TaskInfo - Data Dump 启用场景 | 454 | // 测试 AddOm2TaskInfo - Data Dump 启用场景 |


flag和sqenlen定义到一起就不用加填充字段了