已合并
refactor: 固定OM2模型API头文件 #4774
zhangfan_hanq创建于 9月7日
refactor: 固定OM2模型API头文件 #4774
已合并
zhangfan_hanq创建于 9月7日
共 23 个文件变更+505-932
@@ -66,6 +66,12 @@ file(GLOB_RECURSE OM2_SRCS CONFIGURE_DEPENDS
66 "common/helper/om2_package_helper.cc"66 "common/helper/om2_package_helper.cc"
67 "common/helper/visual_json_converter.cc"67 "common/helper/visual_json_converter.cc"
68)68)
69+set(OM2_MODEL_API_HEADER "${AIR_CODE_DIR}/inc/framework/om2/model_api/om2_model_api.h")
70+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${OM2_MODEL_API_HEADER}")
71+file(READ "${OM2_MODEL_API_HEADER}" OM2_MODEL_API_CONTENT)
72+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/common/om2/codegen/om2_model_api_resource.cc.in"
73+ "${CMAKE_CURRENT_BINARY_DIR}/om2_model_api_resource.cc" @ONLY)
74+list(APPEND OM2_SRCS "${CMAKE_CURRENT_BINARY_DIR}/om2_model_api_resource.cc")
69set(SRC_BASE_LIST75set(SRC_BASE_LIST
70 "common/context/ctx.cc"76 "common/context/ctx.cc"
71 "common/context/local_context.cc"77 "common/context/local_context.cc"
@@ -484,26 +484,31 @@ endif
484 return SUCCESS;484 return SUCCESS;
485}485}
486 486 
487+Status ReplaceInclude(std::string &data, const std::string &include_name, const std::string &include_path,
488+ const bool required = true) {
489+ const std::string old_include = "#include \"" + include_name + "\"";
490+ const std::string new_include = "#include \"" + include_path + "\"";
491+ size_t pos = 0U;
492+ bool replaced = false;
493+ pos = data.find(old_include, pos);
494+ while (pos != std::string::npos) {
495+ (void)data.replace(pos, old_include.size(), new_include);
496+ pos += new_include.size();
497+ replaced = true;
498+ pos = data.find(old_include, pos);
499+ }
500+ GE_ASSERT_TRUE(!required || replaced, "[OM2] Include %s not found", include_name.c_str());
501+ return SUCCESS;
502+}
503+ 
487Status CreateCompileCppFiles(const Om2CodegenArtifacts &artifacts, const std::string &interface_name,504Status CreateCompileCppFiles(const Om2CodegenArtifacts &artifacts, const std::string &interface_name,
488 const std::string &header_fd_path, std::vector<MemFdFile> &cpp_files) {505 const std::string &header_fd_path, std::vector<MemFdFile> &cpp_files) {
489- const std::string old_include = "#include \"" + interface_name + "\"";
490- const std::string new_include = "#include \"" + header_fd_path + "\"";
491 for (const auto &artifact : artifacts) {506 for (const auto &artifact : artifacts) {
492 if (!IsCppFile(artifact.file_name)) {507 if (!IsCppFile(artifact.file_name)) {
493 continue;508 continue;
494 }509 }
495 std::string compile_data = artifact.data;510 std::string compile_data = artifact.data;
496- size_t pos = 0U;511+ GE_ASSERT_SUCCESS(ReplaceInclude(compile_data, interface_name, header_fd_path));
497- bool replaced = false;
498- pos = compile_data.find(old_include, pos);
499- while (pos != std::string::npos) {
500- (void)compile_data.replace(pos, old_include.size(), new_include);
501- pos += new_include.size();
502- replaced = true;
503- pos = compile_data.find(old_include, pos);
504- }
505- GE_ASSERT_TRUE(replaced, "[OM2] Interface include %s not found in %s", interface_name.c_str(),
506- artifact.file_name.c_str());
507 512 
508 MemFdFile cpp_file;513 MemFdFile cpp_file;
509 GE_ASSERT_SUCCESS(CreateMemFdFile(artifact.file_name, compile_data, cpp_file));514 GE_ASSERT_SUCCESS(CreateMemFdFile(artifact.file_name, compile_data, cpp_file));
@@ -550,24 +555,32 @@ std::string Om2Utils::NormalizeCpuArch(const std::string &cpu) {
550 555 
551Status Om2Utils::CompileGeneratedCppToSo(const Om2CodegenArtifacts &artifacts, const std::string &model_name,556Status Om2Utils::CompileGeneratedCppToSo(const Om2CodegenArtifacts &artifacts, const std::string &model_name,
552 Om2CodegenArtifact &so_artifact, const bool is_release) {557 Om2CodegenArtifact &so_artifact, const bool is_release) {
553- const std::string interface_name = model_name + "_interface.h";558+ constexpr char kModelApiName[] = "om2_model_api.h";
559+ const std::string interface_name = model_name + "_internal.h";
554 const Om2CodegenArtifact *interface_artifact = nullptr;560 const Om2CodegenArtifact *interface_artifact = nullptr;
555 GE_ASSERT_SUCCESS(FindArtifact(artifacts, interface_name, interface_artifact));561 GE_ASSERT_SUCCESS(FindArtifact(artifacts, interface_name, interface_artifact));
562+ const Om2CodegenArtifact *model_api_artifact = nullptr;
563+ GE_ASSERT_SUCCESS(FindArtifact(artifacts, kModelApiName, model_api_artifact));
556 const Om2CodegenArtifact *makefile_artifact = nullptr;564 const Om2CodegenArtifact *makefile_artifact = nullptr;
557 GE_ASSERT_SUCCESS(FindArtifact(artifacts, "Makefile", makefile_artifact));565 GE_ASSERT_SUCCESS(FindArtifact(artifacts, "Makefile", makefile_artifact));
558 566 
567+ MemFdFile model_api_file;
559 MemFdFile header_file;568 MemFdFile header_file;
560 std::vector<MemFdFile> cpp_files;569 std::vector<MemFdFile> cpp_files;
561 std::string so_path;570 std::string so_path;
562 MemFdFile makefile_file;571 MemFdFile makefile_file;
563- auto memfd_cleanup_callback = [&header_file, &cpp_files, &so_path, &makefile_file]() {572+ auto memfd_cleanup_callback = [&model_api_file, &header_file, &cpp_files, &so_path, &makefile_file]() {
573+ CloseMemFdFile(model_api_file);
564 CloseMemFdFile(header_file);574 CloseMemFdFile(header_file);
565 CloseMemFdFiles(cpp_files);575 CloseMemFdFiles(cpp_files);
566 RemoveTempFile(so_path);576 RemoveTempFile(so_path);
567 CloseMemFdFile(makefile_file);577 CloseMemFdFile(makefile_file);
568 };578 };
569 GE_MAKE_GUARD(memfd_cleanup, memfd_cleanup_callback);579 GE_MAKE_GUARD(memfd_cleanup, memfd_cleanup_callback);
570- GE_ASSERT_SUCCESS(CreateMemFdFile(interface_name, interface_artifact->data, header_file));580+ GE_ASSERT_SUCCESS(CreateMemFdFile(kModelApiName, model_api_artifact->data, model_api_file));
581+ std::string interface_data = interface_artifact->data;
582+ GE_ASSERT_SUCCESS(ReplaceInclude(interface_data, kModelApiName, model_api_file.fd_path));
583+ GE_ASSERT_SUCCESS(CreateMemFdFile(interface_name, interface_data, header_file));
571 GE_ASSERT_SUCCESS(CreateCompileCppFiles(artifacts, interface_name, header_file.fd_path, cpp_files));584 GE_ASSERT_SUCCESS(CreateCompileCppFiles(artifacts, interface_name, header_file.fd_path, cpp_files));
572 GE_CHK_BOOL_RET_STATUS(!cpp_files.empty(), FAILED, "[OM2] No generated cpp artifacts found for model %s",585 GE_CHK_BOOL_RET_STATUS(!cpp_files.empty(), FAILED, "[OM2] No generated cpp artifacts found for model %s",
573 model_name.c_str());586 model_name.c_str());
@@ -74,7 +74,6 @@ StablePartRole InferStablePartRole(StablePartId id) {
74 case StablePartId::kReadBinaryFileToBuffer:74 case StablePartId::kReadBinaryFileToBuffer:
75 case StablePartId::kGenerateJsonFile:75 case StablePartId::kGenerateJsonFile:
76 case StablePartId::kLoadAndRunExternalApis:76 case StablePartId::kLoadAndRunExternalApis:
77- case StablePartId::kInterfaceDumpApis:
78 case StablePartId::kLoadAndRunDumpHelpers:77 case StablePartId::kLoadAndRunDumpHelpers:
79 return StablePartRole::kHelperFunctionGroup;78 return StablePartRole::kHelperFunctionGroup;
80 case StablePartId::kScopeGuard:79 case StablePartId::kScopeGuard:
@@ -108,7 +108,7 @@ enum class StablePartId : uint8_t {
108 kReadBinaryFileToBuffer,108 kReadBinaryFileToBuffer,
109 kGenerateJsonFile,109 kGenerateJsonFile,
110 kLoadAndRunExternalApis,110 kLoadAndRunExternalApis,
111- kInterfaceDumpApis,111+ kInterfaceInternalTypes,
112 kLoadAndRunDumpHelpers,112 kLoadAndRunDumpHelpers,
113 kCreateLabelListForLabelSwitch,113 kCreateLabelListForLabelSwitch,
114 kCreateLabelListForLabelGotoEx,114 kCreateLabelListForLabelGotoEx,
@@ -428,188 +428,8 @@ Status ResolveStablePart(StablePartId id, std::string &output) {
428 " return Om2ModelDestroy(&model_handle);\n"428 " return Om2ModelDestroy(&model_handle);\n"
429 "}\n";429 "}\n";
430 return SUCCESS;430 return SUCCESS;
431- case StablePartId::kInterfaceDumpApis:431+ case StablePartId::kInterfaceInternalTypes:
432 output =432 output =
433- "struct GertModelTaskIoEntry {\n"
434- " uint64_t struct_size = sizeof(GertModelTaskIoEntry);\n"
435- " const gert::Tensor *tensor = nullptr;\n"
436- " uint64_t offset = 0;\n"
437- "};\n"
438- "\n"
439- "enum GertModelArgKind : uint64_t {\n"
440- " GERT_MODEL_ARG_INPUT = 0,\n"
441- " GERT_MODEL_ARG_OUTPUT = 1,\n"
442- " GERT_MODEL_ARG_WORKSPACE = 2,\n"
443- " GERT_MODEL_ARG_TILING = 3,\n"
444- " GERT_MODEL_ARG_SHAPE_INFO = 4,\n"
445- " GERT_MODEL_ARG_LEVEL1_DESC = 5,\n"
446- " GERT_MODEL_ARG_PLACEHOLDER = 6,\n"
447- " GERT_MODEL_ARG_CUSTOM_VALUE = 7,\n"
448- " GERT_MODEL_ARG_FFTS_ADDR = 8,\n"
449- " GERT_MODEL_ARG_EVENT_ADDR = 9,\n"
450- " GERT_MODEL_ARG_OVERFLOW_ADDR = 10,\n"
451- " GERT_MODEL_ARG_EMPTY_ADDR = 11,\n"
452- " GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU\n"
453- "};\n"
454- "\n"
455- "struct GertModelArgSlotInfo {\n"
456- " uint64_t struct_size = sizeof(GertModelArgSlotInfo);\n"
457- " GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND;\n"
458- " uint64_t flags = 0;\n"
459- " uint64_t args_offset = 0;\n"
460- " uint64_t value = 0;\n"
461- " uint64_t related_index = 0;\n"
462- " uint64_t event_id = 0;\n"
463- " uint64_t level1_target_offset = 0;\n"
464- "};\n"
465- "\n"
466- "struct GertModelTaskRawInfo {\n"
467- " uint64_t struct_size = sizeof(GertModelTaskRawInfo);\n"
468- " uint64_t need_assert_or_printf = 0;\n"
469- " uint64_t arg_num = 0;\n"
470- " const struct GertModelArgSlotInfo *args = nullptr;\n"
471- "};\n"
472- "\n"
473- "struct GertModelTaskDesc {\n"
474- " uint64_t struct_size = sizeof(GertModelTaskDesc);\n"
475- " const char *op_name = nullptr;\n"
476- " const char *op_type = nullptr;\n"
477- " uint64_t task_id = 0;\n"
478- " uint64_t stream_id = 0;\n"
479- " uint64_t context_id = 0;\n"
480- " uint64_t thread_id = 0;\n"
481- " uint64_t block_dim = 0;\n"
482- " uint64_t op_desc_id = 0;\n"
483- " uintptr_t args_base = 0;\n"
484- " uint64_t args_size = 0;\n"
485- " uint64_t input_num = 0;\n"
486- " const struct GertModelTaskIoEntry *inputs = nullptr;\n"
487- " uint64_t output_num = 0;\n"
488- " const struct GertModelTaskIoEntry *outputs = nullptr;\n"
489- " uint64_t workspace_num = 0;\n"
490- " const uint64_t *workspace_addrs = nullptr;\n"
491- " const uint64_t *workspace_sizes = nullptr;\n"
492- " uint64_t task_type = 0;\n"
493- " uint64_t kernel_type = 10000U;\n"
494- " void *stream = nullptr;\n"
495- " uint64_t is_raw_address = 0;\n"
496- " const struct GertModelTaskRawInfo *task_raw_info = nullptr;\n"
497- " uint64_t launch_begin = 0;\n"
498- " const char *original_op_names = nullptr;\n"
499- " uint64_t input_mem_size = 0;\n"
500- " uint64_t output_mem_size = 0;\n"
501- " uint64_t workspace_mem_size = 0;\n"
502- " uint64_t weight_mem_size = 0;\n"
503- "};\n"
504- "\n"
505- "struct GertModelBaseInfo {\n"
506- " uint64_t struct_size = sizeof(GertModelBaseInfo);\n"
507- " const void *rt_model_handle = nullptr;\n"
508- "};\n"
509- "\n"
510- "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n"
511- "\n"
512- "enum GertModelTaskLaunchType : uint64_t {\n"
513- " ACL_RT_LAUNCH_KERNEL_V2 = 0,\n"
514- " RT_STARS_TASK_LAUNCH_WITH_FLAG = 1,\n"
515- "};\n"
516- "\n"
517- "struct GertModelLaunchKernelV2Params {\n"
518- " uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params);\n"
519- " aclrtFuncHandle func_handle = nullptr;\n"
520- " uint32_t block_dim = 0;\n"
521- " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n"
522- " uint32_t abi_pad_1 = 0;\n"
523- " const void *args_data = nullptr;\n"
524- " size_t args_size = 0;\n"
525- " aclrtLaunchKernelCfg *config = nullptr;\n"
526- " aclrtStream stream = nullptr;\n"
527- "};\n"
528- "\n"
529- "struct GertModelLaunchStarsTaskWithFlagParams {\n"
530- " uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams);\n"
531- " const void *task_sqe = nullptr;\n"
532- " uint32_t sqe_len = 0;\n"
533- " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n"
534- " uint32_t abi_pad_1 = 0;\n"
535- " aclrtStream stream = nullptr;\n"
536- " uint32_t flag = 0;\n"
537- " // 用于填充空洞,保持结构体布局与 ACL 接口一致。\n"
538- " uint32_t abi_pad_2 = 0;\n"
539- "};\n"
540- "\n"
541- "union GertModelTaskLaunchParams {\n"
542- " GertModelLaunchKernelV2Params launch_kernel_v2_params;\n"
543- " GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params;\n"
544- "};\n"
545- "\n"
546- "struct GertModelTaskLaunchInfo {\n"
547- " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n"
548- " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n"
549- " GertModelTaskDesc *task_info = nullptr;\n"
550- " const GertModelTaskLaunchParams *launch_params = nullptr;\n"
551- "};\n"
552- "\n"
553- "using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);\n"
554- "using LockBinHandleStoreFunc = int32_t (*)();\n"
555- "using UnlockBinHandleStoreFunc = int32_t (*)();\n"
556- "using QueryBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle *bin_handle);\n"
557- "using SaveBinHandleToStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle bin_handle);\n"
558- "using ReleaseBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, uint8_t *need_unload);\n"
559- "\n"
560- "struct GertModelLoadCallbacks {\n"
561- " uint64_t struct_size = sizeof(GertModelLoadCallbacks);\n"
562- " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n"
563- " GertModelLaunchFunc launch_func = nullptr;\n"
564- " LockBinHandleStoreFunc lock_bin_handle_store = nullptr;\n"
565- " UnlockBinHandleStoreFunc unlock_bin_handle_store = nullptr;\n"
566- " QueryBinHandleFromStoreFunc query_bin_handle_from_store = nullptr;\n"
567- " SaveBinHandleToStoreFunc save_bin_handle_to_store = nullptr;\n"
568- " ReleaseBinHandleFromStoreFunc release_bin_handle_from_store = nullptr;\n"
569- "};\n"
570- "\n"
571- "using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo "
572- "*info);\n"
573- "\n"
574- "struct GertModelRunReportInfo {\n"
575- " uint64_t struct_size = sizeof(GertModelRunReportInfo);\n"
576- " uint64_t model_id = 0;\n"
577- " aclrtStream stream = nullptr;\n"
578- " uint64_t is_async = 0;\n"
579- "};\n"
580- "\n"
581- "struct GertModelRunCallbacks {\n"
582- " uint64_t struct_size = sizeof(GertModelRunCallbacks);\n"
583- " ReportModelRunFunc report_run_info_preprocess = nullptr;\n"
584- " ReportModelRunFunc report_run_info_postprocess = nullptr;\n"
585- "};\n"
586- "\n"
587- "struct GertModelLoadConfig {\n"
588- " uint64_t struct_size = sizeof(GertModelLoadConfig);\n"
589- " const char **bin_files = nullptr;\n"
590- " const void **bin_data = nullptr;\n"
591- " uint64_t *bin_size = nullptr;\n"
592- " uint64_t bin_num = 0;\n"
593- " void **constants = nullptr;\n"
594- " void **var_addrs = nullptr;\n"
595- " void *work_ptr = nullptr;\n"
596- " uint64_t *session_id = nullptr;\n"
597- " uint64_t model_id = 0; // used for logging\n"
598- " void *instance_handle = nullptr;\n"
599- " const struct GertModelLoadCallbacks *callbacks = nullptr;\n"
600- " int64_t priority = 0;\n"
601- " uint64_t reuse_zero_copy = 0;\n"
602- " aclmdlRI external_rt_model = nullptr;\n"
603- " aclrtStream *external_streams = nullptr;\n"
604- " uint64_t external_stream_num = 0;\n"
605- " aclrtEvent *external_events = nullptr;\n"
606- " uint64_t external_event_num = 0;\n"
607- " aclrtLabel *external_labels = nullptr;\n"
608- " uint64_t external_label_num = 0;\n"
609- " aclrtNotify *external_notifies = nullptr;\n"
610- " uint64_t external_notify_num = 0;\n"
611- "};\n"
612- "\n"
613 "struct GertModelExternalResources {\n"433 "struct GertModelExternalResources {\n"
614 " uint64_t struct_size = sizeof(GertModelExternalResources);\n"434 " uint64_t struct_size = sizeof(GertModelExternalResources);\n"
615 " aclmdlRI external_rt_model = nullptr;\n"435 " aclmdlRI external_rt_model = nullptr;\n"
@@ -621,32 +441,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) {
621 " uint64_t external_event_num = 0;\n"441 " uint64_t external_event_num = 0;\n"
622 " aclrtLabel *external_labels = nullptr;\n"442 " aclrtLabel *external_labels = nullptr;\n"
623 " uint64_t external_label_num = 0;\n"443 " uint64_t external_label_num = 0;\n"
624- "};\n"
625- "\n"
626- "struct GertModelRunConfig {\n"
627- " uint64_t struct_size = sizeof(GertModelRunConfig);\n"
628- " uint64_t input_count = 0;\n"
629- " gert::Tensor **input_data = nullptr;\n"
630- " uint64_t output_count = 0;\n"
631- " gert::Tensor **output_data = nullptr;\n"
632- " uint64_t stream_sync_timeout_ms = 0;\n"
633- " const struct GertModelRunCallbacks *run_callbacks = nullptr;\n"
634- "};\n"
635- "\n"
636- "struct GertModelUnloadConfig {\n"
637- " uint64_t struct_size = sizeof(GertModelUnloadConfig);\n"
638- "};\n"
639- "\n"
640- "struct GertModelLoadOutput {\n"
641- " uint64_t struct_size = sizeof(GertModelLoadOutput);\n"
642- "};\n"
643- "\n"
644- "struct GertModelRunOutput {\n"
645- " uint64_t struct_size = sizeof(GertModelRunOutput);\n"
646- "};\n"
647- "\n"
648- "struct GertModelUnloadOutput {\n"
649- " uint64_t struct_size = sizeof(GertModelUnloadOutput);\n"
650 "};\n";444 "};\n";
651 return SUCCESS;445 return SUCCESS;
652 case StablePartId::kLoadAndRunDumpHelpers:446 case StablePartId::kLoadAndRunDumpHelpers:
@@ -254,45 +254,4 @@ std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildRtForwardDecls() {
254 };254 };
255}255}
256 256 
257-std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildExternalApiDecls() {
258- return {
259- ast_.TypeAlias("void *", "GertModelHandle"),
260- ast_.DeclareFunction(
261- "GertModelLoad",
262- {ast_.Var("const struct GertModelLoadConfig *", "config"), ast_.Var("GertModelHandle *", "model_handle"),
263- ast_.Var("struct GertModelLoadOutput *", "output")},
264- "int32_t"),
265- ast_.DeclareFunction(
266- "GertModelRunAsync",
267- {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("aclrtStream", "stream"),
268- ast_.Var("const struct GertModelRunConfig *", "config"), ast_.Var("struct GertModelRunOutput *", "output")},
269- "int32_t"),
270- ast_.DeclareFunction(
271- "GertModelRun",
272- {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelRunConfig *", "config"),
273- ast_.Var("struct GertModelRunOutput *", "output")},
274- "int32_t"),
275- ast_.DeclareFunction(
276- "GertModelUnload",
277- {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelUnloadConfig *", "config"),
278- ast_.Var("struct GertModelUnloadOutput *", "output")},
279- "int32_t"),
280- ast_.DeclareFunction("GertModelGetStreamNum", {}, "uint64_t"),
281- ast_.DeclareFunction("GertModelGetStreamDesc",
282- {ast_.Var("uint32_t *", "stream_flags"), ast_.Var("uint64_t", "stream_num"),
283- ast_.Var("void *", "extended_attrs")},
284- "int32_t"),
285- ast_.DeclareFunction("GertModelGetEventNum", {}, "uint64_t"),
286- ast_.DeclareFunction("GertModelGetEventDesc",
287- {ast_.Var("uint32_t *", "event_flags"), ast_.Var("uint64_t", "event_num"),
288- ast_.Var("void *", "extended_attrs")},
289- "int32_t"),
290- ast_.DeclareFunction("GertModelGetLabelNum", {}, "uint64_t"),
291- ast_.DeclareFunction("GertModelGetNotifyNum", {}, "uint64_t"),
292- ast_.DeclareFunction("GertModelGetNotifyDesc",
293- {ast_.Var("uint64_t *", "notify_flags"), ast_.Var("uint64_t", "notify_num"),
294- ast_.Var("void *", "extended_attrs")},
295- "int32_t"),
296- };
297-}
298} // namespace ge257} // namespace ge
@@ -28,7 +28,6 @@ class InterfaceFileCodeGenerator : public CodeGeneratorBase {
28 FunctionDef *BuildAclrtMallocFunction() const;28 FunctionDef *BuildAclrtMallocFunction() const;
29 ClassDecl *BuildOm2ArgsTableClass();29 ClassDecl *BuildOm2ArgsTableClass();
30 ClassDecl *BuildOm2ModelClass(const Om2CodegenModel &codegen_model);30 ClassDecl *BuildOm2ModelClass(const Om2CodegenModel &codegen_model);
31- std::vector<DeclNode *> BuildExternalApiDecls();
32 std::vector<DeclNode *> BuildRtForwardDecls();31 std::vector<DeclNode *> BuildRtForwardDecls();
33 32 
34 private:33 private:
@@ -21,7 +21,8 @@ void Om2CodePrinter::SetFileInfo(GeneratedFileIndex generated_file_index, const
21}21}
22 22 
23void Om2CodePrinter::InitDefaultFileInfo(const std::string &model_name) {23void Om2CodePrinter::InitDefaultFileInfo(const std::string &model_name) {
24- SetFileInfo(GeneratedFileIndex::kInterfaceHeaderFile, model_name + "_interface.h");24+ SetFileInfo(GeneratedFileIndex::kModelApiHeaderFile, "om2_model_api.h");
25+ SetFileInfo(GeneratedFileIndex::kInterfaceHeaderFile, model_name + "_internal.h");
25 SetFileInfo(GeneratedFileIndex::kResourcesFile, model_name + "_resources.cpp");26 SetFileInfo(GeneratedFileIndex::kResourcesFile, model_name + "_resources.cpp");
26 SetFileInfo(GeneratedFileIndex::kArgsManagerFile, model_name + "_args_manager.cpp");27 SetFileInfo(GeneratedFileIndex::kArgsManagerFile, model_name + "_args_manager.cpp");
27 SetFileInfo(GeneratedFileIndex::kKernelRegistryFile, model_name + "_kernel_reg.cpp");28 SetFileInfo(GeneratedFileIndex::kKernelRegistryFile, model_name + "_kernel_reg.cpp");
@@ -17,7 +17,8 @@
17 17 
18namespace ge {18namespace ge {
19enum class GeneratedFileIndex : uint32_t {19enum class GeneratedFileIndex : uint32_t {
20- kKernelRegistryFile = 0U,20+ kModelApiHeaderFile = 0U,
21+ kKernelRegistryFile,
21 kResourcesFile,22 kResourcesFile,
22 kArgsManagerFile,23 kArgsManagerFile,
23 kLoadingAndRunningFile,24 kLoadingAndRunningFile,
@@ -0,0 +1,17 @@
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+#include <string_view>
12+ 
13+namespace ge {
14+std::string_view GetOm2ModelApiHeader() {
15+ return R"OM2_API_HDR_RSRC(@OM2_MODEL_API_CONTENT@)OM2_API_HDR_RSRC";
16+}
17+} // namespace ge
@@ -9,6 +9,7 @@
9 */9 */
10 10 
11#include "program_generator.h"11#include "program_generator.h"
12+#include <string_view>
12#include "common/om2/codegen/ast/ast_nodes.h"13#include "common/om2/codegen/ast/ast_nodes.h"
13#include "common/om2/codegen/emitter/cpp_emitter.h"14#include "common/om2/codegen/emitter/cpp_emitter.h"
14#include "common/om2/codegen/file_code_generator/args_manager_file_code_generator.h"15#include "common/om2/codegen/file_code_generator/args_manager_file_code_generator.h"
@@ -20,6 +21,8 @@
20#include "framework/common/debug/ge_log.h"21#include "framework/common/debug/ge_log.h"
21 22 
22namespace ge {23namespace ge {
24+std::string_view GetOm2ModelApiHeader();
25+ 
23namespace {26namespace {
24Status EmitFile(const GeneratedFileIndex file_index, const AstNode *unit, Om2CodePrinter &code_printer) {27Status EmitFile(const GeneratedFileIndex file_index, const AstNode *unit, Om2CodePrinter &code_printer) {
25 GE_ASSERT_TRUE(unit != nullptr, "[OM2] Program %zu AST is null.", static_cast<size_t>(file_index));28 GE_ASSERT_TRUE(unit != nullptr, "[OM2] Program %zu AST is null.", static_cast<size_t>(file_index));
@@ -42,6 +45,7 @@ Status EmitFile(const GeneratedFileIndex file_index, const AstNode *unit, Om2Cod
42 45 
43Status ProgramGenerator::GenerateProgram(Om2CodePrinter &code_printer) {46Status ProgramGenerator::GenerateProgram(Om2CodePrinter &code_printer) {
44 GE_ASSERT_SUCCESS(GenerateKernelRegSource(code_printer));47 GE_ASSERT_SUCCESS(GenerateKernelRegSource(code_printer));
48+ GE_ASSERT_SUCCESS(GenerateModelApiHeader(code_printer));
45 GE_ASSERT_SUCCESS(GenerateInterfaceHeader(code_printer));49 GE_ASSERT_SUCCESS(GenerateInterfaceHeader(code_printer));
46 GE_ASSERT_SUCCESS(GenerateResourcesSource(code_printer));50 GE_ASSERT_SUCCESS(GenerateResourcesSource(code_printer));
47 GE_ASSERT_SUCCESS(GenerateLoadAndRunSource(code_printer));51 GE_ASSERT_SUCCESS(GenerateLoadAndRunSource(code_printer));
@@ -50,6 +54,11 @@ Status ProgramGenerator::GenerateProgram(Om2CodePrinter &code_printer) {
50 return SUCCESS;54 return SUCCESS;
51}55}
52 56 
57+Status ProgramGenerator::GenerateModelApiHeader(Om2CodePrinter &code_printer) {
58+ code_printer.AddContent(GeneratedFileIndex::kModelApiHeaderFile, std::string(GetOm2ModelApiHeader()));
59+ return SUCCESS;
60+}
61+ 
53std::vector<DeclNode *> ProgramGenerator::BuildInterfaceHeaderIncludes() const {62std::vector<DeclNode *> ProgramGenerator::BuildInterfaceHeaderIncludes() const {
54 return {63 return {
55 ast_.Include("iostream", IncludeDecl::Kind::kAngle),64 ast_.Include("iostream", IncludeDecl::Kind::kAngle),
@@ -82,14 +91,14 @@ std::vector<DeclNode *> ProgramGenerator::BuildInterfaceHeaderIncludes() const {
82 91 
83Status ProgramGenerator::GenerateInterfaceHeader(Om2CodePrinter &code_printer) {92Status ProgramGenerator::GenerateInterfaceHeader(Om2CodePrinter &code_printer) {
84 InterfaceFileCodeGenerator interface_handler(ast_);93 InterfaceFileCodeGenerator interface_handler(ast_);
85- auto external_api_decls = interface_handler.BuildExternalApiDecls();
86 auto rt_forward_decls = interface_handler.BuildRtForwardDecls();94 auto rt_forward_decls = interface_handler.BuildRtForwardDecls();
87 auto file_items = BuildInterfaceHeaderIncludes();95 auto file_items = BuildInterfaceHeaderIncludes();
96+ file_items.push_back(ast_.Include("om2_model_api.h"));
88 file_items.push_back(ast_.Space());97 file_items.push_back(ast_.Space());
89 file_items.push_back(ast_.StablePart(StablePartId::kOm2LogMacros, StablePartPlacement::kTranslationUnit));98 file_items.push_back(ast_.StablePart(StablePartId::kOm2LogMacros, StablePartPlacement::kTranslationUnit));
90 file_items.push_back(ast_.StablePart(StablePartId::kInterfaceMacros));99 file_items.push_back(ast_.StablePart(StablePartId::kInterfaceMacros));
91 file_items.push_back(ast_.StablePart(StablePartId::kInterfacePointerHelpers));100 file_items.push_back(ast_.StablePart(StablePartId::kInterfacePointerHelpers));
92- file_items.push_back(ast_.StablePart(StablePartId::kInterfaceDumpApis));101+ file_items.push_back(ast_.StablePart(StablePartId::kInterfaceInternalTypes));
93 file_items.insert(file_items.end(), rt_forward_decls.begin(), rt_forward_decls.end());102 file_items.insert(file_items.end(), rt_forward_decls.begin(), rt_forward_decls.end());
94 file_items.push_back(ast_.Namespace(103 file_items.push_back(ast_.Namespace(
95 "om2",104 "om2",
@@ -110,7 +119,6 @@ Status ProgramGenerator::GenerateInterfaceHeader(Om2CodePrinter &code_printer) {
110 ast_.StablePart(StablePartId::kOpDefStructs, StablePartPlacement::kNamespace),119 ast_.StablePart(StablePartId::kOpDefStructs, StablePartPlacement::kNamespace),
111 interface_handler.BuildOm2ModelClass(codegen_model_),120 interface_handler.BuildOm2ModelClass(codegen_model_),
112 }));121 }));
113- file_items.push_back(ast_.ExternBlock("C", external_api_decls));
114 auto *translation_unit = ast_.File(file_items);122 auto *translation_unit = ast_.File(file_items);
115 GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kInterfaceHeaderFile, translation_unit, code_printer));123 GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kInterfaceHeaderFile, translation_unit, code_printer));
116 return SUCCESS;124 return SUCCESS;
@@ -131,7 +139,7 @@ Status ProgramGenerator::GenerateResourcesSource(Om2CodePrinter &code_printer) {
131 resources_items.push_back(ast_.StablePart(StablePartId::kCreateLabelListForLabelGotoEx));139 resources_items.push_back(ast_.StablePart(StablePartId::kCreateLabelListForLabelGotoEx));
132 }140 }
133 auto *translation_unit = ast_.File({141 auto *translation_unit = ast_.File({
134- ast_.Include(codegen_model_.model_name + "_interface.h"),142+ ast_.Include(codegen_model_.model_name + "_internal.h"),
135 ast_.Space(),143 ast_.Space(),
136 ast_.Namespace("om2", resources_items),144 ast_.Namespace("om2", resources_items),
137 });145 });
@@ -143,7 +151,7 @@ Status ProgramGenerator::GenerateResourcesSource(Om2CodePrinter &code_printer) {
143Status ProgramGenerator::GenerateArgsManagerSource(Om2CodePrinter &code_printer) {151Status ProgramGenerator::GenerateArgsManagerSource(Om2CodePrinter &code_printer) {
144 ArgsManagerFileCodeGenerator args_manager_handler(ast_);152 ArgsManagerFileCodeGenerator args_manager_handler(ast_);
145 auto *translation_unit = ast_.File({153 auto *translation_unit = ast_.File({
146- ast_.Include(codegen_model_.model_name + "_interface.h"),154+ ast_.Include(codegen_model_.model_name + "_internal.h"),
147 ast_.Space(),155 ast_.Space(),
148 ast_.Namespace("om2",156 ast_.Namespace("om2",
149 {157 {
@@ -177,7 +185,7 @@ Status ProgramGenerator::GenerateKernelRegSource(Om2CodePrinter &code_printer) {
177 kernel_reg_handler.BuildRegisterCustAicpuKernel(),185 kernel_reg_handler.BuildRegisterCustAicpuKernel(),
178 };186 };
179 auto *translation_unit = ast_.File({187 auto *translation_unit = ast_.File({
180- ast_.Include(codegen_model_.model_name + "_interface.h"),188+ ast_.Include(codegen_model_.model_name + "_internal.h"),
181 ast_.Namespace("om2",189 ast_.Namespace("om2",
182 {190 {
183 ast_.Namespace("", anonymous_items),191 ast_.Namespace("", anonymous_items),
@@ -200,7 +208,7 @@ Status ProgramGenerator::GenerateLoadAndRunSource(Om2CodePrinter &code_printer)
200 (void)anonymous_items.insert(anonymous_items.begin(),208 (void)anonymous_items.insert(anonymous_items.begin(),
201 ast_.StablePart(StablePartId::kLoadAndRunDumpHelpers, StablePartPlacement::kNamespace));209 ast_.StablePart(StablePartId::kLoadAndRunDumpHelpers, StablePartPlacement::kNamespace));
202 anonymous_items.push_back(load_and_run_handler.BuildOpDefTable(codegen_model_, task_code_builder_list_));210 anonymous_items.push_back(load_and_run_handler.BuildOpDefTable(codegen_model_, task_code_builder_list_));
203- std::vector<DeclNode *> body_items = {ast_.Include(codegen_model_.model_name + "_interface.h")};211+ std::vector<DeclNode *> body_items = {ast_.Include(codegen_model_.model_name + "_internal.h")};
204 if (has_custom_kernel_) {212 if (has_custom_kernel_) {
205 body_items.emplace_back(ast_.Include("graph/custom_op.h"));213 body_items.emplace_back(ast_.Include("graph/custom_op.h"));
206 body_items.emplace_back(ast_.Include("exe_graph/runtime/gert_mem_allocator.h"));214 body_items.emplace_back(ast_.Include("exe_graph/runtime/gert_mem_allocator.h"));
@@ -36,6 +36,7 @@ class ProgramGenerator {
36 Status GenerateProgram(Om2CodePrinter &code_printer);36 Status GenerateProgram(Om2CodePrinter &code_printer);
37 37 
38 private:38 private:
39+ Status GenerateModelApiHeader(Om2CodePrinter &code_printer);
39 Status GenerateInterfaceHeader(Om2CodePrinter &code_printer);40 Status GenerateInterfaceHeader(Om2CodePrinter &code_printer);
40 std::vector<DeclNode *> BuildInterfaceHeaderIncludes() const;41 std::vector<DeclNode *> BuildInterfaceHeaderIncludes() const;
41 Status GenerateResourcesSource(Om2CodePrinter &code_printer);42 Status GenerateResourcesSource(Om2CodePrinter &code_printer);
@@ -0,0 +1,298 @@
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+#ifndef OM2_MODEL_API_H_
12+#define OM2_MODEL_API_H_
13+ 
14+#include <cstddef>
15+#include <cstdint>
16+ 
17+#include "acl/acl_rt.h"
18+ 
19+namespace gert {
20+class Tensor;
21+} // namespace gert
22+ 
23+/**
24+ * @brief OM2 算子单个输入或输出 Tensor 与 args buffer 地址槽位的映射信息。
25+ */
26+struct GertModelTaskIoEntry {
27+ uint64_t struct_size = sizeof(GertModelTaskIoEntry); // 布局变化时更新
28+ const gert::Tensor *tensor = nullptr; // 输入,Tensor 基础信息指针,不允许为空。
29+ uint64_t offset = 0; // 输入,Tensor 地址在 args buffer 中的偏移,单位为字节。
30+};
31+ 
32+/**
33+ * @brief L0 异常 dump 的 kernel 参数槽位类型。
34+ */
35+enum GertModelArgKind : uint64_t {
36+ GERT_MODEL_ARG_INPUT = 0, // 输入 Tensor 地址槽位。
37+ GERT_MODEL_ARG_OUTPUT = 1, // 输出 Tensor 地址槽位。
38+ GERT_MODEL_ARG_WORKSPACE = 2, // Workspace 地址槽位。
39+ GERT_MODEL_ARG_TILING = 3, // Tiling 数据地址槽位。
40+ GERT_MODEL_ARG_SHAPE_INFO = 4, // Shape 信息地址槽位。
41+ GERT_MODEL_ARG_LEVEL1_DESC = 5, // 一级描述信息地址槽位。
42+ GERT_MODEL_ARG_PLACEHOLDER = 6, // 占位地址槽位。
43+ GERT_MODEL_ARG_CUSTOM_VALUE = 7, // 自定义立即数槽位。
44+ GERT_MODEL_ARG_FFTS_ADDR = 8, // FFTS 地址槽位。
45+ GERT_MODEL_ARG_EVENT_ADDR = 9, // Event 地址槽位。
46+ GERT_MODEL_ARG_OVERFLOW_ADDR = 10, // Overflow 地址槽位。
47+ GERT_MODEL_ARG_EMPTY_ADDR = 11, // 空地址槽位。
48+ GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU
49+};
50+ 
51+/**
52+ * @brief L0 异常 dump 的单个 kernel 参数槽位原始信息。
53+ */
54+struct GertModelArgSlotInfo {
55+ uint64_t struct_size = sizeof(GertModelArgSlotInfo); // 结构体版本号,布局变化时更新
56+ GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND; // 输入,槽位类型,取值见 GertModelArgKind。
57+ uint64_t flags = 0; // 输入,预留标志位,当前填 0。
58+ uint64_t args_offset = 0; // 输入,槽位在 args buffer 中的偏移,单位为字节。
59+ uint64_t value = 0; // 输入,槽位附加值。Tiling 或 Shape 信息场景表示数据大小,其他场景按 kind 解释。
60+ uint64_t related_index = 0; // 输入,关联索引。输入、输出或 Workspace 场景表示对应数组下标。
61+ uint64_t event_id = 0; // 输入,Event 场景的事件 ID,非 Event 场景填 0。
62+ uint64_t level1_target_offset = 0; // 输入,一级描述信息指向的目标槽位偏移,单位为字节。
63+};
64+ 
65+/**
66+ * @brief L0 异常 dump 的 kernel 参数原始信息列表。
67+ */
68+struct GertModelTaskRawInfo {
69+ uint64_t struct_size = sizeof(GertModelTaskRawInfo); // 结构体版本号,布局变化时更新
70+ uint64_t need_assert_or_printf = 0; // 输入,是否需要 assert 或 printf 相关异常 dump,0 表示不需要,非 0 表示需要。
71+ uint64_t arg_num = 0; // 输入,args 指向的槽位个数。
72+ const GertModelArgSlotInfo *args = nullptr; // 输入,槽位信息数组首地址。arg_num 为 0 时可以为空指针。
73+};
74+ 
75+/**
76+ * @brief OM2 算子任务 dump 信息。
77+ */
78+struct GertModelTaskDesc {
79+ uint64_t struct_size = sizeof(GertModelTaskDesc); // 结构体版本号,布局变化时更新
80+ const char *op_name = nullptr; // 输入,算子名称,不允许为空。
81+ const char *op_type = nullptr; // 输入,算子类型,不允许为空。
82+ uint64_t task_id = 0; // 输入,运行时 task ID。
83+ uint64_t stream_id = 0; // 输入,运行时 stream ID。
84+ uint64_t context_id = 0; // 输入,运行时 context ID。
85+ uint64_t thread_id = 0; // 输入,运行时 thread ID。
86+ uint64_t block_dim = 0; // 输入,Kernel launch block dim,非 Kernel 任务填 0。
87+ uint64_t op_desc_id = 0; // 输入,OpDesc ID。
88+ uintptr_t args_base = 0; // 输入,args buffer 基地址。
89+ uint64_t args_size = 0; // 输入,args buffer 大小,单位为字节。
90+ uint64_t input_num = 0; // 输入,inputs 指向的输入 Tensor 个数。
91+ const GertModelTaskIoEntry *inputs = nullptr; // 输入,输入 Tensor 映射数组首地址。input_num 为 0 时可以为空指针。
92+ uint64_t output_num = 0; // 输入,outputs 指向的输出 Tensor 个数。
93+ const GertModelTaskIoEntry *outputs = nullptr; // 输入,输出 Tensor 映射数组首地址。output_num 为 0 时可以为空指针。
94+ uint64_t workspace_num = 0; // 输入,Workspace 个数。
95+ const uint64_t *workspace_addrs = nullptr; // 输入,Workspace 地址数组首地址。workspace_num 为 0 时可以为空指针。
96+ const uint64_t *workspace_sizes =
97+ nullptr; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。
98+ uint64_t task_type = 0; // 输入,任务类型,取值与 ModelTaskType 保持一致。
99+ uint64_t kernel_type = 10000U; // 输入,kernel 类型,取值与 ge::ccKernelType 保持一致,默认 INVALID。
100+ void *stream = nullptr; // 输入,rtStream_t 运行时流句柄。
101+ uint64_t is_raw_address = 0; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。
102+ const GertModelTaskRawInfo *task_raw_info =
103+ nullptr; // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。
104+ uint64_t launch_begin = 0; // 输入,kernel launch 开始时间戳。
105+ const char *original_op_names = nullptr; // 输入,分号分隔的原始算子名称列表。非融合算子为 nullptr。
106+ uint64_t input_mem_size = 0; // 输入,输入内存大小,单位为字节。
107+ uint64_t output_mem_size = 0; // 输入,输出内存大小,单位为字节。
108+ uint64_t workspace_mem_size = 0; // 输入,workspace 内存大小,单位为字节。
109+ uint64_t weight_mem_size = 0; // 输入,权重内存大小,单位为字节。
110+};
111+ 
112+// GertModelBaseInfo: report_model_base_info 回调入参(codegen → executor 传递 rt_model_handle)
113+struct GertModelBaseInfo {
114+ uint64_t struct_size = sizeof(GertModelBaseInfo); // 布局变化时更新
115+ const void *rt_model_handle = nullptr; // 输入:codegen 创建的 aclmdlRI*(InitResources 后即可获得)
116+};
117+ 
118+using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const GertModelBaseInfo *info);
119+ 
120+enum GertModelTaskLaunchType : uint64_t {
121+ ACL_RT_LAUNCH_KERNEL_V2 = 0, // 通过 aclrtLaunchKernelWithConfigV2 下发。
122+ RT_STARS_TASK_LAUNCH_WITH_FLAG = 1 // 通过 rtStarsTaskLaunchWithFlag 下发。
123+};
124+ 
125+/**
126+ * @brief 普通 Kernel 下发参数。
127+ */
128+struct GertModelLaunchKernelV2Params {
129+ uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params); // 布局变化时更新。
130+ aclrtFuncHandle func_handle = nullptr; // 输入,待下发的 Kernel 函数。
131+ uint32_t block_dim = 0; // 输入,Kernel block dim。
132+ uint32_t abi_pad_1 = 0; // ABI 填充,保持与 ACL 接口布局一致。
133+ const void *args_data = nullptr; // 输入,Kernel 参数地址。
134+ size_t args_size = 0; // 输入,Kernel 参数大小,单位为字节。
135+ aclrtLaunchKernelCfg *config = nullptr; // 输入,Kernel 下发配置。
136+ aclrtStream stream = nullptr; // 输入,下发流。
137+};
138+ 
139+/**
140+ * @brief Stars Task 下发参数。
141+ */
142+struct GertModelLaunchStarsTaskWithFlagParams {
143+ uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams); // 布局变化时更新。
144+ const void *task_sqe = nullptr; // 输入,Task SQE 地址。
145+ uint32_t sqe_len = 0; // 输入,SQE 长度,单位为字节。
146+ uint32_t abi_pad_1 = 0; // ABI 填充,保持与 ACL 接口布局一致。
147+ aclrtStream stream = nullptr; // 输入,下发流。
148+ uint32_t flag = 0; // 输入,下发标志。
149+ uint32_t abi_pad_2 = 0; // ABI 填充,保持与 ACL 接口布局一致。
150+};
151+ 
152+/**
153+ * @brief 任务下发参数联合体,根据 GertModelTaskLaunchInfo::launch_type 选择成员。
154+ */
155+union GertModelTaskLaunchParams {
156+ GertModelLaunchKernelV2Params launch_kernel_v2_params;
157+ GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params;
158+};
159+ 
160+/**
161+ * @brief 运行时任务下发回调入参。
162+ */
163+struct GertModelTaskLaunchInfo {
164+ uint64_t struct_size = sizeof(GertModelTaskLaunchInfo); // 布局变化时更新。
165+ GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2; // 输入,下发类型。
166+ GertModelTaskDesc *task_info = nullptr; // 输入,任务 DFX 信息;调用方可补充运行时 task ID。
167+ const GertModelTaskLaunchParams *launch_params = nullptr; // 输入,与下发类型对应的参数。
168+};
169+ 
170+using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);
171+using LockBinHandleStoreFunc = int32_t (*)();
172+using UnlockBinHandleStoreFunc = int32_t (*)();
173+using QueryBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle *bin_handle);
174+using SaveBinHandleToStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle bin_handle);
175+using ReleaseBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, uint8_t *need_unload);
176+ 
177+/**
178+ * @brief 模型加载期由执行器提供给模型 SO 的回调集合。
179+ */
180+struct GertModelLoadCallbacks {
181+ uint64_t struct_size = sizeof(GertModelLoadCallbacks); // 布局变化时更新。
182+ ReportModelBaseInfoFunc report_model_base_info = nullptr; // 上报模型运行时句柄。
183+ GertModelLaunchFunc launch_func = nullptr; // 下发单个任务。
184+ LockBinHandleStoreFunc lock_bin_handle_store = nullptr; // 锁定二进制句柄缓存。
185+ UnlockBinHandleStoreFunc unlock_bin_handle_store = nullptr; // 解锁二进制句柄缓存。
186+ QueryBinHandleFromStoreFunc query_bin_handle_from_store = nullptr; // 查询缓存。
187+ SaveBinHandleToStoreFunc save_bin_handle_to_store = nullptr; // 写入缓存。
188+ ReleaseBinHandleFromStoreFunc release_bin_handle_from_store = nullptr; // 释放缓存。
189+};
190+ 
191+using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo *info);
192+ 
193+/**
194+ * @brief 模型执行前后 DFX 回调入参。
195+ */
196+struct GertModelRunReportInfo {
197+ uint64_t struct_size = sizeof(GertModelRunReportInfo); // 布局变化时更新。
198+ uint64_t model_id = 0; // 输入,模型 ID。
199+ aclrtStream stream = nullptr; // 输入,执行流。
200+ uint64_t is_async = 0; // 输入,是否异步执行。
201+};
202+ 
203+/**
204+ * @brief 模型执行期 DFX 回调集合。
205+ */
206+struct GertModelRunCallbacks {
207+ uint64_t struct_size = sizeof(GertModelRunCallbacks); // 布局变化时更新。
208+ ReportModelRunFunc report_run_info_preprocess = nullptr; // 执行前回调。
209+ ReportModelRunFunc report_run_info_postprocess = nullptr; // 执行后回调。
210+};
211+ 
212+/**
213+ * @brief GertModelLoad 的加载参数。
214+ */
215+struct GertModelLoadConfig {
216+ uint64_t struct_size = sizeof(GertModelLoadConfig); // 布局变化时更新。
217+ const char **bin_files = nullptr; // 输入,二进制文件路径数组。
218+ const void **bin_data = nullptr; // 输入,二进制内存地址数组。
219+ uint64_t *bin_size = nullptr; // 输入,二进制大小数组,单位为字节。
220+ uint64_t bin_num = 0; // 输入,二进制个数。
221+ void **constants = nullptr; // 输入,常量地址数组。
222+ void **var_addrs = nullptr; // 输入,变量地址数组。
223+ void *work_ptr = nullptr; // 输入,工作空间地址。
224+ uint64_t *session_id = nullptr; // 输入,Session ID。
225+ uint64_t model_id = 0; // 输入,用于日志和 DFX 的模型 ID。
226+ void *instance_handle = nullptr; // 输入,执行器实例句柄。
227+ const GertModelLoadCallbacks *callbacks = nullptr; // 输入,加载期回调集合。
228+ int64_t priority = 0; // 输入,模型优先级。
229+ uint64_t reuse_zero_copy = 0; // 输入,是否复用零拷贝资源。
230+ aclmdlRI external_rt_model = nullptr; // 输入,外部运行时模型句柄。
231+ aclrtStream *external_streams = nullptr; // 输入,外部流数组。
232+ uint64_t external_stream_num = 0; // 输入,外部流个数。
233+ aclrtEvent *external_events = nullptr; // 输入,外部 Event 数组。
234+ uint64_t external_event_num = 0; // 输入,外部 Event 个数。
235+ aclrtLabel *external_labels = nullptr; // 输入,外部 Label 数组。
236+ uint64_t external_label_num = 0; // 输入,外部 Label 个数。
237+ aclrtNotify *external_notifies = nullptr; // 输入,外部 Notify 数组。
238+ uint64_t external_notify_num = 0; // 输入,外部 Notify 个数。
239+};
240+ 
241+/**
242+ * @brief GertModelRun 和 GertModelRunAsync 的执行参数。
243+ */
244+struct GertModelRunConfig {
245+ uint64_t struct_size = sizeof(GertModelRunConfig); // 布局变化时更新。
246+ uint64_t input_count = 0; // 输入,模型输入个数。
247+ gert::Tensor **input_data = nullptr; // 输入,模型输入 Tensor 数组。
248+ uint64_t output_count = 0; // 输入,模型输出个数。
249+ gert::Tensor **output_data = nullptr; // 输入,模型输出 Tensor 数组。
250+ uint64_t stream_sync_timeout_ms = 0; // 输入,同步执行的流同步超时,单位为毫秒。
251+ const GertModelRunCallbacks *run_callbacks = nullptr; // 输入,执行期 DFX 回调集合。
252+};
253+ 
254+/** @brief GertModelUnload 的预留参数。 */
255+struct GertModelUnloadConfig {
256+ uint64_t struct_size = sizeof(GertModelUnloadConfig);
257+};
258+ 
259+/** @brief GertModelLoad 的预留输出。 */
260+struct GertModelLoadOutput {
261+ uint64_t struct_size = sizeof(GertModelLoadOutput);
262+};
263+ 
264+/** @brief GertModelRun 和 GertModelRunAsync 的预留输出。 */
265+struct GertModelRunOutput {
266+ uint64_t struct_size = sizeof(GertModelRunOutput);
267+};
268+ 
269+/** @brief GertModelUnload 的预留输出。 */
270+struct GertModelUnloadOutput {
271+ uint64_t struct_size = sizeof(GertModelUnloadOutput);
272+};
273+ 
274+#ifdef __cplusplus
275+extern "C" {
276+#endif
277+ 
278+typedef void *GertModelHandle;
279+ 
280+int32_t GertModelLoad(const GertModelLoadConfig *config, GertModelHandle *model_handle, GertModelLoadOutput *output);
281+int32_t GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, const GertModelRunConfig *config,
282+ GertModelRunOutput *output);
283+int32_t GertModelRun(GertModelHandle model_handle, const GertModelRunConfig *config, GertModelRunOutput *output);
284+int32_t GertModelUnload(GertModelHandle model_handle, const GertModelUnloadConfig *config,
285+ GertModelUnloadOutput *output);
286+uint64_t GertModelGetStreamNum();
287+int32_t GertModelGetStreamDesc(uint32_t *stream_flags, uint64_t stream_num, void *extended_attrs);
288+uint64_t GertModelGetEventNum();
289+int32_t GertModelGetEventDesc(uint32_t *event_flags, uint64_t event_num, void *extended_attrs);
290+uint64_t GertModelGetLabelNum();
291+uint64_t GertModelGetNotifyNum();
292+int32_t GertModelGetNotifyDesc(uint64_t *notify_flags, uint64_t notify_num, void *extended_attrs);
293+ 
294+#ifdef __cplusplus
295+}
296+#endif
297+ 
298+#endif // OM2_MODEL_API_H_
@@ -11,190 +11,30 @@
11#ifndef GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_11#ifndef GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_
12#define GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_12#define GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_
13 13 
14-#include <stdint.h>14+#include "framework/om2/model_api/om2_model_api.h"
15-#include <stddef.h>
16-#include <memory>
17-#include "acl/acl_rt.h"
18-#include "exe_graph/runtime/runtime_tensor.h"
19-#include "acl/acl_base_rt.h"
20 15 
21-#if defined(_MSC_VER)
22-#define OM2_C_API_EXPORT __declspec(dllexport)
23-#else
24-#define OM2_C_API_EXPORT __attribute__((visibility("default")))
25-#endif
26- 
27-// ============ Tensor信息 ============
28-/**
29- * @brief OM2 算子单个输入或输出 Tensor 与 args buffer 地址槽位的映射信息。
30- */
31-struct GertModelTaskIoEntry {
32- uint64_t struct_size = sizeof(GertModelTaskIoEntry); // 布局变化时更新
33- const gert::Tensor *tensor = nullptr; // 输入,Tensor 基础信息指针,不允许为空。
34- uint64_t offset = 0; // 输入,Tensor 地址在 args buffer 中的偏移,单位为字节。
35-};
36- 
37-/**
38- * @brief L0 异常 dump 的 kernel 参数槽位类型。
39- */
40-enum GertModelArgKind : uint64_t {
41- GERT_MODEL_ARG_INPUT = 0, // 输入 Tensor 地址槽位。
42- GERT_MODEL_ARG_OUTPUT = 1, // 输出 Tensor 地址槽位。
43- GERT_MODEL_ARG_WORKSPACE = 2, // Workspace 地址槽位。
44- GERT_MODEL_ARG_TILING = 3, // Tiling 数据地址槽位。
45- GERT_MODEL_ARG_SHAPE_INFO = 4, // Shape 信息地址槽位。
46- GERT_MODEL_ARG_LEVEL1_DESC = 5, // 一级描述信息地址槽位。
47- GERT_MODEL_ARG_PLACEHOLDER = 6, // 占位地址槽位。
48- GERT_MODEL_ARG_CUSTOM_VALUE = 7, // 自定义立即数槽位。
49- GERT_MODEL_ARG_FFTS_ADDR = 8, // FFTS 地址槽位。
50- GERT_MODEL_ARG_EVENT_ADDR = 9, // Event 地址槽位。
51- GERT_MODEL_ARG_OVERFLOW_ADDR = 10, // Overflow 地址槽位。
52- GERT_MODEL_ARG_EMPTY_ADDR = 11, // 空地址槽位。
53- GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU
54-};
55- 
56-/**
57- * @brief L0 异常 dump 的单个 kernel 参数槽位原始信息。
58- */
59-struct GertModelArgSlotInfo {
60- uint64_t struct_size = sizeof(GertModelArgSlotInfo); // 结构体版本号,布局变化时更新
61- GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND; // 输入,槽位类型,取值见 GertModelArgKind。
62- uint64_t flags = 0; // 输入,预留标志位,当前填 0。
63- uint64_t args_offset = 0; // 输入,槽位在 args buffer 中的偏移,单位为字节。
64- uint64_t value = 0; // 输入,槽位附加值。Tiling 或 Shape 信息场景表示数据大小,其他场景按 kind 解释。
65- uint64_t related_index = 0; // 输入,关联索引。输入、输出或 Workspace 场景表示对应数组下标。
66- uint64_t event_id = 0; // 输入,Event 场景的事件 ID,非 Event 场景填 0。
67- uint64_t level1_target_offset = 0; // 输入,一级描述信息指向的目标槽位偏移,单位为字节。
68-};
69- 
70-/**
71- * @brief L0 异常 dump 的 kernel 参数原始信息列表。
72- */
73-struct GertModelTaskRawInfo {
74- uint64_t struct_size = sizeof(GertModelTaskRawInfo); // 结构体版本号,布局变化时更新
75- // 输入,是否需要 assert 或 printf 相关异常 dump,0 表示不需要,非 0 表示需要。
76- uint64_t need_assert_or_printf = 0;
77- uint64_t arg_num = 0; // 输入,args 指向的槽位个数。
78- // 输入,槽位信息数组首地址。arg_num 为 0 时可以为空指针。
79- const struct GertModelArgSlotInfo *args = nullptr;
80-};
81- 
82-// ============ Task Dump 信息 ============
83-/**
84- * @brief OM2 算子任务 dump 信息。
85- */
86-struct GertModelTaskDesc {
87- uint64_t struct_size = sizeof(GertModelTaskDesc); // 结构体版本号,布局变化时更新
88- // 基础信息
89- const char *op_name = nullptr; // 输入,算子名称,不允许为空。
90- const char *op_type = nullptr; // 输入,算子类型,不允许为空。
91- uint64_t task_id = 0; // 输入,运行时 task ID。
92- uint64_t stream_id = 0; // 输入,运行时 stream ID。
93- uint64_t context_id = 0; // 输入,运行时 context ID。
94- uint64_t thread_id = 0; // 输入,运行时 thread ID。
95- uint64_t block_dim = 0; // 输入,Kernel launch block dim,非 Kernel 任务填 0。
96- uint64_t op_desc_id = 0; // 输入,OpDesc ID。
97- uintptr_t args_base = 0; // 输入,args buffer 基地址。
98- uint64_t args_size = 0; // 输入,args buffer 大小,单位为字节。
99- 
100- // 输入输出
101- uint64_t input_num = 0; // 输入,inputs 指向的输入 Tensor 个数。
102- // 输入,输入 Tensor 映射数组首地址。input_num 为 0 时可以为空指针。
103- const struct GertModelTaskIoEntry *inputs = nullptr;
104- uint64_t output_num = 0; // 输入,outputs 指向的输出 Tensor 个数。
105- // 输入,输出 Tensor 映射数组首地址。output_num 为 0 时可以为空指针。
106- const struct GertModelTaskIoEntry *outputs = nullptr;
107- 
108- // Workspace
109- uint64_t workspace_num = 0; // 输入,Workspace 个数。
110- const uint64_t *workspace_addrs = nullptr; // 输入,Workspace 地址数组首地址。workspace_num 为 0 时可以为空指针。
111- const uint64_t *workspace_sizes =
112- nullptr; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。
113- 
114- // 其他
115- uint64_t task_type = 0; // 输入,任务类型,取值与 ModelTaskType 保持一致。
116- uint64_t kernel_type = 10000U; // 输入,kernel 类型,取值与 ge::ccKernelType 保持一致,默认 INVALID。
117- void *stream = nullptr; // 输入,rtStream_t 运行时流句柄。
118- uint64_t is_raw_address = 0; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。
119- // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。
120- const struct GertModelTaskRawInfo *task_raw_info = nullptr;
121- 
122- // kernel launch 计时
123- uint64_t launch_begin = 0; // 输入,kernel launch 开始时间戳
124- 
125- // 融合算子信息
126- const char *original_op_names = nullptr; // 输入,分号分隔的原始算子名称列表。非融合算子为 nullptr。
127- uint64_t input_mem_size = 0; // 输入,输入内存大小,单位为字节。
128- uint64_t output_mem_size = 0; // 输入,输出内存大小,单位为字节。
129- uint64_t workspace_mem_size = 0; // 输入,workspace 内存大小,单位为字节。
130- uint64_t weight_mem_size = 0; // 输入,权重内存大小,单位为字节。
131-};
132- 
133-// ============ Run 阶段回调函数类型定义 ============
134- 
135-using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo *info);
136- 
137-struct GertModelRunReportInfo {
138- uint64_t struct_size = sizeof(GertModelRunReportInfo); // 布局变化时更新
139- uint64_t model_id = 0; // 模型 id
140- aclrtStream stream = nullptr; // 执行流(async: exe_stream; sync: nullptr)
141- uint64_t is_async = 0; // 区分同步/异步
142-};
143- 
144-struct GertModelRunCallbacks {
145- uint64_t struct_size = sizeof(GertModelRunCallbacks); // 布局变化时更新
146- ReportModelRunFunc report_run_info_preprocess = nullptr; // aclmdlRIExecute 前回调
147- ReportModelRunFunc report_run_info_postprocess = nullptr; // aclmdlRIExecute 后回调
148-};
149- 
150-// ============ Dump 回调函数入参 struct 的类型定义 ============
151- 
152-// GertModelBaseInfo: report_model_base_info 回调入参(codegen → executor 传递 rt_model_handle)
153-struct GertModelBaseInfo {
154- uint64_t struct_size = sizeof(GertModelBaseInfo); // 布局变化时更新
155- const void *rt_model_handle = nullptr; // 输入:codegen 创建的 aclmdlRI*(InitResources 后即可获得)
156-};
157- 
158-using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);
159- 
160-// ============ 弱符号接口 ============
161/**16/**
162 * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。17 * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。
163- * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。
164- * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。
165- * @param task_info 输入,算子任务 dump 信息指针,不允许为空。
166- * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。
167- * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。
168 * @return 返回 0 表示成功,返回其他值表示失败。18 * @return 返回 0 表示成功,返回其他值表示失败。
169 */19 */
170-int32_t ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info,20+int32_t ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, const GertModelTaskDesc *task_info,
171 const void *extended_attrs, size_t extended_attrs_size);21 const void *extended_attrs, size_t extended_attrs_size);
172 22 
173/**23/**
174 * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。24 * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。
175- * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。
176- * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。
177- * @param task_info 输入,算子任务 dump 信息指针,不允许为空。
178- * @param extended_attrs 输入,预留扩展属性指针,当前必须为空指针。
179- * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。
180 * @return 返回 0 表示成功,返回其他值表示失败。25 * @return 返回 0 表示成功,返回其他值表示失败。
181 */26 */
182-int32_t ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info,27+int32_t ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, const GertModelTaskDesc *task_info,
183 const void *extended_attrs, size_t extended_attrs_size);28 const void *extended_attrs, size_t extended_attrs_size);
184 29 
185/**30/**
186 * @brief 查询指定算子是否需要 Data Dump。31 * @brief 查询指定算子是否需要 Data Dump。
187- * @param model_id 输入,模型 ID。当前预留,接口内部暂不使用。
188- * @param instance_handle 输入,Om2ModelExecutor 实例指针,不允许为空。
189- * @param op_name 输入,算子名称。
190- * @param is_data_dump 输出,该算子是否需要 Data Dump,0 表示不需要,1 表示需要。
191 * @return 返回 0 表示成功,返回其他值表示失败。32 * @return 返回 0 表示成功,返回其他值表示失败。
192 */33 */
193int32_t IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, uint8_t *is_data_dump);34int32_t IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, uint8_t *is_data_dump);
194 35 
195-int32_t ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info);36+int32_t ReportModelBaseInfo(void *instance_handle, const GertModelBaseInfo *info);
196- 37+int32_t ReportRunInfoPreprocess(void *instance_handle, const GertModelRunReportInfo *info);
197-int32_t ReportRunInfoPreprocess(void *instance_handle, const struct GertModelRunReportInfo *info);38+int32_t ReportRunInfoPostprocess(void *instance_handle, const GertModelRunReportInfo *info);
198-int32_t ReportRunInfoPostprocess(void *instance_handle, const struct GertModelRunReportInfo *info);
199 39 
200#endif // GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_40#endif // GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_
@@ -14,7 +14,7 @@
14#include <stdint.h>14#include <stdint.h>
15 15 
16#include "acl/acl_rt.h"16#include "acl/acl_rt.h"
17-#include "framework/runtime/gert_model/gert_model_executor_types.h"17+#include "framework/om2/model_api/om2_model_api.h"
18 18 
19#ifdef __cplusplus19#ifdef __cplusplus
20extern "C" {20extern "C" {
@@ -11,80 +11,7 @@
11#ifndef GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_11#ifndef GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_
12#define GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_12#define GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_
13 13 
14-#include "framework/runtime/dump/model_dump_c_api.h"14+// Kept as a compatibility include for existing runtime users. The ABI types are defined only once.
15- 15+#include "framework/om2/model_api/om2_model_api.h"
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 abi_pad_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 abi_pad_1 = 0;
41- aclrtStream stream = nullptr;
42- uint32_t flag = 0;
43- // 用于填充空洞,保持结构体布局与 ACL 接口一致。
44- uint32_t abi_pad_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- GertModelTaskDesc *task_info = nullptr;
57- const GertModelTaskLaunchParams *launch_params = nullptr;
58-};
59- 
60-#ifdef __cplusplus
61-extern "C" {
62-#endif
63- 
64-typedef int32_t (*GertModelLaunchFunc)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);
65- 
66-using LockBinHandleStoreFunc = int32_t (*)();
67-using UnlockBinHandleStoreFunc = int32_t (*)();
68-using QueryBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle *bin_handle);
69-using SaveBinHandleToStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle bin_handle);
70-using ReleaseBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, uint8_t *need_unload);
71- 
72-#ifdef __cplusplus
73-}
74-#endif
75- 
76-struct GertModelLoadCallbacks {
77- uint64_t struct_size = sizeof(GertModelLoadCallbacks); // 布局变化时更新
78- 
79- // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调;
80- // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo)
81- ReportModelBaseInfoFunc report_model_base_info = nullptr;
82- GertModelLaunchFunc launch_func = nullptr;
83- LockBinHandleStoreFunc lock_bin_handle_store = nullptr;
84- UnlockBinHandleStoreFunc unlock_bin_handle_store = nullptr;
85- QueryBinHandleFromStoreFunc query_bin_handle_from_store = nullptr;
86- SaveBinHandleToStoreFunc save_bin_handle_to_store = nullptr;
87- ReleaseBinHandleFromStoreFunc release_bin_handle_from_store = nullptr;
88-};
89 16 
90#endif // GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_17#endif // GE_FRAMEWORK_RUNTIME_GERT_MODEL_GERT_MODEL_EXECUTOR_TYPES_H_
@@ -9,6 +9,7 @@
9 */9 */
10 10 
11#include "framework/runtime/gert_model/gert_model_executor_callbacks.h"11#include "framework/runtime/gert_model/gert_model_executor_callbacks.h"
12+#include "framework/runtime/dump/model_dump_c_api.h"
12 13 
13#include <array>14#include <array>
14#include <cstddef>15#include <cstddef>
@@ -19,6 +19,7 @@
19#include <unistd.h>19#include <unistd.h>
20#include "acl/acl_rt.h"20#include "acl/acl_rt.h"
21#include "registry/op_impl_space_registry_v2.h"21#include "registry/op_impl_space_registry_v2.h"
22+#include "framework/om2/model_api/om2_model_api.h"
22#include "framework/runtime/rt_session.h"23#include "framework/runtime/rt_session.h"
23#include "framework/runtime/gert_model/gert_model_executor_callbacks.h"24#include "framework/runtime/gert_model/gert_model_executor_callbacks.h"
24#include "framework/runtime/dump/model_dump_manager.h"25#include "framework/runtime/dump/model_dump_manager.h"
@@ -54,65 +55,6 @@ constexpr size_t kMaxErrorStringLen = 128U;
54constexpr size_t FILE_MAGIC_HEADER_SIZE = 4U;55constexpr size_t FILE_MAGIC_HEADER_SIZE = 4U;
55constexpr uint8_t OM2_MAGIC[] = {0x50, 0x4B, 0x03, 0x04};56constexpr uint8_t OM2_MAGIC[] = {0x50, 0x4B, 0x03, 0x04};
56 57 
57-using GertModelHandle = void *;
58- 
59-// 入参合并为结构体:首字段 struct_size 版本号,新字段只能追加;整数类型统一 uint64_t
60-struct GertModelLoadConfig { // 合并 Create+Load:容纳原 Om2ModelCreate 全部参数
61- uint64_t struct_size = sizeof(GertModelLoadConfig); // 布局变化时更新
62- const char **bin_files = nullptr; // 输入:bin 文件路径列表
63- const void **bin_data = nullptr; // 输入:bin 内存数据列表
64- uint64_t *bin_size = nullptr; // 输入:bin 大小列表
65- uint64_t bin_num = 0; // 输入:bin 数量
66- void **constants = nullptr; // 输入:常量
67- void **var_addrs = nullptr; // 输入:vars
68- void *work_ptr = nullptr; // 输入:工作内存指针
69- uint64_t *session_id = nullptr; // 输入:session id
70- uint64_t model_id = 0; // 输入:model id,打印日志用
71- void *instance_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数
72- const struct GertModelLoadCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump)
73- int64_t priority = 0; // 输入:优先级
74- uint64_t reuse_zero_copy = 0; // 输入:是否复用零拷贝内存
75- aclmdlRI external_rt_model = nullptr; // 输入:外部创建的 rtModel,可空(nullptr = pbody 自行创建)
76- aclrtStream *external_streams = nullptr; // 输入:外部创建的 stream 数组,可空
77- uint64_t external_stream_num = 0; // 输入:外部 stream 数量
78- aclrtEvent *external_events = nullptr; // 输入:外部创建的 event 数组,可空
79- uint64_t external_event_num = 0; // 输入:外部 event 数量
80- aclrtLabel *external_labels = nullptr; // 输入:外部创建的 label 数组,可空
81- uint64_t external_label_num = 0; // 输入:外部 label 数量
82- aclrtNotify *external_notifies = nullptr; // 输入:外部创建的 notify 数组,可空
83- uint64_t external_notify_num = 0; // 输入:外部 notify 数量
84-};
85- 
86-struct GertModelRunConfig {
87- uint64_t struct_size = sizeof(GertModelRunConfig); // 布局变化时更新
88- uint64_t input_count = 0; // 输入数量
89- gert::Tensor **input_data = nullptr; // 输入数据
90- uint64_t output_count = 0; // 输出数量
91- gert::Tensor **output_data = nullptr; // 输出数据
92- uint64_t stream_sync_timeout_ms = 0; // Run 使用(同步超时);RunAsync 置 0
93- const struct GertModelRunCallbacks *run_callbacks;
94-};
95- 
96-struct GertModelUnloadConfig {
97- uint64_t struct_size = sizeof(GertModelUnloadConfig); // 布局变化时更新
98-};
99- 
100-// ============================================================
101-// 接口输出结构:所有接口 Config 为输入,Output 为输出;首字段 struct_size 版本号,新字段只能追加
102-// ============================================================
103- 
104-struct GertModelLoadOutput {
105- uint64_t struct_size = sizeof(GertModelLoadOutput); // 布局变化时更新
106-};
107- 
108-struct GertModelRunOutput {
109- uint64_t struct_size = sizeof(GertModelRunOutput); // 布局变化时更新
110-};
111- 
112-struct GertModelUnloadOutput {
113- uint64_t struct_size = sizeof(GertModelUnloadOutput); // 布局变化时更新
114-};
115- 
116using LoadFunc = int (*)(const struct GertModelLoadConfig *config, GertModelHandle *model_handle,58using LoadFunc = int (*)(const struct GertModelLoadConfig *config, GertModelHandle *model_handle,
117 struct GertModelLoadOutput *output);59 struct GertModelLoadOutput *output);
118using RunFunc = int (*)(GertModelHandle model_handle, const struct GertModelRunConfig *config,60using RunFunc = int (*)(GertModelHandle model_handle, const struct GertModelRunConfig *config,
@@ -1665,7 +1665,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreNode) {
1665 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",1665 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
1666 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",1666 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
1667 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",1667 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
1668- "fake_test/data/model_0/runtime/csrc/g1_interface.h",1668+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
1669+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
1669 "fake_test/data/model_0/runtime/csrc/Makefile",1670 "fake_test/data/model_0/runtime/csrc/Makefile",
1670 "fake_test/data/model_0/runtime/libg1_om2.so",1671 "fake_test/data/model_0/runtime/libg1_om2.so",
1671 "fake_test/data/constants/model_0_constants_config.json",1672 "fake_test/data/constants/model_0_constants_config.json",
@@ -1693,7 +1694,7 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreNode) {
1693 EXPECT_NE(load_and_run.find("OM2_CHK_STATUS(args_table_.CopyArgsToDevice(nullptr, false));"), std::string::npos);1694 EXPECT_NE(load_and_run.find("OM2_CHK_STATUS(args_table_.CopyArgsToDevice(nullptr, false));"), std::string::npos);
1694 1695 
1695 size_t interface_size = 0U;1696 size_t interface_size = 0U;
1696- const auto interface_buf = archive.ExtractToMem("fake_test/data/model_0/runtime/csrc/g1_interface.h", interface_size);1697+ const auto interface_buf = archive.ExtractToMem("fake_test/data/model_0/runtime/csrc/g1_internal.h", interface_size);
1697 ASSERT_NE(interface_buf, nullptr);1698 ASSERT_NE(interface_buf, nullptr);
1698 const std::string interface_header(reinterpret_cast<const char *>(interface_buf.get()), interface_size);1699 const std::string interface_header(reinterpret_cast<const char *>(interface_buf.get()), interface_size);
1699 EXPECT_NE(interface_header.find("CopyArgsToDevice(void *stream, bool is_async)"), std::string::npos);1700 EXPECT_NE(interface_header.find("CopyArgsToDevice(void *stream, bool is_async)"), std::string::npos);
@@ -2104,7 +2105,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAtomicAicoreNode) {
2104 "fake_test_atomic/data/model_0/runtime/csrc/g1_resources.cpp",2105 "fake_test_atomic/data/model_0/runtime/csrc/g1_resources.cpp",
2105 "fake_test_atomic/data/model_0/runtime/csrc/g1_args_manager.cpp",2106 "fake_test_atomic/data/model_0/runtime/csrc/g1_args_manager.cpp",
2106 "fake_test_atomic/data/model_0/runtime/csrc/g1_load_and_run.cpp",2107 "fake_test_atomic/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2107- "fake_test_atomic/data/model_0/runtime/csrc/g1_interface.h",2108+ "fake_test_atomic/data/model_0/runtime/csrc/om2_model_api.h",
2109+ "fake_test_atomic/data/model_0/runtime/csrc/g1_internal.h",
2108 "fake_test_atomic/data/model_0/runtime/csrc/Makefile",2110 "fake_test_atomic/data/model_0/runtime/csrc/Makefile",
2109 "fake_test_atomic/data/model_0/runtime/libg1_om2.so",2111 "fake_test_atomic/data/model_0/runtime/libg1_om2.so",
2110 "fake_test_atomic/data/constants/model_0_constants_config.json",2112 "fake_test_atomic/data/constants/model_0_constants_config.json",
@@ -2143,7 +2145,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithInternalConst) {
2143 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2145 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2144 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2146 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2145 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2147 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2146- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2148+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2149+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2147 "fake_test/data/model_0/runtime/csrc/Makefile",2150 "fake_test/data/model_0/runtime/csrc/Makefile",
2148 "fake_test/data/model_0/runtime/libg1_om2.so",2151 "fake_test/data/model_0/runtime/libg1_om2.so",
2149 "fake_test/data/constants/constant_0",2152 "fake_test/data/constants/constant_0",
@@ -2189,7 +2192,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithFileConstMeta) {
2189 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2192 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2190 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2193 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2191 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2194 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2192- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2195+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2196+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2193 "fake_test/data/model_0/runtime/csrc/Makefile",2197 "fake_test/data/model_0/runtime/csrc/Makefile",
2194 "fake_test/data/model_0/runtime/libg1_om2.so",2198 "fake_test/data/model_0/runtime/libg1_om2.so",
2195 "fake_test/data/constants/constant_0",2199 "fake_test/data/constants/constant_0",
@@ -2351,7 +2355,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreOp2) {
2351 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2355 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2352 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2356 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2353 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2357 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2354- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2358+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2359+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2355 "fake_test/data/model_0/runtime/csrc/Makefile",2360 "fake_test/data/model_0/runtime/csrc/Makefile",
2356 "fake_test/data/model_0/runtime/libg1_om2.so",2361 "fake_test/data/model_0/runtime/libg1_om2.so",
2357 "fake_test/data/constants/model_0_constants_config.json",2362 "fake_test/data/constants/model_0_constants_config.json",
@@ -2383,7 +2388,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicoreOpOfDynamicIo) {
2383 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2388 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2384 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2389 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2385 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2390 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2386- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2391+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2392+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2387 "fake_test/data/model_0/runtime/csrc/Makefile",2393 "fake_test/data/model_0/runtime/csrc/Makefile",
2388 "fake_test/data/model_0/runtime/libg1_om2.so",2394 "fake_test/data/model_0/runtime/libg1_om2.so",
2389 "fake_test/data/constants/model_0_constants_config.json",2395 "fake_test/data/constants/model_0_constants_config.json",
@@ -2415,7 +2421,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithAicpuOp) {
2415 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2421 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2416 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2422 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2417 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2423 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2418- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2424+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2425+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2419 "fake_test/data/model_0/runtime/csrc/Makefile",2426 "fake_test/data/model_0/runtime/csrc/Makefile",
2420 "fake_test/data/model_0/runtime/libg1_om2.so",2427 "fake_test/data/model_0/runtime/libg1_om2.so",
2421 "fake_test/data/constants/model_0_constants_config.json",2428 "fake_test/data/constants/model_0_constants_config.json",
@@ -2446,7 +2453,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithCustAicpuOp) {
2446 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2453 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2447 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2454 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2448 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2455 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2449- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2456+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2457+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2450 "fake_test/data/model_0/runtime/csrc/Makefile",2458 "fake_test/data/model_0/runtime/csrc/Makefile",
2451 "fake_test/data/model_0/runtime/libg1_om2.so",2459 "fake_test/data/model_0/runtime/libg1_om2.so",
2452 "fake_test/data/constants/model_0_constants_config.json",2460 "fake_test/data/constants/model_0_constants_config.json",
@@ -2497,7 +2505,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithTfAicpuOp) {
2497 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2505 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2498 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2506 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2499 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2507 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2500- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2508+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2509+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2501 "fake_test/data/model_0/runtime/csrc/Makefile",2510 "fake_test/data/model_0/runtime/csrc/Makefile",
2502 "fake_test/data/model_0/runtime/libg1_om2.so",2511 "fake_test/data/model_0/runtime/libg1_om2.so",
2503 "fake_test/data/constants/model_0_constants_config.json",2512 "fake_test/data/constants/model_0_constants_config.json",
@@ -2645,7 +2654,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithCmoTask) {
2645 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2654 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2646 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2655 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2647 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2656 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2648- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2657+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2658+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2649 "fake_test/data/model_0/runtime/csrc/Makefile",2659 "fake_test/data/model_0/runtime/csrc/Makefile",
2650 "fake_test/data/model_0/runtime/libg1_om2.so",2660 "fake_test/data/model_0/runtime/libg1_om2.so",
2651 "fake_test/data/constants/model_0_constants_config.json",2661 "fake_test/data/constants/model_0_constants_config.json",
@@ -2677,7 +2687,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithBarrierTask) {
2677 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2687 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2678 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2688 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2679 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2689 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2680- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2690+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2691+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2681 "fake_test/data/model_0/runtime/csrc/Makefile",2692 "fake_test/data/model_0/runtime/csrc/Makefile",
2682 "fake_test/data/model_0/runtime/libg1_om2.so",2693 "fake_test/data/model_0/runtime/libg1_om2.so",
2683 "fake_test/data/constants/model_0_constants_config.json",2694 "fake_test/data/constants/model_0_constants_config.json",
@@ -2904,7 +2915,8 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithSeparatelyCleanTask) {
2904 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",2915 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
2905 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",2916 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
2906 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",2917 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
2907- "fake_test/data/model_0/runtime/csrc/g1_interface.h",2918+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
2919+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
2908 "fake_test/data/model_0/runtime/csrc/Makefile",2920 "fake_test/data/model_0/runtime/csrc/Makefile",
2909 "fake_test/data/model_0/runtime/libg1_om2.so",2921 "fake_test/data/model_0/runtime/libg1_om2.so",
2910 "fake_test/data/constants/model_0_constants_config.json",2922 "fake_test/data/constants/model_0_constants_config.json",
@@ -179,11 +179,12 @@ GeModelPtr CreateGeModelWithControlTasks() {
179}179}
180 180 
181const std::map<GeneratedFileIndex, std::string> kGeneratedFileNames = {181const std::map<GeneratedFileIndex, std::string> kGeneratedFileNames = {
182+ {GeneratedFileIndex::kModelApiHeaderFile, "om2_model_api.h"},
182 {GeneratedFileIndex::kKernelRegistryFile, "g1_kernel_reg.cpp"},183 {GeneratedFileIndex::kKernelRegistryFile, "g1_kernel_reg.cpp"},
183 {GeneratedFileIndex::kResourcesFile, "g1_resources.cpp"},184 {GeneratedFileIndex::kResourcesFile, "g1_resources.cpp"},
184 {GeneratedFileIndex::kArgsManagerFile, "g1_args_manager.cpp"},185 {GeneratedFileIndex::kArgsManagerFile, "g1_args_manager.cpp"},
185 {GeneratedFileIndex::kLoadingAndRunningFile, "g1_load_and_run.cpp"},186 {GeneratedFileIndex::kLoadingAndRunningFile, "g1_load_and_run.cpp"},
186- {GeneratedFileIndex::kInterfaceHeaderFile, "g1_interface.h"},187+ {GeneratedFileIndex::kInterfaceHeaderFile, "g1_internal.h"},
187 {GeneratedFileIndex::kCMakeListsFile, "Makefile"},188 {GeneratedFileIndex::kCMakeListsFile, "Makefile"},
188};189};
189 190 
@@ -327,6 +328,10 @@ TEST_F(ControlTaskCodeGeneratorUt, GenerateControlTaskFiles_Ok) {
327 ASSERT_EQ(ReadGeneratedArtifact(artifacts, GeneratedFileIndex::kInterfaceHeaderFile, header_file), SUCCESS);328 ASSERT_EQ(ReadGeneratedArtifact(artifacts, GeneratedFileIndex::kInterfaceHeaderFile, header_file), SUCCESS);
328 ASSERT_FALSE(header_file.empty());329 ASSERT_FALSE(header_file.empty());
329 330 
331+ std::string model_api_header;
332+ ASSERT_EQ(ReadGeneratedArtifact(artifacts, GeneratedFileIndex::kModelApiHeaderFile, model_api_header), SUCCESS);
333+ ASSERT_FALSE(model_api_header.empty());
334+ 
330 std::string resources_file;335 std::string resources_file;
331 ASSERT_EQ(ReadGeneratedArtifact(artifacts, GeneratedFileIndex::kResourcesFile, resources_file), SUCCESS);336 ASSERT_EQ(ReadGeneratedArtifact(artifacts, GeneratedFileIndex::kResourcesFile, resources_file), SUCCESS);
332 ASSERT_FALSE(resources_file.empty());337 ASSERT_FALSE(resources_file.empty());
@@ -1217,7 +1222,7 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo
1217}1222}
1218#endif)";1223#endif)";
1219 [[maybe_unused]] const std::string expected_resources = R"(#line 1 "g1_resources.cpp"1224 [[maybe_unused]] const std::string expected_resources = R"(#line 1 "g1_resources.cpp"
1220-#include "_interface.h"1225+#include "_internal.h"
1221 1226 
1222namespace om2 {1227namespace om2 {
1223Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority)1228Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority)
@@ -868,57 +868,6 @@ TEST_F(Om2CodegenUt, AstDsl_IgnoreOutputRemoveFile_Ok) {
868 });868 });
869}869}
870 870 
871-TEST_F(Om2CodegenUt, InterfaceDumpApis_EmitInCLinkageAndPtrToU64Outside_Ok) {
872- AstContext ctx;
873- AstBuildContext ast(ctx);
874- 
875- auto *tu = ast.File({
876- ast.StablePart(StablePartId::kInterfacePointerHelpers),
877- ast.ExternBlock("C", {ast.StablePart(StablePartId::kInterfaceDumpApis)}),
878- });
879- ASSERT_NE(tu, nullptr);
880- 
881- const auto output = EmitNode(*tu);
882- ExpectContainsAll(output, {
883- "inline void *ValueToPtr(const uint64_t value) {\n",
884- "inline uint64_t PtrToU64(const void *ptr) {\n",
885- "extern \"C\" {\n",
886- "enum GertModelArgKind : uint64_t {\n",
887- "struct GertModelArgSlotInfo {\n",
888- "struct GertModelTaskRawInfo {\n",
889- "const struct GertModelTaskRawInfo *task_raw_info = nullptr;\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 abi_pad_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 abi_pad_1 = 0;\n",
906- " aclrtStream stream = nullptr;\n",
907- " uint32_t flag = 0;\n",
908- " uint32_t abi_pad_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;",
913- });
914- EXPECT_LT(output.find(" uint64_t task_type = 0;\n"), output.find(" uint64_t kernel_type = 10000U;\n"));
915- EXPECT_EQ(output.find("report_task_preprocess"), std::string::npos);
916- EXPECT_EQ(output.find("report_task_postprocess"), std::string::npos);
917- EXPECT_EQ(output.find("get_data_dump_enabled"), std::string::npos);
918- EXPECT_LT(output.find("inline uint64_t PtrToU64"), output.find("extern \"C\" {"));
919- EXPECT_GT(output.find("struct Om2Tensor"), output.find("extern \"C\" {"));
920-}
921- 
922TEST_F(Om2CodegenUt, LoadAndRunDumpHelpers_EmitInAnonymousNamespace_Ok) {871TEST_F(Om2CodegenUt, LoadAndRunDumpHelpers_EmitInAnonymousNamespace_Ok) {
923 AstContext ctx;872 AstContext ctx;
924 AstBuildContext ast(ctx);873 AstBuildContext ast(ctx);
@@ -1021,10 +970,11 @@ TEST_F(Om2CodegenUt, CompileGeneratedCppToSo_MakefileVariableContinuation_Ok) {
1021 ScopedEnvVar asan_guard("ASAN_OPTIONS", "detect_leaks=0:halt_on_error=0");970 ScopedEnvVar asan_guard("ASAN_OPTIONS", "detect_leaks=0:halt_on_error=0");
1022 ScopedEnvVar lsan_guard("LSAN_OPTIONS", "exitcode=0");971 ScopedEnvVar lsan_guard("LSAN_OPTIONS", "exitcode=0");
1023 const std::string model_name = "continuation_test";972 const std::string model_name = "continuation_test";
1024- const std::string interface_name = model_name + "_interface.h";973+ const std::string interface_name = model_name + "_internal.h";
1025 const std::string include_line = "#include \"" + interface_name + "\"\n";974 const std::string include_line = "#include \"" + interface_name + "\"\n";
1026 Om2CodegenArtifacts artifacts = {975 Om2CodegenArtifacts artifacts = {
1027- {interface_name, "#pragma once\n#define CONTINUATION_TEST_VALUE 7\n"},976+ {"om2_model_api.h", "#pragma once\n"},
977+ {interface_name, "#pragma once\n#include \"om2_model_api.h\"\n#define CONTINUATION_TEST_VALUE 7\n"},
1028 {model_name + "_resources.cpp",978 {model_name + "_resources.cpp",
1029 include_line + "extern \"C\" int ContinuationTestResources() { return CONTINUATION_TEST_VALUE; }\n"},979 include_line + "extern \"C\" int ContinuationTestResources() { return CONTINUATION_TEST_VALUE; }\n"},
1030 {model_name + "_kernel_reg.cpp",980 {model_name + "_kernel_reg.cpp",
@@ -1062,10 +1012,11 @@ $(TARGET): $(SRC_FILES)
1062 1012 
1063// build_config 校验 UT:通过 SetGraphOption 注入 ge.buildConfig,走 CompileGeneratedCppToSo 触发校验1013// build_config 校验 UT:通过 SetGraphOption 注入 ge.buildConfig,走 CompileGeneratedCppToSo 触发校验
1064static Om2CodegenArtifacts MakeBuildConfigTestArtifacts(const std::string &model_name) {1014static Om2CodegenArtifacts MakeBuildConfigTestArtifacts(const std::string &model_name) {
1065- const std::string interface_name = model_name + "_interface.h";1015+ const std::string interface_name = model_name + "_internal.h";
1066 const std::string include_line = "#include \"" + interface_name + "\"\n";1016 const std::string include_line = "#include \"" + interface_name + "\"\n";
1067 return {1017 return {
1068- {interface_name, "#pragma once\n#define BC_TEST_VALUE 1\n"},1018+ {"om2_model_api.h", "#pragma once\n"},
1019+ {interface_name, "#pragma once\n#include \"om2_model_api.h\"\n#define BC_TEST_VALUE 1\n"},
1069 {model_name + "_load_and_run.cpp", include_line + "extern \"C\" int BcTest() { return BC_TEST_VALUE; }\n"},1020 {model_name + "_load_and_run.cpp", include_line + "extern \"C\" int BcTest() { return BC_TEST_VALUE; }\n"},
1070 {"Makefile", R"(CXX := c++1021 {"Makefile", R"(CXX := c++
1071TARGET := ../libbc_test_om2.so1022TARGET := ../libbc_test_om2.so
@@ -1082,6 +1033,14 @@ $(TARGET): $(SRC_FILES)
1082 };1033 };
1083}1034}
1084 1035 
1036+TEST_F(Om2CodegenUt, CompileGeneratedCppToSo_MissingModelApiArtifact_Failed) {
1037+ const std::string model_name = "missing_model_api";
1038+ auto artifacts = MakeBuildConfigTestArtifacts(model_name);
1039+ artifacts.erase(artifacts.begin());
1040+ Om2CodegenArtifact so_artifact;
1041+ EXPECT_NE(Om2Utils::CompileGeneratedCppToSo(artifacts, model_name, so_artifact, false), SUCCESS);
1042+}
1043+ 
1085std::string GetNativeMachine() {1044std::string GetNativeMachine() {
1086 struct utsname uts;1045 struct utsname uts;
1087 if (uname(&uts) != 0) {1046 if (uname(&uts) != 0) {
@@ -1504,7 +1463,6 @@ TEST_F(Om2CodegenUt, StablePartProvider_AllIds_Ok) {
1504 {StablePartId::kScopeGuard, "class ScopeGuard"},1463 {StablePartId::kScopeGuard, "class ScopeGuard"},
1505 {StablePartId::kReadBinaryFileToBuffer, "BinaryBuffer ReadBinaryFileToBuffer"},1464 {StablePartId::kReadBinaryFileToBuffer, "BinaryBuffer ReadBinaryFileToBuffer"},
1506 {StablePartId::kGenerateJsonFile, "aclError GenerateJsonFile"},1465 {StablePartId::kGenerateJsonFile, "aclError GenerateJsonFile"},
1507- {StablePartId::kInterfaceDumpApis, "struct GertModelTaskDesc"},
1508 {StablePartId::kOm2LogMacros, "#define OM2_LOGD"},1466 {StablePartId::kOm2LogMacros, "#define OM2_LOGD"},
1509 };1467 };
1510 1468 
@@ -1538,7 +1496,8 @@ TEST_F(Om2CodegenUt, Om2CodePrinter_GetFileName_DefaultNames) {
1538 const std::string model_name = "test_model";1496 const std::string model_name = "test_model";
1539 Om2CodePrinter printer(model_name);1497 Om2CodePrinter printer(model_name);
1540 1498 
1541- EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kInterfaceHeaderFile), model_name + "_interface.h");1499+ EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kModelApiHeaderFile), "om2_model_api.h");
1500+ EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kInterfaceHeaderFile), model_name + "_internal.h");
1542 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kResourcesFile), model_name + "_resources.cpp");1501 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kResourcesFile), model_name + "_resources.cpp");
1543 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kArgsManagerFile), model_name + "_args_manager.cpp");1502 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kArgsManagerFile), model_name + "_args_manager.cpp");
1544 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kKernelRegistryFile), model_name + "_kernel_reg.cpp");1503 EXPECT_EQ(printer.GetFileName(GeneratedFileIndex::kKernelRegistryFile), model_name + "_kernel_reg.cpp");
@@ -1428,11 +1428,12 @@ ProgramGenerator CreateProgramGenerator(GeRootModelPtr &ge_root_model, bool has_
1428}1428}
1429 1429 
1430const std::map<GeneratedFileIndex, std::string> kGeneratedFileNames = {1430const std::map<GeneratedFileIndex, std::string> kGeneratedFileNames = {
1431+ {GeneratedFileIndex::kModelApiHeaderFile, "om2_model_api.h"},
1431 {GeneratedFileIndex::kKernelRegistryFile, "g1_kernel_reg.cpp"},1432 {GeneratedFileIndex::kKernelRegistryFile, "g1_kernel_reg.cpp"},
1432 {GeneratedFileIndex::kResourcesFile, "g1_resources.cpp"},1433 {GeneratedFileIndex::kResourcesFile, "g1_resources.cpp"},
1433 {GeneratedFileIndex::kArgsManagerFile, "g1_args_manager.cpp"},1434 {GeneratedFileIndex::kArgsManagerFile, "g1_args_manager.cpp"},
1434 {GeneratedFileIndex::kLoadingAndRunningFile, "g1_load_and_run.cpp"},1435 {GeneratedFileIndex::kLoadingAndRunningFile, "g1_load_and_run.cpp"},
1435- {GeneratedFileIndex::kInterfaceHeaderFile, "g1_interface.h"},1436+ {GeneratedFileIndex::kInterfaceHeaderFile, "g1_internal.h"},
1436 {GeneratedFileIndex::kCMakeListsFile, "Makefile"},1437 {GeneratedFileIndex::kCMakeListsFile, "Makefile"},
1437};1438};
1438 1439 
@@ -1457,9 +1458,10 @@ Status GenerateProgramFiles(ProgramGenerator &generator, std::map<GeneratedFileI
1457 Om2CodegenArtifacts artifacts;1458 Om2CodegenArtifacts artifacts;
1458 code_printer.GetOutputFiles(artifacts);1459 code_printer.GetOutputFiles(artifacts);
1459 outputs.clear();1460 outputs.clear();
1460- for (const auto file_index : {GeneratedFileIndex::kKernelRegistryFile, GeneratedFileIndex::kResourcesFile,1461+ for (const auto file_index : {GeneratedFileIndex::kModelApiHeaderFile, GeneratedFileIndex::kKernelRegistryFile,
1461- GeneratedFileIndex::kArgsManagerFile, GeneratedFileIndex::kLoadingAndRunningFile,1462+ GeneratedFileIndex::kResourcesFile, GeneratedFileIndex::kArgsManagerFile,
1462- GeneratedFileIndex::kInterfaceHeaderFile, GeneratedFileIndex::kCMakeListsFile}) {1463+ GeneratedFileIndex::kLoadingAndRunningFile, GeneratedFileIndex::kInterfaceHeaderFile,
1464+ GeneratedFileIndex::kCMakeListsFile}) {
1463 std::string output;1465 std::string output;
1464 GE_ASSERT_SUCCESS(ReadGeneratedArtifact(artifacts, file_index, output));1466 GE_ASSERT_SUCCESS(ReadGeneratedArtifact(artifacts, file_index, output));
1465 outputs.emplace(file_index, std::move(output));1467 outputs.emplace(file_index, std::move(output));
@@ -1469,7 +1471,7 @@ Status GenerateProgramFiles(ProgramGenerator &generator, std::map<GeneratedFileI
1469 1471 
1470std::string GetExpectedArgsManagerSource() {1472std::string GetExpectedArgsManagerSource() {
1471 return R"(#line 1 "g1_args_manager.cpp"1473 return R"(#line 1 "g1_args_manager.cpp"
1472-#include "g1_interface.h"1474+#include "g1_internal.h"
1473 1475 
1474namespace om2 {1476namespace om2 {
1475aclError Om2ArgsTable::Init() {1477aclError Om2ArgsTable::Init() {
@@ -1629,7 +1631,7 @@ TEST_F(ProgramGeneratorUt, GenerateResourcesSource_Ok) {
1629 std::map<GeneratedFileIndex, std::string> outputs;1631 std::map<GeneratedFileIndex, std::string> outputs;
1630 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);1632 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
1631 const std::string expected = R"(#line 1 "g1_resources.cpp"1633 const std::string expected = R"(#line 1 "g1_resources.cpp"
1632-#include "g1_interface.h"1634+#include "g1_internal.h"
1633 1635 
1634namespace om2 {1636namespace om2 {
1635Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, const GertModelLoadCallbacks *callbacks, int32_t priority)1637Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, const GertModelLoadCallbacks *callbacks, int32_t priority)
@@ -1789,6 +1791,7 @@ TEST_F(ProgramGeneratorUt, GenerateInterfaceHeader_Ok) {
1789#include <unistd.h>1791#include <unistd.h>
1790#include <cinttypes>1792#include <cinttypes>
1791#include "mmpa/mmpa_api.h"1793#include "mmpa/mmpa_api.h"
1794+#include "om2_model_api.h"
1792 1795 
1793// OM2 Logging Macros1796// OM2 Logging Macros
1794#define OM2_MODULE_NAME static_cast<int32_t>(GE)1797#define OM2_MODULE_NAME static_cast<int32_t>(GE)
@@ -1940,185 +1943,6 @@ inline std::vector<uint64_t> FlattenHostArgs(Args&&... args) {
1940 return buf;1943 return buf;
1941}1944}
1942 1945 
1943-struct GertModelTaskIoEntry {
1944- uint64_t struct_size = sizeof(GertModelTaskIoEntry);
1945- const gert::Tensor *tensor = nullptr;
1946- uint64_t offset = 0;
1947-};
1948- 
1949-enum GertModelArgKind : uint64_t {
1950- GERT_MODEL_ARG_INPUT = 0,
1951- GERT_MODEL_ARG_OUTPUT = 1,
1952- GERT_MODEL_ARG_WORKSPACE = 2,
1953- GERT_MODEL_ARG_TILING = 3,
1954- GERT_MODEL_ARG_SHAPE_INFO = 4,
1955- GERT_MODEL_ARG_LEVEL1_DESC = 5,
1956- GERT_MODEL_ARG_PLACEHOLDER = 6,
1957- GERT_MODEL_ARG_CUSTOM_VALUE = 7,
1958- GERT_MODEL_ARG_FFTS_ADDR = 8,
1959- GERT_MODEL_ARG_EVENT_ADDR = 9,
1960- GERT_MODEL_ARG_OVERFLOW_ADDR = 10,
1961- GERT_MODEL_ARG_EMPTY_ADDR = 11,
1962- GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU
1963-};
1964- 
1965-struct GertModelArgSlotInfo {
1966- uint64_t struct_size = sizeof(GertModelArgSlotInfo);
1967- GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND;
1968- uint64_t flags = 0;
1969- uint64_t args_offset = 0;
1970- uint64_t value = 0;
1971- uint64_t related_index = 0;
1972- uint64_t event_id = 0;
1973- uint64_t level1_target_offset = 0;
1974-};
1975- 
1976-struct GertModelTaskRawInfo {
1977- uint64_t struct_size = sizeof(GertModelTaskRawInfo);
1978- uint64_t need_assert_or_printf = 0;
1979- uint64_t arg_num = 0;
1980- const struct GertModelArgSlotInfo *args = nullptr;
1981-};
1982- 
1983-struct GertModelTaskDesc {
1984- uint64_t struct_size = sizeof(GertModelTaskDesc);
1985- const char *op_name = nullptr;
1986- const char *op_type = nullptr;
1987- uint64_t task_id = 0;
1988- uint64_t stream_id = 0;
1989- uint64_t context_id = 0;
1990- uint64_t thread_id = 0;
1991- uint64_t block_dim = 0;
1992- uint64_t op_desc_id = 0;
1993- uintptr_t args_base = 0;
1994- uint64_t args_size = 0;
1995- uint64_t input_num = 0;
1996- const struct GertModelTaskIoEntry *inputs = nullptr;
1997- uint64_t output_num = 0;
1998- const struct GertModelTaskIoEntry *outputs = nullptr;
1999- uint64_t workspace_num = 0;
2000- const uint64_t *workspace_addrs = nullptr;
2001- const uint64_t *workspace_sizes = nullptr;
2002- uint64_t task_type = 0;
2003- uint64_t kernel_type = 10000U;
2004- void *stream = nullptr;
2005- uint64_t is_raw_address = 0;
2006- const struct GertModelTaskRawInfo *task_raw_info = nullptr;
2007- uint64_t launch_begin = 0;
2008- const char *original_op_names = nullptr;
2009- uint64_t input_mem_size = 0;
2010- uint64_t output_mem_size = 0;
2011- uint64_t workspace_mem_size = 0;
2012- uint64_t weight_mem_size = 0;
2013-};
2014- 
2015-struct GertModelBaseInfo {
2016- uint64_t struct_size = sizeof(GertModelBaseInfo);
2017- const void *rt_model_handle = nullptr;
2018-};
2019- 
2020-using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);
2021- 
2022-enum GertModelTaskLaunchType : uint64_t {
2023- ACL_RT_LAUNCH_KERNEL_V2 = 0,
2024- RT_STARS_TASK_LAUNCH_WITH_FLAG = 1,
2025-};
2026- 
2027-struct GertModelLaunchKernelV2Params {
2028- uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params);
2029- aclrtFuncHandle func_handle = nullptr;
2030- uint32_t block_dim = 0;
2031- // 用于填充空洞,保持结构体布局与 ACL 接口一致。
2032- uint32_t abi_pad_1 = 0;
2033- const void *args_data = nullptr;
2034- size_t args_size = 0;
2035- aclrtLaunchKernelCfg *config = nullptr;
2036- aclrtStream stream = nullptr;
2037-};
2038- 
2039-struct GertModelLaunchStarsTaskWithFlagParams {
2040- uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams);
2041- const void *task_sqe = nullptr;
2042- uint32_t sqe_len = 0;
2043- // 用于填充空洞,保持结构体布局与 ACL 接口一致。
2044- uint32_t abi_pad_1 = 0;
2045- aclrtStream stream = nullptr;
2046- uint32_t flag = 0;
2047- // 用于填充空洞,保持结构体布局与 ACL 接口一致。
2048- uint32_t abi_pad_2 = 0;
2049-};
2050- 
2051-union GertModelTaskLaunchParams {
2052- GertModelLaunchKernelV2Params launch_kernel_v2_params;
2053- GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params;
2054-};
2055- 
2056-struct GertModelTaskLaunchInfo {
2057- uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);
2058- GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;
2059- GertModelTaskDesc *task_info = nullptr;
2060- const GertModelTaskLaunchParams *launch_params = nullptr;
2061-};
2062- 
2063-using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);
2064-using LockBinHandleStoreFunc = int32_t (*)();
2065-using UnlockBinHandleStoreFunc = int32_t (*)();
2066-using QueryBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle *bin_handle);
2067-using SaveBinHandleToStoreFunc = int32_t (*)(const char *bin_id, aclrtBinHandle bin_handle);
2068-using ReleaseBinHandleFromStoreFunc = int32_t (*)(const char *bin_id, uint8_t *need_unload);
2069- 
2070-struct GertModelLoadCallbacks {
2071- uint64_t struct_size = sizeof(GertModelLoadCallbacks);
2072- ReportModelBaseInfoFunc report_model_base_info = nullptr;
2073- GertModelLaunchFunc launch_func = nullptr;
2074- LockBinHandleStoreFunc lock_bin_handle_store = nullptr;
2075- UnlockBinHandleStoreFunc unlock_bin_handle_store = nullptr;
2076- QueryBinHandleFromStoreFunc query_bin_handle_from_store = nullptr;
2077- SaveBinHandleToStoreFunc save_bin_handle_to_store = nullptr;
2078- ReleaseBinHandleFromStoreFunc release_bin_handle_from_store = nullptr;
2079-};
2080- 
2081-using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo *info);
2082- 
2083-struct GertModelRunReportInfo {
2084- uint64_t struct_size = sizeof(GertModelRunReportInfo);
2085- uint64_t model_id = 0;
2086- aclrtStream stream = nullptr;
2087- uint64_t is_async = 0;
2088-};
2089- 
2090-struct GertModelRunCallbacks {
2091- uint64_t struct_size = sizeof(GertModelRunCallbacks);
2092- ReportModelRunFunc report_run_info_preprocess = nullptr;
2093- ReportModelRunFunc report_run_info_postprocess = nullptr;
2094-};
2095- 
2096-struct GertModelLoadConfig {
2097- uint64_t struct_size = sizeof(GertModelLoadConfig);
2098- const char **bin_files = nullptr;
2099- const void **bin_data = nullptr;
2100- uint64_t *bin_size = nullptr;
2101- uint64_t bin_num = 0;
2102- void **constants = nullptr;
2103- void **var_addrs = nullptr;
2104- void *work_ptr = nullptr;
2105- uint64_t *session_id = nullptr;
2106- uint64_t model_id = 0; // used for logging
2107- void *instance_handle = nullptr;
2108- const struct GertModelLoadCallbacks *callbacks = nullptr;
2109- int64_t priority = 0;
2110- uint64_t reuse_zero_copy = 0;
2111- aclmdlRI external_rt_model = nullptr;
2112- aclrtStream *external_streams = nullptr;
2113- uint64_t external_stream_num = 0;
2114- aclrtEvent *external_events = nullptr;
2115- uint64_t external_event_num = 0;
2116- aclrtLabel *external_labels = nullptr;
2117- uint64_t external_label_num = 0;
2118- aclrtNotify *external_notifies = nullptr;
2119- uint64_t external_notify_num = 0;
2120-};
2121- 
2122struct GertModelExternalResources {1946struct GertModelExternalResources {
2123 uint64_t struct_size = sizeof(GertModelExternalResources);1947 uint64_t struct_size = sizeof(GertModelExternalResources);
2124 aclmdlRI external_rt_model = nullptr;1948 aclmdlRI external_rt_model = nullptr;
@@ -2132,32 +1956,6 @@ struct GertModelExternalResources {
2132 uint64_t external_label_num = 0;1956 uint64_t external_label_num = 0;
2133};1957};
2134 1958 
2135-struct GertModelRunConfig {
2136- uint64_t struct_size = sizeof(GertModelRunConfig);
2137- uint64_t input_count = 0;
2138- gert::Tensor **input_data = nullptr;
2139- uint64_t output_count = 0;
2140- gert::Tensor **output_data = nullptr;
2141- uint64_t stream_sync_timeout_ms = 0;
2142- const struct GertModelRunCallbacks *run_callbacks = nullptr;
2143-};
2144- 
2145-struct GertModelUnloadConfig {
2146- uint64_t struct_size = sizeof(GertModelUnloadConfig);
2147-};
2148- 
2149-struct GertModelLoadOutput {
2150- uint64_t struct_size = sizeof(GertModelLoadOutput);
2151-};
2152- 
2153-struct GertModelRunOutput {
2154- uint64_t struct_size = sizeof(GertModelRunOutput);
2155-};
2156- 
2157-struct GertModelUnloadOutput {
2158- uint64_t struct_size = sizeof(GertModelUnloadOutput);
2159-};
2160- 
2161struct rtLabelDevInfo {1959struct rtLabelDevInfo {
2162 uint16_t modelId;1960 uint16_t modelId;
2163 uint16_t streamId;1961 uint16_t streamId;
@@ -2639,39 +2437,25 @@ class Om2Model {
2639 int32_t priority_;2437 int32_t priority_;
2640};2438};
2641} // namespace om22439} // namespace om2
2642-#ifdef __cplusplus
2643-extern "C" {
2644-#endif
2645- 
2646-typedef void *GertModelHandle;
2647- 
2648-int32_t GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output);
2649- 
2650-int32_t GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output);
2651- 
2652-int32_t GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output);
2653- 
2654-int32_t GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output);
2655- 
2656-uint64_t GertModelGetStreamNum();
2657- 
2658-int32_t GertModelGetStreamDesc(uint32_t *stream_flags, uint64_t stream_num, void *extended_attrs);
2659- 
2660-uint64_t GertModelGetEventNum();
2661- 
2662-int32_t GertModelGetEventDesc(uint32_t *event_flags, uint64_t event_num, void *extended_attrs);
2663- 
2664-uint64_t GertModelGetLabelNum();
2665- 
2666-uint64_t GertModelGetNotifyNum();
2667- 
2668-int32_t GertModelGetNotifyDesc(uint64_t *notify_flags, uint64_t notify_num, void *extended_attrs);
2669- 
2670-#ifdef __cplusplus
2671-}
2672-#endif
2673)";2440)";
2674 ASSERT_EQ(outputs[GeneratedFileIndex::kInterfaceHeaderFile], expected);2441 ASSERT_EQ(outputs[GeneratedFileIndex::kInterfaceHeaderFile], expected);
2442+ 
2443+ const auto &model_api_header = outputs[GeneratedFileIndex::kModelApiHeaderFile];
2444+ EXPECT_NE(model_api_header.find("struct GertModelLoadCallbacks"), std::string::npos);
2445+ EXPECT_NE(model_api_header.find("GertModelLaunchFunc launch_func"), std::string::npos);
2446+ EXPECT_NE(model_api_header.find("void *work_ptr"), std::string::npos);
2447+ 
2448+ const auto &internal_header = outputs[GeneratedFileIndex::kInterfaceHeaderFile];
2449+ EXPECT_NE(internal_header.find("constexpr size_t kModelWorkSize"), std::string::npos);
2450+ EXPECT_NE(internal_header.find("constexpr size_t kModelZeroCopySize"), std::string::npos);
2451+ EXPECT_NE(internal_header.find("inline aclError AclrtMalloc"), std::string::npos);
2452+ EXPECT_NE(internal_header.find("aclrtMallocWithCfg"), std::string::npos);
2453+ EXPECT_NE(internal_header.find("RT_MEMORY_HBM"), std::string::npos);
2454+ EXPECT_NE(internal_header.find("ACL_MEM_TYPE_HIGH_BAND_WIDTH"), std::string::npos);
2455+ EXPECT_NE(internal_header.find("ACL_RT_MEM_ATTR_MODULE_ID"), std::string::npos);
2456+ EXPECT_NE(internal_header.find(" case RT_MEMORY_HBM:\n default:\n return aclrtMallocWithCfg"),
2457+ std::string::npos);
2458+ EXPECT_EQ(internal_header.find("reuse_zero_copy_"), std::string::npos);
2675}2459}
2676 2460 
2677TEST_F(ProgramGeneratorUt, GenerateKernelRegSource_Ok) {2461TEST_F(ProgramGeneratorUt, GenerateKernelRegSource_Ok) {
@@ -2681,7 +2465,7 @@ TEST_F(ProgramGeneratorUt, GenerateKernelRegSource_Ok) {
2681 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);2465 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
2682 2466 
2683 const std::string kernel_reg_expected = R"OM2(#line 1 "g1_kernel_reg.cpp"2467 const std::string kernel_reg_expected = R"OM2(#line 1 "g1_kernel_reg.cpp"
2684-#include "g1_interface.h"2468+#include "g1_internal.h"
2685namespace om2 {2469namespace om2 {
2686namespace {2470namespace {
2687constexpr uint32_t kMaxJsonFileLen = 512U;2471constexpr uint32_t kMaxJsonFileLen = 512U;
@@ -2861,9 +2645,10 @@ TEST_F(ProgramGeneratorUt, GenerateProgram_FileStorageShape_Ok) {
2861 std::map<GeneratedFileIndex, std::string> outputs;2645 std::map<GeneratedFileIndex, std::string> outputs;
2862 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);2646 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
2863 2647 
2864- for (const auto file_index : {GeneratedFileIndex::kKernelRegistryFile, GeneratedFileIndex::kResourcesFile,2648+ for (const auto file_index : {GeneratedFileIndex::kModelApiHeaderFile, GeneratedFileIndex::kKernelRegistryFile,
2865- GeneratedFileIndex::kArgsManagerFile, GeneratedFileIndex::kLoadingAndRunningFile,2649+ GeneratedFileIndex::kResourcesFile, GeneratedFileIndex::kArgsManagerFile,
2866- GeneratedFileIndex::kInterfaceHeaderFile, GeneratedFileIndex::kCMakeListsFile}) {2650+ GeneratedFileIndex::kLoadingAndRunningFile, GeneratedFileIndex::kInterfaceHeaderFile,
2651+ GeneratedFileIndex::kCMakeListsFile}) {
2867 ASSERT_NE(outputs.find(file_index), outputs.end());2652 ASSERT_NE(outputs.find(file_index), outputs.end());
2868 ASSERT_FALSE(outputs[file_index].empty());2653 ASSERT_FALSE(outputs[file_index].empty());
2869 }2654 }
@@ -2876,7 +2661,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_Ok) {
2876 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);2661 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
2877 2662 
2878 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"2663 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"
2879-#include "g1_interface.h"2664+#include "g1_internal.h"
2880 2665 
2881namespace om2 {2666namespace om2 {
2882namespace {2667namespace {
@@ -3567,7 +3352,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource2_Ok) {
3567 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);3352 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
3568 3353 
3569 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"3354 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"
3570-#include "g1_interface.h"3355+#include "g1_internal.h"
3571 3356 
3572namespace om2 {3357namespace om2 {
3573namespace {3358namespace {
@@ -4269,10 +4054,11 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_AicpuEmptyShape_Ok) {
4269 std::map<GeneratedFileIndex, std::string> outputs;4054 std::map<GeneratedFileIndex, std::string> outputs;
4270 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);4055 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
4271 4056 
4272- // Verify all 6 files are generated4057+ // Verify all 7 files are generated
4273- for (const auto file_index : {GeneratedFileIndex::kKernelRegistryFile, GeneratedFileIndex::kResourcesFile,4058+ for (const auto file_index : {GeneratedFileIndex::kModelApiHeaderFile, GeneratedFileIndex::kKernelRegistryFile,
4274- GeneratedFileIndex::kArgsManagerFile, GeneratedFileIndex::kLoadingAndRunningFile,4059+ GeneratedFileIndex::kResourcesFile, GeneratedFileIndex::kArgsManagerFile,
4275- GeneratedFileIndex::kInterfaceHeaderFile, GeneratedFileIndex::kCMakeListsFile}) {4060+ GeneratedFileIndex::kLoadingAndRunningFile, GeneratedFileIndex::kInterfaceHeaderFile,
4061+ GeneratedFileIndex::kCMakeListsFile}) {
4276 EXPECT_NE(outputs.find(file_index), outputs.end());4062 EXPECT_NE(outputs.find(file_index), outputs.end());
4277 EXPECT_FALSE(outputs[file_index].empty());4063 EXPECT_FALSE(outputs[file_index].empty());
4278 }4064 }
@@ -4290,7 +4076,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForAicpu_Ok) {
4290 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);4076 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
4291 4077 
4292 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"4078 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"
4293-#include "g1_interface.h"4079+#include "g1_internal.h"
4294 4080 
4295namespace om2 {4081namespace om2 {
4296namespace {4082namespace {
@@ -5013,7 +4799,7 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForDynamicIo_Ok) {
5013 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);4799 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
5014 4800 
5015 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"4801 const std::string expected = R"(#line 1 "g1_load_and_run.cpp"
5016-#include "g1_interface.h"4802+#include "g1_internal.h"
5017 4803 
5018namespace om2 {4804namespace om2 {
5019namespace {4805namespace {
@@ -7348,9 +7134,10 @@ TEST_F(ProgramGeneratorUt, GenerateProgram_AllKernel_Ok) {
7348 std::map<GeneratedFileIndex, std::string> outputs;7134 std::map<GeneratedFileIndex, std::string> outputs;
7349 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);7135 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
7350 7136 
7351- for (const auto file_index : {GeneratedFileIndex::kKernelRegistryFile, GeneratedFileIndex::kResourcesFile,7137+ for (const auto file_index : {GeneratedFileIndex::kModelApiHeaderFile, GeneratedFileIndex::kKernelRegistryFile,
7352- GeneratedFileIndex::kArgsManagerFile, GeneratedFileIndex::kLoadingAndRunningFile,7138+ GeneratedFileIndex::kResourcesFile, GeneratedFileIndex::kArgsManagerFile,
7353- GeneratedFileIndex::kInterfaceHeaderFile, GeneratedFileIndex::kCMakeListsFile}) {7139+ GeneratedFileIndex::kLoadingAndRunningFile, GeneratedFileIndex::kInterfaceHeaderFile,
7140+ GeneratedFileIndex::kCMakeListsFile}) {
7354 ASSERT_NE(outputs.find(file_index), outputs.end());7141 ASSERT_NE(outputs.find(file_index), outputs.end());
7355 ASSERT_FALSE(outputs[file_index].empty());7142 ASSERT_FALSE(outputs[file_index].empty());
7356 }7143 }
@@ -7514,9 +7301,10 @@ TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSourceForSeparatelyCleanTask_Ok) {
7514 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);7301 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
7515 7302 
7516 // Verify all expected files are generated7303 // Verify all expected files are generated
7517- for (const auto file_index : {GeneratedFileIndex::kKernelRegistryFile, GeneratedFileIndex::kResourcesFile,7304+ for (const auto file_index : {GeneratedFileIndex::kModelApiHeaderFile, GeneratedFileIndex::kKernelRegistryFile,
7518- GeneratedFileIndex::kArgsManagerFile, GeneratedFileIndex::kLoadingAndRunningFile,7305+ GeneratedFileIndex::kResourcesFile, GeneratedFileIndex::kArgsManagerFile,
7519- GeneratedFileIndex::kInterfaceHeaderFile, GeneratedFileIndex::kCMakeListsFile}) {7306+ GeneratedFileIndex::kLoadingAndRunningFile, GeneratedFileIndex::kInterfaceHeaderFile,
7307+ GeneratedFileIndex::kCMakeListsFile}) {
7520 ASSERT_NE(outputs.find(file_index), outputs.end());7308 ASSERT_NE(outputs.find(file_index), outputs.end());
7521 ASSERT_FALSE(outputs[file_index].empty());7309 ASSERT_FALSE(outputs[file_index].empty());
7522 }7310 }
@@ -7586,34 +7374,35 @@ TEST_F(ProgramGeneratorUt, GenerateLoggingFunctionality_Ok) {
7586// OM2 Profiling — codegen 输出中包含 profiling 相关模式7374// OM2 Profiling — codegen 输出中包含 profiling 相关模式
7587// =========================================================================7375// =========================================================================
7588 7376 
7589-TEST_F(ProgramGeneratorUt, GenerateInterfaceHeader_ContainsProfilingTypes) {7377+TEST_F(ProgramGeneratorUt, GenerateHeaders_ContainsProfilingTypes) {
7590 GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp();7378 GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp();
7591 auto generator = CreateProgramGenerator(ge_root_model);7379 auto generator = CreateProgramGenerator(ge_root_model);
7592 std::map<GeneratedFileIndex, std::string> outputs;7380 std::map<GeneratedFileIndex, std::string> outputs;
7593 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);7381 ASSERT_EQ(GenerateProgramFiles(generator, outputs), SUCCESS);
7594 7382 
7595- const auto &header = outputs[GeneratedFileIndex::kInterfaceHeaderFile];7383+ const auto &model_api_header = outputs[GeneratedFileIndex::kModelApiHeaderFile];
7384+ const auto &internal_header = outputs[GeneratedFileIndex::kInterfaceHeaderFile];
7596 7385 
7597- // profiling/prof_common.h 和 mmpa/mmpa_api.h 应包含在头文件中7386+ // profiling/prof_common.h 和 mmpa/mmpa_api.h 属于内部实现依赖。
7598- EXPECT_NE(header.find("#include \"profiling/prof_common.h\""), std::string::npos);7387+ EXPECT_NE(internal_header.find("#include \"profiling/prof_common.h\""), std::string::npos);
7599- EXPECT_NE(header.find("#include \"mmpa/mmpa_api.h\""), std::string::npos);7388+ EXPECT_NE(internal_header.find("#include \"mmpa/mmpa_api.h\""), std::string::npos);
7600 // GertModelRunCallbacks 和 GertModelRunReportInfo 结构体应该存在7389 // GertModelRunCallbacks 和 GertModelRunReportInfo 结构体应该存在
7601- EXPECT_NE(header.find("struct GertModelRunCallbacks"), std::string::npos);7390+ EXPECT_NE(model_api_header.find("struct GertModelRunCallbacks"), std::string::npos);
7602- EXPECT_NE(header.find("struct GertModelRunReportInfo"), std::string::npos);7391+ EXPECT_NE(model_api_header.find("struct GertModelRunReportInfo"), std::string::npos);
7603- EXPECT_NE(header.find("ReportModelRunFunc"), std::string::npos);7392+ EXPECT_NE(model_api_header.find("ReportModelRunFunc"), std::string::npos);
7604- EXPECT_NE(header.find("report_run_info_preprocess"), std::string::npos);7393+ EXPECT_NE(model_api_header.find("report_run_info_preprocess"), std::string::npos);
7605- EXPECT_NE(header.find("report_run_info_postprocess"), std::string::npos);7394+ EXPECT_NE(model_api_header.find("report_run_info_postprocess"), std::string::npos);
7606 // GertModelTaskDesc 新增 profiling 字段7395 // GertModelTaskDesc 新增 profiling 字段
7607- EXPECT_NE(header.find("uint64_t launch_begin"), std::string::npos);7396+ EXPECT_NE(model_api_header.find("uint64_t launch_begin"), std::string::npos);
7608- EXPECT_NE(header.find("original_op_names"), std::string::npos);7397+ EXPECT_NE(model_api_header.find("original_op_names"), std::string::npos);
7609- EXPECT_NE(header.find("input_mem_size"), std::string::npos);7398+ EXPECT_NE(model_api_header.find("input_mem_size"), std::string::npos);
7610- EXPECT_NE(header.find("output_mem_size"), std::string::npos);7399+ EXPECT_NE(model_api_header.find("output_mem_size"), std::string::npos);
7611- EXPECT_NE(header.find("workspace_mem_size"), std::string::npos);7400+ EXPECT_NE(model_api_header.find("workspace_mem_size"), std::string::npos);
7612- EXPECT_NE(header.find("weight_mem_size"), std::string::npos);7401+ EXPECT_NE(model_api_header.find("weight_mem_size"), std::string::npos);
7613 // Om2Model 和外部 API 接收 GertModelRunCallbacks*7402 // Om2Model 和外部 API 接收 GertModelRunCallbacks*
7614- EXPECT_NE(header.find("GertModelRunCallbacks"), std::string::npos);7403+ EXPECT_NE(internal_header.find("GertModelRunCallbacks"), std::string::npos);
7615 // AicoreDispatchInfo 中应有 fusion_op 字段7404 // AicoreDispatchInfo 中应有 fusion_op 字段
7616- EXPECT_NE(header.find("fusion_op"), std::string::npos);7405+ EXPECT_NE(internal_header.find("fusion_op"), std::string::npos);
7617}7406}
7618 7407 
7619TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_ContainsProfilingPatterns) {7408TEST_F(ProgramGeneratorUt, GenerateLoadAndRunSource_ContainsProfilingPatterns) {
@@ -452,7 +452,8 @@ TEST_F(Om2PackageHelperUt, ConvertOm2Model_Ok_GenOm2WithAicoreNode) {
452 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",452 "fake_test/data/model_0/runtime/csrc/g1_resources.cpp",
453 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",453 "fake_test/data/model_0/runtime/csrc/g1_args_manager.cpp",
454 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",454 "fake_test/data/model_0/runtime/csrc/g1_load_and_run.cpp",
455- "fake_test/data/model_0/runtime/csrc/g1_interface.h",455+ "fake_test/data/model_0/runtime/csrc/om2_model_api.h",
456+ "fake_test/data/model_0/runtime/csrc/g1_internal.h",
456 "fake_test/data/model_0/runtime/csrc/Makefile",457 "fake_test/data/model_0/runtime/csrc/Makefile",
457 "fake_test/data/model_0/runtime/libg1_om2.so",458 "fake_test/data/model_0/runtime/libg1_om2.so",
458 "fake_test/data/constants/constant_0",459 "fake_test/data/constants/constant_0",
@@ -478,7 +479,7 @@ TEST_F(Om2PackageHelperUt, ConvertOm2Model_Ok_GenOm2WithAicoreNode) {
478 const auto cpp_buf = archive.ExtractToMem(cpp_entry, cpp_size);479 const auto cpp_buf = archive.ExtractToMem(cpp_entry, cpp_size);
479 ASSERT_NE(cpp_buf, nullptr);480 ASSERT_NE(cpp_buf, nullptr);
480 const std::string cpp_content(reinterpret_cast<const char *>(cpp_buf.get()), cpp_size);481 const std::string cpp_content(reinterpret_cast<const char *>(cpp_buf.get()), cpp_size);
481- EXPECT_NE(cpp_content.find("#include \"g1_interface.h\""), std::string::npos) << cpp_entry;482+ EXPECT_NE(cpp_content.find("#include \"g1_internal.h\""), std::string::npos) << cpp_entry;
482 EXPECT_EQ(cpp_content.find("/proc/self/fd/"), std::string::npos) << cpp_entry;483 EXPECT_EQ(cpp_content.find("/proc/self/fd/"), std::string::npos) << cpp_entry;
483 }484 }
484 size_t makefile_size = 0;485 size_t makefile_size = 0;
@@ -633,7 +634,8 @@ TEST_F(Om2PackageHelperUt, SaveToOmModel_SaveModeFalse_ReturnsModelBuffer) {
633 "g1/data/model_0/runtime/csrc/g1_resources.cpp",634 "g1/data/model_0/runtime/csrc/g1_resources.cpp",
634 "g1/data/model_0/runtime/csrc/g1_args_manager.cpp",635 "g1/data/model_0/runtime/csrc/g1_args_manager.cpp",
635 "g1/data/model_0/runtime/csrc/g1_load_and_run.cpp",636 "g1/data/model_0/runtime/csrc/g1_load_and_run.cpp",
636- "g1/data/model_0/runtime/csrc/g1_interface.h",637+ "g1/data/model_0/runtime/csrc/om2_model_api.h",
638+ "g1/data/model_0/runtime/csrc/g1_internal.h",
637 "g1/data/model_0/runtime/csrc/Makefile",639 "g1/data/model_0/runtime/csrc/Makefile",
638 "g1/data/model_0/runtime/libg1_om2.so",640 "g1/data/model_0/runtime/libg1_om2.so",
639 "g1/data/constants/constant_0",641 "g1/data/constants/constant_0",
@@ -710,8 +712,8 @@ TEST_F(Om2PackageHelperUt, ConvertOm2Model_Fail_GenFailedAndRemoveOm2File) {
710 712 
711TEST_F(Om2PackageHelperUt, Om2CodegenAndCompile_Fail_DoesNotDumpGeneratedFiles) {713TEST_F(Om2PackageHelperUt, Om2CodegenAndCompile_Fail_DoesNotDumpGeneratedFiles) {
712 const std::vector<std::string> dump_files = {714 const std::vector<std::string> dump_files = {
713- "g1_kernel_reg.cpp", "g1_resources.cpp", "g1_args_manager.cpp",715+ "g1_kernel_reg.cpp", "g1_resources.cpp", "g1_args_manager.cpp", "g1_load_and_run.cpp", "om2_model_api.h",
714- "g1_load_and_run.cpp", "g1_interface.h", "Makefile",716+ "g1_internal.h", "Makefile",
715 };717 };
716 for (const auto &file_name : dump_files) {718 for (const auto &file_name : dump_files) {
717 RemoveOm2DumpFile(file_name);719 RemoveOm2DumpFile(file_name);