已合并
feat: OM2 so C 接口整改 #4559
fary86创建于 8 天前
feat: OM2 so C 接口整改 #4559
已合并
共 18 个文件变更+1206-324
| @@ -303,7 +303,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 303 | return SUCCESS; | 303 | return SUCCESS; |
| 304 | case StablePartId::kLoadAndRunExternalApis: | 304 | case StablePartId::kLoadAndRunExternalApis: |
| 305 | output = | 305 | output = |
| 306 | - "aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, " | 306 | + "aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, " |
| 307 | "const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, " | 307 | "const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, " |
| 308 | "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t " | 308 | "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t " |
| 309 | "priority) {\n" | 309 | "priority) {\n" |
| @@ -330,23 +330,23 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 330 | " delete obj;\n" | 330 | " delete obj;\n" |
| 331 | " return ret;\n" | 331 | " return ret;\n" |
| 332 | " }\n" | 332 | " }\n" |
| 333 | - " *model_handle = reinterpret_cast<om2::Om2ModelHandle>(obj);\n" | 333 | + " *model_handle = reinterpret_cast<GertModelHandle>(obj);\n" |
| 334 | " *rt_model_handle = obj->GetRtModelHandle();\n" | 334 | " *rt_model_handle = obj->GetRtModelHandle();\n" |
| 335 | " OM2_LOGI(\"Om2ModelCreate done\");\n" | 335 | " OM2_LOGI(\"Om2ModelCreate done\");\n" |
| 336 | " return ACL_SUCCESS;\n" | 336 | " return ACL_SUCCESS;\n" |
| 337 | "}\n" | 337 | "}\n" |
| 338 | "\n" | 338 | "\n" |
| 339 | - "aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle) {\n" | 339 | + "aclError Om2ModelLoad(GertModelHandle *model_handle) {\n" |
| 340 | " OM2_LOGI(\"Om2ModelLoad\");\n" | 340 | " OM2_LOGI(\"Om2ModelLoad\");\n" |
| 341 | " if ((model_handle == nullptr) || (*model_handle == nullptr)) {\n" | 341 | " if ((model_handle == nullptr) || (*model_handle == nullptr)) {\n" |
| 342 | " OM2_LOGE(\"Om2ModelLoad: invalid handle\");\n" | 342 | " OM2_LOGE(\"Om2ModelLoad: invalid handle\");\n" |
| 343 | " return ACL_ERROR_FAILURE;\n" | 343 | " return ACL_ERROR_FAILURE;\n" |
| 344 | " }\n" | 344 | " }\n" |
| 345 | - " return static_cast<om2::Om2Model*>(*model_handle)->Load();\n" | 345 | + " return static_cast<om2::Om2Model*>(*model_handle)->Load(nullptr);\n" |
| 346 | "}\n" | 346 | "}\n" |
| 347 | "\n" | 347 | "\n" |
| 348 | - "aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, " | 348 | + "aclError Om2ModelRunAsync(GertModelHandle *model_handle, aclrtStream stream, int input_count, " |
| 349 | - "void **input_data, int output_count, void **output_data, " | 349 | + "gert::Tensor **input_data, int output_count, gert::Tensor **output_data, " |
| 350 | "Om2ProfInfos *prof_info) {\n" | 350 | "Om2ProfInfos *prof_info) {\n" |
| 351 | " OM2_LOGI(\"Om2ModelRunAsync\");\n" | 351 | " OM2_LOGI(\"Om2ModelRunAsync\");\n" |
| 352 | " return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, " | 352 | " return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, " |
| @@ -354,18 +354,85 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 354 | "output_data, prof_info);\n" | 354 | "output_data, prof_info);\n" |
| 355 | "}\n" | 355 | "}\n" |
| 356 | "\n" | 356 | "\n" |
| 357 | - "aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int " | 357 | + "aclError Om2ModelRun(GertModelHandle *model_handle, int input_count, gert::Tensor **input_data, int " |
| 358 | "output_count, " | 358 | "output_count, " |
| 359 | - "void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) {\n" | 359 | + "gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) {\n" |
| 360 | " OM2_LOGI(\"Om2ModelRun\");\n" | 360 | " OM2_LOGI(\"Om2ModelRun\");\n" |
| 361 | " return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, " | 361 | " return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, " |
| 362 | "output_data, stream_sync_timeout, prof_info);\n" | 362 | "output_data, stream_sync_timeout, prof_info);\n" |
| 363 | "}\n" | 363 | "}\n" |
| 364 | "\n" | 364 | "\n" |
| 365 | - "aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle) {\n" | 365 | + "aclError Om2ModelDestroy(GertModelHandle *model_handle) {\n" |
| 366 | " OM2_LOGI(\"Om2ModelDestroy\");\n" | 366 | " OM2_LOGI(\"Om2ModelDestroy\");\n" |
| 367 | " delete static_cast<om2::Om2Model*>(*model_handle);\n" | 367 | " delete static_cast<om2::Om2Model*>(*model_handle);\n" |
| 368 | " return ACL_SUCCESS;\n" | 368 | " return ACL_SUCCESS;\n" |
| 369 | + "}\n" | ||
| 370 | + "\n" | ||
| 371 | + "// ==================== model load/run/unload api ====================\n" | ||
| 372 | + "\n" | ||
| 373 | + "int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle,\n" | ||
| 374 | + " struct GertModelLoadOutput *output) {\n" | ||
| 375 | + " if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) {\n" | ||
| 376 | + " OM2_LOGE(\"GertModelLoad: invalid handle or config\");\n" | ||
| 377 | + " return ACL_ERROR_FAILURE;\n" | ||
| 378 | + " }\n" | ||
| 379 | + " if (output != nullptr) {\n" | ||
| 380 | + " OM2_LOGE(\"GertModelLoad: output is reserved, should be null\");\n" | ||
| 381 | + " return ACL_ERROR_FAILURE;\n" | ||
| 382 | + " }\n" | ||
| 383 | + " aclmdlRI rt_model_handle;\n" | ||
| 384 | + " // Create Model\n" | ||
| 385 | + " OM2_CHK_STATUS(Om2ModelCreate(model_handle, &rt_model_handle, config->bin_files, config->bin_data,\n" | ||
| 386 | + " config->bin_size, config->bin_num, config->constants, config->var_addrs,\n" | ||
| 387 | + " config->work_ptr, config->session_id, config->model_id,\n" | ||
| 388 | + " config->instance_handle, config->priority));\n" | ||
| 389 | + " OM2_LOGI(\"GertModelLoad: handle=%p, model_id=%\" PRIu64 \", priority=%\" PRIi64 \",\"\n" | ||
| 390 | + " \" bin_num=%\" PRIu64 \"\", *model_handle, config->model_id,\n" | ||
| 391 | + " config->priority, config->bin_num);\n" | ||
| 392 | + " // Load Model\n" | ||
| 393 | + " return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks);\n" | ||
| 394 | + "}\n" | ||
| 395 | + "\n" | ||
| 396 | + "int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream,\n" | ||
| 397 | + " const struct GertModelRunConfig *config, struct GertModelRunOutput *output) {\n" | ||
| 398 | + " if ((model_handle == nullptr) || (config == nullptr)) {\n" | ||
| 399 | + " OM2_LOGE(\"GertModelRunAsync: invalid handle or config\");\n" | ||
| 400 | + " return ACL_ERROR_FAILURE;\n" | ||
| 401 | + " }\n" | ||
| 402 | + " OM2_LOGI(\"GertModelRunAsync: handle=%p, stream=%p, input_count=%\" PRIu64 \",\"\n" | ||
| 403 | + " \" output_count=%\" PRIu64 \"\", model_handle, stream, config->input_count,\n" | ||
| 404 | + " config->output_count);\n" | ||
| 405 | + " Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info);\n" | ||
| 406 | + " return Om2ModelRunAsync(&model_handle, stream, config->input_count, config->input_data,\n" | ||
| 407 | + " config->output_count, config->output_data, prof_info);\n" | ||
| 408 | + "}\n" | ||
| 409 | + "\n" | ||
| 410 | + "int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config,\n" | ||
| 411 | + " struct GertModelRunOutput *output) {\n" | ||
| 412 | + " if ((model_handle == nullptr) || (config == nullptr)) {\n" | ||
| 413 | + " OM2_LOGE(\"GertModelRun: invalid handle or config\");\n" | ||
| 414 | + " return ACL_ERROR_FAILURE;\n" | ||
| 415 | + " }\n" | ||
| 416 | + " OM2_LOGI(\"GertModelRun: handle=%p, stream_sync_timeout_ms=%\" PRIu64 \",\"\n" | ||
| 417 | + " \" input_count=%\" PRIu64 \", output_count=%\" PRIu64 \"\", model_handle,\n" | ||
| 418 | + " config->stream_sync_timeout_ms, config->input_count, config->output_count);\n" | ||
| 419 | + " Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info);\n" | ||
| 420 | + " return Om2ModelRun(&model_handle, config->input_count, config->input_data, config->output_count,\n" | ||
| 421 | + " config->output_data, config->stream_sync_timeout_ms, prof_info);\n" | ||
| 422 | + "}\n" | ||
| 423 | + "\n" | ||
| 424 | + "int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config,\n" | ||
| 425 | + " struct GertModelUnloadOutput *output) {\n" | ||
| 426 | + " if (model_handle == nullptr) {\n" | ||
| 427 | + " OM2_LOGE(\"GertModelUnload: invalid handle\");\n" | ||
| 428 | + " return ACL_ERROR_FAILURE;\n" | ||
| 429 | + " }\n" | ||
| 430 | + " if ((config != nullptr) || (output != nullptr)) {\n" | ||
| 431 | + " OM2_LOGE(\"GertModelUnload: config and output are reserved, should be null\");\n" | ||
| 432 | + " return ACL_ERROR_FAILURE;\n" | ||
| 433 | + " }\n" | ||
| 434 | + " OM2_LOGI(\"GertModelRun: handle=%p\", model_handle);\n" | ||
| 435 | + " return Om2ModelDestroy(&model_handle);\n" | ||
| 369 | "}\n"; | 436 | "}\n"; |
| 370 | return SUCCESS; | 437 | return SUCCESS; |
| 371 | case StablePartId::kInterfaceDumpApis: | 438 | case StablePartId::kInterfaceDumpApis: |
| @@ -437,6 +504,30 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 437 | " uint64_t weight_mem_size;\n" | 504 | " uint64_t weight_mem_size;\n" |
| 438 | "};\n" | 505 | "};\n" |
| 439 | "\n" | 506 | "\n" |
| 507 | + "struct GertModelDumpEnabledInfo {\n" | ||
| 508 | + " uint64_t struct_size = sizeof(GertModelDumpEnabledInfo);\n" | ||
| 509 | + " const char *op_name = nullptr;\n" | ||
| 510 | + " uint64_t enabled = 0;\n" | ||
| 511 | + "};\n" | ||
| 512 | + "\n" | ||
| 513 | + "struct GertModelBaseInfo {\n" | ||
| 514 | + " uint64_t struct_size = sizeof(GertModelBaseInfo);\n" | ||
| 515 | + " const void *rt_model_handle = nullptr;\n" | ||
| 516 | + "};\n" | ||
| 517 | + "\n" | ||
| 518 | + "using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info);\n" | ||
| 519 | + "using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo " | ||
| 520 | + "*info);\n" | ||
| 521 | + "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n" | ||
| 522 | + "\n" | ||
| 523 | + "struct GertModelCallbacks {\n" | ||
| 524 | + " uint64_t struct_size = sizeof(GertModelCallbacks);\n" | ||
| 525 | + " ReportTaskProcessFunc report_task_preprocess = nullptr;\n" | ||
| 526 | + " ReportTaskProcessFunc report_task_postprocess = nullptr;\n" | ||
| 527 | + " GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr;\n" | ||
| 528 | + " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n" | ||
| 529 | + "};\n" | ||
| 530 | + "\n" | ||
| 440 | "#pragma pack(push)\n" | 531 | "#pragma pack(push)\n" |
| 441 | "#pragma pack(1)\n" | 532 | "#pragma pack(1)\n" |
| 442 | "struct ProfTraceUserData {\n" | 533 | "struct ProfTraceUserData {\n" |
| @@ -462,6 +553,55 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 462 | " uint32_t thread_id;\n" | 553 | " uint32_t thread_id;\n" |
| 463 | "};\n" | 554 | "};\n" |
| 464 | "\n" | 555 | "\n" |
| 556 | + "struct Om2ProfInfos {\n" | ||
| 557 | + " uint64_t struct_size = sizeof(Om2ProfInfos);\n" | ||
| 558 | + " uint64_t count = 0;\n" | ||
| 559 | + " Om2ProfUnit *prof_unit = nullptr;\n" | ||
| 560 | + " uint64_t step_id = 0;\n" | ||
| 561 | + "};\n" | ||
| 562 | + "\n" | ||
| 563 | + "struct GertModelLoadConfig {\n" | ||
| 564 | + " uint64_t struct_size = sizeof(GertModelLoadConfig);\n" | ||
| 565 | + " const char **bin_files = nullptr;\n" | ||
| 566 | + " const void **bin_data = nullptr;\n" | ||
| 567 | + " uint64_t *bin_size = nullptr;\n" | ||
| 568 | + " uint64_t bin_num = 0;\n" | ||
| 569 | + " void **constants = nullptr;\n" | ||
| 570 | + " void **var_addrs = nullptr;\n" | ||
| 571 | + " void *work_ptr = nullptr;\n" | ||
| 572 | + " uint64_t *session_id = nullptr;\n" | ||
| 573 | + " uint64_t model_id = 0; // used for logging\n" | ||
| 574 | + " void *instance_handle = nullptr;\n" | ||
| 575 | + " const struct GertModelCallbacks *callbacks = nullptr;\n" | ||
| 576 | + " int64_t priority = 0;\n" | ||
| 577 | + "};\n" | ||
| 578 | + "\n" | ||
| 579 | + "struct GertModelRunConfig {\n" | ||
| 580 | + " uint64_t struct_size = sizeof(GertModelRunConfig);\n" | ||
| 581 | + " uint64_t input_count = 0;\n" | ||
| 582 | + " gert::Tensor **input_data = nullptr;\n" | ||
| 583 | + " uint64_t output_count = 0;\n" | ||
| 584 | + " gert::Tensor **output_data = nullptr;\n" | ||
| 585 | + " uint64_t stream_sync_timeout_ms = 0;\n" | ||
| 586 | + "};\n" | ||
| 587 | + "\n" | ||
| 588 | + "struct GertModelUnloadConfig {\n" | ||
| 589 | + " uint64_t struct_size = sizeof(GertModelUnloadConfig);\n" | ||
| 590 | + "};\n" | ||
| 591 | + "\n" | ||
| 592 | + "struct GertModelLoadOutput {\n" | ||
| 593 | + " uint64_t struct_size = sizeof(GertModelLoadOutput);\n" | ||
| 594 | + "};\n" | ||
| 595 | + "\n" | ||
| 596 | + "struct GertModelRunOutput {\n" | ||
| 597 | + " uint64_t struct_size = sizeof(GertModelRunOutput);\n" | ||
| 598 | + " Om2ProfInfos *prof_info = nullptr;\n" | ||
| 599 | + "};\n" | ||
| 600 | + "\n" | ||
| 601 | + "struct GertModelUnloadOutput {\n" | ||
| 602 | + " uint64_t struct_size = sizeof(GertModelUnloadOutput);\n" | ||
| 603 | + "};\n" | ||
| 604 | + "\n" | ||
| 465 | "extern \"C\" {\n" | 605 | "extern \"C\" {\n" |
| 466 | "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n" | 606 | "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n" |
| 467 | " void* instance_handle,\n" | 607 | " void* instance_handle,\n" |
| @@ -11,10 +11,6 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | namespace ge { | 13 | namespace ge { |
| 14 | -TypeAliasDecl *InterfaceFileCodeGenerator::BuildOm2ModelHandleAlias() { | ||
| 15 | - return ast_.TypeAlias("void *", "Om2ModelHandle"); | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | StructDecl *InterfaceFileCodeGenerator::BuildBinDataInfoStruct() { | 14 | StructDecl *InterfaceFileCodeGenerator::BuildBinDataInfoStruct() { |
| 19 | return ast_.Struct("BinDataInfo", { | 15 | return ast_.Struct("BinDataInfo", { |
| 20 | ast_.Field("const void *", "data"), | 16 | ast_.Field("const void *", "data"), |
| @@ -22,15 +18,6 @@ StructDecl *InterfaceFileCodeGenerator::BuildBinDataInfoStruct() { | |||
| 22 | }); | 18 | }); |
| 23 | } | 19 | } |
| 24 | 20 | ||
| 25 | -StructDecl *InterfaceFileCodeGenerator::BuildOm2ProfInfosStruct() { | ||
| 26 | - return ast_.Struct("Om2ProfInfos", { | ||
| 27 | - ast_.Field("uint32_t", "version"), | ||
| 28 | - ast_.Field("uint32_t", "count"), | ||
| 29 | - ast_.Field("Om2ProfUnit *", "profUnit"), | ||
| 30 | - ast_.Field("uint64_t", "step_id"), | ||
| 31 | - }); | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | StructDecl *InterfaceFileCodeGenerator::BuildAicpuParamHeadStruct() { | 21 | StructDecl *InterfaceFileCodeGenerator::BuildAicpuParamHeadStruct() { |
| 35 | return ast_.Struct("AicpuParamHead", { | 22 | return ast_.Struct("AicpuParamHead", { |
| 36 | ast_.Field("uint32_t", "length"), | 23 | ast_.Field("uint32_t", "length"), |
| @@ -125,17 +112,17 @@ ClassDecl *InterfaceFileCodeGenerator::BuildOm2ModelClass(const Om2CodegenModel | |||
| 125 | ast_.DeclareMethod("~Om2Model", {}, ""), | 112 | ast_.DeclareMethod("~Om2Model", {}, ""), |
| 126 | ast_.DeclareMethod("InitResources", {}, "aclError"), | 113 | ast_.DeclareMethod("InitResources", {}, "aclError"), |
| 127 | ast_.DeclareMethod("RegisterKernels", {}, "aclError"), | 114 | ast_.DeclareMethod("RegisterKernels", {}, "aclError"), |
| 128 | - ast_.DeclareMethod("Load", {}, "aclError"), | 115 | + ast_.DeclareMethod("Load", {ast_.Var("const GertModelCallbacks *", "callbacks")}, "aclError"), |
| 129 | ast_.DeclareMethod("GetRtModelHandle", {}, "aclmdlRI"), | 116 | ast_.DeclareMethod("GetRtModelHandle", {}, "aclmdlRI"), |
| 130 | ast_.DeclareMethod("Run", | 117 | ast_.DeclareMethod("Run", |
| 131 | - {ast_.Var("size_t", "input_count"), ast_.Var("void **", "input_data"), | 118 | + {ast_.Var("size_t", "input_count"), ast_.Var("gert::Tensor **", "input_data"), |
| 132 | - ast_.Var("size_t", "output_count"), ast_.Var("void **", "output_data"), | 119 | + ast_.Var("size_t", "output_count"), ast_.Var("gert::Tensor **", "output_data"), |
| 133 | ast_.Var("int32_t", "stream_sync_timeout"), ast_.Var("Om2ProfInfos *", "prof_info")}, | 120 | ast_.Var("int32_t", "stream_sync_timeout"), ast_.Var("Om2ProfInfos *", "prof_info")}, |
| 134 | "aclError"), | 121 | "aclError"), |
| 135 | ast_.DeclareMethod("RunAsync", | 122 | ast_.DeclareMethod("RunAsync", |
| 136 | {ast_.Var("aclrtStream &", "exe_stream"), ast_.Var("size_t", "input_count"), | 123 | {ast_.Var("aclrtStream &", "exe_stream"), ast_.Var("size_t", "input_count"), |
| 137 | - ast_.Var("void **", "input_data"), ast_.Var("size_t", "output_count"), | 124 | + ast_.Var("gert::Tensor **", "input_data"), ast_.Var("size_t", "output_count"), |
| 138 | - ast_.Var("void **", "output_data"), ast_.Var("Om2ProfInfos *", "prof_info")}, | 125 | + ast_.Var("gert::Tensor **", "output_data"), ast_.Var("Om2ProfInfos *", "prof_info")}, |
| 139 | "aclError"), | 126 | "aclError"), |
| 140 | ast_.DeclareMethod("ReleaseResources", {}, "aclError"), | 127 | ast_.DeclareMethod("ReleaseResources", {}, "aclError"), |
| 141 | ast_.Private(), | 128 | ast_.Private(), |
| @@ -215,28 +202,27 @@ std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildRtForwardDecls() { | |||
| 215 | 202 | ||
| 216 | std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildExternalApiDecls() { | 203 | std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildExternalApiDecls() { |
| 217 | return { | 204 | return { |
| 205 | + ast_.TypeAlias("void *", "GertModelHandle"), | ||
| 218 | ast_.DeclareFunction( | 206 | ast_.DeclareFunction( |
| 219 | - "Om2ModelCreate", | 207 | + "GertModelLoad", |
| 220 | - {ast_.Var("om2::Om2ModelHandle *", "model_handle"), ast_.Var("aclmdlRI *", "rt_model_handle"), | 208 | + {ast_.Var("const struct GertModelLoadConfig *", "config"), ast_.Var("GertModelHandle *", "model_handle"), |
| 221 | - ast_.Var("const char **", "bin_files"), ast_.Var("const void **", "bin_data"), | 209 | + ast_.Var("struct GertModelLoadOutput *", "output")}, |
| 222 | - ast_.Var("size_t *", "bin_size"), ast_.Var("int", "bin_num"), ast_.Var("void **", "constants"), | 210 | + "int"), |
| 223 | - ast_.Var("void **", "var_addrs"), ast_.Var("void *", "work_ptr"), ast_.Var("uint64_t *", "session_id"), | ||
| 224 | - ast_.Var("uint32_t", "model_id"), ast_.Var("void *", "instance_handle"), ast_.Var("int32_t", "priority")}, | ||
| 225 | - "aclError"), | ||
| 226 | - ast_.DeclareFunction("Om2ModelLoad", {ast_.Var("om2::Om2ModelHandle *", "model_handle")}, "aclError"), | ||
| 227 | ast_.DeclareFunction( | 211 | ast_.DeclareFunction( |
| 228 | - "Om2ModelRunAsync", | 212 | + "GertModelRunAsync", |
| 229 | - {ast_.Var("om2::Om2ModelHandle *", "model_handle"), ast_.Var("aclrtStream", "stream"), | 213 | + {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("aclrtStream", "stream"), |
| 230 | - ast_.Var("int", "input_count"), ast_.Var("void **", "input_data"), ast_.Var("int", "output_count"), | 214 | + ast_.Var("const struct GertModelRunConfig *", "config"), ast_.Var("struct GertModelRunOutput *", "output")}, |
| 231 | - ast_.Var("void **", "output_data"), ast_.Var("Om2ProfInfos *", "prof_info")}, | 215 | + "int"), |
| 232 | - "aclError"), | ||
| 233 | ast_.DeclareFunction( | 216 | ast_.DeclareFunction( |
| 234 | - "Om2ModelRun", | 217 | + "GertModelRun", |
| 235 | - {ast_.Var("om2::Om2ModelHandle *", "model_handle"), ast_.Var("int", "input_count"), | 218 | + {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelRunConfig *", "config"), |
| 236 | - ast_.Var("void **", "input_data"), ast_.Var("int", "output_count"), ast_.Var("void **", "output_data"), | 219 | + ast_.Var("struct GertModelRunOutput *", "output")}, |
| 237 | - ast_.Var("int32_t", "stream_sync_timeout"), ast_.Var("Om2ProfInfos *", "prof_info")}, | 220 | + "int"), |
| 238 | - "aclError"), | 221 | + ast_.DeclareFunction( |
| 239 | - ast_.DeclareFunction("Om2ModelDestroy", {ast_.Var("om2::Om2ModelHandle *", "model_handle")}, "aclError"), | 222 | + "GertModelUnload", |
| 223 | + {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelUnloadConfig *", "config"), | ||
| 224 | + ast_.Var("struct GertModelUnloadOutput *", "output")}, | ||
| 225 | + "int"), | ||
| 240 | }; | 226 | }; |
| 241 | } | 227 | } |
| 242 | } // namespace ge | 228 | } // namespace ge |
| @@ -19,9 +19,7 @@ class InterfaceFileCodeGenerator : public CodeGeneratorBase { | |||
| 19 | using CodeGeneratorBase::CodeGeneratorBase; | 19 | using CodeGeneratorBase::CodeGeneratorBase; |
| 20 | ~InterfaceFileCodeGenerator() override = default; | 20 | ~InterfaceFileCodeGenerator() override = default; |
| 21 | 21 | ||
| 22 | - TypeAliasDecl *BuildOm2ModelHandleAlias(); | ||
| 23 | StructDecl *BuildBinDataInfoStruct(); | 22 | StructDecl *BuildBinDataInfoStruct(); |
| 24 | - StructDecl *BuildOm2ProfInfosStruct(); | ||
| 25 | StructDecl *BuildAicpuParamHeadStruct(); | 23 | StructDecl *BuildAicpuParamHeadStruct(); |
| 26 | StructDecl *BuildAicpuSessionInfoStruct(); | 24 | StructDecl *BuildAicpuSessionInfoStruct(); |
| 27 | StructDecl *BuildTfAiCpuExInfoStruct(); | 25 | StructDecl *BuildTfAiCpuExInfoStruct(); |
| @@ -83,7 +83,7 @@ MethodDef *LoadAndRunFileCodeGenerator::BuildLoadMethod(const Om2CodegenModel &c | |||
| 83 | const std::vector<TaskCodeBuilderPtr> &task_code_builders) { | 83 | const std::vector<TaskCodeBuilderPtr> &task_code_builders) { |
| 84 | std::vector<BodyItem> body; | 84 | std::vector<BodyItem> body; |
| 85 | (void)BuildLoadBody(body, codegen_model, task_code_builders); | 85 | (void)BuildLoadBody(body, codegen_model, task_code_builders); |
| 86 | - return ast_.DefineMethod("Om2Model", "Load", {}, "aclError", body); | 86 | + return ast_.DefineMethod("Om2Model", "Load", {ast_.Var("const GertModelCallbacks *", "callbacks")}, "aclError", body); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | MethodDef *LoadAndRunFileCodeGenerator::BuildGetRtModelHandleMethod() const { | 89 | MethodDef *LoadAndRunFileCodeGenerator::BuildGetRtModelHandleMethod() const { |
| @@ -128,6 +128,15 @@ Status LoadAndRunFileCodeGenerator::BuildLoadBody(std::vector<BodyItem> &body, c | |||
| 128 | 128 | ||
| 129 | body.push_back(ast_.VarDecl(ctx_var, ctx_init_list)); | 129 | body.push_back(ast_.VarDecl(ctx_var, ctx_init_list)); |
| 130 | 130 | ||
| 131 | + // 执行 ReportModelBaseInfo 回调 | ||
| 132 | + auto param_callbacks = ast_.Var("", "callbacks"); | ||
| 133 | + body.push_back( | ||
| 134 | + ast_.If((param_callbacks != "nullptr" && param_callbacks.Arrow("report_model_base_info") != "nullptr"), | ||
| 135 | + {ast_.VarDecl(ast_.Var("GertModelBaseInfo", "cfg"), | ||
| 136 | + ast_.InitList({ast_.Var("", "sizeof(GertModelBaseInfo)"), ctx_var.Attr("model_handle")})), | ||
| 137 | + ChkStatus(ast_.Call("callbacks->report_model_base_info", | ||
| 138 | + {ctx_var.Attr("instance_handle"), ast_.Var("", "cfg").Addr()}))})); | ||
| 139 | + | ||
| 131 | // 方案 A:for 循环分发(优先使用) | 140 | // 方案 A:for 循环分发(优先使用) |
| 132 | std::vector<BodyItem> dispatch_loop_items; | 141 | std::vector<BodyItem> dispatch_loop_items; |
| 133 | dispatch_loop_items.push_back( | 142 | dispatch_loop_items.push_back( |
| @@ -173,9 +182,9 @@ MethodDef *LoadAndRunFileCodeGenerator::BuildRunAsyncMethod(const Om2CodegenMode | |||
| 173 | (void)BuildRunBodyImpl(body, codegen_model, true); | 182 | (void)BuildRunBodyImpl(body, codegen_model, true); |
| 174 | auto exe_stream = ast_.Var("aclrtStream &", "exe_stream"); | 183 | auto exe_stream = ast_.Var("aclrtStream &", "exe_stream"); |
| 175 | auto input_count = ast_.Var("size_t", "input_count"); | 184 | auto input_count = ast_.Var("size_t", "input_count"); |
| 176 | - auto input_data = ast_.Var("void **", "input_data"); | 185 | + auto input_data = ast_.Var("gert::Tensor **", "input_data"); |
| 177 | auto output_count = ast_.Var("size_t", "output_count"); | 186 | auto output_count = ast_.Var("size_t", "output_count"); |
| 178 | - auto output_data = ast_.Var("void **", "output_data"); | 187 | + auto output_data = ast_.Var("gert::Tensor **", "output_data"); |
| 179 | auto prof_info = ast_.Var("Om2ProfInfos *", "prof_info"); | 188 | auto prof_info = ast_.Var("Om2ProfInfos *", "prof_info"); |
| 180 | return ast_.DefineMethod("Om2Model", "RunAsync", | 189 | return ast_.DefineMethod("Om2Model", "RunAsync", |
| 181 | {exe_stream, input_count, input_data, output_count, output_data, prof_info}, "aclError", | 190 | {exe_stream, input_count, input_data, output_count, output_data, prof_info}, "aclError", |
| @@ -186,9 +195,9 @@ MethodDef *LoadAndRunFileCodeGenerator::BuildRunMethod(const Om2CodegenModel &co | |||
| 186 | std::vector<BodyItem> body; | 195 | std::vector<BodyItem> body; |
| 187 | (void)BuildRunBodyImpl(body, codegen_model, false); | 196 | (void)BuildRunBodyImpl(body, codegen_model, false); |
| 188 | auto input_count = ast_.Var("size_t", "input_count"); | 197 | auto input_count = ast_.Var("size_t", "input_count"); |
| 189 | - auto input_data = ast_.Var("void **", "input_data"); | 198 | + auto input_data = ast_.Var("gert::Tensor **", "input_data"); |
| 190 | auto output_count = ast_.Var("size_t", "output_count"); | 199 | auto output_count = ast_.Var("size_t", "output_count"); |
| 191 | - auto output_data = ast_.Var("void **", "output_data"); | 200 | + auto output_data = ast_.Var("gert::Tensor **", "output_data"); |
| 192 | auto stream_sync_timeout = ast_.Var("int32_t", "stream_sync_timeout"); | 201 | auto stream_sync_timeout = ast_.Var("int32_t", "stream_sync_timeout"); |
| 193 | auto prof_info = ast_.Var("Om2ProfInfos *", "prof_info"); | 202 | auto prof_info = ast_.Var("Om2ProfInfos *", "prof_info"); |
| 194 | return ast_.DefineMethod("Om2Model", "Run", | 203 | return ast_.DefineMethod("Om2Model", "Run", |
| @@ -329,8 +338,7 @@ void LoadAndRunFileCodeGenerator::BuildRunBodyDeclareTensorIoVars(std::vector<Bo | |||
| 329 | } | 338 | } |
| 330 | if (should_declare_tensor) { | 339 | if (should_declare_tensor) { |
| 331 | auto tensor = ast_.Var("auto", tensor_var_name); | 340 | auto tensor = ast_.Var("auto", tensor_var_name); |
| 332 | - body.push_back(ast_.VarDecl( | 341 | + body.push_back(ast_.VarDecl(tensor, (entry.is_input ? input_data : output_data)[entry.index])); |
| 333 | - tensor, ast_.ReinterpretCast("gert::Tensor *", (entry.is_input ? input_data : output_data)[entry.index]))); | ||
| 334 | } | 342 | } |
| 335 | } | 343 | } |
| 336 | } | 344 | } |
| @@ -536,7 +544,7 @@ FunctionDef *LoadAndRunFileCodeGenerator::BuildCommitProfUnit() const { | |||
| 536 | auto unit_var = ast_.Var("auto &", "unit"); | 544 | auto unit_var = ast_.Var("auto &", "unit"); |
| 537 | return ast_.DefineFunction( | 545 | return ast_.DefineFunction( |
| 538 | "CommitProfUnit", {prof_info, prof_type, begin_time}, "void", | 546 | "CommitProfUnit", {prof_info, prof_type, begin_time}, "void", |
| 539 | - {ast_.VarDecl(unit_var, prof_info.Arrow("profUnit")[prof_info.Arrow("count")]), | 547 | + {ast_.VarDecl(unit_var, prof_info.Arrow("prof_unit")[prof_info.Arrow("count")]), |
| 540 | ast_.Assign(unit_var.Attr("type"), prof_type), ast_.Assign(unit_var.Attr("begin_time"), begin_time), | 548 | ast_.Assign(unit_var.Attr("type"), prof_type), ast_.Assign(unit_var.Attr("begin_time"), begin_time), |
| 541 | ast_.Assign(unit_var.Attr("end_time"), ast_.Call("MsprofSysCycleTime", {})), | 549 | ast_.Assign(unit_var.Attr("end_time"), ast_.Call("MsprofSysCycleTime", {})), |
| 542 | ast_.Assign(unit_var.Attr("thread_id"), ast_.StaticCast("uint32_t", ast_.Call("mmGetTid", {}))), | 550 | ast_.Assign(unit_var.Attr("thread_id"), ast_.StaticCast("uint32_t", ast_.Call("mmGetTid", {}))), |
| @@ -90,13 +90,11 @@ Status ProgramGenerator::GenerateInterfaceHeader(Om2CodePrinter &code_printer) { | |||
| 90 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceMacros)); | 90 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceMacros)); |
| 91 | file_items.push_back(ast_.StablePart(StablePartId::kInterfacePointerHelpers)); | 91 | file_items.push_back(ast_.StablePart(StablePartId::kInterfacePointerHelpers)); |
| 92 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceDumpApis)); | 92 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceDumpApis)); |
| 93 | - file_items.push_back(interface_handler.BuildOm2ProfInfosStruct()); | ||
| 94 | file_items.insert(file_items.end(), rt_forward_decls.begin(), rt_forward_decls.end()); | 93 | file_items.insert(file_items.end(), rt_forward_decls.begin(), rt_forward_decls.end()); |
| 95 | file_items.push_back(ast_.Namespace( | 94 | file_items.push_back(ast_.Namespace( |
| 96 | "om2", { | 95 | "om2", { |
| 97 | ast_.Field("constexpr int32_t", "INPUT_NUM", static_cast<int>(codegen_model_.model_io.input_count)), | 96 | ast_.Field("constexpr int32_t", "INPUT_NUM", static_cast<int>(codegen_model_.model_io.input_count)), |
| 98 | ast_.Field("constexpr int32_t", "OUTPUT_NUM", static_cast<int>(codegen_model_.model_io.output_count)), | 97 | ast_.Field("constexpr int32_t", "OUTPUT_NUM", static_cast<int>(codegen_model_.model_io.output_count)), |
| 99 | - interface_handler.BuildOm2ModelHandleAlias(), | ||
| 100 | interface_handler.BuildBinDataInfoStruct(), | 98 | interface_handler.BuildBinDataInfoStruct(), |
| 101 | interface_handler.BuildAicpuParamHeadStruct(), | 99 | interface_handler.BuildAicpuParamHeadStruct(), |
| 102 | interface_handler.BuildAicpuSessionInfoStruct(), | 100 | interface_handler.BuildAicpuSessionInfoStruct(), |
| @@ -153,14 +153,44 @@ struct Om2ProfUnit { | |||
| 153 | }; | 153 | }; |
| 154 | 154 | ||
| 155 | struct Om2ProfInfos { | 155 | struct Om2ProfInfos { |
| 156 | - uint32_t version; // 版本号,使用 sizeof(Om2ProfInfos) 自动兼容 | 156 | + uint64_t struct_size = sizeof(Om2ProfInfos); // 版本号,使用 sizeof(Om2ProfInfos) 自动兼容 |
| 157 | - uint32_t count; // profUnit 有效条目数 | 157 | + uint64_t count = 0; // prof_unit 有效条目数 |
| 158 | - Om2ProfUnit *profUnit; // 指针,Executor 分配,codegen 填充 | 158 | + Om2ProfUnit *prof_unit = nullptr; // 指针,Executor 分配,codegen 填充 |
| 159 | - uint64_t step_id; // 输入:Executor 设置,0 不上报 StepInfo | 159 | + uint64_t step_id = 0; // 输入:Executor 设置,0 不上报 StepInfo |
| 160 | }; | 160 | }; |
| 161 | 161 | ||
| 162 | constexpr uint32_t kOm2ProfInfosVersion = sizeof(Om2ProfInfos); | 162 | constexpr uint32_t kOm2ProfInfosVersion = sizeof(Om2ProfInfos); |
| 163 | 163 | ||
| 164 | +// ============ Dump 回调函数入参 struct 的类型定义 ============ | ||
| 165 | + | ||
| 166 | +// get_data_dump_enabled 回调入参 | ||
| 167 | +struct GertModelDumpEnabledInfo { | ||
| 168 | + uint64_t struct_size = sizeof(GertModelDumpEnabledInfo); // 布局变化时更新 | ||
| 169 | + const char *op_name = nullptr; // 算子名 | ||
| 170 | + uint64_t enabled = 0; // 输出:是否使能 dump | ||
| 171 | +}; | ||
| 172 | + | ||
| 173 | +// GertModelBaseInfo: init_model_dump_info 回调入参(codegen → executor 传递 rt_model_handle) | ||
| 174 | +struct GertModelBaseInfo { | ||
| 175 | + uint64_t struct_size = sizeof(GertModelBaseInfo); // 布局变化时更新 | ||
| 176 | + const void *rt_model_handle = nullptr; // 输入:codegen 创建的 aclmdlRI*(InitResources 后即可获得) | ||
| 177 | +}; | ||
| 178 | + | ||
| 179 | +using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info); | ||
| 180 | +using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | ||
| 181 | +using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | ||
| 182 | + | ||
| 183 | +struct GertModelCallbacks { | ||
| 184 | + uint64_t struct_size = sizeof(GertModelCallbacks); // 布局变化时更新 | ||
| 185 | + | ||
| 186 | + ReportTaskProcessFunc report_task_preprocess = nullptr; | ||
| 187 | + ReportTaskProcessFunc report_task_postprocess = nullptr; | ||
| 188 | + GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; | ||
| 189 | + // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调; | ||
| 190 | + // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo) | ||
| 191 | + ReportModelBaseInfoFunc report_model_base_info = nullptr; | ||
| 192 | +}; | ||
| 193 | + | ||
| 164 | // ============ 弱符号接口 ============ | 194 | // ============ 弱符号接口 ============ |
| 165 | /** | 195 | /** |
| 166 | * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。 | 196 | * @brief 在 OM2 算子任务 launch 前执行 DFX 预处理。 |
| @@ -199,6 +229,7 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *insta | |||
| 199 | int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, | 229 | int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, |
| 200 | uint8_t *is_data_dump); | 230 | uint8_t *is_data_dump); |
| 201 | 231 | ||
| 232 | +int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info); | ||
| 202 | 233 | ||
| 203 | } | 234 | } |
| 204 | 235 | ||
| @@ -75,6 +75,9 @@ class VISIBILITY_EXPORT ModelDumpManager { | |||
| 75 | // 模型级信息接口 | 75 | // 模型级信息接口 |
| 76 | // ======================================================================== | 76 | // ======================================================================== |
| 77 | Status SetModelDumpInfo(const ModelDumpInfo &model_info); | 77 | Status SetModelDumpInfo(const ModelDumpInfo &model_info); |
| 78 | + ModelDumpInfo &GetModelDumpInfo() { | ||
| 79 | + return model_info_; | ||
| 80 | + } | ||
| 78 | void SetClearDfxCacheFlagAfterLoad(bool clear_cache); | 81 | void SetClearDfxCacheFlagAfterLoad(bool clear_cache); |
| 79 | Status ReportModelLoadBegin() const; | 82 | Status ReportModelLoadBegin() const; |
| 80 | Status ReportModelLoadEnd() const; | 83 | Status ReportModelLoadEnd() const; |
| @@ -70,4 +70,25 @@ int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_han | |||
| 70 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); | 70 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | +int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info) { | ||
| 74 | + if ((instance_handle == nullptr)) { | ||
| 75 | + GELOGW("ModelExecutor handle is null, skip"); | ||
| 76 | + return PARAM_INVALID; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + if ((info == nullptr) || (info->rt_model_handle == nullptr)) { | ||
| 80 | + GELOGW("Input parameter info or info->rt_model_handle is null, skip"); | ||
| 81 | + return PARAM_INVALID; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + auto *dump_manager = static_cast<ge::dump::ModelDumpManager *>(instance_handle); | ||
| 85 | + if (dump_manager == nullptr) { | ||
| 86 | + GELOGW("Dump manager is null, skip"); | ||
| 87 | + return PARAM_INVALID; | ||
| 88 | + } | ||
| 89 | + ge::dump::ModelDumpInfo &model_dump_info = dump_manager->GetModelDumpInfo(); | ||
| 90 | + model_dump_info.rt_model_handle = const_cast<void *>(info->rt_model_handle); | ||
| 91 | + | ||
| 92 | + return dump_manager->SetModelDumpInfo(model_dump_info); | ||
| 93 | +} | ||
| 73 | } // extern "C" | 94 | } // extern "C" |
| @@ -97,7 +97,8 @@ Status ModelDumpManager::ReportModelLevelProf(const Om2ProfInfos &prof_info) con | |||
| 97 | GELOGW("[OM2][Prof] Skip ReportModelLevelProf, profiling_impl is null, model_id=%u", model_info_.model_id); | 97 | GELOGW("[OM2][Prof] Skip ReportModelLevelProf, profiling_impl is null, model_id=%u", model_info_.model_id); |
| 98 | return SUCCESS; | 98 | return SUCCESS; |
| 99 | } | 99 | } |
| 100 | - GELOGD("[OM2][Prof] ReportModelLevelProf begin, model_id=%u, count=%u", model_info_.model_id, prof_info.count); | 100 | + GELOGD("[OM2][Prof] ReportModelLevelProf begin, model_id=%u, count=%" PRIu64 "", model_info_.model_id, |
| 101 | + prof_info.count); | ||
| 101 | auto ret = profiling_impl_->ReportModelLevelProf(prof_info, model_info_.model_id); | 102 | auto ret = profiling_impl_->ReportModelLevelProf(prof_info, model_info_.model_id); |
| 102 | GELOGD("[OM2][Prof] ReportModelLevelProf end, model_id=%u, ret=%u", model_info_.model_id, ret); | 103 | GELOGD("[OM2][Prof] ReportModelLevelProf end, model_id=%u, ret=%u", model_info_.model_id, ret); |
| 103 | return ret; | 104 | return ret; |
| @@ -375,10 +375,10 @@ Status ProfilingImpl::ReportModelLevelProf(const Om2ProfInfos &prof_info, uint32 | |||
| 375 | return SUCCESS; | 375 | return SUCCESS; |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | - GELOGD("[OM2][Prof] Report OM2 model level profiling, model_id=%u, count=%u", model_id, prof_info.count); | 378 | + GELOGD("[OM2][Prof] Report OM2 model level profiling, model_id=%u, count=%" PRIu64 "", model_id, prof_info.count); |
| 379 | 379 | ||
| 380 | for (uint32_t i = 0U; i < prof_info.count; ++i) { | 380 | for (uint32_t i = 0U; i < prof_info.count; ++i) { |
| 381 | - auto &unit = prof_info.profUnit[i]; | 381 | + auto &unit = prof_info.prof_unit[i]; |
| 382 | if (unit.type >= OM2_PROF_TYPE_COUNT) { | 382 | if (unit.type >= OM2_PROF_TYPE_COUNT) { |
| 383 | GELOGW("[OM2][Prof] Invalid prof type=%u at index=%u, model_id=%u, skipping", unit.type, i, model_id); | 383 | GELOGW("[OM2][Prof] Invalid prof type=%u at index=%u, model_id=%u, skipping", unit.type, i, model_id); |
| 384 | continue; | 384 | continue; |
| @@ -417,7 +417,7 @@ Status ProfilingImpl::ReportModelLevelProf(const Om2ProfInfos &prof_info, uint32 | |||
| 417 | } | 417 | } |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | - GELOGD("[OM2][Prof] ReportModelLevelProf done, model_id=%u, total=%u entries", model_id, prof_info.count); | 420 | + GELOGD("[OM2][Prof] ReportModelLevelProf done, model_id=%u, total=%" PRIu64 " entries", model_id, prof_info.count); |
| 421 | return SUCCESS; | 421 | return SUCCESS; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| @@ -9,6 +9,7 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | 15 | ||
| @@ -49,13 +50,63 @@ constexpr size_t kMaxErrorStringLen = 128U; | |||
| 49 | constexpr size_t FILE_MAGIC_HEADER_SIZE = 4U; | 50 | constexpr size_t FILE_MAGIC_HEADER_SIZE = 4U; |
| 50 | constexpr uint8_t OM2_MAGIC[] = {0x50, 0x4B, 0x03, 0x04}; | 51 | constexpr uint8_t OM2_MAGIC[] = {0x50, 0x4B, 0x03, 0x04}; |
| 51 | 52 | ||
| 52 | -using Om2ModelHandle = void *; | 53 | +using GertModelHandle = void *; |
| 53 | -using CreateFunc = ge::graphStatus (*)(Om2ModelHandle *, rtModel_t *, const char **, const void **, size_t *, int, | 54 | + |
| 54 | - void **, void **, void *, uint64_t *, uint32_t, void *, int32_t); | 55 | +// 入参合并为结构体:首字段 struct_size 版本号,新字段只能追加;整数类型统一 uint64_t |
| 55 | -using LoadFunc = ge::graphStatus (*)(Om2ModelHandle *); | 56 | +struct GertModelLoadConfig { // 合并 Create+Load:容纳原 Om2ModelCreate 全部参数 |
| 56 | -using DestroyFunc = ge::graphStatus (*)(Om2ModelHandle *); | 57 | + uint64_t struct_size = sizeof(GertModelLoadConfig); // 布局变化时更新 |
| 57 | -using RunFunc = ge::graphStatus (*)(Om2ModelHandle *, int, void **, int, void **, int32_t, Om2ProfInfos *); | 58 | + const char **bin_files = nullptr; // 输入:bin 文件路径列表 |
| 58 | -using RunAsyncFunc = ge::graphStatus (*)(Om2ModelHandle *, rtStream_t, int, void **, int, void **, Om2ProfInfos *); | 59 | + const void **bin_data = nullptr; // 输入:bin 内存数据列表 |
| 60 | + uint64_t *bin_size = nullptr; // 输入:bin 大小列表 | ||
| 61 | + uint64_t bin_num = 0; // 输入:bin 数量 | ||
| 62 | + void **constants = nullptr; // 输入:常量 | ||
| 63 | + void **var_addrs = nullptr; // 输入:vars | ||
| 64 | + void *work_ptr = nullptr; // 输入:工作内存指针 | ||
| 65 | + uint64_t *session_id = nullptr; // 输入:session id | ||
| 66 | + uint64_t model_id = 0; // 输入:model id,打印日志用 | ||
| 67 | + void *instance_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数 | ||
| 68 | + const struct GertModelCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump) | ||
| 69 | + int64_t priority = 0; // 输入:优先级 | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +struct GertModelRunConfig { | ||
| 73 | + uint64_t struct_size = sizeof(GertModelRunConfig); // 布局变化时更新 | ||
| 74 | + uint64_t input_count = 0; // 输入数量 | ||
| 75 | + gert::Tensor **input_data = nullptr; // 输入数据 | ||
| 76 | + uint64_t output_count = 0; // 输出数量 | ||
| 77 | + gert::Tensor **output_data = nullptr; // 输出数据 | ||
| 78 | + uint64_t stream_sync_timeout_ms = 0; // Run 使用(同步超时);RunAsync 置 0 | ||
| 79 | +}; | ||
| 80 | + | ||
| 81 | +struct GertModelUnloadConfig { | ||
| 82 | + uint64_t struct_size = sizeof(GertModelUnloadConfig); // 布局变化时更新 | ||
| 83 | +}; | ||
| 84 | + | ||
| 85 | +// ============================================================ | ||
| 86 | +// 接口输出结构:所有接口 Config 为输入,Output 为输出;首字段 struct_size 版本号,新字段只能追加 | ||
| 87 | +// ============================================================ | ||
| 88 | + | ||
| 89 | +struct GertModelLoadOutput { | ||
| 90 | + uint64_t struct_size = sizeof(GertModelLoadOutput); // 布局变化时更新 | ||
| 91 | +}; | ||
| 92 | + | ||
| 93 | +struct GertModelRunOutput { | ||
| 94 | + uint64_t struct_size = sizeof(GertModelRunOutput); // 布局变化时更新 | ||
| 95 | + Om2ProfInfos *prof_info = nullptr; // 输出:性能 profiling 数据,可空(不使能 profiling 时置空) | ||
| 96 | +}; | ||
| 97 | + | ||
| 98 | +struct GertModelUnloadOutput { | ||
| 99 | + uint64_t struct_size = sizeof(GertModelUnloadOutput); // 布局变化时更新 | ||
| 100 | +}; | ||
| 101 | + | ||
| 102 | +using LoadFunc = int (*)(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, | ||
| 103 | + struct GertModelLoadOutput *output); | ||
| 104 | +using RunFunc = int (*)(GertModelHandle model_handle, const struct GertModelRunConfig *config, | ||
| 105 | + struct GertModelRunOutput *output); | ||
| 106 | +using RunAsyncFunc = int (*)(GertModelHandle model_handle, aclrtStream stream, const struct GertModelRunConfig *config, | ||
| 107 | + struct GertModelRunOutput *output); | ||
| 108 | +using UnloadFunc = int (*)(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, | ||
| 109 | + struct GertModelUnloadOutput *output); | ||
| 59 | 110 | ||
| 60 | struct CustSharedLibInfo { | 111 | struct CustSharedLibInfo { |
| 61 | std::string so_file; | 112 | std::string so_file; |
| @@ -71,11 +122,10 @@ struct RunModelInfo { | |||
| 71 | std::string model_name; | 122 | std::string model_name; |
| 72 | std::string root_graph_name; | 123 | std::string root_graph_name; |
| 73 | std::vector<CustSharedLibInfo> cust_shared_libs; | 124 | std::vector<CustSharedLibInfo> cust_shared_libs; |
| 74 | - Om2ModelHandle model_handle = nullptr; | 125 | + GertModelHandle model_handle = nullptr; |
| 75 | rtModel_t rt_model_handle = nullptr; | 126 | rtModel_t rt_model_handle = nullptr; |
| 76 | - CreateFunc create_func = nullptr; | ||
| 77 | LoadFunc load_func = nullptr; | 127 | LoadFunc load_func = nullptr; |
| 78 | - DestroyFunc destroy_func = nullptr; | 128 | + UnloadFunc unload_func = nullptr; |
| 79 | RunFunc run_func = nullptr; | 129 | RunFunc run_func = nullptr; |
| 80 | RunAsyncFunc run_async_func = nullptr; | 130 | RunAsyncFunc run_async_func = nullptr; |
| 81 | }; | 131 | }; |
| @@ -875,16 +925,14 @@ class Om2ModelExecutor::Impl { | |||
| 875 | 925 | ||
| 876 | ge::Status ResolveSymbols() { | 926 | ge::Status ResolveSymbols() { |
| 877 | GE_ASSERT_TRUE(run_model_info_.so_handle != nullptr); | 927 | GE_ASSERT_TRUE(run_model_info_.so_handle != nullptr); |
| 878 | - run_model_info_.create_func = reinterpret_cast<CreateFunc>(mmDlsym(run_model_info_.so_handle, "Om2ModelCreate")); | 928 | + run_model_info_.load_func = reinterpret_cast<LoadFunc>(mmDlsym(run_model_info_.so_handle, "GertModelLoad")); |
| 879 | - GE_ASSERT_NOTNULL(run_model_info_.create_func); | ||
| 880 | - run_model_info_.load_func = reinterpret_cast<LoadFunc>(mmDlsym(run_model_info_.so_handle, "Om2ModelLoad")); | ||
| 881 | GE_ASSERT_NOTNULL(run_model_info_.load_func); | 929 | GE_ASSERT_NOTNULL(run_model_info_.load_func); |
| 882 | - run_model_info_.destroy_func = reinterpret_cast<DestroyFunc>(mmDlsym(run_model_info_.so_handle, "Om2ModelDestroy")); | 930 | + run_model_info_.unload_func = reinterpret_cast<UnloadFunc>(mmDlsym(run_model_info_.so_handle, "GertModelUnload")); |
| 883 | - GE_ASSERT_NOTNULL(run_model_info_.destroy_func); | 931 | + GE_ASSERT_NOTNULL(run_model_info_.unload_func); |
| 884 | - run_model_info_.run_func = reinterpret_cast<RunFunc>(mmDlsym(run_model_info_.so_handle, "Om2ModelRun")); | 932 | + run_model_info_.run_func = reinterpret_cast<RunFunc>(mmDlsym(run_model_info_.so_handle, "GertModelRun")); |
| 885 | GE_ASSERT_NOTNULL(run_model_info_.run_func); | 933 | GE_ASSERT_NOTNULL(run_model_info_.run_func); |
| 886 | run_model_info_.run_async_func = | 934 | run_model_info_.run_async_func = |
| 887 | - reinterpret_cast<RunAsyncFunc>(mmDlsym(run_model_info_.so_handle, "Om2ModelRunAsync")); | 935 | + reinterpret_cast<RunAsyncFunc>(mmDlsym(run_model_info_.so_handle, "GertModelRunAsync")); |
| 888 | GE_ASSERT_NOTNULL(run_model_info_.run_async_func); | 936 | GE_ASSERT_NOTNULL(run_model_info_.run_async_func); |
| 889 | return ge::SUCCESS; | 937 | return ge::SUCCESS; |
| 890 | } | 938 | } |
| @@ -937,7 +985,7 @@ class Om2ModelExecutor::Impl { | |||
| 937 | device_id_ = load_arg.device_id; | 985 | device_id_ = load_arg.device_id; |
| 938 | std::vector<const char *> bin_files(kernel_bin_info.size()); | 986 | std::vector<const char *> bin_files(kernel_bin_info.size()); |
| 939 | std::vector<const void *> bin_data(kernel_bin_info.size()); | 987 | std::vector<const void *> bin_data(kernel_bin_info.size()); |
| 940 | - std::vector<size_t> bin_sizes(kernel_bin_info.size()); | 988 | + std::vector<uint64_t> bin_sizes(kernel_bin_info.size()); |
| 941 | void *work_ptr = nullptr; | 989 | void *work_ptr = nullptr; |
| 942 | for (auto i = 0U; i < kernel_bin_info.size(); ++i) { | 990 | for (auto i = 0U; i < kernel_bin_info.size(); ++i) { |
| 943 | bin_files[i] = kernel_bin_info[i].file.c_str(); | 991 | bin_files[i] = kernel_bin_info[i].file.c_str(); |
| @@ -962,11 +1010,29 @@ class Om2ModelExecutor::Impl { | |||
| 962 | } | 1010 | } |
| 963 | 1011 | ||
| 964 | GE_ASSERT_SUCCESS(PrepareVarAddrs(model_data, static_cast<uint32_t>(load_arg.device_id), var_addrs)); | 1012 | GE_ASSERT_SUCCESS(PrepareVarAddrs(model_data, static_cast<uint32_t>(load_arg.device_id), var_addrs)); |
| 965 | - GE_ASSERT_SUCCESS(run_model_info_.create_func( | 1013 | + |
| 966 | - &run_model_info_.model_handle, &run_model_info_.rt_model_handle, bin_files.data(), bin_data.data(), | 1014 | + GE_ASSERT_NOTNULL(run_model_info_.load_func); |
| 967 | - bin_sizes.data(), static_cast<int>(bin_data.size()), constants.empty() ? nullptr : constants.data(), | 1015 | + GertModelCallbacks callbacks = {.struct_size = sizeof(GertModelCallbacks), |
| 968 | - var_addrs.empty() ? nullptr : var_addrs.data(), work_ptr, &session_id_, load_arg.model_id, dump_manager_.get(), | 1016 | + .report_task_preprocess = nullptr, |
| 969 | - load_arg.priority)); | 1017 | + .report_task_postprocess = nullptr, |
| 1018 | + .get_data_dump_enabled = nullptr, | ||
| 1019 | + .report_model_base_info = ReportModelBaseInfo}; | ||
| 1020 | + struct GertModelLoadConfig config = {.struct_size = sizeof(GertModelLoadConfig), | ||
| 1021 | + .bin_files = bin_files.data(), | ||
| 1022 | + .bin_data = bin_data.data(), | ||
| 1023 | + .bin_size = bin_sizes.data(), | ||
| 1024 | + .bin_num = bin_data.size(), | ||
| 1025 | + .constants = constants.empty() ? nullptr : constants.data(), | ||
| 1026 | + .var_addrs = var_addrs.empty() ? nullptr : var_addrs.data(), | ||
| 1027 | + .work_ptr = work_ptr, | ||
| 1028 | + .session_id = &session_id_, | ||
| 1029 | + .model_id = load_arg.model_id, | ||
| 1030 | + .instance_handle = dump_manager_.get(), | ||
| 1031 | + .callbacks = &callbacks, | ||
| 1032 | + .priority = load_arg.priority}; | ||
| 1033 | + GE_ASSERT_SUCCESS(run_model_info_.load_func(&config, &run_model_info_.model_handle, nullptr)); | ||
| 1034 | + GE_ASSERT_NOTNULL(run_model_info_.model_handle); | ||
| 1035 | + | ||
| 970 | return ge::GRAPH_SUCCESS; | 1036 | return ge::GRAPH_SUCCESS; |
| 971 | } | 1037 | } |
| 972 | 1038 | ||
| @@ -975,11 +1041,10 @@ class Om2ModelExecutor::Impl { | |||
| 975 | uint64_t session_id) { | 1041 | uint64_t session_id) { |
| 976 | std::vector<void *> constants; | 1042 | std::vector<void *> constants; |
| 977 | std::vector<void *> var_addrs; | 1043 | std::vector<void *> var_addrs; |
| 978 | - GE_ASSERT_SUCCESS( | ||
| 979 | - CreateModelFromStruct(model_data, weight_buf, kernel_bin_info, load_arg, session_id, constants, var_addrs)); | ||
| 980 | GE_ASSERT_SUCCESS(InitModelDumpInfo(load_arg)); | 1044 | GE_ASSERT_SUCCESS(InitModelDumpInfo(load_arg)); |
| 981 | ReportModelLoadBegin(); | 1045 | ReportModelLoadBegin(); |
| 982 | - GE_ASSERT_SUCCESS(LoadModel()); | 1046 | + GE_ASSERT_SUCCESS( |
| 1047 | + CreateModelFromStruct(model_data, weight_buf, kernel_bin_info, load_arg, session_id, constants, var_addrs)); | ||
| 983 | ReportModelLoadEnd(); | 1048 | ReportModelLoadEnd(); |
| 984 | GE_ASSERT_SUCCESS(DispatchDumpInfo()); | 1049 | GE_ASSERT_SUCCESS(DispatchDumpInfo()); |
| 985 | weight_buf.reset(nullptr); | 1050 | weight_buf.reset(nullptr); |
| @@ -997,14 +1062,14 @@ class Om2ModelExecutor::Impl { | |||
| 997 | } | 1062 | } |
| 998 | 1063 | ||
| 999 | ge::Status InitModelDumpInfo(const Om2ModelLoadArg &load_arg) { | 1064 | ge::Status InitModelDumpInfo(const Om2ModelLoadArg &load_arg) { |
| 1000 | - GE_ASSERT_NOTNULL(run_model_info_.rt_model_handle); | ||
| 1001 | GE_ASSERT_TRUE(dump_manager_ != nullptr); | 1065 | GE_ASSERT_TRUE(dump_manager_ != nullptr); |
| 1002 | - ge::dump::ModelDumpInfo model_dump_info{}; | 1066 | + ge::dump::ModelDumpInfo &model_dump_info = dump_manager_->GetModelDumpInfo(); |
| 1003 | model_dump_info.model_id = load_arg.model_id; | 1067 | model_dump_info.model_id = load_arg.model_id; |
| 1004 | model_dump_info.model_name = run_model_info_.model_name.c_str(); | 1068 | model_dump_info.model_name = run_model_info_.model_name.c_str(); |
| 1005 | model_dump_info.root_graph_name = run_model_info_.root_graph_name.c_str(); | 1069 | model_dump_info.root_graph_name = run_model_info_.root_graph_name.c_str(); |
| 1006 | model_dump_info.device_id = static_cast<uint32_t>(load_arg.device_id); | 1070 | model_dump_info.device_id = static_cast<uint32_t>(load_arg.device_id); |
| 1007 | - model_dump_info.rt_model_handle = run_model_info_.rt_model_handle; | 1071 | + // model_dump_info.rt_model_handle will be set value when callback ReportModelBaseInfo was triggered |
| 1072 | + model_dump_info.rt_model_handle = nullptr; | ||
| 1008 | model_dump_info.step_id_addr = 0U; | 1073 | model_dump_info.step_id_addr = 0U; |
| 1009 | model_dump_info.loop_cond_addr = 0U; | 1074 | model_dump_info.loop_cond_addr = 0U; |
| 1010 | model_dump_info.iterations_per_loop_addr = 0U; | 1075 | model_dump_info.iterations_per_loop_addr = 0U; |
| @@ -1015,7 +1080,6 @@ class Om2ModelExecutor::Impl { | |||
| 1015 | model_dump_info.model_id, model_dump_info.model_name, model_dump_info.root_graph_name, | 1080 | model_dump_info.model_id, model_dump_info.model_name, model_dump_info.root_graph_name, |
| 1016 | model_dump_info.device_id, model_dump_info.rt_model_handle, model_dump_info.step_id_addr, | 1081 | model_dump_info.device_id, model_dump_info.rt_model_handle, model_dump_info.step_id_addr, |
| 1017 | model_dump_info.loop_cond_addr, model_dump_info.iterations_per_loop_addr); | 1082 | model_dump_info.loop_cond_addr, model_dump_info.iterations_per_loop_addr); |
| 1018 | - GE_ASSERT_SUCCESS(dump_manager_->SetModelDumpInfo(model_dump_info)); | ||
| 1019 | GELOGI("[OM2][Dump] Set model dump info success, model_id=%u.", model_dump_info.model_id); | 1083 | GELOGI("[OM2][Dump] Set model dump info success, model_id=%u.", model_dump_info.model_id); |
| 1020 | return ge::SUCCESS; | 1084 | return ge::SUCCESS; |
| 1021 | } | 1085 | } |
| @@ -1040,13 +1104,6 @@ class Om2ModelExecutor::Impl { | |||
| 1040 | } | 1104 | } |
| 1041 | } | 1105 | } |
| 1042 | 1106 | ||
| 1043 | - ge::Status LoadModel() { | ||
| 1044 | - GE_ASSERT_NOTNULL(run_model_info_.load_func); | ||
| 1045 | - GE_ASSERT_NOTNULL(run_model_info_.model_handle); | ||
| 1046 | - GE_ASSERT_SUCCESS(run_model_info_.load_func(&run_model_info_.model_handle)); | ||
| 1047 | - return ge::SUCCESS; | ||
| 1048 | - } | ||
| 1049 | - | ||
| 1050 | ge::Status DispatchDumpInfo() { | 1107 | ge::Status DispatchDumpInfo() { |
| 1051 | GE_ASSERT_TRUE(dump_manager_ != nullptr); | 1108 | GE_ASSERT_TRUE(dump_manager_ != nullptr); |
| 1052 | GELOGI("[OM2][Dump] Dispatch dump info begin, model_id=%u, model_name=%s, root_graph_name=%s.", model_id_, | 1109 | GELOGI("[OM2][Dump] Dispatch dump info begin, model_id=%u, model_name=%s, root_graph_name=%s.", model_id_, |
| @@ -1066,9 +1123,15 @@ class Om2ModelExecutor::Impl { | |||
| 1066 | Om2ProfInfos prof_info = {kOm2ProfInfosVersion, 0, prof_units, step_id_}; | 1123 | Om2ProfInfos prof_info = {kOm2ProfInfosVersion, 0, prof_units, step_id_}; |
| 1067 | Om2ProfInfos *prof_info_ptr = | 1124 | Om2ProfInfos *prof_info_ptr = |
| 1068 | (dump_manager_ != nullptr && dump_manager_->IsProfilingEnabled()) ? &prof_info : nullptr; | 1125 | (dump_manager_ != nullptr && dump_manager_->IsProfilingEnabled()) ? &prof_info : nullptr; |
| 1069 | - GE_ASSERT_SUCCESS(run_model_info_.run_func(&run_model_info_.model_handle, inputs.size(), | 1126 | + |
| 1070 | - reinterpret_cast<void **>(inputs.data()), outputs.size(), | 1127 | + struct GertModelRunConfig config = {.struct_size = sizeof(GertModelRunConfig), |
| 1071 | - reinterpret_cast<void **>(outputs.data()), timeout, prof_info_ptr)); | 1128 | + .input_count = inputs.size(), |
| 1129 | + .input_data = inputs.data(), | ||
| 1130 | + .output_count = outputs.size(), | ||
| 1131 | + .output_data = outputs.data(), | ||
| 1132 | + .stream_sync_timeout_ms = static_cast<uint64_t>(timeout)}; | ||
| 1133 | + struct GertModelRunOutput output = {.struct_size = sizeof(GertModelRunOutput), .prof_info = prof_info_ptr}; | ||
| 1134 | + GE_ASSERT_SUCCESS(run_model_info_.run_func(run_model_info_.model_handle, &config, &output)); | ||
| 1072 | if (prof_info_ptr != nullptr) { | 1135 | if (prof_info_ptr != nullptr) { |
| 1073 | GELOGD("[OM2][Prof] Run done, model_id=%u, prof_count=%u, step_id=%lu", model_id_, prof_info.count, step_id_); | 1136 | GELOGD("[OM2][Prof] Run done, model_id=%u, prof_count=%u, step_id=%lu", model_id_, prof_info.count, step_id_); |
| 1074 | dump_manager_->ReportModelLevelProf(prof_info); | 1137 | dump_manager_->ReportModelLevelProf(prof_info); |
| @@ -1087,9 +1150,14 @@ class Om2ModelExecutor::Impl { | |||
| 1087 | Om2ProfInfos prof_info = {kOm2ProfInfosVersion, 0, prof_units, step_id_}; | 1150 | Om2ProfInfos prof_info = {kOm2ProfInfosVersion, 0, prof_units, step_id_}; |
| 1088 | Om2ProfInfos *prof_info_ptr = | 1151 | Om2ProfInfos *prof_info_ptr = |
| 1089 | (dump_manager_ != nullptr && dump_manager_->IsProfilingEnabled()) ? &prof_info : nullptr; | 1152 | (dump_manager_ != nullptr && dump_manager_->IsProfilingEnabled()) ? &prof_info : nullptr; |
| 1090 | - GE_ASSERT_SUCCESS(run_model_info_.run_async_func(&run_model_info_.model_handle, stream, inputs.size(), | 1153 | + struct GertModelRunConfig config = {.struct_size = sizeof(GertModelRunConfig), |
| 1091 | - reinterpret_cast<void **>(inputs.data()), outputs.size(), | 1154 | + .input_count = inputs.size(), |
| 1092 | - reinterpret_cast<void **>(outputs.data()), prof_info_ptr)); | 1155 | + .input_data = inputs.data(), |
| 1156 | + .output_count = outputs.size(), | ||
| 1157 | + .output_data = outputs.data(), | ||
| 1158 | + .stream_sync_timeout_ms = 0}; | ||
| 1159 | + struct GertModelRunOutput output = {.struct_size = sizeof(GertModelRunOutput), .prof_info = prof_info_ptr}; | ||
| 1160 | + GE_ASSERT_SUCCESS(run_model_info_.run_async_func(run_model_info_.model_handle, stream, &config, &output)); | ||
| 1093 | if (prof_info_ptr != nullptr) { | 1161 | if (prof_info_ptr != nullptr) { |
| 1094 | GELOGD("[OM2][Prof] RunAsync done, model_id=%u, prof_count=%u, step_id=%lu", model_id_, prof_info.count, | 1162 | GELOGD("[OM2][Prof] RunAsync done, model_id=%u, prof_count=%u, step_id=%lu", model_id_, prof_info.count, |
| 1095 | step_id_); | 1163 | step_id_); |
| @@ -1332,13 +1400,13 @@ class Om2ModelExecutor::Impl { | |||
| 1332 | if (dump_manager_ != nullptr) { | 1400 | if (dump_manager_ != nullptr) { |
| 1333 | dump_manager_.reset(); | 1401 | dump_manager_.reset(); |
| 1334 | } | 1402 | } |
| 1335 | - if (run_model_info_.destroy_func != nullptr && run_model_info_.model_handle != nullptr) { | 1403 | + if (run_model_info_.unload_func != nullptr && run_model_info_.model_handle != nullptr) { |
| 1336 | - const auto destroy_ret = run_model_info_.destroy_func(&run_model_info_.model_handle); | 1404 | + const auto unload_ret = run_model_info_.unload_func(run_model_info_.model_handle, nullptr, nullptr); |
| 1337 | - if (destroy_ret != ge::GRAPH_SUCCESS) { | 1405 | + if (unload_ret != ge::GRAPH_SUCCESS) { |
| 1338 | GELOGI("[OM2] Resource release issue for so file: %s", run_model_info_.so_file.c_str()); | 1406 | GELOGI("[OM2] Resource release issue for so file: %s", run_model_info_.so_file.c_str()); |
| 1339 | } | 1407 | } |
| 1340 | } else { | 1408 | } else { |
| 1341 | - GELOGI("[OM2] Destroy func not found or model not created, so file: %s", run_model_info_.so_file.c_str()); | 1409 | + GELOGI("[OM2] Unload func not found or model not created, so file: %s", run_model_info_.so_file.c_str()); |
| 1342 | } | 1410 | } |
| 1343 | if (run_model_info_.so_handle != nullptr) { | 1411 | if (run_model_info_.so_handle != nullptr) { |
| 1344 | if (mmDlclose(run_model_info_.so_handle) != 0) { | 1412 | if (mmDlclose(run_model_info_.so_handle) != 0) { |
| @@ -806,22 +806,71 @@ std::string MakeFakeOm2ConstantsConfigJson() { | |||
| 806 | })"; | 806 | })"; |
| 807 | } | 807 | } |
| 808 | 808 | ||
| 809 | -std::string MakeFakeOm2InterfaceHeader() { | 809 | +const std::string fake_interface_header_src = R"(#pragma once |
| 810 | - return R"(#pragma once | ||
| 811 | 810 | ||
| 812 | 811 | ||
| 813 | 812 | ||
| 813 | +namespace gert { | ||
| 814 | + class Tensor; | ||
| 815 | +} | ||
| 816 | + | ||
| 817 | +struct GertModelLoadConfig { | ||
| 818 | + uint64_t struct_size = sizeof(GertModelLoadConfig); | ||
| 819 | + const char **bin_files = nullptr; | ||
| 820 | + const void **bin_data = nullptr; | ||
| 821 | + uint64_t *bin_size = nullptr; | ||
| 822 | + uint64_t bin_num = 0; | ||
| 823 | + void **constants = nullptr; | ||
| 824 | + void **var_addrs = nullptr; | ||
| 825 | + void *work_ptr = nullptr; | ||
| 826 | + uint64_t *session_id = nullptr; | ||
| 827 | + uint64_t model_id = 0; // used for logging | ||
| 828 | + void *instance_handle = nullptr; | ||
| 829 | + const struct GertModelCallbacks *callbacks = nullptr; | ||
| 830 | + int64_t priority = 0; | ||
| 831 | +}; | ||
| 832 | + | ||
| 833 | +struct GertModelRunConfig { | ||
| 834 | + uint64_t struct_size = sizeof(GertModelRunConfig); | ||
| 835 | + uint64_t input_count = 0; | ||
| 836 | + gert::Tensor **input_data = nullptr; | ||
| 837 | + uint64_t output_count = 0; | ||
| 838 | + gert::Tensor **output_data = nullptr; | ||
| 839 | + uint64_t stream_sync_timeout_ms = 0; | ||
| 840 | +}; | ||
| 841 | + | ||
| 842 | +struct GertModelUnloadConfig { | ||
| 843 | + uint64_t struct_size = sizeof(GertModelUnloadConfig); | ||
| 844 | +}; | ||
| 845 | + | ||
| 846 | +struct GertModelLoadOutput { | ||
| 847 | + uint64_t struct_size = sizeof(GertModelLoadOutput); | ||
| 848 | +}; | ||
| 849 | + | ||
| 850 | +struct GertModelRunOutput { | ||
| 851 | + uint64_t struct_size = sizeof(GertModelRunOutput); | ||
| 852 | + void *prof_info = nullptr; | ||
| 853 | +}; | ||
| 854 | + | ||
| 855 | +struct GertModelUnloadOutput { | ||
| 856 | + uint64_t struct_size = sizeof(GertModelUnloadOutput); | ||
| 857 | +}; | ||
| 858 | + | ||
| 814 | extern "C" { | 859 | extern "C" { |
| 815 | -int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **bin_files, const void **bin_data, | 860 | +typedef void *GertModelHandle; |
| 816 | - size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, | 861 | + |
| 817 | - uint32_t model_id, void *instance_handle, int32_t priority); | 862 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output); |
| 818 | -int Om2ModelLoad(void **model_handle); | 863 | + |
| 819 | -int Om2ModelRunAsync(void **model_handle, void *stream, int input_count, void **input_data, int output_count, | 864 | +int GertModelRunAsync(GertModelHandle model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 820 | - void **output_data); | 865 | + |
| 821 | -int Om2ModelRun(void **model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout); | 866 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 822 | -int Om2ModelDestroy(void **model_handle); | 867 | + |
| 868 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output); | ||
| 823 | } | 869 | } |
| 824 | )"; | 870 | )"; |
| 871 | + | ||
| 872 | +std::string MakeFakeOm2InterfaceHeader() { | ||
| 873 | + return fake_interface_header_src; | ||
| 825 | } | 874 | } |
| 826 | 875 | ||
| 827 | std::string MakeFakeOm2LoadAndRunCreateCpp() { | 876 | std::string MakeFakeOm2LoadAndRunCreateCpp() { |
| @@ -835,53 +884,42 @@ struct FakeModel { | |||
| 835 | }; | 884 | }; |
| 836 | } | 885 | } |
| 837 | 886 | ||
| 838 | -extern "C" int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **, const void **, size_t *, int, | 887 | +extern "C" int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output) { |
| 839 | - void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t, void *, int32_t) { | 888 | + if ((model_handle == nullptr) || (config == nullptr) || (config->work_ptr == nullptr) || (config->constants == nullptr) || (config->constants[0] == nullptr)) { |
| 840 | - if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (work_ptr == nullptr) || (constants == nullptr) || | ||
| 841 | - (constants[0] == nullptr)) { | ||
| 842 | return 1; | 889 | return 1; |
| 843 | } | 890 | } |
| 844 | auto *model = new (std::nothrow) FakeModel(); | 891 | auto *model = new (std::nothrow) FakeModel(); |
| 845 | if (model == nullptr) { | 892 | if (model == nullptr) { |
| 846 | return 1; | 893 | return 1; |
| 847 | } | 894 | } |
| 848 | - model->session_id = (session_id == nullptr) ? 0UL : *session_id; | 895 | + model->session_id = (config->session_id == nullptr) ? 0UL : *config->session_id; |
| 849 | *model_handle = model; | 896 | *model_handle = model; |
| 850 | - *rt_model_handle = reinterpret_cast<void *>(0x12345678U); | ||
| 851 | return 0; | 897 | return 0; |
| 852 | } | 898 | } |
| 853 | - | ||
| 854 | -extern "C" int Om2ModelLoad(void **model_handle) { | ||
| 855 | - return ((model_handle == nullptr) || (*model_handle == nullptr)) ? 1 : 0; | ||
| 856 | -} | ||
| 857 | )"; | 899 | )"; |
| 858 | } | 900 | } |
| 859 | 901 | ||
| 860 | std::string MakeFakeOm2LoadAndRunExecuteCpp() { | 902 | std::string MakeFakeOm2LoadAndRunExecuteCpp() { |
| 861 | return R"( | 903 | return R"( |
| 862 | -extern "C" int Om2ModelRunAsync(void **model_handle, void *, int input_count, void **input_data, int output_count, | 904 | +extern "C" int GertModelRunAsync(GertModelHandle model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 863 | - void **output_data) { | 905 | + if ((model_handle == nullptr) || (config == nullptr) || (config->input_data == nullptr) || (config->output_data == nullptr)) { |
| 864 | - if ((model_handle == nullptr) || (*model_handle == nullptr) || (input_data == nullptr) || (output_data == nullptr)) { | ||
| 865 | return 1; | 906 | return 1; |
| 866 | } | 907 | } |
| 867 | - return (input_count == 2 && output_count == 1) ? 0 : 1; | 908 | + return (config->input_count == 2 && config->output_count == 1) ? 0 : 1; |
| 868 | } | 909 | } |
| 869 | 910 | ||
| 870 | -extern "C" int Om2ModelRun(void **model_handle, int input_count, void **input_data, int output_count, | 911 | +extern "C" int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 871 | - void **output_data, int32_t stream_sync_timeout) { | 912 | + if ((model_handle == nullptr) || (config == nullptr) || (config->input_data == nullptr) || (config->output_data == nullptr)) { |
| 872 | - if ((model_handle == nullptr) || (*model_handle == nullptr) || (input_data == nullptr) || (output_data == nullptr)) { | ||
| 873 | return 1; | 913 | return 1; |
| 874 | } | 914 | } |
| 875 | - (void)stream_sync_timeout; // Mock 实现不使用该参数 | 915 | + return (config->input_count == 2 && config->output_count == 1) ? 0 : 1; |
| 876 | - return (input_count == 2 && output_count == 1) ? 0 : 1; | ||
| 877 | } | 916 | } |
| 878 | 917 | ||
| 879 | -extern "C" int Om2ModelDestroy(void **model_handle) { | 918 | +extern "C" int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output) { |
| 880 | - if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 919 | + if ((model_handle == nullptr)) { |
| 881 | return 0; | 920 | return 0; |
| 882 | } | 921 | } |
| 883 | - delete static_cast<FakeModel *>(*model_handle); | 922 | + delete static_cast<FakeModel *>(model_handle); |
| 884 | - *model_handle = nullptr; | ||
| 885 | return 0; | 923 | return 0; |
| 886 | } | 924 | } |
| 887 | )"; | 925 | )"; |
| @@ -269,23 +269,72 @@ void EnableOm2OnlineMode() { | |||
| 269 | ASSERT_EQ(setenv("ENABLE_RUNTIME_OM2", "1", 1), 0); | 269 | ASSERT_EQ(setenv("ENABLE_RUNTIME_OM2", "1", 1), 0); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | -std::string MakeFakeOm2SoSource() { | 272 | +static const std::string fake_om2_so_src = R"( |
| 273 | - return R"( | ||
| 274 | - | ||
| 275 | 273 | ||
| 274 | + | ||
| 275 | + | ||
| 276 | +struct GertModelLoadConfig { | ||
| 277 | + uint64_t struct_size; | ||
| 278 | + const char **bin_files; | ||
| 279 | + const void **bin_data; | ||
| 280 | + uint64_t *bin_size; | ||
| 281 | + uint64_t bin_num; | ||
| 282 | + void **constants; | ||
| 283 | + void **var_addrs; | ||
| 284 | + void *work_ptr; | ||
| 285 | + uint64_t *session_id; | ||
| 286 | + uint64_t model_id; | ||
| 287 | + void *instance_handle; | ||
| 288 | + const struct GertModelCallbacks *callbacks; | ||
| 289 | + int64_t priority; | ||
| 290 | +}; | ||
| 291 | + | ||
| 292 | +struct GertModelRunConfig { | ||
| 293 | + uint64_t struct_size; | ||
| 294 | + uint64_t input_count; | ||
| 295 | + void **input_data; | ||
| 296 | + uint64_t output_count; | ||
| 297 | + void **output_data; | ||
| 298 | + uint64_t stream_sync_timeout; | ||
| 299 | +}; | ||
| 300 | + | ||
| 301 | +struct GertModelUnloadConfig { | ||
| 302 | + uint64_t struct_size; | ||
| 303 | +}; | ||
| 304 | + | ||
| 305 | +struct GertModelLoadOutput { | ||
| 306 | + uint64_t struct_size; | ||
| 307 | +}; | ||
| 308 | + | ||
| 309 | +struct GertModelRunOutput { | ||
| 310 | + uint64_t struct_size; | ||
| 311 | + void *prof_info; | ||
| 312 | +}; | ||
| 313 | + | ||
| 314 | +struct GertModelUnloadOutput { | ||
| 315 | + uint64_t struct_size; | ||
| 316 | +}; | ||
| 317 | + | ||
| 276 | extern "C" { | 318 | extern "C" { |
| 277 | -int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **, const void **, | 319 | +int GertModelLoad(const struct GertModelLoadConfig *config, void **model_handle, struct GertModelLoadOutput *output) { |
| 278 | - size_t *, int, void **, void **, void *, uint64_t *, unsigned int, void *, int32_t) { | 320 | + if (model_handle) *model_handle = (void *)0x1; |
| 279 | - if (model_handle) *model_handle = (void*)0x1; | ||
| 280 | - if (rt_model_handle) *rt_model_handle = (void*)0x2; | ||
| 281 | return 0; | 321 | return 0; |
| 282 | } | 322 | } |
| 283 | -int Om2ModelLoad(void **) { return 0; } | 323 | + |
| 284 | -int Om2ModelRun(void **, int, void **, int, void **, int) { return 0; } | 324 | +int GertModelRunAsync(void *model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 285 | -int Om2ModelRunAsync(void **, void *, int, void **, int, void **) { return 0; } | 325 | + return 0; |
| 286 | -int Om2ModelDestroy(void **) { return 0; } | 326 | +} |
| 327 | + | ||
| 328 | +int GertModelRun(void *model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 329 | + return 0; | ||
| 330 | +} | ||
| 331 | + | ||
| 332 | +int GertModelUnload(void *model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output) { return 0; } | ||
| 287 | } | 333 | } |
| 288 | )"; | 334 | )"; |
| 335 | + | ||
| 336 | +std::string MakeFakeOm2SoSource() { | ||
| 337 | + return fake_om2_so_src; | ||
| 289 | } | 338 | } |
| 290 | 339 | ||
| 291 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { | 340 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { |
| @@ -598,6 +598,29 @@ struct Om2TaskInfo { | |||
| 598 | uint64_t weight_mem_size; | 598 | uint64_t weight_mem_size; |
| 599 | }; | 599 | }; |
| 600 | 600 | ||
| 601 | +struct GertModelDumpEnabledInfo { | ||
| 602 | + uint64_t struct_size = sizeof(GertModelDumpEnabledInfo); | ||
| 603 | + const char *op_name = nullptr; | ||
| 604 | + uint64_t enabled = 0; | ||
| 605 | +}; | ||
| 606 | + | ||
| 607 | +struct GertModelBaseInfo { | ||
| 608 | + uint64_t struct_size = sizeof(GertModelBaseInfo); | ||
| 609 | + const void *rt_model_handle = nullptr; | ||
| 610 | +}; | ||
| 611 | + | ||
| 612 | +using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info); | ||
| 613 | +using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | ||
| 614 | +using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | ||
| 615 | + | ||
| 616 | +struct GertModelCallbacks { | ||
| 617 | + uint64_t struct_size = sizeof(GertModelCallbacks); | ||
| 618 | + ReportTaskProcessFunc report_task_preprocess = nullptr; | ||
| 619 | + ReportTaskProcessFunc report_task_postprocess = nullptr; | ||
| 620 | + GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; | ||
| 621 | + ReportModelBaseInfoFunc report_model_base_info = nullptr; | ||
| 622 | +}; | ||
| 623 | + | ||
| 601 | 624 | ||
| 602 | 625 | ||
| 603 | struct ProfTraceUserData { | 626 | struct ProfTraceUserData { |
| @@ -623,6 +646,55 @@ struct Om2ProfUnit { | |||
| 623 | uint32_t thread_id; | 646 | uint32_t thread_id; |
| 624 | }; | 647 | }; |
| 625 | 648 | ||
| 649 | +struct Om2ProfInfos { | ||
| 650 | + uint64_t struct_size = sizeof(Om2ProfInfos); | ||
| 651 | + uint64_t count = 0; | ||
| 652 | + Om2ProfUnit *prof_unit = nullptr; | ||
| 653 | + uint64_t step_id = 0; | ||
| 654 | +}; | ||
| 655 | + | ||
| 656 | +struct GertModelLoadConfig { | ||
| 657 | + uint64_t struct_size = sizeof(GertModelLoadConfig); | ||
| 658 | + const char **bin_files = nullptr; | ||
| 659 | + const void **bin_data = nullptr; | ||
| 660 | + uint64_t *bin_size = nullptr; | ||
| 661 | + uint64_t bin_num = 0; | ||
| 662 | + void **constants = nullptr; | ||
| 663 | + void **var_addrs = nullptr; | ||
| 664 | + void *work_ptr = nullptr; | ||
| 665 | + uint64_t *session_id = nullptr; | ||
| 666 | + uint64_t model_id = 0; // used for logging | ||
| 667 | + void *instance_handle = nullptr; | ||
| 668 | + const struct GertModelCallbacks *callbacks = nullptr; | ||
| 669 | + int64_t priority = 0; | ||
| 670 | +}; | ||
| 671 | + | ||
| 672 | +struct GertModelRunConfig { | ||
| 673 | + uint64_t struct_size = sizeof(GertModelRunConfig); | ||
| 674 | + uint64_t input_count = 0; | ||
| 675 | + gert::Tensor **input_data = nullptr; | ||
| 676 | + uint64_t output_count = 0; | ||
| 677 | + gert::Tensor **output_data = nullptr; | ||
| 678 | + uint64_t stream_sync_timeout_ms = 0; | ||
| 679 | +}; | ||
| 680 | + | ||
| 681 | +struct GertModelUnloadConfig { | ||
| 682 | + uint64_t struct_size = sizeof(GertModelUnloadConfig); | ||
| 683 | +}; | ||
| 684 | + | ||
| 685 | +struct GertModelLoadOutput { | ||
| 686 | + uint64_t struct_size = sizeof(GertModelLoadOutput); | ||
| 687 | +}; | ||
| 688 | + | ||
| 689 | +struct GertModelRunOutput { | ||
| 690 | + uint64_t struct_size = sizeof(GertModelRunOutput); | ||
| 691 | + Om2ProfInfos *prof_info = nullptr; | ||
| 692 | +}; | ||
| 693 | + | ||
| 694 | +struct GertModelUnloadOutput { | ||
| 695 | + uint64_t struct_size = sizeof(GertModelUnloadOutput); | ||
| 696 | +}; | ||
| 697 | + | ||
| 626 | extern "C" { | 698 | extern "C" { |
| 627 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, | 699 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, |
| 628 | void* instance_handle, | 700 | void* instance_handle, |
| @@ -642,13 +714,6 @@ __attribute__((weak)) int32_t IsDataDumpEnabled(uint32_t model_id, | |||
| 642 | uint8_t* is_data_dump); | 714 | uint8_t* is_data_dump); |
| 643 | } | 715 | } |
| 644 | 716 | ||
| 645 | -struct Om2ProfInfos { | ||
| 646 | - uint32_t version; | ||
| 647 | - uint32_t count; | ||
| 648 | - Om2ProfUnit *profUnit; | ||
| 649 | - uint64_t step_id; | ||
| 650 | -}; | ||
| 651 | - | ||
| 652 | struct rtLabelDevInfo { | 717 | struct rtLabelDevInfo { |
| 653 | uint16_t modelId; | 718 | uint16_t modelId; |
| 654 | uint16_t streamId; | 719 | uint16_t streamId; |
| @@ -669,8 +734,6 @@ rtError_t rtCmoAddrTaskLaunch(void *cmoAddrInfo, uint64_t destMax, rtCmoOpCode_t | |||
| 669 | namespace om2 { | 734 | namespace om2 { |
| 670 | constexpr int32_t INPUT_NUM = 1; | 735 | constexpr int32_t INPUT_NUM = 1; |
| 671 | constexpr int32_t OUTPUT_NUM = 1; | 736 | constexpr int32_t OUTPUT_NUM = 1; |
| 672 | -typedef void *Om2ModelHandle; | ||
| 673 | - | ||
| 674 | struct BinDataInfo { | 737 | struct BinDataInfo { |
| 675 | const void *data; | 738 | const void *data; |
| 676 | size_t size; | 739 | size_t size; |
| @@ -1056,10 +1119,10 @@ class Om2Model { | |||
| 1056 | ~Om2Model(); | 1119 | ~Om2Model(); |
| 1057 | aclError InitResources(); | 1120 | aclError InitResources(); |
| 1058 | aclError RegisterKernels(); | 1121 | aclError RegisterKernels(); |
| 1059 | - aclError Load(); | 1122 | + aclError Load(const GertModelCallbacks *callbacks); |
| 1060 | aclmdlRI GetRtModelHandle(); | 1123 | aclmdlRI GetRtModelHandle(); |
| 1061 | - aclError Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); | 1124 | + aclError Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); |
| 1062 | - aclError RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info); | 1125 | + aclError RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info); |
| 1063 | aclError ReleaseResources(); | 1126 | aclError ReleaseResources(); |
| 1064 | private: | 1127 | private: |
| 1065 | void **constants_; | 1128 | void **constants_; |
| @@ -1099,15 +1162,15 @@ class Om2Model { | |||
| 1099 | extern "C" { | 1162 | extern "C" { |
| 1100 | 1163 | ||
| 1101 | 1164 | ||
| 1102 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority); | 1165 | +typedef void *GertModelHandle; |
| 1103 | 1166 | ||
| 1104 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle); | 1167 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output); |
| 1105 | 1168 | ||
| 1106 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info); | 1169 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 1107 | 1170 | ||
| 1108 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); | 1171 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 1109 | 1172 | ||
| 1110 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle); | 1173 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output); |
| 1111 | 1174 | ||
| 1112 | 1175 | ||
| 1113 | } | 1176 | } |
| @@ -1973,6 +1973,29 @@ struct Om2TaskInfo { | |||
| 1973 | uint64_t weight_mem_size; | 1973 | uint64_t weight_mem_size; |
| 1974 | }; | 1974 | }; |
| 1975 | 1975 | ||
| 1976 | +struct GertModelDumpEnabledInfo { | ||
| 1977 | + uint64_t struct_size = sizeof(GertModelDumpEnabledInfo); | ||
| 1978 | + const char *op_name = nullptr; | ||
| 1979 | + uint64_t enabled = 0; | ||
| 1980 | +}; | ||
| 1981 | + | ||
| 1982 | +struct GertModelBaseInfo { | ||
| 1983 | + uint64_t struct_size = sizeof(GertModelBaseInfo); | ||
| 1984 | + const void *rt_model_handle = nullptr; | ||
| 1985 | +}; | ||
| 1986 | + | ||
| 1987 | +using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info); | ||
| 1988 | +using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | ||
| 1989 | +using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | ||
| 1990 | + | ||
| 1991 | +struct GertModelCallbacks { | ||
| 1992 | + uint64_t struct_size = sizeof(GertModelCallbacks); | ||
| 1993 | + ReportTaskProcessFunc report_task_preprocess = nullptr; | ||
| 1994 | + ReportTaskProcessFunc report_task_postprocess = nullptr; | ||
| 1995 | + GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; | ||
| 1996 | + ReportModelBaseInfoFunc report_model_base_info = nullptr; | ||
| 1997 | +}; | ||
| 1998 | + | ||
| 1976 | 1999 | ||
| 1977 | 2000 | ||
| 1978 | struct ProfTraceUserData { | 2001 | struct ProfTraceUserData { |
| @@ -1998,6 +2021,55 @@ struct Om2ProfUnit { | |||
| 1998 | uint32_t thread_id; | 2021 | uint32_t thread_id; |
| 1999 | }; | 2022 | }; |
| 2000 | 2023 | ||
| 2024 | +struct Om2ProfInfos { | ||
| 2025 | + uint64_t struct_size = sizeof(Om2ProfInfos); | ||
| 2026 | + uint64_t count = 0; | ||
| 2027 | + Om2ProfUnit *prof_unit = nullptr; | ||
| 2028 | + uint64_t step_id = 0; | ||
| 2029 | +}; | ||
| 2030 | + | ||
| 2031 | +struct GertModelLoadConfig { | ||
| 2032 | + uint64_t struct_size = sizeof(GertModelLoadConfig); | ||
| 2033 | + const char **bin_files = nullptr; | ||
| 2034 | + const void **bin_data = nullptr; | ||
| 2035 | + uint64_t *bin_size = nullptr; | ||
| 2036 | + uint64_t bin_num = 0; | ||
| 2037 | + void **constants = nullptr; | ||
| 2038 | + void **var_addrs = nullptr; | ||
| 2039 | + void *work_ptr = nullptr; | ||
| 2040 | + uint64_t *session_id = nullptr; | ||
| 2041 | + uint64_t model_id = 0; // used for logging | ||
| 2042 | + void *instance_handle = nullptr; | ||
| 2043 | + const struct GertModelCallbacks *callbacks = nullptr; | ||
| 2044 | + int64_t priority = 0; | ||
| 2045 | +}; | ||
| 2046 | + | ||
| 2047 | +struct GertModelRunConfig { | ||
| 2048 | + uint64_t struct_size = sizeof(GertModelRunConfig); | ||
| 2049 | + uint64_t input_count = 0; | ||
| 2050 | + gert::Tensor **input_data = nullptr; | ||
| 2051 | + uint64_t output_count = 0; | ||
| 2052 | + gert::Tensor **output_data = nullptr; | ||
| 2053 | + uint64_t stream_sync_timeout_ms = 0; | ||
| 2054 | +}; | ||
| 2055 | + | ||
| 2056 | +struct GertModelUnloadConfig { | ||
| 2057 | + uint64_t struct_size = sizeof(GertModelUnloadConfig); | ||
| 2058 | +}; | ||
| 2059 | + | ||
| 2060 | +struct GertModelLoadOutput { | ||
| 2061 | + uint64_t struct_size = sizeof(GertModelLoadOutput); | ||
| 2062 | +}; | ||
| 2063 | + | ||
| 2064 | +struct GertModelRunOutput { | ||
| 2065 | + uint64_t struct_size = sizeof(GertModelRunOutput); | ||
| 2066 | + Om2ProfInfos *prof_info = nullptr; | ||
| 2067 | +}; | ||
| 2068 | + | ||
| 2069 | +struct GertModelUnloadOutput { | ||
| 2070 | + uint64_t struct_size = sizeof(GertModelUnloadOutput); | ||
| 2071 | +}; | ||
| 2072 | + | ||
| 2001 | extern "C" { | 2073 | extern "C" { |
| 2002 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, | 2074 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, |
| 2003 | void* instance_handle, | 2075 | void* instance_handle, |
| @@ -2017,13 +2089,6 @@ __attribute__((weak)) int32_t IsDataDumpEnabled(uint32_t model_id, | |||
| 2017 | uint8_t* is_data_dump); | 2089 | uint8_t* is_data_dump); |
| 2018 | } | 2090 | } |
| 2019 | 2091 | ||
| 2020 | -struct Om2ProfInfos { | ||
| 2021 | - uint32_t version; | ||
| 2022 | - uint32_t count; | ||
| 2023 | - Om2ProfUnit *profUnit; | ||
| 2024 | - uint64_t step_id; | ||
| 2025 | -}; | ||
| 2026 | - | ||
| 2027 | struct rtLabelDevInfo { | 2092 | struct rtLabelDevInfo { |
| 2028 | uint16_t modelId; | 2093 | uint16_t modelId; |
| 2029 | uint16_t streamId; | 2094 | uint16_t streamId; |
| @@ -2044,8 +2109,6 @@ rtError_t rtCmoAddrTaskLaunch(void *cmoAddrInfo, uint64_t destMax, rtCmoOpCode_t | |||
| 2044 | namespace om2 { | 2109 | namespace om2 { |
| 2045 | constexpr int32_t INPUT_NUM = 2; | 2110 | constexpr int32_t INPUT_NUM = 2; |
| 2046 | constexpr int32_t OUTPUT_NUM = 1; | 2111 | constexpr int32_t OUTPUT_NUM = 1; |
| 2047 | -typedef void *Om2ModelHandle; | ||
| 2048 | - | ||
| 2049 | struct BinDataInfo { | 2112 | struct BinDataInfo { |
| 2050 | const void *data; | 2113 | const void *data; |
| 2051 | size_t size; | 2114 | size_t size; |
| @@ -2431,10 +2494,10 @@ class Om2Model { | |||
| 2431 | ~Om2Model(); | 2494 | ~Om2Model(); |
| 2432 | aclError InitResources(); | 2495 | aclError InitResources(); |
| 2433 | aclError RegisterKernels(); | 2496 | aclError RegisterKernels(); |
| 2434 | - aclError Load(); | 2497 | + aclError Load(const GertModelCallbacks *callbacks); |
| 2435 | aclmdlRI GetRtModelHandle(); | 2498 | aclmdlRI GetRtModelHandle(); |
| 2436 | - aclError Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); | 2499 | + aclError Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); |
| 2437 | - aclError RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info); | 2500 | + aclError RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info); |
| 2438 | aclError ReleaseResources(); | 2501 | aclError ReleaseResources(); |
| 2439 | private: | 2502 | private: |
| 2440 | void **constants_; | 2503 | void **constants_; |
| @@ -2471,15 +2534,15 @@ class Om2Model { | |||
| 2471 | extern "C" { | 2534 | extern "C" { |
| 2472 | 2535 | ||
| 2473 | 2536 | ||
| 2474 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority); | 2537 | +typedef void *GertModelHandle; |
| 2475 | 2538 | ||
| 2476 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle); | 2539 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output); |
| 2477 | 2540 | ||
| 2478 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info); | 2541 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 2479 | 2542 | ||
| 2480 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info); | 2543 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 2481 | 2544 | ||
| 2482 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle); | 2545 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output); |
| 2483 | 2546 | ||
| 2484 | 2547 | ||
| 2485 | } | 2548 | } |
| @@ -2886,7 +2949,7 @@ aclError AssembleLaunchConfig(LaunchKernelCfgHolder &holder, const LaunchKernelC | |||
| 2886 | } | 2949 | } |
| 2887 | 2950 | ||
| 2888 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { | 2951 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { |
| 2889 | - auto &unit = prof_info->profUnit[prof_info->count]; | 2952 | + auto &unit = prof_info->prof_unit[prof_info->count]; |
| 2890 | unit.type = type; | 2953 | unit.type = type; |
| 2891 | unit.begin_time = begin_time; | 2954 | unit.begin_time = begin_time; |
| 2892 | unit.end_time = MsprofSysCycleTime(); | 2955 | unit.end_time = MsprofSysCycleTime(); |
| @@ -3149,10 +3212,14 @@ aclmdlRI Om2Model::GetRtModelHandle() { | |||
| 3149 | return model_handle_; | 3212 | return model_handle_; |
| 3150 | } | 3213 | } |
| 3151 | 3214 | ||
| 3152 | -aclError Om2Model::Load() { | 3215 | +aclError Om2Model::Load(const GertModelCallbacks *callbacks) { |
| 3153 | OM2_LOGI("Load begin"); | 3216 | OM2_LOGI("Load begin"); |
| 3154 | dev_ext_info_mem_ptrs_.resize(0); | 3217 | dev_ext_info_mem_ptrs_.resize(0); |
| 3155 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; | 3218 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; |
| 3219 | + if (((callbacks != nullptr) && (callbacks->report_model_base_info != nullptr))) { | ||
| 3220 | + GertModelBaseInfo cfg = {sizeof(GertModelBaseInfo), ctx.model_handle}; | ||
| 3221 | + OM2_CHK_STATUS(callbacks->report_model_base_info(ctx.instance_handle, &cfg)); | ||
| 3222 | + } | ||
| 3156 | 3223 | ||
| 3157 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { | 3224 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { |
| 3158 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); | 3225 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); |
| @@ -3166,7 +3233,7 @@ aclError Om2Model::Load() { | |||
| 3166 | return ACL_SUCCESS; | 3233 | return ACL_SUCCESS; |
| 3167 | } | 3234 | } |
| 3168 | 3235 | ||
| 3169 | -aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info) { | 3236 | +aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 3170 | OM2_LOGI("RunAsync begin"); | 3237 | OM2_LOGI("RunAsync begin"); |
| 3171 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 3238 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 3172 | return ACL_ERROR_FAILURE; | 3239 | return ACL_ERROR_FAILURE; |
| @@ -3177,9 +3244,9 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 3177 | if ((prof_info != nullptr)) { | 3244 | if ((prof_info != nullptr)) { |
| 3178 | _t_input_begin = MsprofSysCycleTime(); | 3245 | _t_input_begin = MsprofSysCycleTime(); |
| 3179 | } | 3246 | } |
| 3180 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 3247 | + auto input_data_0_tensor = input_data[0]; |
| 3181 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 3248 | + auto input_data_1_tensor = input_data[1]; |
| 3182 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 3249 | + auto output_data_0_tensor = output_data[0]; |
| 3183 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 3250 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 3184 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 3251 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 3185 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 3252 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -3218,7 +3285,7 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 3218 | return ACL_SUCCESS; | 3285 | return ACL_SUCCESS; |
| 3219 | } | 3286 | } |
| 3220 | 3287 | ||
| 3221 | -aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 3288 | +aclError Om2Model::Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 3222 | OM2_LOGI("Run begin"); | 3289 | OM2_LOGI("Run begin"); |
| 3223 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 3290 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 3224 | return ACL_ERROR_FAILURE; | 3291 | return ACL_ERROR_FAILURE; |
| @@ -3234,9 +3301,9 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 3234 | if ((prof_info != nullptr)) { | 3301 | if ((prof_info != nullptr)) { |
| 3235 | _t_input_begin = MsprofSysCycleTime(); | 3302 | _t_input_begin = MsprofSysCycleTime(); |
| 3236 | } | 3303 | } |
| 3237 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 3304 | + auto input_data_0_tensor = input_data[0]; |
| 3238 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 3305 | + auto input_data_1_tensor = input_data[1]; |
| 3239 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 3306 | + auto output_data_0_tensor = output_data[0]; |
| 3240 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 3307 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 3241 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 3308 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 3242 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 3309 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -3275,7 +3342,7 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 3275 | return ACL_SUCCESS; | 3342 | return ACL_SUCCESS; |
| 3276 | } | 3343 | } |
| 3277 | } // namespace om2 | 3344 | } // namespace om2 |
| 3278 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { | 3345 | +aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { |
| 3279 | OM2_LOGI("Om2ModelCreate"); | 3346 | OM2_LOGI("Om2ModelCreate"); |
| 3280 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { | 3347 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { |
| 3281 | OM2_LOGE("Om2ModelCreate: invalid handle"); | 3348 | OM2_LOGE("Om2ModelCreate: invalid handle"); |
| @@ -3298,35 +3365,102 @@ aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_ha | |||
| 3298 | delete obj; | 3365 | delete obj; |
| 3299 | return ret; | 3366 | return ret; |
| 3300 | } | 3367 | } |
| 3301 | - *model_handle = reinterpret_cast<om2::Om2ModelHandle>(obj); | 3368 | + *model_handle = reinterpret_cast<GertModelHandle>(obj); |
| 3302 | *rt_model_handle = obj->GetRtModelHandle(); | 3369 | *rt_model_handle = obj->GetRtModelHandle(); |
| 3303 | OM2_LOGI("Om2ModelCreate done"); | 3370 | OM2_LOGI("Om2ModelCreate done"); |
| 3304 | return ACL_SUCCESS; | 3371 | return ACL_SUCCESS; |
| 3305 | } | 3372 | } |
| 3306 | 3373 | ||
| 3307 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle) { | 3374 | +aclError Om2ModelLoad(GertModelHandle *model_handle) { |
| 3308 | OM2_LOGI("Om2ModelLoad"); | 3375 | OM2_LOGI("Om2ModelLoad"); |
| 3309 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 3376 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { |
| 3310 | OM2_LOGE("Om2ModelLoad: invalid handle"); | 3377 | OM2_LOGE("Om2ModelLoad: invalid handle"); |
| 3311 | return ACL_ERROR_FAILURE; | 3378 | return ACL_ERROR_FAILURE; |
| 3312 | } | 3379 | } |
| 3313 | - return static_cast<om2::Om2Model*>(*model_handle)->Load(); | 3380 | + return static_cast<om2::Om2Model*>(*model_handle)->Load(nullptr); |
| 3314 | } | 3381 | } |
| 3315 | 3382 | ||
| 3316 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info) { | 3383 | +aclError Om2ModelRunAsync(GertModelHandle *model_handle, aclrtStream stream, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 3317 | OM2_LOGI("Om2ModelRunAsync"); | 3384 | OM2_LOGI("Om2ModelRunAsync"); |
| 3318 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); | 3385 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); |
| 3319 | } | 3386 | } |
| 3320 | 3387 | ||
| 3321 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 3388 | +aclError Om2ModelRun(GertModelHandle *model_handle, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 3322 | OM2_LOGI("Om2ModelRun"); | 3389 | OM2_LOGI("Om2ModelRun"); |
| 3323 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); | 3390 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); |
| 3324 | } | 3391 | } |
| 3325 | 3392 | ||
| 3326 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle) { | 3393 | +aclError Om2ModelDestroy(GertModelHandle *model_handle) { |
| 3327 | OM2_LOGI("Om2ModelDestroy"); | 3394 | OM2_LOGI("Om2ModelDestroy"); |
| 3328 | delete static_cast<om2::Om2Model*>(*model_handle); | 3395 | delete static_cast<om2::Om2Model*>(*model_handle); |
| 3329 | return ACL_SUCCESS; | 3396 | return ACL_SUCCESS; |
| 3397 | +} | ||
| 3398 | + | ||
| 3399 | +// ==================== model load/run/unload api ==================== | ||
| 3400 | + | ||
| 3401 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, | ||
| 3402 | + struct GertModelLoadOutput *output) { | ||
| 3403 | + if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) { | ||
| 3404 | + OM2_LOGE("GertModelLoad: invalid handle or config"); | ||
| 3405 | + return ACL_ERROR_FAILURE; | ||
| 3406 | + } | ||
| 3407 | + if (output != nullptr) { | ||
| 3408 | + OM2_LOGE("GertModelLoad: output is reserved, should be null"); | ||
| 3409 | + return ACL_ERROR_FAILURE; | ||
| 3410 | + } | ||
| 3411 | + aclmdlRI rt_model_handle; | ||
| 3412 | + // Create Model | ||
| 3413 | + OM2_CHK_STATUS(Om2ModelCreate(model_handle, &rt_model_handle, config->bin_files, config->bin_data, | ||
| 3414 | + config->bin_size, config->bin_num, config->constants, config->var_addrs, | ||
| 3415 | + config->work_ptr, config->session_id, config->model_id, | ||
| 3416 | + config->instance_handle, config->priority)); | ||
| 3417 | + OM2_LOGI("GertModelLoad: handle=%p, model_id=%" PRIu64 ", priority=%" PRIi64 "," | ||
| 3418 | + " bin_num=%" PRIu64 "", *model_handle, config->model_id, | ||
| 3419 | + config->priority, config->bin_num); | ||
| 3420 | + // Load Model | ||
| 3421 | + return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks); | ||
| 3422 | +} | ||
| 3423 | + | ||
| 3424 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, | ||
| 3425 | + const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 3426 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 3427 | + OM2_LOGE("GertModelRunAsync: invalid handle or config"); | ||
| 3428 | + return ACL_ERROR_FAILURE; | ||
| 3429 | + } | ||
| 3430 | + OM2_LOGI("GertModelRunAsync: handle=%p, stream=%p, input_count=%" PRIu64 "," | ||
| 3431 | + " output_count=%" PRIu64 "", model_handle, stream, config->input_count, | ||
| 3432 | + config->output_count); | ||
| 3433 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 3434 | + return Om2ModelRunAsync(&model_handle, stream, config->input_count, config->input_data, | ||
| 3435 | + config->output_count, config->output_data, prof_info); | ||
| 3436 | +} | ||
| 3437 | + | ||
| 3438 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, | ||
| 3439 | + struct GertModelRunOutput *output) { | ||
| 3440 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 3441 | + OM2_LOGE("GertModelRun: invalid handle or config"); | ||
| 3442 | + return ACL_ERROR_FAILURE; | ||
| 3443 | + } | ||
| 3444 | + OM2_LOGI("GertModelRun: handle=%p, stream_sync_timeout_ms=%" PRIu64 "," | ||
| 3445 | + " input_count=%" PRIu64 ", output_count=%" PRIu64 "", model_handle, | ||
| 3446 | + config->stream_sync_timeout_ms, config->input_count, config->output_count); | ||
| 3447 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 3448 | + return Om2ModelRun(&model_handle, config->input_count, config->input_data, config->output_count, | ||
| 3449 | + config->output_data, config->stream_sync_timeout_ms, prof_info); | ||
| 3450 | +} | ||
| 3451 | + | ||
| 3452 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, | ||
| 3453 | + struct GertModelUnloadOutput *output) { | ||
| 3454 | + if (model_handle == nullptr) { | ||
| 3455 | + OM2_LOGE("GertModelUnload: invalid handle"); | ||
| 3456 | + return ACL_ERROR_FAILURE; | ||
| 3457 | + } | ||
| 3458 | + if ((config != nullptr) || (output != nullptr)) { | ||
| 3459 | + OM2_LOGE("GertModelUnload: config and output are reserved, should be null"); | ||
| 3460 | + return ACL_ERROR_FAILURE; | ||
| 3461 | + } | ||
| 3462 | + OM2_LOGI("GertModelRun: handle=%p", model_handle); | ||
| 3463 | + return Om2ModelDestroy(&model_handle); | ||
| 3330 | })"; | 3464 | })"; |
| 3331 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 3465 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); |
| 3332 | } | 3466 | } |
| @@ -3564,7 +3698,7 @@ aclError AssembleLaunchConfig(LaunchKernelCfgHolder &holder, const LaunchKernelC | |||
| 3564 | } | 3698 | } |
| 3565 | 3699 | ||
| 3566 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { | 3700 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { |
| 3567 | - auto &unit = prof_info->profUnit[prof_info->count]; | 3701 | + auto &unit = prof_info->prof_unit[prof_info->count]; |
| 3568 | unit.type = type; | 3702 | unit.type = type; |
| 3569 | unit.begin_time = begin_time; | 3703 | unit.begin_time = begin_time; |
| 3570 | unit.end_time = MsprofSysCycleTime(); | 3704 | unit.end_time = MsprofSysCycleTime(); |
| @@ -3827,10 +3961,14 @@ aclmdlRI Om2Model::GetRtModelHandle() { | |||
| 3827 | return model_handle_; | 3961 | return model_handle_; |
| 3828 | } | 3962 | } |
| 3829 | 3963 | ||
| 3830 | -aclError Om2Model::Load() { | 3964 | +aclError Om2Model::Load(const GertModelCallbacks *callbacks) { |
| 3831 | OM2_LOGI("Load begin"); | 3965 | OM2_LOGI("Load begin"); |
| 3832 | dev_ext_info_mem_ptrs_.resize(0); | 3966 | dev_ext_info_mem_ptrs_.resize(0); |
| 3833 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; | 3967 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; |
| 3968 | + if (((callbacks != nullptr) && (callbacks->report_model_base_info != nullptr))) { | ||
| 3969 | + GertModelBaseInfo cfg = {sizeof(GertModelBaseInfo), ctx.model_handle}; | ||
| 3970 | + OM2_CHK_STATUS(callbacks->report_model_base_info(ctx.instance_handle, &cfg)); | ||
| 3971 | + } | ||
| 3834 | 3972 | ||
| 3835 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { | 3973 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { |
| 3836 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); | 3974 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); |
| @@ -3844,7 +3982,7 @@ aclError Om2Model::Load() { | |||
| 3844 | return ACL_SUCCESS; | 3982 | return ACL_SUCCESS; |
| 3845 | } | 3983 | } |
| 3846 | 3984 | ||
| 3847 | -aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info) { | 3985 | +aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 3848 | OM2_LOGI("RunAsync begin"); | 3986 | OM2_LOGI("RunAsync begin"); |
| 3849 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 3987 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 3850 | return ACL_ERROR_FAILURE; | 3988 | return ACL_ERROR_FAILURE; |
| @@ -3855,9 +3993,9 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 3855 | if ((prof_info != nullptr)) { | 3993 | if ((prof_info != nullptr)) { |
| 3856 | _t_input_begin = MsprofSysCycleTime(); | 3994 | _t_input_begin = MsprofSysCycleTime(); |
| 3857 | } | 3995 | } |
| 3858 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 3996 | + auto input_data_0_tensor = input_data[0]; |
| 3859 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 3997 | + auto input_data_1_tensor = input_data[1]; |
| 3860 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 3998 | + auto output_data_0_tensor = output_data[0]; |
| 3861 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 3999 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 3862 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 4000 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 3863 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 4001 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -3896,7 +4034,7 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 3896 | return ACL_SUCCESS; | 4034 | return ACL_SUCCESS; |
| 3897 | } | 4035 | } |
| 3898 | 4036 | ||
| 3899 | -aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 4037 | +aclError Om2Model::Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 3900 | OM2_LOGI("Run begin"); | 4038 | OM2_LOGI("Run begin"); |
| 3901 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 4039 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 3902 | return ACL_ERROR_FAILURE; | 4040 | return ACL_ERROR_FAILURE; |
| @@ -3912,9 +4050,9 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 3912 | if ((prof_info != nullptr)) { | 4050 | if ((prof_info != nullptr)) { |
| 3913 | _t_input_begin = MsprofSysCycleTime(); | 4051 | _t_input_begin = MsprofSysCycleTime(); |
| 3914 | } | 4052 | } |
| 3915 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 4053 | + auto input_data_0_tensor = input_data[0]; |
| 3916 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 4054 | + auto input_data_1_tensor = input_data[1]; |
| 3917 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 4055 | + auto output_data_0_tensor = output_data[0]; |
| 3918 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 4056 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 3919 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 4057 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 3920 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 4058 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -3953,7 +4091,7 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 3953 | return ACL_SUCCESS; | 4091 | return ACL_SUCCESS; |
| 3954 | } | 4092 | } |
| 3955 | } // namespace om2 | 4093 | } // namespace om2 |
| 3956 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { | 4094 | +aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { |
| 3957 | OM2_LOGI("Om2ModelCreate"); | 4095 | OM2_LOGI("Om2ModelCreate"); |
| 3958 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { | 4096 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { |
| 3959 | OM2_LOGE("Om2ModelCreate: invalid handle"); | 4097 | OM2_LOGE("Om2ModelCreate: invalid handle"); |
| @@ -3976,35 +4114,102 @@ aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_ha | |||
| 3976 | delete obj; | 4114 | delete obj; |
| 3977 | return ret; | 4115 | return ret; |
| 3978 | } | 4116 | } |
| 3979 | - *model_handle = reinterpret_cast<om2::Om2ModelHandle>(obj); | 4117 | + *model_handle = reinterpret_cast<GertModelHandle>(obj); |
| 3980 | *rt_model_handle = obj->GetRtModelHandle(); | 4118 | *rt_model_handle = obj->GetRtModelHandle(); |
| 3981 | OM2_LOGI("Om2ModelCreate done"); | 4119 | OM2_LOGI("Om2ModelCreate done"); |
| 3982 | return ACL_SUCCESS; | 4120 | return ACL_SUCCESS; |
| 3983 | } | 4121 | } |
| 3984 | 4122 | ||
| 3985 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle) { | 4123 | +aclError Om2ModelLoad(GertModelHandle *model_handle) { |
| 3986 | OM2_LOGI("Om2ModelLoad"); | 4124 | OM2_LOGI("Om2ModelLoad"); |
| 3987 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 4125 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { |
| 3988 | OM2_LOGE("Om2ModelLoad: invalid handle"); | 4126 | OM2_LOGE("Om2ModelLoad: invalid handle"); |
| 3989 | return ACL_ERROR_FAILURE; | 4127 | return ACL_ERROR_FAILURE; |
| 3990 | } | 4128 | } |
| 3991 | - return static_cast<om2::Om2Model*>(*model_handle)->Load(); | 4129 | + return static_cast<om2::Om2Model*>(*model_handle)->Load(nullptr); |
| 3992 | } | 4130 | } |
| 3993 | 4131 | ||
| 3994 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info) { | 4132 | +aclError Om2ModelRunAsync(GertModelHandle *model_handle, aclrtStream stream, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 3995 | OM2_LOGI("Om2ModelRunAsync"); | 4133 | OM2_LOGI("Om2ModelRunAsync"); |
| 3996 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); | 4134 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); |
| 3997 | } | 4135 | } |
| 3998 | 4136 | ||
| 3999 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 4137 | +aclError Om2ModelRun(GertModelHandle *model_handle, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 4000 | OM2_LOGI("Om2ModelRun"); | 4138 | OM2_LOGI("Om2ModelRun"); |
| 4001 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); | 4139 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); |
| 4002 | } | 4140 | } |
| 4003 | 4141 | ||
| 4004 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle) { | 4142 | +aclError Om2ModelDestroy(GertModelHandle *model_handle) { |
| 4005 | OM2_LOGI("Om2ModelDestroy"); | 4143 | OM2_LOGI("Om2ModelDestroy"); |
| 4006 | delete static_cast<om2::Om2Model*>(*model_handle); | 4144 | delete static_cast<om2::Om2Model*>(*model_handle); |
| 4007 | return ACL_SUCCESS; | 4145 | return ACL_SUCCESS; |
| 4146 | +} | ||
| 4147 | + | ||
| 4148 | +// ==================== model load/run/unload api ==================== | ||
| 4149 | + | ||
| 4150 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, | ||
| 4151 | + struct GertModelLoadOutput *output) { | ||
| 4152 | + if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) { | ||
| 4153 | + OM2_LOGE("GertModelLoad: invalid handle or config"); | ||
| 4154 | + return ACL_ERROR_FAILURE; | ||
| 4155 | + } | ||
| 4156 | + if (output != nullptr) { | ||
| 4157 | + OM2_LOGE("GertModelLoad: output is reserved, should be null"); | ||
| 4158 | + return ACL_ERROR_FAILURE; | ||
| 4159 | + } | ||
| 4160 | + aclmdlRI rt_model_handle; | ||
| 4161 | + // Create Model | ||
| 4162 | + OM2_CHK_STATUS(Om2ModelCreate(model_handle, &rt_model_handle, config->bin_files, config->bin_data, | ||
| 4163 | + config->bin_size, config->bin_num, config->constants, config->var_addrs, | ||
| 4164 | + config->work_ptr, config->session_id, config->model_id, | ||
| 4165 | + config->instance_handle, config->priority)); | ||
| 4166 | + OM2_LOGI("GertModelLoad: handle=%p, model_id=%" PRIu64 ", priority=%" PRIi64 "," | ||
| 4167 | + " bin_num=%" PRIu64 "", *model_handle, config->model_id, | ||
| 4168 | + config->priority, config->bin_num); | ||
| 4169 | + // Load Model | ||
| 4170 | + return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks); | ||
| 4171 | +} | ||
| 4172 | + | ||
| 4173 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, | ||
| 4174 | + const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 4175 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 4176 | + OM2_LOGE("GertModelRunAsync: invalid handle or config"); | ||
| 4177 | + return ACL_ERROR_FAILURE; | ||
| 4178 | + } | ||
| 4179 | + OM2_LOGI("GertModelRunAsync: handle=%p, stream=%p, input_count=%" PRIu64 "," | ||
| 4180 | + " output_count=%" PRIu64 "", model_handle, stream, config->input_count, | ||
| 4181 | + config->output_count); | ||
| 4182 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 4183 | + return Om2ModelRunAsync(&model_handle, stream, config->input_count, config->input_data, | ||
| 4184 | + config->output_count, config->output_data, prof_info); | ||
| 4185 | +} | ||
| 4186 | + | ||
| 4187 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, | ||
| 4188 | + struct GertModelRunOutput *output) { | ||
| 4189 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 4190 | + OM2_LOGE("GertModelRun: invalid handle or config"); | ||
| 4191 | + return ACL_ERROR_FAILURE; | ||
| 4192 | + } | ||
| 4193 | + OM2_LOGI("GertModelRun: handle=%p, stream_sync_timeout_ms=%" PRIu64 "," | ||
| 4194 | + " input_count=%" PRIu64 ", output_count=%" PRIu64 "", model_handle, | ||
| 4195 | + config->stream_sync_timeout_ms, config->input_count, config->output_count); | ||
| 4196 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 4197 | + return Om2ModelRun(&model_handle, config->input_count, config->input_data, config->output_count, | ||
| 4198 | + config->output_data, config->stream_sync_timeout_ms, prof_info); | ||
| 4199 | +} | ||
| 4200 | + | ||
| 4201 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, | ||
| 4202 | + struct GertModelUnloadOutput *output) { | ||
| 4203 | + if (model_handle == nullptr) { | ||
| 4204 | + OM2_LOGE("GertModelUnload: invalid handle"); | ||
| 4205 | + return ACL_ERROR_FAILURE; | ||
| 4206 | + } | ||
| 4207 | + if ((config != nullptr) || (output != nullptr)) { | ||
| 4208 | + OM2_LOGE("GertModelUnload: config and output are reserved, should be null"); | ||
| 4209 | + return ACL_ERROR_FAILURE; | ||
| 4210 | + } | ||
| 4211 | + OM2_LOGI("GertModelRun: handle=%p", model_handle); | ||
| 4212 | + return Om2ModelDestroy(&model_handle); | ||
| 4008 | })"; | 4213 | })"; |
| 4009 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 4214 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); |
| 4010 | } | 4215 | } |
| @@ -4274,7 +4479,7 @@ aclError AssembleLaunchConfig(LaunchKernelCfgHolder &holder, const LaunchKernelC | |||
| 4274 | } | 4479 | } |
| 4275 | 4480 | ||
| 4276 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { | 4481 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { |
| 4277 | - auto &unit = prof_info->profUnit[prof_info->count]; | 4482 | + auto &unit = prof_info->prof_unit[prof_info->count]; |
| 4278 | unit.type = type; | 4483 | unit.type = type; |
| 4279 | unit.begin_time = begin_time; | 4484 | unit.begin_time = begin_time; |
| 4280 | unit.end_time = MsprofSysCycleTime(); | 4485 | unit.end_time = MsprofSysCycleTime(); |
| @@ -4566,10 +4771,14 @@ aclmdlRI Om2Model::GetRtModelHandle() { | |||
| 4566 | return model_handle_; | 4771 | return model_handle_; |
| 4567 | } | 4772 | } |
| 4568 | 4773 | ||
| 4569 | -aclError Om2Model::Load() { | 4774 | +aclError Om2Model::Load(const GertModelCallbacks *callbacks) { |
| 4570 | OM2_LOGI("Load begin"); | 4775 | OM2_LOGI("Load begin"); |
| 4571 | dev_ext_info_mem_ptrs_.resize(2); | 4776 | dev_ext_info_mem_ptrs_.resize(2); |
| 4572 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; | 4777 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; |
| 4778 | + if (((callbacks != nullptr) && (callbacks->report_model_base_info != nullptr))) { | ||
| 4779 | + GertModelBaseInfo cfg = {sizeof(GertModelBaseInfo), ctx.model_handle}; | ||
| 4780 | + OM2_CHK_STATUS(callbacks->report_model_base_info(ctx.instance_handle, &cfg)); | ||
| 4781 | + } | ||
| 4573 | 4782 | ||
| 4574 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { | 4783 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { |
| 4575 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); | 4784 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); |
| @@ -4585,7 +4794,7 @@ aclError Om2Model::Load() { | |||
| 4585 | return ACL_SUCCESS; | 4794 | return ACL_SUCCESS; |
| 4586 | } | 4795 | } |
| 4587 | 4796 | ||
| 4588 | -aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info) { | 4797 | +aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 4589 | OM2_LOGI("RunAsync begin"); | 4798 | OM2_LOGI("RunAsync begin"); |
| 4590 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 4799 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 4591 | return ACL_ERROR_FAILURE; | 4800 | return ACL_ERROR_FAILURE; |
| @@ -4596,9 +4805,9 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 4596 | if ((prof_info != nullptr)) { | 4805 | if ((prof_info != nullptr)) { |
| 4597 | _t_input_begin = MsprofSysCycleTime(); | 4806 | _t_input_begin = MsprofSysCycleTime(); |
| 4598 | } | 4807 | } |
| 4599 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 4808 | + auto input_data_0_tensor = input_data[0]; |
| 4600 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 4809 | + auto input_data_1_tensor = input_data[1]; |
| 4601 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 4810 | + auto output_data_0_tensor = output_data[0]; |
| 4602 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 4811 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 4603 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 4812 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 4604 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 4813 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -4637,7 +4846,7 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 4637 | return ACL_SUCCESS; | 4846 | return ACL_SUCCESS; |
| 4638 | } | 4847 | } |
| 4639 | 4848 | ||
| 4640 | -aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 4849 | +aclError Om2Model::Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 4641 | OM2_LOGI("Run begin"); | 4850 | OM2_LOGI("Run begin"); |
| 4642 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 4851 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 4643 | return ACL_ERROR_FAILURE; | 4852 | return ACL_ERROR_FAILURE; |
| @@ -4653,9 +4862,9 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 4653 | if ((prof_info != nullptr)) { | 4862 | if ((prof_info != nullptr)) { |
| 4654 | _t_input_begin = MsprofSysCycleTime(); | 4863 | _t_input_begin = MsprofSysCycleTime(); |
| 4655 | } | 4864 | } |
| 4656 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 4865 | + auto input_data_0_tensor = input_data[0]; |
| 4657 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 4866 | + auto input_data_1_tensor = input_data[1]; |
| 4658 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 4867 | + auto output_data_0_tensor = output_data[0]; |
| 4659 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 4868 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 4660 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 4869 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 4661 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 4870 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -4694,7 +4903,7 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 4694 | return ACL_SUCCESS; | 4903 | return ACL_SUCCESS; |
| 4695 | } | 4904 | } |
| 4696 | } // namespace om2 | 4905 | } // namespace om2 |
| 4697 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { | 4906 | +aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { |
| 4698 | OM2_LOGI("Om2ModelCreate"); | 4907 | OM2_LOGI("Om2ModelCreate"); |
| 4699 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { | 4908 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { |
| 4700 | OM2_LOGE("Om2ModelCreate: invalid handle"); | 4909 | OM2_LOGE("Om2ModelCreate: invalid handle"); |
| @@ -4717,35 +4926,102 @@ aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_ha | |||
| 4717 | delete obj; | 4926 | delete obj; |
| 4718 | return ret; | 4927 | return ret; |
| 4719 | } | 4928 | } |
| 4720 | - *model_handle = reinterpret_cast<om2::Om2ModelHandle>(obj); | 4929 | + *model_handle = reinterpret_cast<GertModelHandle>(obj); |
| 4721 | *rt_model_handle = obj->GetRtModelHandle(); | 4930 | *rt_model_handle = obj->GetRtModelHandle(); |
| 4722 | OM2_LOGI("Om2ModelCreate done"); | 4931 | OM2_LOGI("Om2ModelCreate done"); |
| 4723 | return ACL_SUCCESS; | 4932 | return ACL_SUCCESS; |
| 4724 | } | 4933 | } |
| 4725 | 4934 | ||
| 4726 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle) { | 4935 | +aclError Om2ModelLoad(GertModelHandle *model_handle) { |
| 4727 | OM2_LOGI("Om2ModelLoad"); | 4936 | OM2_LOGI("Om2ModelLoad"); |
| 4728 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 4937 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { |
| 4729 | OM2_LOGE("Om2ModelLoad: invalid handle"); | 4938 | OM2_LOGE("Om2ModelLoad: invalid handle"); |
| 4730 | return ACL_ERROR_FAILURE; | 4939 | return ACL_ERROR_FAILURE; |
| 4731 | } | 4940 | } |
| 4732 | - return static_cast<om2::Om2Model*>(*model_handle)->Load(); | 4941 | + return static_cast<om2::Om2Model*>(*model_handle)->Load(nullptr); |
| 4733 | } | 4942 | } |
| 4734 | 4943 | ||
| 4735 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info) { | 4944 | +aclError Om2ModelRunAsync(GertModelHandle *model_handle, aclrtStream stream, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 4736 | OM2_LOGI("Om2ModelRunAsync"); | 4945 | OM2_LOGI("Om2ModelRunAsync"); |
| 4737 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); | 4946 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); |
| 4738 | } | 4947 | } |
| 4739 | 4948 | ||
| 4740 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 4949 | +aclError Om2ModelRun(GertModelHandle *model_handle, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 4741 | OM2_LOGI("Om2ModelRun"); | 4950 | OM2_LOGI("Om2ModelRun"); |
| 4742 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); | 4951 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); |
| 4743 | } | 4952 | } |
| 4744 | 4953 | ||
| 4745 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle) { | 4954 | +aclError Om2ModelDestroy(GertModelHandle *model_handle) { |
| 4746 | OM2_LOGI("Om2ModelDestroy"); | 4955 | OM2_LOGI("Om2ModelDestroy"); |
| 4747 | delete static_cast<om2::Om2Model*>(*model_handle); | 4956 | delete static_cast<om2::Om2Model*>(*model_handle); |
| 4748 | return ACL_SUCCESS; | 4957 | return ACL_SUCCESS; |
| 4958 | +} | ||
| 4959 | + | ||
| 4960 | +// ==================== model load/run/unload api ==================== | ||
| 4961 | + | ||
| 4962 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, | ||
| 4963 | + struct GertModelLoadOutput *output) { | ||
| 4964 | + if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) { | ||
| 4965 | + OM2_LOGE("GertModelLoad: invalid handle or config"); | ||
| 4966 | + return ACL_ERROR_FAILURE; | ||
| 4967 | + } | ||
| 4968 | + if (output != nullptr) { | ||
| 4969 | + OM2_LOGE("GertModelLoad: output is reserved, should be null"); | ||
| 4970 | + return ACL_ERROR_FAILURE; | ||
| 4971 | + } | ||
| 4972 | + aclmdlRI rt_model_handle; | ||
| 4973 | + // Create Model | ||
| 4974 | + OM2_CHK_STATUS(Om2ModelCreate(model_handle, &rt_model_handle, config->bin_files, config->bin_data, | ||
| 4975 | + config->bin_size, config->bin_num, config->constants, config->var_addrs, | ||
| 4976 | + config->work_ptr, config->session_id, config->model_id, | ||
| 4977 | + config->instance_handle, config->priority)); | ||
| 4978 | + OM2_LOGI("GertModelLoad: handle=%p, model_id=%" PRIu64 ", priority=%" PRIi64 "," | ||
| 4979 | + " bin_num=%" PRIu64 "", *model_handle, config->model_id, | ||
| 4980 | + config->priority, config->bin_num); | ||
| 4981 | + // Load Model | ||
| 4982 | + return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks); | ||
| 4983 | +} | ||
| 4984 | + | ||
| 4985 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, | ||
| 4986 | + const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 4987 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 4988 | + OM2_LOGE("GertModelRunAsync: invalid handle or config"); | ||
| 4989 | + return ACL_ERROR_FAILURE; | ||
| 4990 | + } | ||
| 4991 | + OM2_LOGI("GertModelRunAsync: handle=%p, stream=%p, input_count=%" PRIu64 "," | ||
| 4992 | + " output_count=%" PRIu64 "", model_handle, stream, config->input_count, | ||
| 4993 | + config->output_count); | ||
| 4994 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 4995 | + return Om2ModelRunAsync(&model_handle, stream, config->input_count, config->input_data, | ||
| 4996 | + config->output_count, config->output_data, prof_info); | ||
| 4997 | +} | ||
| 4998 | + | ||
| 4999 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, | ||
| 5000 | + struct GertModelRunOutput *output) { | ||
| 5001 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 5002 | + OM2_LOGE("GertModelRun: invalid handle or config"); | ||
| 5003 | + return ACL_ERROR_FAILURE; | ||
| 5004 | + } | ||
| 5005 | + OM2_LOGI("GertModelRun: handle=%p, stream_sync_timeout_ms=%" PRIu64 "," | ||
| 5006 | + " input_count=%" PRIu64 ", output_count=%" PRIu64 "", model_handle, | ||
| 5007 | + config->stream_sync_timeout_ms, config->input_count, config->output_count); | ||
| 5008 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 5009 | + return Om2ModelRun(&model_handle, config->input_count, config->input_data, config->output_count, | ||
| 5010 | + config->output_data, config->stream_sync_timeout_ms, prof_info); | ||
| 5011 | +} | ||
| 5012 | + | ||
| 5013 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, | ||
| 5014 | + struct GertModelUnloadOutput *output) { | ||
| 5015 | + if (model_handle == nullptr) { | ||
| 5016 | + OM2_LOGE("GertModelUnload: invalid handle"); | ||
| 5017 | + return ACL_ERROR_FAILURE; | ||
| 5018 | + } | ||
| 5019 | + if ((config != nullptr) || (output != nullptr)) { | ||
| 5020 | + OM2_LOGE("GertModelUnload: config and output are reserved, should be null"); | ||
| 5021 | + return ACL_ERROR_FAILURE; | ||
| 5022 | + } | ||
| 5023 | + OM2_LOGI("GertModelRun: handle=%p", model_handle); | ||
| 5024 | + return Om2ModelDestroy(&model_handle); | ||
| 4749 | })"; | 5025 | })"; |
| 4750 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 5026 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); |
| 4751 | } | 5027 | } |
| @@ -4983,7 +5259,7 @@ aclError AssembleLaunchConfig(LaunchKernelCfgHolder &holder, const LaunchKernelC | |||
| 4983 | } | 5259 | } |
| 4984 | 5260 | ||
| 4985 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { | 5261 | void CommitProfUnit(Om2ProfInfos *prof_info, Om2ProfType type, uint64_t begin_time) { |
| 4986 | - auto &unit = prof_info->profUnit[prof_info->count]; | 5262 | + auto &unit = prof_info->prof_unit[prof_info->count]; |
| 4987 | unit.type = type; | 5263 | unit.type = type; |
| 4988 | unit.begin_time = begin_time; | 5264 | unit.begin_time = begin_time; |
| 4989 | unit.end_time = MsprofSysCycleTime(); | 5265 | unit.end_time = MsprofSysCycleTime(); |
| @@ -5266,10 +5542,14 @@ aclmdlRI Om2Model::GetRtModelHandle() { | |||
| 5266 | return model_handle_; | 5542 | return model_handle_; |
| 5267 | } | 5543 | } |
| 5268 | 5544 | ||
| 5269 | -aclError Om2Model::Load() { | 5545 | +aclError Om2Model::Load(const GertModelCallbacks *callbacks) { |
| 5270 | OM2_LOGI("Load begin"); | 5546 | OM2_LOGI("Load begin"); |
| 5271 | dev_ext_info_mem_ptrs_.resize(0); | 5547 | dev_ext_info_mem_ptrs_.resize(0); |
| 5272 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; | 5548 | DispatchOpContext ctx = {total_dev_mem_ptr_, session_scope_mem_ptr_, constants_, var_addrs_, args_table_, func_handles_.data(), model_id_, instance_handle_, model_handle_, event_list_, mem_event_id_mem_map_, dev_dynamic_mem_ptrs_, overflow_addr_, label_list_, notify_list_, stream_list_, label_goto_args_, label_goto_ex_label_list_, label_switch_label_list_, session_id_, dev_ext_info_mem_ptrs_, &kernel_id_}; |
| 5549 | + if (((callbacks != nullptr) && (callbacks->report_model_base_info != nullptr))) { | ||
| 5550 | + GertModelBaseInfo cfg = {sizeof(GertModelBaseInfo), ctx.model_handle}; | ||
| 5551 | + OM2_CHK_STATUS(callbacks->report_model_base_info(ctx.instance_handle, &cfg)); | ||
| 5552 | + } | ||
| 5273 | 5553 | ||
| 5274 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { | 5554 | for (uint32_t _op_idx = 0U; (_op_idx < (sizeof(kOpDefs) / sizeof(kOpDefs[0]))); _op_idx++) { |
| 5275 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); | 5555 | OM2_CHK_STATUS(DispatchOp(&kOpDefs[_op_idx], ctx)); |
| @@ -5283,7 +5563,7 @@ aclError Om2Model::Load() { | |||
| 5283 | return ACL_SUCCESS; | 5563 | return ACL_SUCCESS; |
| 5284 | } | 5564 | } |
| 5285 | 5565 | ||
| 5286 | -aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void **input_data, size_t output_count, void **output_data, Om2ProfInfos *prof_info) { | 5566 | +aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 5287 | OM2_LOGI("RunAsync begin"); | 5567 | OM2_LOGI("RunAsync begin"); |
| 5288 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 5568 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 5289 | return ACL_ERROR_FAILURE; | 5569 | return ACL_ERROR_FAILURE; |
| @@ -5294,9 +5574,9 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 5294 | if ((prof_info != nullptr)) { | 5574 | if ((prof_info != nullptr)) { |
| 5295 | _t_input_begin = MsprofSysCycleTime(); | 5575 | _t_input_begin = MsprofSysCycleTime(); |
| 5296 | } | 5576 | } |
| 5297 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 5577 | + auto input_data_0_tensor = input_data[0]; |
| 5298 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 5578 | + auto input_data_1_tensor = input_data[1]; |
| 5299 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 5579 | + auto output_data_0_tensor = output_data[0]; |
| 5300 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 5580 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 5301 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 5581 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 5302 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 5582 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -5335,7 +5615,7 @@ aclError Om2Model::RunAsync(aclrtStream &exe_stream, size_t input_count, void ** | |||
| 5335 | return ACL_SUCCESS; | 5615 | return ACL_SUCCESS; |
| 5336 | } | 5616 | } |
| 5337 | 5617 | ||
| 5338 | -aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 5618 | +aclError Om2Model::Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 5339 | OM2_LOGI("Run begin"); | 5619 | OM2_LOGI("Run begin"); |
| 5340 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { | 5620 | if (((input_count != om2::INPUT_NUM) || (output_count != om2::OUTPUT_NUM))) { |
| 5341 | return ACL_ERROR_FAILURE; | 5621 | return ACL_ERROR_FAILURE; |
| @@ -5351,9 +5631,9 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 5351 | if ((prof_info != nullptr)) { | 5631 | if ((prof_info != nullptr)) { |
| 5352 | _t_input_begin = MsprofSysCycleTime(); | 5632 | _t_input_begin = MsprofSysCycleTime(); |
| 5353 | } | 5633 | } |
| 5354 | - auto input_data_0_tensor = reinterpret_cast<gert::Tensor *>(input_data[0]); | 5634 | + auto input_data_0_tensor = input_data[0]; |
| 5355 | - auto input_data_1_tensor = reinterpret_cast<gert::Tensor *>(input_data[1]); | 5635 | + auto input_data_1_tensor = input_data[1]; |
| 5356 | - auto output_data_0_tensor = reinterpret_cast<gert::Tensor *>(output_data[0]); | 5636 | + auto output_data_0_tensor = output_data[0]; |
| 5357 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); | 5637 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 0, reinterpret_cast<uintptr_t>(input_data_0_tensor->GetAddr()))); |
| 5358 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); | 5638 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(0, 1, reinterpret_cast<uintptr_t>(input_data_1_tensor->GetAddr()))); |
| 5359 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); | 5639 | OM2_CHK_STATUS(args_table_.UpdateHostArgs(1, 0, reinterpret_cast<uintptr_t>(output_data_0_tensor->GetAddr()))); |
| @@ -5392,7 +5672,7 @@ aclError Om2Model::Run(size_t input_count, void **input_data, size_t output_coun | |||
| 5392 | return ACL_SUCCESS; | 5672 | return ACL_SUCCESS; |
| 5393 | } | 5673 | } |
| 5394 | } // namespace om2 | 5674 | } // namespace om2 |
| 5395 | -aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { | 5675 | +aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, const char **bin_files, const void **bin_data, size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) { |
| 5396 | OM2_LOGI("Om2ModelCreate"); | 5676 | OM2_LOGI("Om2ModelCreate"); |
| 5397 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { | 5677 | if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) { |
| 5398 | OM2_LOGE("Om2ModelCreate: invalid handle"); | 5678 | OM2_LOGE("Om2ModelCreate: invalid handle"); |
| @@ -5415,35 +5695,102 @@ aclError Om2ModelCreate(om2::Om2ModelHandle *model_handle, aclmdlRI *rt_model_ha | |||
| 5415 | delete obj; | 5695 | delete obj; |
| 5416 | return ret; | 5696 | return ret; |
| 5417 | } | 5697 | } |
| 5418 | - *model_handle = reinterpret_cast<om2::Om2ModelHandle>(obj); | 5698 | + *model_handle = reinterpret_cast<GertModelHandle>(obj); |
| 5419 | *rt_model_handle = obj->GetRtModelHandle(); | 5699 | *rt_model_handle = obj->GetRtModelHandle(); |
| 5420 | OM2_LOGI("Om2ModelCreate done"); | 5700 | OM2_LOGI("Om2ModelCreate done"); |
| 5421 | return ACL_SUCCESS; | 5701 | return ACL_SUCCESS; |
| 5422 | } | 5702 | } |
| 5423 | 5703 | ||
| 5424 | -aclError Om2ModelLoad(om2::Om2ModelHandle *model_handle) { | 5704 | +aclError Om2ModelLoad(GertModelHandle *model_handle) { |
| 5425 | OM2_LOGI("Om2ModelLoad"); | 5705 | OM2_LOGI("Om2ModelLoad"); |
| 5426 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 5706 | if ((model_handle == nullptr) || (*model_handle == nullptr)) { |
| 5427 | OM2_LOGE("Om2ModelLoad: invalid handle"); | 5707 | OM2_LOGE("Om2ModelLoad: invalid handle"); |
| 5428 | return ACL_ERROR_FAILURE; | 5708 | return ACL_ERROR_FAILURE; |
| 5429 | } | 5709 | } |
| 5430 | - return static_cast<om2::Om2Model*>(*model_handle)->Load(); | 5710 | + return static_cast<om2::Om2Model*>(*model_handle)->Load(nullptr); |
| 5431 | } | 5711 | } |
| 5432 | 5712 | ||
| 5433 | -aclError Om2ModelRunAsync(om2::Om2ModelHandle *model_handle, aclrtStream stream, int input_count, void **input_data, int output_count, void **output_data, Om2ProfInfos *prof_info) { | 5713 | +aclError Om2ModelRunAsync(GertModelHandle *model_handle, aclrtStream stream, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, Om2ProfInfos *prof_info) { |
| 5434 | OM2_LOGI("Om2ModelRunAsync"); | 5714 | OM2_LOGI("Om2ModelRunAsync"); |
| 5435 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); | 5715 | return static_cast<om2::Om2Model*>(*model_handle)->RunAsync(stream, input_count, input_data, output_count, output_data, prof_info); |
| 5436 | } | 5716 | } |
| 5437 | 5717 | ||
| 5438 | -aclError Om2ModelRun(om2::Om2ModelHandle *model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { | 5718 | +aclError Om2ModelRun(GertModelHandle *model_handle, int input_count, gert::Tensor **input_data, int output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, Om2ProfInfos *prof_info) { |
| 5439 | OM2_LOGI("Om2ModelRun"); | 5719 | OM2_LOGI("Om2ModelRun"); |
| 5440 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); | 5720 | return static_cast<om2::Om2Model*>(*model_handle)->Run(input_count, input_data, output_count, output_data, stream_sync_timeout, prof_info); |
| 5441 | } | 5721 | } |
| 5442 | 5722 | ||
| 5443 | -aclError Om2ModelDestroy(om2::Om2ModelHandle *model_handle) { | 5723 | +aclError Om2ModelDestroy(GertModelHandle *model_handle) { |
| 5444 | OM2_LOGI("Om2ModelDestroy"); | 5724 | OM2_LOGI("Om2ModelDestroy"); |
| 5445 | delete static_cast<om2::Om2Model*>(*model_handle); | 5725 | delete static_cast<om2::Om2Model*>(*model_handle); |
| 5446 | return ACL_SUCCESS; | 5726 | return ACL_SUCCESS; |
| 5727 | +} | ||
| 5728 | + | ||
| 5729 | +// ==================== model load/run/unload api ==================== | ||
| 5730 | + | ||
| 5731 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, | ||
| 5732 | + struct GertModelLoadOutput *output) { | ||
| 5733 | + if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) { | ||
| 5734 | + OM2_LOGE("GertModelLoad: invalid handle or config"); | ||
| 5735 | + return ACL_ERROR_FAILURE; | ||
| 5736 | + } | ||
| 5737 | + if (output != nullptr) { | ||
| 5738 | + OM2_LOGE("GertModelLoad: output is reserved, should be null"); | ||
| 5739 | + return ACL_ERROR_FAILURE; | ||
| 5740 | + } | ||
| 5741 | + aclmdlRI rt_model_handle; | ||
| 5742 | + // Create Model | ||
| 5743 | + OM2_CHK_STATUS(Om2ModelCreate(model_handle, &rt_model_handle, config->bin_files, config->bin_data, | ||
| 5744 | + config->bin_size, config->bin_num, config->constants, config->var_addrs, | ||
| 5745 | + config->work_ptr, config->session_id, config->model_id, | ||
| 5746 | + config->instance_handle, config->priority)); | ||
| 5747 | + OM2_LOGI("GertModelLoad: handle=%p, model_id=%" PRIu64 ", priority=%" PRIi64 "," | ||
| 5748 | + " bin_num=%" PRIu64 "", *model_handle, config->model_id, | ||
| 5749 | + config->priority, config->bin_num); | ||
| 5750 | + // Load Model | ||
| 5751 | + return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks); | ||
| 5752 | +} | ||
| 5753 | + | ||
| 5754 | +int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream, | ||
| 5755 | + const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 5756 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 5757 | + OM2_LOGE("GertModelRunAsync: invalid handle or config"); | ||
| 5758 | + return ACL_ERROR_FAILURE; | ||
| 5759 | + } | ||
| 5760 | + OM2_LOGI("GertModelRunAsync: handle=%p, stream=%p, input_count=%" PRIu64 "," | ||
| 5761 | + " output_count=%" PRIu64 "", model_handle, stream, config->input_count, | ||
| 5762 | + config->output_count); | ||
| 5763 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 5764 | + return Om2ModelRunAsync(&model_handle, stream, config->input_count, config->input_data, | ||
| 5765 | + config->output_count, config->output_data, prof_info); | ||
| 5766 | +} | ||
| 5767 | + | ||
| 5768 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, | ||
| 5769 | + struct GertModelRunOutput *output) { | ||
| 5770 | + if ((model_handle == nullptr) || (config == nullptr)) { | ||
| 5771 | + OM2_LOGE("GertModelRun: invalid handle or config"); | ||
| 5772 | + return ACL_ERROR_FAILURE; | ||
| 5773 | + } | ||
| 5774 | + OM2_LOGI("GertModelRun: handle=%p, stream_sync_timeout_ms=%" PRIu64 "," | ||
| 5775 | + " input_count=%" PRIu64 ", output_count=%" PRIu64 "", model_handle, | ||
| 5776 | + config->stream_sync_timeout_ms, config->input_count, config->output_count); | ||
| 5777 | + Om2ProfInfos *prof_info = (output == nullptr ? nullptr : output->prof_info); | ||
| 5778 | + return Om2ModelRun(&model_handle, config->input_count, config->input_data, config->output_count, | ||
| 5779 | + config->output_data, config->stream_sync_timeout_ms, prof_info); | ||
| 5780 | +} | ||
| 5781 | + | ||
| 5782 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, | ||
| 5783 | + struct GertModelUnloadOutput *output) { | ||
| 5784 | + if (model_handle == nullptr) { | ||
| 5785 | + OM2_LOGE("GertModelUnload: invalid handle"); | ||
| 5786 | + return ACL_ERROR_FAILURE; | ||
| 5787 | + } | ||
| 5788 | + if ((config != nullptr) || (output != nullptr)) { | ||
| 5789 | + OM2_LOGE("GertModelUnload: config and output are reserved, should be null"); | ||
| 5790 | + return ACL_ERROR_FAILURE; | ||
| 5791 | + } | ||
| 5792 | + OM2_LOGI("GertModelRun: handle=%p", model_handle); | ||
| 5793 | + return Om2ModelDestroy(&model_handle); | ||
| 5447 | })"; | 5794 | })"; |
| 5448 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); | 5795 | ASSERT_EQ(outputs[GeneratedFileIndex::kLoadingAndRunningFile], expected + "\n"); |
| 5449 | } | 5796 | } |
| @@ -385,28 +385,77 @@ std::string MakeVarResourceJson(const size_t init_data_offset, const size_t init | |||
| 385 | return root.Dump(); | 385 | return root.Dump(); |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | -std::string MakeInterfaceHeader() { | 388 | +static std::string interface_header_src = R"(#pragma once |
| 389 | - return R"(#pragma once | ||
| 390 | 389 | ||
| 391 | 390 | ||
| 392 | 391 | ||
| 393 | 392 | ||
| 393 | +namespace gert { | ||
| 394 | + class Tensor; | ||
| 395 | +} | ||
| 396 | + | ||
| 394 | namespace om2 { | 397 | namespace om2 { |
| 395 | struct FakeModel { | 398 | struct FakeModel { |
| 396 | uint64_t session_id; | 399 | uint64_t session_id; |
| 397 | }; | 400 | }; |
| 398 | } | 401 | } |
| 402 | +struct GertModelLoadConfig { | ||
| 403 | + uint64_t struct_size = sizeof(GertModelLoadConfig); | ||
| 404 | + const char **bin_files = nullptr; | ||
| 405 | + const void **bin_data = nullptr; | ||
| 406 | + uint64_t *bin_size = nullptr; | ||
| 407 | + uint64_t bin_num = 0; | ||
| 408 | + void **constants = nullptr; | ||
| 409 | + void **var_addrs = nullptr; | ||
| 410 | + void *work_ptr = nullptr; | ||
| 411 | + uint64_t *session_id = nullptr; | ||
| 412 | + uint64_t model_id = 0; // used for logging | ||
| 413 | + void *instance_handle = nullptr; | ||
| 414 | + const struct GertModelCallbacks *callbacks = nullptr; | ||
| 415 | + int64_t priority = 0; | ||
| 416 | +}; | ||
| 417 | + | ||
| 418 | +struct GertModelRunConfig { | ||
| 419 | + uint64_t struct_size = sizeof(GertModelRunConfig); | ||
| 420 | + uint64_t input_count = 0; | ||
| 421 | + gert::Tensor **input_data = nullptr; | ||
| 422 | + uint64_t output_count = 0; | ||
| 423 | + gert::Tensor **output_data = nullptr; | ||
| 424 | + uint64_t stream_sync_timeout_ms = 0; | ||
| 425 | +}; | ||
| 426 | + | ||
| 427 | +struct GertModelUnloadConfig { | ||
| 428 | + uint64_t struct_size = sizeof(GertModelUnloadConfig); | ||
| 429 | +}; | ||
| 430 | + | ||
| 431 | +struct GertModelLoadOutput { | ||
| 432 | + uint64_t struct_size = sizeof(GertModelLoadOutput); | ||
| 433 | +}; | ||
| 434 | + | ||
| 435 | +struct GertModelRunOutput { | ||
| 436 | + uint64_t struct_size = sizeof(GertModelRunOutput); | ||
| 437 | + void *prof_info = nullptr; | ||
| 438 | +}; | ||
| 439 | + | ||
| 440 | +struct GertModelUnloadOutput { | ||
| 441 | + uint64_t struct_size = sizeof(GertModelUnloadOutput); | ||
| 442 | +}; | ||
| 399 | 443 | ||
| 400 | extern "C" { | 444 | extern "C" { |
| 401 | -int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **bin_files, const void **bin_data, | 445 | +typedef void *GertModelHandle; |
| 402 | - size_t *bin_size, int bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority); | 446 | + |
| 403 | -int Om2ModelLoad(void **model_handle); | 447 | +int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output); |
| 404 | -int Om2ModelRunAsync(void **model_handle, void *stream, int input_count, void **input_data, int output_count, | 448 | + |
| 405 | - void **output_data); | 449 | +int GertModelRunAsync(GertModelHandle model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 406 | -int Om2ModelRun(void **model_handle, int input_count, void **input_data, int output_count, void **output_data, int32_t stream_sync_timeout); | 450 | + |
| 407 | -int Om2ModelDestroy(void **model_handle); | 451 | +int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output); |
| 452 | + | ||
| 453 | +int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output); | ||
| 408 | } | 454 | } |
| 409 | )"; | 455 | )"; |
| 456 | + | ||
| 457 | +std::string MakeInterfaceHeader() { | ||
| 458 | + return interface_header_src; | ||
| 410 | } | 459 | } |
| 411 | 460 | ||
| 412 | std::string MakeLoadAndRunCpp() { | 461 | std::string MakeLoadAndRunCpp() { |
| @@ -544,26 +593,23 @@ bool CheckInstanceHandle(void *instance_handle) { | |||
| 544 | } | 593 | } |
| 545 | } // namespace | 594 | } // namespace |
| 546 | 595 | ||
| 547 | -extern "C" int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **, const void **, size_t *, int, | 596 | +extern "C" int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output) { |
| 548 | - void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, | 597 | + if ((model_handle == nullptr) || (config == nullptr)) { |
| 549 | - void *instance_handle, int32_t priority) { | ||
| 550 | - if ((model_handle == nullptr) || (rt_model_handle == nullptr)) { | ||
| 551 | return 1; | 598 | return 1; |
| 552 | } | 599 | } |
| 553 | - if (!CheckWorkPtr(work_ptr) || !CheckConst0(constants) || !CheckConst0Ptr(constants) || | 600 | + if (!CheckWorkPtr(config->work_ptr) || !CheckConst0(config->constants) || !CheckConst0Ptr(config->constants) || |
| 554 | - !CheckConstByIndex(constants, 1U, "OM2_EXPECT_CONST1_MODE", "OM2_EXPECT_CONST1_FIRST_BYTE") || | 601 | + !CheckConstByIndex(config->constants, 1U, "OM2_EXPECT_CONST1_MODE", "OM2_EXPECT_CONST1_FIRST_BYTE") || |
| 555 | - !CheckConstByIndex(constants, 2U, "OM2_EXPECT_CONST2_MODE", "OM2_EXPECT_CONST2_FIRST_BYTE") || | 602 | + !CheckConstByIndex(config->constants, 2U, "OM2_EXPECT_CONST2_MODE", "OM2_EXPECT_CONST2_FIRST_BYTE") || |
| 556 | - !CheckConstPtrEqual(constants) || !CheckVar0(var_addrs) || | 603 | + !CheckConstPtrEqual(config->constants) || !CheckVar0(config->var_addrs) || |
| 557 | - !CheckSessionId(session_id) || !CheckModelId(model_id) || !CheckInstanceHandle(instance_handle)) { | 604 | + !CheckSessionId(config->session_id) || !CheckModelId(config->model_id) || !CheckInstanceHandle(config->instance_handle)) { |
| 558 | return 1; | 605 | return 1; |
| 559 | } | 606 | } |
| 560 | auto *model = new (std::nothrow) om2::FakeModel(); | 607 | auto *model = new (std::nothrow) om2::FakeModel(); |
| 561 | if (model == nullptr) { | 608 | if (model == nullptr) { |
| 562 | return 1; | 609 | return 1; |
| 563 | } | 610 | } |
| 564 | - model->session_id = (session_id == nullptr) ? 0UL : *session_id; | 611 | + model->session_id = (config->session_id == nullptr) ? 0UL : *config->session_id; |
| 565 | *model_handle = model; | 612 | *model_handle = model; |
| 566 | - *rt_model_handle = reinterpret_cast<void *>(kFakeRtModelHandleValue); | ||
| 567 | const char *trace = std::getenv("OM2_CALL_TRACE"); | 613 | const char *trace = std::getenv("OM2_CALL_TRACE"); |
| 568 | if (trace != nullptr) { | 614 | if (trace != nullptr) { |
| 569 | std::ofstream ofs(trace, std::ios::app); | 615 | std::ofstream ofs(trace, std::ios::app); |
| @@ -572,38 +618,25 @@ extern "C" int Om2ModelCreate(void **model_handle, void **rt_model_handle, const | |||
| 572 | return 0; | 618 | return 0; |
| 573 | } | 619 | } |
| 574 | 620 | ||
| 575 | -extern "C" int Om2ModelLoad(void **model_handle) { | 621 | +extern "C" int GertModelRunAsync(GertModelHandle model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 576 | - const char *trace = std::getenv("OM2_CALL_TRACE"); | 622 | + if ((model_handle == nullptr) || (config == nullptr) || (config->input_data == nullptr) || (config->output_data == nullptr)) { |
| 577 | - if (trace != nullptr) { | ||
| 578 | - std::ofstream ofs(trace, std::ios::app); | ||
| 579 | - ofs << "load\n"; | ||
| 580 | - } | ||
| 581 | - return ((model_handle == nullptr) || (*model_handle == nullptr)) ? 1 : 0; | ||
| 582 | -} | ||
| 583 | - | ||
| 584 | -extern "C" int Om2ModelRunAsync(void **model_handle, void *, int input_count, void **input_data, int output_count, | ||
| 585 | - void **output_data) { | ||
| 586 | - if ((model_handle == nullptr) || (*model_handle == nullptr) || (input_data == nullptr) || (output_data == nullptr)) { | ||
| 587 | return 1; | 623 | return 1; |
| 588 | } | 624 | } |
| 589 | - return (input_count == 2 && output_count == 1) ? 0 : 1; | 625 | + return (config->input_count == 2 && config->output_count == 1) ? 0 : 1; |
| 590 | } | 626 | } |
| 591 | 627 | ||
| 592 | -extern "C" int Om2ModelRun(void **model_handle, int input_count, void **input_data, int output_count, | 628 | +extern "C" int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 593 | - void **output_data, int32_t stream_sync_timeout) { | 629 | + if ((model_handle == nullptr) || (config == nullptr) || (config->input_data == nullptr) || (config->output_data == nullptr)) { |
| 594 | - if ((model_handle == nullptr) || (*model_handle == nullptr) || (input_data == nullptr) || (output_data == nullptr)) { | ||
| 595 | return 1; | 630 | return 1; |
| 596 | } | 631 | } |
| 597 | - (void)stream_sync_timeout; // Mock 实现不使用该参数 | 632 | + return (config->input_count == 2 && config->output_count == 1) ? 0 : 1; |
| 598 | - return (input_count == 2 && output_count == 1) ? 0 : 1; | ||
| 599 | } | 633 | } |
| 600 | 634 | ||
| 601 | -extern "C" int Om2ModelDestroy(void **model_handle) { | 635 | +extern "C" int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output) { |
| 602 | - if ((model_handle == nullptr) || (*model_handle == nullptr)) { | 636 | + if (model_handle == nullptr) { |
| 603 | return 0; | 637 | return 0; |
| 604 | } | 638 | } |
| 605 | - delete static_cast<om2::FakeModel *>(*model_handle); | 639 | + delete static_cast<om2::FakeModel *>(model_handle); |
| 606 | - *model_handle = nullptr; | ||
| 607 | return 0; | 640 | return 0; |
| 608 | } | 641 | } |
| 609 | )"; | 642 | )"; |
| @@ -1527,7 +1560,7 @@ TEST_F(Om2ModelExecutorUt, load_calls_model_load_after_model_create) { | |||
| 1527 | 1560 | ||
| 1528 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); | 1561 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); |
| 1529 | 1562 | ||
| 1530 | - EXPECT_EQ(ReadTraceFile(trace_file), std::vector<std::string>({"create", "load"})); | 1563 | + EXPECT_EQ(ReadTraceFile(trace_file), std::vector<std::string>({"create"})); |
| 1531 | } | 1564 | } |
| 1532 | 1565 | ||
| 1533 | TEST_F(Om2ModelExecutorUt, load_fallbacks_root_graph_name_to_model_name_when_meta_missing) { | 1566 | TEST_F(Om2ModelExecutorUt, load_fallbacks_root_graph_name_to_model_name_when_meta_missing) { |
| @@ -40,23 +40,72 @@ void WriteTextFile(const std::string &file_path, const std::string &content) { | |||
| 40 | ofs << content; | 40 | ofs << content; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | -std::string MakeFakeSoSource() { | 43 | +static const std::string fake_om2_so_src = R"( |
| 44 | - return R"( | ||
| 45 | - | ||
| 46 | 44 | ||
| 45 | + | ||
| 46 | + | ||
| 47 | +struct GertModelLoadConfig { | ||
| 48 | + uint64_t struct_size; | ||
| 49 | + const char **bin_files; | ||
| 50 | + const void **bin_data; | ||
| 51 | + uint64_t *bin_size; | ||
| 52 | + uint64_t bin_num; | ||
| 53 | + void **constants; | ||
| 54 | + void **var_addrs; | ||
| 55 | + void *work_ptr; | ||
| 56 | + uint64_t *session_id; | ||
| 57 | + uint64_t model_id; | ||
| 58 | + void *instance_handle; | ||
| 59 | + const struct GertModelCallbacks *callbacks; | ||
| 60 | + int64_t priority; | ||
| 61 | +}; | ||
| 62 | + | ||
| 63 | +struct GertModelRunConfig { | ||
| 64 | + uint64_t struct_size; | ||
| 65 | + uint64_t input_count; | ||
| 66 | + void **input_data; | ||
| 67 | + uint64_t output_count; | ||
| 68 | + void **output_data; | ||
| 69 | + uint64_t stream_sync_timeout; | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +struct GertModelUnloadConfig { | ||
| 73 | + uint64_t struct_size; | ||
| 74 | +}; | ||
| 75 | + | ||
| 76 | +struct GertModelLoadOutput { | ||
| 77 | + uint64_t struct_size; | ||
| 78 | +}; | ||
| 79 | + | ||
| 80 | +struct GertModelRunOutput { | ||
| 81 | + uint64_t struct_size; | ||
| 82 | + void *prof_info; | ||
| 83 | +}; | ||
| 84 | + | ||
| 85 | +struct GertModelUnloadOutput { | ||
| 86 | + uint64_t struct_size; | ||
| 87 | +}; | ||
| 88 | + | ||
| 47 | extern "C" { | 89 | extern "C" { |
| 48 | -int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **, const void **, | 90 | +int GertModelLoad(const struct GertModelLoadConfig *config, void **model_handle, struct GertModelLoadOutput *output) { |
| 49 | - size_t *, int, void **, void **, void *, uint64_t *, unsigned int, void *, int32_t) { | 91 | + if (model_handle) *model_handle = (void *)0x1; |
| 50 | - if (model_handle) *model_handle = (void*)0x1; | ||
| 51 | - if (rt_model_handle) *rt_model_handle = (void*)0x2; | ||
| 52 | return 0; | 92 | return 0; |
| 53 | } | 93 | } |
| 54 | -int Om2ModelLoad(void **) { return 0; } | 94 | + |
| 55 | -int Om2ModelRun(void **, int, void **, int, void **, int) { return 0; } | 95 | +int GertModelRunAsync(void *model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 56 | -int Om2ModelRunAsync(void **, void *, int, void **, int, void **) { return 0; } | 96 | + return 0; |
| 57 | -int Om2ModelDestroy(void **) { return 0; } | 97 | +} |
| 98 | + | ||
| 99 | +int GertModelRun(void *model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 100 | + return 0; | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +int GertModelUnload(void *model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output) { return 0; } | ||
| 58 | } | 104 | } |
| 59 | )"; | 105 | )"; |
| 106 | + | ||
| 107 | +std::string MakeFakeSoSource() { | ||
| 108 | + return fake_om2_so_src; | ||
| 60 | } | 109 | } |
| 61 | 110 | ||
| 62 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { | 111 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { |
| @@ -71,23 +71,72 @@ void EnableOm2OnlineMode() { | |||
| 71 | ASSERT_EQ(setenv("ENABLE_RUNTIME_OM2", "1", 1), 0); | 71 | ASSERT_EQ(setenv("ENABLE_RUNTIME_OM2", "1", 1), 0); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -std::string MakeFakeOm2SoSource() { | 74 | +static const std::string fake_om2_so_src = R"( |
| 75 | - return R"( | ||
| 76 | - | ||
| 77 | 75 | ||
| 76 | + | ||
| 77 | + | ||
| 78 | +struct GertModelLoadConfig { | ||
| 79 | + uint64_t struct_size; | ||
| 80 | + const char **bin_files; | ||
| 81 | + const void **bin_data; | ||
| 82 | + uint64_t *bin_size; | ||
| 83 | + uint64_t bin_num; | ||
| 84 | + void **constants; | ||
| 85 | + void **var_addrs; | ||
| 86 | + void *work_ptr; | ||
| 87 | + uint64_t *session_id; | ||
| 88 | + uint64_t model_id; | ||
| 89 | + void *instance_handle; | ||
| 90 | + const struct GertModelCallbacks *callbacks; | ||
| 91 | + int64_t priority; | ||
| 92 | +}; | ||
| 93 | + | ||
| 94 | +struct GertModelRunConfig { | ||
| 95 | + uint64_t struct_size; | ||
| 96 | + uint64_t input_count; | ||
| 97 | + void **input_data; | ||
| 98 | + uint64_t output_count; | ||
| 99 | + void **output_data; | ||
| 100 | + uint64_t stream_sync_timeout; | ||
| 101 | +}; | ||
| 102 | + | ||
| 103 | +struct GertModelUnloadConfig { | ||
| 104 | + uint64_t struct_size; | ||
| 105 | +}; | ||
| 106 | + | ||
| 107 | +struct GertModelLoadOutput { | ||
| 108 | + uint64_t struct_size; | ||
| 109 | +}; | ||
| 110 | + | ||
| 111 | +struct GertModelRunOutput { | ||
| 112 | + uint64_t struct_size; | ||
| 113 | + void *prof_info; | ||
| 114 | +}; | ||
| 115 | + | ||
| 116 | +struct GertModelUnloadOutput { | ||
| 117 | + uint64_t struct_size; | ||
| 118 | +}; | ||
| 119 | + | ||
| 78 | extern "C" { | 120 | extern "C" { |
| 79 | -int Om2ModelCreate(void **model_handle, void **rt_model_handle, const char **, const void **, | 121 | +int GertModelLoad(const struct GertModelLoadConfig *config, void **model_handle, struct GertModelLoadOutput *output) { |
| 80 | - size_t *, int, void **, void **, void *, uint64_t *, unsigned int, void *, int32_t) { | 122 | + if (model_handle) *model_handle = (void *)0x1; |
| 81 | - if (model_handle) *model_handle = (void*)0x1; | ||
| 82 | - if (rt_model_handle) *rt_model_handle = (void*)0x2; | ||
| 83 | return 0; | 123 | return 0; |
| 84 | } | 124 | } |
| 85 | -int Om2ModelLoad(void **) { return 0; } | 125 | + |
| 86 | -int Om2ModelRun(void **, int, void **, int, void **, int) { return 0; } | 126 | +int GertModelRunAsync(void *model_handle, void *stream, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { |
| 87 | -int Om2ModelRunAsync(void **, void *, int, void **, int, void **) { return 0; } | 127 | + return 0; |
| 88 | -int Om2ModelDestroy(void **) { return 0; } | 128 | +} |
| 129 | + | ||
| 130 | +int GertModelRun(void *model_handle, const struct GertModelRunConfig *config, struct GertModelRunOutput *output) { | ||
| 131 | + return 0; | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +int GertModelUnload(void *model_handle, const struct GertModelUnloadConfig *config, struct GertModelUnloadOutput *output) { return 0; } | ||
| 89 | } | 135 | } |
| 90 | )"; | 136 | )"; |
| 137 | + | ||
| 138 | +std::string MakeFakeOm2SoSource() { | ||
| 139 | + return fake_om2_so_src; | ||
| 91 | } | 140 | } |
| 92 | 141 | ||
| 93 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { | 142 | std::vector<uint8_t> ReadFileBytes(const std::string &path) { |


这个om2名字需要改吗?是放下一次PR修改?