已合并
【feat】: OM2兼容性修改struct重命名和类型调整、OM2 的pbody 内部申请workspace内存、om2 executor支持资源申请 #4647
lidaoming1创建于 8月31日
【feat】: OM2兼容性修改struct重命名和类型调整、OM2 的pbody 内部申请workspace内存、om2 executor支持资源申请 #4647
已合并
共 44 个文件变更+2065-1107
| @@ -89,6 +89,9 @@ class CodeGeneratorBase { | |||
| 89 | ExprRef AclrtMalloc(Arg dev_ptr, Arg size, Arg policy) const { | 89 | ExprRef AclrtMalloc(Arg dev_ptr, Arg size, Arg policy) const { |
| 90 | return ast_.Call("aclrtMalloc", {dev_ptr, size, policy}); | 90 | return ast_.Call("aclrtMalloc", {dev_ptr, size, policy}); |
| 91 | } | 91 | } |
| 92 | + ExprRef AclrtMallocWithCfg(Arg dev_ptr, Arg size, Arg policy, Arg cfg) const { | ||
| 93 | + return ast_.Call("aclrtMallocWithCfg", {dev_ptr, size, policy, cfg}); | ||
| 94 | + } | ||
| 92 | ExprRef AclrtMemcpy(Arg dst, Arg dest_max, Arg src, Arg count, Arg kind) const { | 95 | ExprRef AclrtMemcpy(Arg dst, Arg dest_max, Arg src, Arg count, Arg kind) const { |
| 93 | return ast_.Call("aclrtMemcpy", {dst, dest_max, src, count, kind}); | 96 | return ast_.Call("aclrtMemcpy", {dst, dest_max, src, count, kind}); |
| 94 | } | 97 | } |
| @@ -908,12 +908,30 @@ Status CppEmitter::Emit(const BlockStmt &node, std::string &output) { | |||
| 908 | indent_level_++; | 908 | indent_level_++; |
| 909 | } | 909 | } |
| 910 | const auto statements = node.GetStatements(); | 910 | const auto statements = node.GetStatements(); |
| 911 | + bool in_case_body = false; | ||
| 911 | for (size_t i = 0; i < statements.Size(); ++i) { | 912 | for (size_t i = 0; i < statements.Size(); ++i) { |
| 913 | + if (dynamic_cast<const CaseStmt *>(statements[i]) != nullptr) { | ||
| 914 | + if (in_case_body) { | ||
| 915 | + --indent_level_; | ||
| 916 | + } | ||
| 917 | + const auto status = statements[i]->Accept(*this, output); | ||
| 918 | + if (status != SUCCESS) { | ||
| 919 | + return status; | ||
| 920 | + } | ||
| 921 | + if (indent_level_ < std::numeric_limits<uint32_t>::max()) { | ||
| 922 | + indent_level_++; | ||
| 923 | + } | ||
| 924 | + in_case_body = true; | ||
| 925 | + continue; | ||
| 926 | + } | ||
| 912 | const auto status = statements[i]->Accept(*this, output); | 927 | const auto status = statements[i]->Accept(*this, output); |
| 913 | if (status != SUCCESS) { | 928 | if (status != SUCCESS) { |
| 914 | return status; | 929 | return status; |
| 915 | } | 930 | } |
| 916 | } | 931 | } |
| 932 | + if (in_case_body) { | ||
| 933 | + --indent_level_; | ||
| 934 | + } | ||
| 917 | if (indent_level_ > 0U) { | 935 | if (indent_level_ > 0U) { |
| 918 | indent_level_--; | 936 | indent_level_--; |
| 919 | } | 937 | } |
| @@ -284,7 +284,11 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 284 | "aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, " | 284 | "aclError Om2ModelCreate(GertModelHandle *model_handle, aclmdlRI *rt_model_handle, " |
| 285 | "const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, " | 285 | "const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, " |
| 286 | "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, " | 286 | "void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, " |
| 287 | - "int32_t priority) {\n" | 287 | + "int32_t priority, uint64_t reuse_zero_copy, aclmdlRI external_rt_model, " |
| 288 | + "aclrtStream *external_streams, uint64_t external_stream_num, " | ||
| 289 | + "aclrtNotify *external_notifies, uint64_t external_notify_num, " | ||
| 290 | + "aclrtEvent *external_events, uint64_t external_event_num, " | ||
| 291 | + "aclrtLabel *external_labels, uint64_t external_label_num) {\n" | ||
| 288 | " OM2_LOGI(\"Om2ModelCreate\");\n" | 292 | " OM2_LOGI(\"Om2ModelCreate\");\n" |
| 289 | " if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) {\n" | 293 | " if ((model_handle == nullptr) || (rt_model_handle == nullptr) || (*model_handle != nullptr)) {\n" |
| 290 | " OM2_LOGE(\"Om2ModelCreate: invalid handle\");\n" | 294 | " OM2_LOGE(\"Om2ModelCreate: invalid handle\");\n" |
| @@ -296,7 +300,9 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 296 | " OM2_LOGE(\"Om2ModelCreate: new Om2Model failed\");\n" | 300 | " OM2_LOGE(\"Om2ModelCreate: new Om2Model failed\");\n" |
| 297 | " return ACL_ERROR_FAILURE;\n" | 301 | " return ACL_ERROR_FAILURE;\n" |
| 298 | " }\n" | 302 | " }\n" |
| 299 | - " auto ret = obj->InitResources();\n" | 303 | + " auto ret = obj->InitResources(reuse_zero_copy, {sizeof(GertModelExternalResources), external_rt_model, " |
| 304 | + "external_streams, external_stream_num, external_notifies, external_notify_num, " | ||
| 305 | + "external_events, external_event_num, external_labels, external_label_num});\n" | ||
| 300 | " if (ret != ACL_SUCCESS) {\n" | 306 | " if (ret != ACL_SUCCESS) {\n" |
| 301 | " OM2_LOGE(\"Om2ModelCreate: InitResources failed, ret: %d\", ret);\n" | 307 | " OM2_LOGE(\"Om2ModelCreate: InitResources failed, ret: %d\", ret);\n" |
| 302 | " delete obj;\n" | 308 | " delete obj;\n" |
| @@ -348,8 +354,8 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 348 | "\n" | 354 | "\n" |
| 349 | "// ==================== model load/run/unload api ====================\n" | 355 | "// ==================== model load/run/unload api ====================\n" |
| 350 | "\n" | 356 | "\n" |
| 351 | - "int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle,\n" | 357 | + "int32_t GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle,\n" |
| 352 | - " struct GertModelLoadOutput *output) {\n" | 358 | + " struct GertModelLoadOutput *output) {\n" |
| 353 | " if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) {\n" | 359 | " if ((model_handle == nullptr) || (*model_handle != nullptr) || (config == nullptr)) {\n" |
| 354 | " OM2_LOGE(\"GertModelLoad: invalid handle or config\");\n" | 360 | " OM2_LOGE(\"GertModelLoad: invalid handle or config\");\n" |
| 355 | " return ACL_ERROR_FAILURE;\n" | 361 | " return ACL_ERROR_FAILURE;\n" |
| @@ -364,7 +370,12 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 364 | " config->bin_size, static_cast<size_t>(config->bin_num), config->constants,\n" | 370 | " config->bin_size, static_cast<size_t>(config->bin_num), config->constants,\n" |
| 365 | " config->var_addrs, config->work_ptr, config->session_id,\n" | 371 | " config->var_addrs, config->work_ptr, config->session_id,\n" |
| 366 | " static_cast<uint32_t>(config->model_id), config->instance_handle,\n" | 372 | " static_cast<uint32_t>(config->model_id), config->instance_handle,\n" |
| 367 | - " static_cast<int32_t>(config->priority)));\n" | 373 | + " static_cast<int32_t>(config->priority), config->reuse_zero_copy,\n" |
| 374 | + " config->external_rt_model,\n" | ||
| 375 | + " config->external_streams, config->external_stream_num,\n" | ||
| 376 | + " config->external_notifies, config->external_notify_num,\n" | ||
| 377 | + " config->external_events, config->external_event_num,\n" | ||
| 378 | + " config->external_labels, config->external_label_num));\n" | ||
| 368 | " OM2_LOGI(\"GertModelLoad: handle=%p, model_id=%\" PRIu64 \", priority=%\" PRIi64 \",\"\n" | 379 | " OM2_LOGI(\"GertModelLoad: handle=%p, model_id=%\" PRIu64 \", priority=%\" PRIi64 \",\"\n" |
| 369 | " \" bin_num=%\" PRIu64 \"\", *model_handle, config->model_id,\n" | 380 | " \" bin_num=%\" PRIu64 \"\", *model_handle, config->model_id,\n" |
| 370 | " config->priority, config->bin_num);\n" | 381 | " config->priority, config->bin_num);\n" |
| @@ -372,8 +383,8 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 372 | " return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks);\n" | 383 | " return static_cast<om2::Om2Model *>(*model_handle)->Load(config->callbacks);\n" |
| 373 | "}\n" | 384 | "}\n" |
| 374 | "\n" | 385 | "\n" |
| 375 | - "int GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream,\n" | 386 | + "int32_t GertModelRunAsync(GertModelHandle model_handle, aclrtStream stream,\n" |
| 376 | - " const struct GertModelRunConfig *config, struct GertModelRunOutput *output) {\n" | 387 | + " const struct GertModelRunConfig *config, struct GertModelRunOutput *output) {\n" |
| 377 | " if ((model_handle == nullptr) || (config == nullptr)) {\n" | 388 | " if ((model_handle == nullptr) || (config == nullptr)) {\n" |
| 378 | " OM2_LOGE(\"GertModelRunAsync: invalid handle or config\");\n" | 389 | " OM2_LOGE(\"GertModelRunAsync: invalid handle or config\");\n" |
| 379 | " return ACL_ERROR_FAILURE;\n" | 390 | " return ACL_ERROR_FAILURE;\n" |
| @@ -387,8 +398,8 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 387 | " config->output_data, run_callbacks);\n" | 398 | " config->output_data, run_callbacks);\n" |
| 388 | "}\n" | 399 | "}\n" |
| 389 | "\n" | 400 | "\n" |
| 390 | - "int GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config,\n" | 401 | + "int32_t GertModelRun(GertModelHandle model_handle, const struct GertModelRunConfig *config,\n" |
| 391 | - " struct GertModelRunOutput *output) {\n" | 402 | + " struct GertModelRunOutput *output) {\n" |
| 392 | " if ((model_handle == nullptr) || (config == nullptr)) {\n" | 403 | " if ((model_handle == nullptr) || (config == nullptr)) {\n" |
| 393 | " OM2_LOGE(\"GertModelRun: invalid handle or config\");\n" | 404 | " OM2_LOGE(\"GertModelRun: invalid handle or config\");\n" |
| 394 | " return ACL_ERROR_FAILURE;\n" | 405 | " return ACL_ERROR_FAILURE;\n" |
| @@ -401,8 +412,8 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 401 | " config->output_data, config->stream_sync_timeout_ms, run_callbacks);\n" | 412 | " config->output_data, config->stream_sync_timeout_ms, run_callbacks);\n" |
| 402 | "}\n" | 413 | "}\n" |
| 403 | "\n" | 414 | "\n" |
| 404 | - "int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config,\n" | 415 | + "int32_t GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadConfig *config,\n" |
| 405 | - " struct GertModelUnloadOutput *output) {\n" | 416 | + " struct GertModelUnloadOutput *output) {\n" |
| 406 | " if (model_handle == nullptr) {\n" | 417 | " if (model_handle == nullptr) {\n" |
| 407 | " OM2_LOGE(\"GertModelUnload: invalid handle\");\n" | 418 | " OM2_LOGE(\"GertModelUnload: invalid handle\");\n" |
| 408 | " return ACL_ERROR_FAILURE;\n" | 419 | " return ACL_ERROR_FAILURE;\n" |
| @@ -417,79 +428,76 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 417 | return SUCCESS; | 428 | return SUCCESS; |
| 418 | case StablePartId::kInterfaceDumpApis: | 429 | case StablePartId::kInterfaceDumpApis: |
| 419 | output = | 430 | output = |
| 420 | - "struct Om2TaskIoEntry {\n" | 431 | + "struct GertModelTaskIoEntry {\n" |
| 421 | - " uint64_t struct_size = sizeof(Om2TaskIoEntry);\n" | 432 | + " uint64_t struct_size = sizeof(GertModelTaskIoEntry);\n" |
| 422 | " const gert::Tensor *tensor = nullptr;\n" | 433 | " const gert::Tensor *tensor = nullptr;\n" |
| 423 | " uint64_t offset = 0;\n" | 434 | " uint64_t offset = 0;\n" |
| 424 | "};\n" | 435 | "};\n" |
| 425 | "\n" | 436 | "\n" |
| 426 | - "enum Om2L0ArgKind {\n" | 437 | + "enum GertModelArgKind : uint64_t {\n" |
| 427 | - " OM2_L0_ARG_INPUT = 0,\n" | 438 | + " GERT_MODEL_ARG_INPUT = 0,\n" |
| 428 | - " OM2_L0_ARG_OUTPUT = 1,\n" | 439 | + " GERT_MODEL_ARG_OUTPUT = 1,\n" |
| 429 | - " OM2_L0_ARG_WORKSPACE = 2,\n" | 440 | + " GERT_MODEL_ARG_WORKSPACE = 2,\n" |
| 430 | - " OM2_L0_ARG_TILING = 3,\n" | 441 | + " GERT_MODEL_ARG_TILING = 3,\n" |
| 431 | - " OM2_L0_ARG_SHAPE_INFO = 4,\n" | 442 | + " GERT_MODEL_ARG_SHAPE_INFO = 4,\n" |
| 432 | - " OM2_L0_ARG_LEVEL1_DESC = 5,\n" | 443 | + " GERT_MODEL_ARG_LEVEL1_DESC = 5,\n" |
| 433 | - " OM2_L0_ARG_PLACEHOLDER = 6,\n" | 444 | + " GERT_MODEL_ARG_PLACEHOLDER = 6,\n" |
| 434 | - " OM2_L0_ARG_CUSTOM_VALUE = 7,\n" | 445 | + " GERT_MODEL_ARG_CUSTOM_VALUE = 7,\n" |
| 435 | - " OM2_L0_ARG_FFTS_ADDR = 8,\n" | 446 | + " GERT_MODEL_ARG_FFTS_ADDR = 8,\n" |
| 436 | - " OM2_L0_ARG_EVENT_ADDR = 9,\n" | 447 | + " GERT_MODEL_ARG_EVENT_ADDR = 9,\n" |
| 437 | - " OM2_L0_ARG_OVERFLOW_ADDR = 10,\n" | 448 | + " GERT_MODEL_ARG_OVERFLOW_ADDR = 10,\n" |
| 438 | - " OM2_L0_ARG_EMPTY_ADDR = 11\n" | 449 | + " GERT_MODEL_ARG_EMPTY_ADDR = 11,\n" |
| 450 | + " GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU\n" | ||
| 439 | "};\n" | 451 | "};\n" |
| 440 | "\n" | 452 | "\n" |
| 441 | - "struct Om2L0ArgSlotInfo {\n" | 453 | + "struct GertModelArgSlotInfo {\n" |
| 442 | - " uint32_t kind;\n" | 454 | + " uint64_t struct_size = sizeof(GertModelArgSlotInfo);\n" |
| 443 | - " uint32_t flags;\n" | 455 | + " GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND;\n" |
| 444 | - " uint64_t args_offset;\n" | 456 | + " uint64_t flags = 0;\n" |
| 445 | - " uint64_t value;\n" | 457 | + " uint64_t args_offset = 0;\n" |
| 446 | - " uint32_t related_index;\n" | 458 | + " uint64_t value = 0;\n" |
| 447 | - " uint32_t event_id;\n" | 459 | + " uint64_t related_index = 0;\n" |
| 448 | - " uint64_t level1_target_offset;\n" | 460 | + " uint64_t event_id = 0;\n" |
| 461 | + " uint64_t level1_target_offset = 0;\n" | ||
| 449 | "};\n" | 462 | "};\n" |
| 450 | "\n" | 463 | "\n" |
| 451 | - "struct Om2L0TaskRawInfo {\n" | 464 | + "struct GertModelTaskRawInfo {\n" |
| 452 | - " uint32_t version;\n" | 465 | + " uint64_t struct_size = sizeof(GertModelTaskRawInfo);\n" |
| 453 | - " uint32_t need_assert_or_printf;\n" | 466 | + " uint64_t need_assert_or_printf = 0;\n" |
| 454 | - " uint64_t arg_num;\n" | 467 | + " uint64_t arg_num = 0;\n" |
| 455 | - " const struct Om2L0ArgSlotInfo* args;\n" | 468 | + " const struct GertModelArgSlotInfo *args = nullptr;\n" |
| 456 | "};\n" | 469 | "};\n" |
| 457 | "\n" | 470 | "\n" |
| 458 | - "struct Om2TaskInfo {\n" | 471 | + "struct GertModelTaskDesc {\n" |
| 459 | - " const char* op_name;\n" | 472 | + " uint64_t struct_size = sizeof(GertModelTaskDesc);\n" |
| 460 | - " const char* op_type;\n" | ||
| 461 | - " uint32_t task_id;\n" | ||
| 462 | - " uint32_t stream_id;\n" | ||
| 463 | - " uint32_t context_id;\n" | ||
| 464 | - " uint32_t thread_id;\n" | ||
| 465 | - " uint32_t block_dim;\n" | ||
| 466 | - " uint64_t op_desc_id;\n" | ||
| 467 | - " uintptr_t args_base;\n" | ||
| 468 | - " uint64_t args_size;\n" | ||
| 469 | - " uint64_t input_num;\n" | ||
| 470 | - " const struct Om2TaskIoEntry* inputs;\n" | ||
| 471 | - " uint32_t output_num;\n" | ||
| 472 | - " const struct Om2TaskIoEntry* outputs;\n" | ||
| 473 | - " uint32_t workspace_num;\n" | ||
| 474 | - " const uint64_t* workspace_addrs;\n" | ||
| 475 | - " const uint64_t* workspace_sizes;\n" | ||
| 476 | - " uint32_t task_type;\n" | ||
| 477 | - " uint64_t kernel_type = 10000U;\n" | ||
| 478 | - " void* stream;\n" | ||
| 479 | - " uint32_t is_raw_address;\n" | ||
| 480 | - " const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n" | ||
| 481 | - " uint64_t launch_begin;\n" | ||
| 482 | - " const char *original_op_names;\n" | ||
| 483 | - " uint64_t input_mem_size;\n" | ||
| 484 | - " uint64_t output_mem_size;\n" | ||
| 485 | - " uint64_t workspace_mem_size;\n" | ||
| 486 | - " uint64_t weight_mem_size;\n" | ||
| 487 | - "};\n" | ||
| 488 | - "\n" | ||
| 489 | - "struct GertModelDumpEnabledInfo {\n" | ||
| 490 | - " uint64_t struct_size = sizeof(GertModelDumpEnabledInfo);\n" | ||
| 491 | " const char *op_name = nullptr;\n" | 473 | " const char *op_name = nullptr;\n" |
| 492 | - " uint64_t enabled = 0;\n" | 474 | + " const char *op_type = nullptr;\n" |
| 475 | + " uint64_t task_id = 0;\n" | ||
| 476 | + " uint64_t stream_id = 0;\n" | ||
| 477 | + " uint64_t context_id = 0;\n" | ||
| 478 | + " uint64_t thread_id = 0;\n" | ||
| 479 | + " uint64_t block_dim = 0;\n" | ||
| 480 | + " uint64_t op_desc_id = 0;\n" | ||
| 481 | + " uintptr_t args_base = 0;\n" | ||
| 482 | + " uint64_t args_size = 0;\n" | ||
| 483 | + " uint64_t input_num = 0;\n" | ||
| 484 | + " const struct GertModelTaskIoEntry *inputs = nullptr;\n" | ||
| 485 | + " uint64_t output_num = 0;\n" | ||
| 486 | + " const struct GertModelTaskIoEntry *outputs = nullptr;\n" | ||
| 487 | + " uint64_t workspace_num = 0;\n" | ||
| 488 | + " const uint64_t *workspace_addrs = nullptr;\n" | ||
| 489 | + " const uint64_t *workspace_sizes = nullptr;\n" | ||
| 490 | + " uint64_t task_type = 0;\n" | ||
| 491 | + " uint64_t kernel_type = 10000U;\n" | ||
| 492 | + " void *stream = nullptr;\n" | ||
| 493 | + " uint64_t is_raw_address = 0;\n" | ||
| 494 | + " const struct GertModelTaskRawInfo *task_raw_info = nullptr;\n" | ||
| 495 | + " uint64_t launch_begin = 0;\n" | ||
| 496 | + " const char *original_op_names = nullptr;\n" | ||
| 497 | + " uint64_t input_mem_size = 0;\n" | ||
| 498 | + " uint64_t output_mem_size = 0;\n" | ||
| 499 | + " uint64_t workspace_mem_size = 0;\n" | ||
| 500 | + " uint64_t weight_mem_size = 0;\n" | ||
| 493 | "};\n" | 501 | "};\n" |
| 494 | "\n" | 502 | "\n" |
| 495 | "struct GertModelBaseInfo {\n" | 503 | "struct GertModelBaseInfo {\n" |
| @@ -497,9 +505,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 497 | " const void *rt_model_handle = nullptr;\n" | 505 | " const void *rt_model_handle = nullptr;\n" |
| 498 | "};\n" | 506 | "};\n" |
| 499 | "\n" | 507 | "\n" |
| 500 | - "using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info);\n" | ||
| 501 | - "using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo " | ||
| 502 | - "*info);\n" | ||
| 503 | "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n" | 508 | "using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info);\n" |
| 504 | "\n" | 509 | "\n" |
| 505 | "enum GertModelTaskLaunchType : uint64_t {\n" | 510 | "enum GertModelTaskLaunchType : uint64_t {\n" |
| @@ -539,14 +544,14 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 539 | "struct GertModelTaskLaunchInfo {\n" | 544 | "struct GertModelTaskLaunchInfo {\n" |
| 540 | " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n" | 545 | " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n" |
| 541 | " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n" | 546 | " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n" |
| 542 | - " Om2TaskInfo *task_info = nullptr;\n" | 547 | + " GertModelTaskDesc *task_info = nullptr;\n" |
| 543 | " const GertModelTaskLaunchParams *launch_params = nullptr;\n" | 548 | " const GertModelTaskLaunchParams *launch_params = nullptr;\n" |
| 544 | "};\n" | 549 | "};\n" |
| 545 | "\n" | 550 | "\n" |
| 546 | "using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);\n" | 551 | "using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info);\n" |
| 547 | "\n" | 552 | "\n" |
| 548 | - "struct GertModelCallbacks {\n" | 553 | + "struct GertModelLoadCallbacks {\n" |
| 549 | - " uint64_t struct_size = sizeof(GertModelCallbacks);\n" | 554 | + " uint64_t struct_size = sizeof(GertModelLoadCallbacks);\n" |
| 550 | " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n" | 555 | " ReportModelBaseInfoFunc report_model_base_info = nullptr;\n" |
| 551 | " GertModelLaunchFunc launch_func = nullptr;\n" | 556 | " GertModelLaunchFunc launch_func = nullptr;\n" |
| 552 | "};\n" | 557 | "};\n" |
| @@ -579,8 +584,31 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 579 | " uint64_t *session_id = nullptr;\n" | 584 | " uint64_t *session_id = nullptr;\n" |
| 580 | " uint64_t model_id = 0; // used for logging\n" | 585 | " uint64_t model_id = 0; // used for logging\n" |
| 581 | " void *instance_handle = nullptr;\n" | 586 | " void *instance_handle = nullptr;\n" |
| 582 | - " const struct GertModelCallbacks *callbacks = nullptr;\n" | 587 | + " const struct GertModelLoadCallbacks *callbacks = nullptr;\n" |
| 583 | " int64_t priority = 0;\n" | 588 | " int64_t priority = 0;\n" |
| 589 | + " uint64_t reuse_zero_copy = 0;\n" | ||
| 590 | + " aclmdlRI external_rt_model = nullptr;\n" | ||
| 591 | + " aclrtStream *external_streams = nullptr;\n" | ||
| 592 | + " uint64_t external_stream_num = 0;\n" | ||
| 593 | + " aclrtEvent *external_events = nullptr;\n" | ||
| 594 | + " uint64_t external_event_num = 0;\n" | ||
| 595 | + " aclrtLabel *external_labels = nullptr;\n" | ||
| 596 | + " uint64_t external_label_num = 0;\n" | ||
| 597 | + " aclrtNotify *external_notifies = nullptr;\n" | ||
| 598 | + " uint64_t external_notify_num = 0;\n" | ||
| 599 | + "};\n" | ||
| 600 | + "\n" | ||
| 601 | + "struct GertModelExternalResources {\n" | ||
| 602 | + " uint64_t struct_size = sizeof(GertModelExternalResources);\n" | ||
| 603 | + " aclmdlRI external_rt_model = nullptr;\n" | ||
| 604 | + " aclrtStream *external_streams = nullptr;\n" | ||
| 605 | + " uint64_t external_stream_num = 0;\n" | ||
| 606 | + " aclrtNotify *external_notifies = nullptr;\n" | ||
| 607 | + " uint64_t external_notify_num = 0;\n" | ||
| 608 | + " aclrtEvent *external_events = nullptr;\n" | ||
| 609 | + " uint64_t external_event_num = 0;\n" | ||
| 610 | + " aclrtLabel *external_labels = nullptr;\n" | ||
| 611 | + " uint64_t external_label_num = 0;\n" | ||
| 584 | "};\n" | 612 | "};\n" |
| 585 | "\n" | 613 | "\n" |
| 586 | "struct GertModelRunConfig {\n" | 614 | "struct GertModelRunConfig {\n" |
| @@ -607,21 +635,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 607 | "\n" | 635 | "\n" |
| 608 | "struct GertModelUnloadOutput {\n" | 636 | "struct GertModelUnloadOutput {\n" |
| 609 | " uint64_t struct_size = sizeof(GertModelUnloadOutput);\n" | 637 | " uint64_t struct_size = sizeof(GertModelUnloadOutput);\n" |
| 610 | - "};\n" | 638 | + "};\n"; |
| 611 | - "\n" | ||
| 612 | - "extern \"C\" {\n" | ||
| 613 | - "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n" | ||
| 614 | - " void* instance_handle,\n" | ||
| 615 | - " const struct Om2TaskInfo* task_info,\n" | ||
| 616 | - " const void* extended_attrs,\n" | ||
| 617 | - " size_t extended_attrs_size);\n" | ||
| 618 | - "\n" | ||
| 619 | - "__attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id,\n" | ||
| 620 | - " void* instance_handle,\n" | ||
| 621 | - " const struct Om2TaskInfo* task_info,\n" | ||
| 622 | - " const void* extended_attrs,\n" | ||
| 623 | - " size_t extended_attrs_size);\n" | ||
| 624 | - "}\n"; | ||
| 625 | return SUCCESS; | 639 | return SUCCESS; |
| 626 | case StablePartId::kLoadAndRunDumpHelpers: | 640 | case StablePartId::kLoadAndRunDumpHelpers: |
| 627 | output = | 641 | output = |
| @@ -643,11 +657,11 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 643 | " return tensor;\n" | 657 | " return tensor;\n" |
| 644 | "}\n" | 658 | "}\n" |
| 645 | "\n" | 659 | "\n" |
| 646 | - "aclError AssembleOm2TaskInfo(Om2TaskInfo *task_info, const char *op_name, const char *op_type,\n" | 660 | + "aclError AssembleOm2TaskInfo(GertModelTaskDesc *task_info, const char *op_name, const char *op_type,\n" |
| 647 | " uint32_t task_id, uint32_t stream_id, uint32_t block_dim,\n" | 661 | " uint32_t task_id, uint32_t stream_id, uint32_t block_dim,\n" |
| 648 | " uint64_t op_desc_id, uintptr_t args_base, uint64_t args_size,\n" | 662 | " uint64_t op_desc_id, uintptr_t args_base, uint64_t args_size,\n" |
| 649 | - " const Om2TaskIoEntry *inputs, uint64_t input_num,\n" | 663 | + " const GertModelTaskIoEntry *inputs, uint64_t input_num,\n" |
| 650 | - " const Om2TaskIoEntry *outputs, uint32_t output_num,\n" | 664 | + " const GertModelTaskIoEntry *outputs, uint32_t output_num,\n" |
| 651 | " const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n" | 665 | " const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n" |
| 652 | " uint32_t workspace_num, uint32_t task_type, void *stream,\n" | 666 | " uint32_t workspace_num, uint32_t task_type, void *stream,\n" |
| 653 | " uint32_t is_raw_address = 0U,\n" | 667 | " uint32_t is_raw_address = 0U,\n" |
| @@ -657,6 +671,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 657 | " uint64_t output_mem_size = 0U,\n" | 671 | " uint64_t output_mem_size = 0U,\n" |
| 658 | " uint64_t workspace_mem_size = 0U,\n" | 672 | " uint64_t workspace_mem_size = 0U,\n" |
| 659 | " uint64_t weight_mem_size = 0U) {\n" | 673 | " uint64_t weight_mem_size = 0U) {\n" |
| 674 | + " task_info->struct_size = sizeof(GertModelTaskDesc);\n" | ||
| 660 | " task_info->op_name = op_name;\n" | 675 | " task_info->op_name = op_name;\n" |
| 661 | " task_info->op_type = op_type;\n" | 676 | " task_info->op_type = op_type;\n" |
| 662 | " task_info->task_id = task_id;\n" | 677 | " task_info->task_id = task_id;\n" |
| @@ -677,7 +692,7 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 677 | " task_info->task_type = task_type;\n" | 692 | " task_info->task_type = task_type;\n" |
| 678 | " task_info->stream = stream;\n" | 693 | " task_info->stream = stream;\n" |
| 679 | " task_info->is_raw_address = is_raw_address;\n" | 694 | " task_info->is_raw_address = is_raw_address;\n" |
| 680 | - " task_info->l0_exception_dump_info = nullptr;\n" | 695 | + " task_info->task_raw_info = nullptr;\n" |
| 681 | " task_info->launch_begin = launch_begin;\n" | 696 | " task_info->launch_begin = launch_begin;\n" |
| 682 | " task_info->original_op_names = original_op_names;\n" | 697 | " task_info->original_op_names = original_op_names;\n" |
| 683 | " task_info->input_mem_size = input_mem_size;\n" | 698 | " task_info->input_mem_size = input_mem_size;\n" |
| @@ -685,76 +700,6 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 685 | " task_info->workspace_mem_size = workspace_mem_size;\n" | 700 | " task_info->workspace_mem_size = workspace_mem_size;\n" |
| 686 | " task_info->weight_mem_size = weight_mem_size;\n" | 701 | " task_info->weight_mem_size = weight_mem_size;\n" |
| 687 | " return ACL_SUCCESS;\n" | 702 | " return ACL_SUCCESS;\n" |
| 688 | - "}\n" | ||
| 689 | - "\n" | ||
| 690 | - "aclError ReportOm2TaskPreprocess(const char *op_name, const char *op_type, uint64_t op_desc_id,\n" | ||
| 691 | - " uintptr_t args_base, uint64_t args_size,\n" | ||
| 692 | - " const std::vector<Om2TaskIoEntry> &inputs,\n" | ||
| 693 | - " const std::vector<Om2TaskIoEntry> &outputs,\n" | ||
| 694 | - " const std::vector<uint64_t> &workspace_addrs,\n" | ||
| 695 | - " const std::vector<uint64_t> &workspace_sizes,\n" | ||
| 696 | - " uint32_t task_type, uint32_t block_dim, void *stream,\n" | ||
| 697 | - " const Om2L0TaskRawInfo *l0_info,\n" | ||
| 698 | - " uint32_t model_id, void *instance_handle,\n" | ||
| 699 | - " uint32_t is_raw_address = 0U) {\n" | ||
| 700 | - " uint32_t stream_id = 0U;\n" | ||
| 701 | - " OM2_CHK_STATUS(aclrtStreamGetId(stream, reinterpret_cast<int32_t *>(&stream_id)));\n" | ||
| 702 | - "\n" | ||
| 703 | - " OM2_CHK_TRUE(workspace_addrs.size() == workspace_sizes.size());\n" | ||
| 704 | - "\n" | ||
| 705 | - " Om2TaskInfo task_info{};\n" | ||
| 706 | - " OM2_CHK_STATUS(AssembleOm2TaskInfo(&task_info, op_name, op_type, 0U, stream_id, block_dim,\n" | ||
| 707 | - " op_desc_id, args_base, args_size,\n" | ||
| 708 | - " inputs.data(), static_cast<uint64_t>(inputs.size()),\n" | ||
| 709 | - " outputs.data(), static_cast<uint32_t>(outputs.size()),\n" | ||
| 710 | - " workspace_addrs.empty() ? nullptr : workspace_addrs.data(),\n" | ||
| 711 | - " workspace_sizes.empty() ? nullptr : workspace_sizes.data(),\n" | ||
| 712 | - " static_cast<uint32_t>(workspace_addrs.size()),\n" | ||
| 713 | - " task_type, stream, is_raw_address));\n" | ||
| 714 | - " task_info.l0_exception_dump_info = l0_info;\n" | ||
| 715 | - " if (ReportDfxTaskPreprocess != nullptr && instance_handle != nullptr) {\n" | ||
| 716 | - " OM2_CHK_STATUS(ReportDfxTaskPreprocess(model_id, instance_handle, &task_info, nullptr, 0U));\n" | ||
| 717 | - " }\n" | ||
| 718 | - " return ACL_SUCCESS;\n" | ||
| 719 | - "}\n" | ||
| 720 | - "\n" | ||
| 721 | - "aclError ReportLaunchedOm2Task(const char *op_name, const char *op_type, uint64_t op_desc_id,\n" | ||
| 722 | - " uintptr_t args_base, uint64_t args_size,\n" | ||
| 723 | - " const Om2TaskIoEntry *inputs, uint64_t input_num,\n" | ||
| 724 | - " const Om2TaskIoEntry *outputs, uint32_t output_num,\n" | ||
| 725 | - " const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n" | ||
| 726 | - " uint32_t workspace_num,\n" | ||
| 727 | - " uint32_t task_type, uint32_t block_dim, void *stream,\n" | ||
| 728 | - " uint32_t model_id, void *instance_handle,\n" | ||
| 729 | - " uint32_t is_raw_address = 0U,\n" | ||
| 730 | - " uint64_t launch_begin = 0U,\n" | ||
| 731 | - " const char *original_op_names = nullptr,\n" | ||
| 732 | - " uint64_t input_mem_size = 0U,\n" | ||
| 733 | - " uint64_t output_mem_size = 0U,\n" | ||
| 734 | - " uint64_t workspace_mem_size = 0U,\n" | ||
| 735 | - " uint64_t weight_mem_size = 0U) {\n" | ||
| 736 | - " uint32_t task_id = 0U;\n" | ||
| 737 | - " OM2_CHK_RT(aclrtGetThreadLastTaskId(&task_id));\n" | ||
| 738 | - "\n" | ||
| 739 | - " uint32_t stream_id = 0U;\n" | ||
| 740 | - " OM2_CHK_STATUS(aclrtStreamGetId(stream, reinterpret_cast<int32_t *>(&stream_id)));\n" | ||
| 741 | - "\n" | ||
| 742 | - " Om2TaskInfo task_info{};\n" | ||
| 743 | - " OM2_CHK_STATUS(AssembleOm2TaskInfo(&task_info, op_name, op_type, task_id, stream_id, block_dim,\n" | ||
| 744 | - " op_desc_id, args_base, args_size,\n" | ||
| 745 | - " inputs, input_num,\n" | ||
| 746 | - " outputs, output_num,\n" | ||
| 747 | - " workspace_addrs, workspace_sizes, workspace_num,\n" | ||
| 748 | - " task_type, stream, is_raw_address,\n" | ||
| 749 | - " launch_begin,\n" | ||
| 750 | - " original_op_names,\n" | ||
| 751 | - " input_mem_size, output_mem_size,\n" | ||
| 752 | - " workspace_mem_size, weight_mem_size));\n" | ||
| 753 | - " task_info.l0_exception_dump_info = nullptr;\n" | ||
| 754 | - " if (ReportDfxTaskPostprocess != nullptr && instance_handle != nullptr) {\n" | ||
| 755 | - " OM2_CHK_STATUS(ReportDfxTaskPostprocess(model_id, instance_handle, &task_info, nullptr, 0U));\n" | ||
| 756 | - " }\n" | ||
| 757 | - " return ACL_SUCCESS;\n" | ||
| 758 | "}\n"; | 703 | "}\n"; |
| 759 | return SUCCESS; | 704 | return SUCCESS; |
| 760 | case StablePartId::kCreateLabelListForLabelSwitch: | 705 | case StablePartId::kCreateLabelListForLabelSwitch: |
| @@ -865,10 +810,10 @@ Status ResolveStablePart(StablePartId id, std::string &output) { | |||
| 865 | " uint16_t time_out; // 超时时间\n" | 810 | " uint16_t time_out; // 超时时间\n" |
| 866 | " uint32_t local_memory_size; // 本地内存大小\n" | 811 | " uint32_t local_memory_size; // 本地内存大小\n" |
| 867 | " } launch;\n" | 812 | " } launch;\n" |
| 868 | - " struct { // L0 信息,构建 Om2L0TaskRawInfo\n" | 813 | + " struct { // 构建 GertModelTaskRawInfo\n" |
| 869 | " uint32_t need_assert_or_printf; // 是否需要 assert/printf\n" | 814 | " uint32_t need_assert_or_printf; // 是否需要 assert/printf\n" |
| 870 | - " uint32_t slots_num; // L0 slot 数量\n" | 815 | + " uint32_t slots_num; // slot 数量\n" |
| 871 | - " const Om2L0ArgSlotInfo *slot_info; // L0 slot 信息数组\n" | 816 | + " const GertModelArgSlotInfo *slot_info; // slot 信息数组\n" |
| 872 | " } slot_args;\n" | 817 | " } slot_args;\n" |
| 873 | " struct { // 融合算子信息,非融合全为 0/nullptr\n" | 818 | " struct { // 融合算子信息,非融合全为 0/nullptr\n" |
| 874 | " const char *original_op_names; // 原始算子名称(分号分隔)\n" | 819 | " const char *original_op_names; // 原始算子名称(分号分隔)\n" |
| @@ -71,6 +71,47 @@ StructDecl *InterfaceFileCodeGenerator::BuildArgsRefreshInfoStruct() { | |||
| 71 | }); | 71 | }); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | +FunctionDef *InterfaceFileCodeGenerator::BuildAclrtMallocFunction() const { | ||
| 75 | + auto ptr = ast_.Var("void **", "ptr"); | ||
| 76 | + auto size = ast_.Var("size_t", "size"); | ||
| 77 | + auto mem_type = ast_.Var("uint32_t", "mem_type"); | ||
| 78 | + auto module_id = ast_.Var("uint16_t", "module_id"); | ||
| 79 | + auto attr = ast_.Var("aclrtMallocAttribute", "attr"); | ||
| 80 | + auto cfg = ast_.Var("aclrtMallocConfig", "cfg"); | ||
| 81 | + | ||
| 82 | + std::vector<BodyItem> body; | ||
| 83 | + body.push_back(ast_.Assign(ast_.Deref(ptr), nullptr)); | ||
| 84 | + body.push_back(ast_.If(size == ast_.UInt(0), {ast_.Return("ACL_SUCCESS")})); | ||
| 85 | + body.push_back(ast_.VarDecl(attr)); | ||
| 86 | + body.push_back(ast_.Assign(attr.Attr("attr"), "ACL_RT_MEM_ATTR_MODULE_ID")); | ||
| 87 | + body.push_back(ast_.Assign(attr.Attr("value").Attr("moduleId"), module_id)); | ||
| 88 | + body.push_back(ast_.VarDecl(cfg)); | ||
| 89 | + body.push_back(ast_.Assign(cfg.Attr("attrs"), attr.Addr())); | ||
| 90 | + body.push_back(ast_.Assign(cfg.Attr("numAttrs"), ast_.UInt(1))); | ||
| 91 | + | ||
| 92 | + std::vector<BodyItem> switch_body; | ||
| 93 | + switch_body.push_back(ast_.Case("RT_MEMORY_TS")); | ||
| 94 | + switch_body.push_back( | ||
| 95 | + ast_.Return(ast_.Call("aclrtMallocForTaskScheduler", {ptr, size, "ACL_MEM_MALLOC_HUGE_FIRST", cfg.Addr()}))); | ||
| 96 | + switch_body.push_back(ast_.Case("RT_MEMORY_HOST")); | ||
| 97 | + switch_body.push_back(ast_.Return(ast_.Call("aclrtMallocHostWithCfg", {ptr, size, cfg.Addr()}))); | ||
| 98 | + switch_body.push_back(ast_.Case("RT_MEMORY_P2P_HBM")); | ||
| 99 | + switch_body.push_back(ast_.Case("RT_MEMORY_P2P_DDR")); | ||
| 100 | + switch_body.push_back( | ||
| 101 | + ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_MALLOC_HUGE_FIRST_P2P", cfg.Addr()}))); | ||
| 102 | + switch_body.push_back(ast_.Case("RT_MEMORY_DDR")); | ||
| 103 | + switch_body.push_back(ast_.Case("RT_MEMORY_DDR_NC")); | ||
| 104 | + switch_body.push_back( | ||
| 105 | + ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_TYPE_LOW_BAND_WIDTH", cfg.Addr()}))); | ||
| 106 | + switch_body.push_back(ast_.Case("RT_MEMORY_HBM")); | ||
| 107 | + switch_body.push_back(ast_.Case(nullptr)); | ||
| 108 | + switch_body.push_back( | ||
| 109 | + ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_TYPE_HIGH_BAND_WIDTH", cfg.Addr()}))); | ||
| 110 | + | ||
| 111 | + body.push_back(ast_.Switch(mem_type, switch_body)); | ||
| 112 | + return ast_.DefineFunction("AclrtMalloc", {ptr, size, mem_type, module_id}, "inline aclError", ast_.Body(body)); | ||
| 113 | +} | ||
| 114 | + | ||
| 74 | ClassDecl *InterfaceFileCodeGenerator::BuildOm2ArgsTableClass() { | 115 | ClassDecl *InterfaceFileCodeGenerator::BuildOm2ArgsTableClass() { |
| 75 | std::vector<DeclNode *> items = { | 116 | std::vector<DeclNode *> items = { |
| 76 | ast_.Public(), | 117 | ast_.Public(), |
| @@ -110,9 +151,12 @@ ClassDecl *InterfaceFileCodeGenerator::BuildOm2ModelClass(const Om2CodegenModel | |||
| 110 | ast_.Var("uint32_t", "model_id"), ast_.Var("void *", "instance_handle"), ast_.Var("int32_t", "priority")}, | 151 | ast_.Var("uint32_t", "model_id"), ast_.Var("void *", "instance_handle"), ast_.Var("int32_t", "priority")}, |
| 111 | ""), | 152 | ""), |
| 112 | ast_.DeclareMethod("~Om2Model", {}, ""), | 153 | ast_.DeclareMethod("~Om2Model", {}, ""), |
| 113 | - ast_.DeclareMethod("InitResources", {}, "aclError"), | 154 | + ast_.DeclareMethod("InitResources", |
| 155 | + {ast_.Var("uint64_t", "reuse_zero_copy"), | ||
| 156 | + ast_.Var("const GertModelExternalResources &", "external_resources")}, | ||
| 157 | + "aclError"), | ||
| 114 | ast_.DeclareMethod("RegisterKernels", {}, "aclError"), | 158 | ast_.DeclareMethod("RegisterKernels", {}, "aclError"), |
| 115 | - ast_.DeclareMethod("Load", {ast_.Var("const GertModelCallbacks *", "callbacks")}, "aclError"), | 159 | + ast_.DeclareMethod("Load", {ast_.Var("const GertModelLoadCallbacks *", "callbacks")}, "aclError"), |
| 116 | ast_.DeclareMethod("GetRtModelHandle", {}, "aclmdlRI"), | 160 | ast_.DeclareMethod("GetRtModelHandle", {}, "aclmdlRI"), |
| 117 | ast_.DeclareMethod( | 161 | ast_.DeclareMethod( |
| 118 | "Run", | 162 | "Run", |
| @@ -131,9 +175,11 @@ ClassDecl *InterfaceFileCodeGenerator::BuildOm2ModelClass(const Om2CodegenModel | |||
| 131 | ast_.Field("void **", "constants_"), | 175 | ast_.Field("void **", "constants_"), |
| 132 | ast_.Field("void **", "var_addrs_"), | 176 | ast_.Field("void **", "var_addrs_"), |
| 133 | ast_.Field("aclmdlRI", "model_handle_"), | 177 | ast_.Field("aclmdlRI", "model_handle_"), |
| 178 | + ast_.Field("bool", "is_external_rt_model_"), | ||
| 134 | }; | 179 | }; |
| 135 | DealParamForOm2ModelClass(items, runtime); | 180 | DealParamForOm2ModelClass(items, runtime); |
| 136 | items.push_back(ast_.Field("void *", "total_dev_mem_ptr_")); | 181 | items.push_back(ast_.Field("void *", "total_dev_mem_ptr_")); |
| 182 | + items.push_back(ast_.Field("bool", "owns_total_dev_mem_", false)); | ||
| 137 | items.push_back(ast_.Field("bool", "is_stream_list_bind_")); | 183 | items.push_back(ast_.Field("bool", "is_stream_list_bind_")); |
| 138 | items.push_back(ast_.Field("std::unordered_map<std::string, BinDataInfo>", "bin_info_map_")); | 184 | items.push_back(ast_.Field("std::unordered_map<std::string, BinDataInfo>", "bin_info_map_")); |
| 139 | items.push_back(ast_.Field("Om2ArgsTable", "args_table_")); | 185 | items.push_back(ast_.Field("Om2ArgsTable", "args_table_")); |
| @@ -157,9 +203,13 @@ void InterfaceFileCodeGenerator::DealParamForOm2ModelClass(std::vector<DeclNode | |||
| 157 | } | 203 | } |
| 158 | items.push_back(ast_.Field("std::vector<aclrtFuncHandle>", "func_handles_")); | 204 | items.push_back(ast_.Field("std::vector<aclrtFuncHandle>", "func_handles_")); |
| 159 | items.push_back(ast_.Field("std::vector<aclrtStream>", "stream_list_")); | 205 | items.push_back(ast_.Field("std::vector<aclrtStream>", "stream_list_")); |
| 206 | + items.push_back(ast_.Field("bool", "is_external_streams_")); | ||
| 160 | items.push_back(ast_.Field("std::vector<aclrtNotify>", "notify_list_")); | 207 | items.push_back(ast_.Field("std::vector<aclrtNotify>", "notify_list_")); |
| 208 | + items.push_back(ast_.Field("bool", "is_external_notifies_")); | ||
| 161 | items.push_back(ast_.Field("std::vector<aclrtEvent>", "event_list_")); | 209 | items.push_back(ast_.Field("std::vector<aclrtEvent>", "event_list_")); |
| 210 | + items.push_back(ast_.Field("bool", "is_external_events_")); | ||
| 162 | items.push_back(ast_.Field("std::vector<aclrtLabel>", "label_list_")); | 211 | items.push_back(ast_.Field("std::vector<aclrtLabel>", "label_list_")); |
| 212 | + items.push_back(ast_.Field("bool", "is_external_labels_")); | ||
| 163 | if (runtime.label_num > 0U) { | 213 | if (runtime.label_num > 0U) { |
| 164 | items.push_back(ast_.Field("aclrtLabelList", "aclrt_label_list_")); | 214 | items.push_back(ast_.Field("aclrtLabelList", "aclrt_label_list_")); |
| 165 | } | 215 | } |
| @@ -208,22 +258,38 @@ std::vector<DeclNode *> InterfaceFileCodeGenerator::BuildExternalApiDecls() { | |||
| 208 | "GertModelLoad", | 258 | "GertModelLoad", |
| 209 | {ast_.Var("const struct GertModelLoadConfig *", "config"), ast_.Var("GertModelHandle *", "model_handle"), | 259 | {ast_.Var("const struct GertModelLoadConfig *", "config"), ast_.Var("GertModelHandle *", "model_handle"), |
| 210 | ast_.Var("struct GertModelLoadOutput *", "output")}, | 260 | ast_.Var("struct GertModelLoadOutput *", "output")}, |
| 211 | - "int"), | 261 | + "int32_t"), |
| 212 | ast_.DeclareFunction( | 262 | ast_.DeclareFunction( |
| 213 | "GertModelRunAsync", | 263 | "GertModelRunAsync", |
| 214 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("aclrtStream", "stream"), | 264 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("aclrtStream", "stream"), |
| 215 | ast_.Var("const struct GertModelRunConfig *", "config"), ast_.Var("struct GertModelRunOutput *", "output")}, | 265 | ast_.Var("const struct GertModelRunConfig *", "config"), ast_.Var("struct GertModelRunOutput *", "output")}, |
| 216 | - "int"), | 266 | + "int32_t"), |
| 217 | ast_.DeclareFunction( | 267 | ast_.DeclareFunction( |
| 218 | "GertModelRun", | 268 | "GertModelRun", |
| 219 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelRunConfig *", "config"), | 269 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelRunConfig *", "config"), |
| 220 | ast_.Var("struct GertModelRunOutput *", "output")}, | 270 | ast_.Var("struct GertModelRunOutput *", "output")}, |
| 221 | - "int"), | 271 | + "int32_t"), |
| 222 | ast_.DeclareFunction( | 272 | ast_.DeclareFunction( |
| 223 | "GertModelUnload", | 273 | "GertModelUnload", |
| 224 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelUnloadConfig *", "config"), | 274 | {ast_.Var("GertModelHandle", "model_handle"), ast_.Var("const struct GertModelUnloadConfig *", "config"), |
| 225 | ast_.Var("struct GertModelUnloadOutput *", "output")}, | 275 | ast_.Var("struct GertModelUnloadOutput *", "output")}, |
| 226 | - "int"), | 276 | + "int32_t"), |
| 277 | + ast_.DeclareFunction("GertModelGetStreamNum", {}, "uint64_t"), | ||
| 278 | + ast_.DeclareFunction("GertModelGetStreamDesc", | ||
| 279 | + {ast_.Var("uint32_t *", "stream_flags"), ast_.Var("uint64_t", "stream_num"), | ||
| 280 | + ast_.Var("void *", "extended_attrs")}, | ||
| 281 | + "int32_t"), | ||
| 282 | + ast_.DeclareFunction("GertModelGetEventNum", {}, "uint64_t"), | ||
| 283 | + ast_.DeclareFunction("GertModelGetEventDesc", | ||
| 284 | + {ast_.Var("uint32_t *", "event_flags"), ast_.Var("uint64_t", "event_num"), | ||
| 285 | + ast_.Var("void *", "extended_attrs")}, | ||
| 286 | + "int32_t"), | ||
| 287 | + ast_.DeclareFunction("GertModelGetLabelNum", {}, "uint64_t"), | ||
| 288 | + ast_.DeclareFunction("GertModelGetNotifyNum", {}, "uint64_t"), | ||
| 289 | + ast_.DeclareFunction("GertModelGetNotifyDesc", | ||
| 290 | + {ast_.Var("uint64_t *", "notify_flags"), ast_.Var("uint64_t", "notify_num"), | ||
| 291 | + ast_.Var("void *", "extended_attrs")}, | ||
| 292 | + "int32_t"), | ||
| 227 | }; | 293 | }; |
| 228 | } | 294 | } |
| 229 | } // namespace ge | 295 | } // namespace ge |
| @@ -25,6 +25,7 @@ class InterfaceFileCodeGenerator : public CodeGeneratorBase { | |||
| 25 | StructDecl *BuildTfAiCpuExInfoStruct(); | 25 | StructDecl *BuildTfAiCpuExInfoStruct(); |
| 26 | StructDecl *BuildArgsInfoStruct(); | 26 | StructDecl *BuildArgsInfoStruct(); |
| 27 | StructDecl *BuildArgsRefreshInfoStruct(); | 27 | StructDecl *BuildArgsRefreshInfoStruct(); |
| 28 | + FunctionDef *BuildAclrtMallocFunction() const; | ||
| 28 | ClassDecl *BuildOm2ArgsTableClass(); | 29 | ClassDecl *BuildOm2ArgsTableClass(); |
| 29 | ClassDecl *BuildOm2ModelClass(const Om2CodegenModel &codegen_model); | 30 | ClassDecl *BuildOm2ModelClass(const Om2CodegenModel &codegen_model); |
| 30 | std::vector<DeclNode *> BuildExternalApiDecls(); | 31 | std::vector<DeclNode *> BuildExternalApiDecls(); |
| @@ -83,7 +83,8 @@ 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", {ast_.Var("const GertModelCallbacks *", "callbacks")}, "aclError", body); | 86 | + return ast_.DefineMethod("Om2Model", "Load", {ast_.Var("const GertModelLoadCallbacks *", "callbacks")}, "aclError", |
| 87 | + body); | ||
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | MethodDef *LoadAndRunFileCodeGenerator::BuildGetRtModelHandleMethod() const { | 90 | MethodDef *LoadAndRunFileCodeGenerator::BuildGetRtModelHandleMethod() const { |
| @@ -162,7 +163,7 @@ Status LoadAndRunFileCodeGenerator::BuildLoadBody(std::vector<BodyItem> &body, c | |||
| 162 | // then: 方案 A(for 循环分发,优先使用),else: 方案 B(逐 task 展开,维测用) | 163 | // then: 方案 A(for 循环分发,优先使用),else: 方案 B(逐 task 展开,维测用) |
| 163 | body.push_back(ast_.If(ast_.UInt(1), dispatch_loop_items, dispatch_expanded_items, true)); | 164 | body.push_back(ast_.If(ast_.UInt(1), dispatch_loop_items, dispatch_expanded_items, true)); |
| 164 | 165 | ||
| 165 | - body.push_back(ChkStatus(AclmdlRIBuildEnd(model_handle_, nullptr))); | 166 | + body.push_back(ast_.If(!is_external_rt_model_, {ChkStatus(AclmdlRIBuildEnd(model_handle_, nullptr))}, {}, false)); |
| 166 | body.push_back(ast_.Call("OM2_LOGI", {ast_.Str("Load done")})); | 167 | body.push_back(ast_.Call("OM2_LOGI", {ast_.Str("Load done")})); |
| 167 | body.push_back(ast_.Return("ACL_SUCCESS")); | 168 | body.push_back(ast_.Return("ACL_SUCCESS")); |
| 168 | return SUCCESS; | 169 | return SUCCESS; |
| @@ -369,51 +370,7 @@ void LoadAndRunFileCodeGenerator::BuildRunBodyCopyOutputs(std::vector<BodyItem> | |||
| 369 | } | 370 | } |
| 370 | } | 371 | } |
| 371 | 372 | ||
| 372 | -Status LoadAndRunFileCodeGenerator::BuildAclrtMallocFunction(std::vector<DeclNode *> &items) const { | ||
| 373 | - auto ptr = ast_.Var("void **", "ptr"); | ||
| 374 | - auto size = ast_.Var("size_t", "size"); | ||
| 375 | - auto mem_type = ast_.Var("uint32_t", "mem_type"); | ||
| 376 | - auto module_id = ast_.Var("uint16_t", "module_id"); | ||
| 377 | - auto attr = ast_.Var("aclrtMallocAttribute", "attr"); | ||
| 378 | - auto cfg = ast_.Var("aclrtMallocConfig", "cfg"); | ||
| 379 | - | ||
| 380 | - std::vector<BodyItem> body; | ||
| 381 | - body.push_back(ast_.Assign(ast_.Deref(ptr), Arg(nullptr))); | ||
| 382 | - body.push_back(ast_.If(size == ast_.UInt(0), {ast_.Return("ACL_SUCCESS")})); | ||
| 383 | - body.push_back(ast_.VarDecl(attr)); | ||
| 384 | - body.push_back(ast_.Assign(attr.Attr("attr"), "ACL_RT_MEM_ATTR_MODULE_ID")); | ||
| 385 | - body.push_back(ast_.Assign(attr.Attr("value").Attr("moduleId"), module_id)); | ||
| 386 | - body.push_back(ast_.VarDecl(cfg)); | ||
| 387 | - body.push_back(ast_.Assign(cfg.Attr("attrs"), attr.Addr())); | ||
| 388 | - body.push_back(ast_.Assign(cfg.Attr("numAttrs"), ast_.UInt(1))); | ||
| 389 | - | ||
| 390 | - std::vector<BodyItem> switch_body; | ||
| 391 | - switch_body.push_back(ast_.Case("RT_MEMORY_TS")); | ||
| 392 | - switch_body.push_back( | ||
| 393 | - ast_.Return(ast_.Call("aclrtMallocForTaskScheduler", {ptr, size, "ACL_MEM_MALLOC_HUGE_FIRST", cfg.Addr()}))); | ||
| 394 | - switch_body.push_back(ast_.Case("RT_MEMORY_HOST")); | ||
| 395 | - switch_body.push_back(ast_.Return(ast_.Call("aclrtMallocHostWithCfg", {ptr, size, cfg.Addr()}))); | ||
| 396 | - switch_body.push_back(ast_.Case("RT_MEMORY_P2P_HBM")); | ||
| 397 | - switch_body.push_back(ast_.Case("RT_MEMORY_P2P_DDR")); | ||
| 398 | - switch_body.push_back( | ||
| 399 | - ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_MALLOC_HUGE_FIRST_P2P", cfg.Addr()}))); | ||
| 400 | - switch_body.push_back(ast_.Case("RT_MEMORY_DDR")); | ||
| 401 | - switch_body.push_back(ast_.Case("RT_MEMORY_DDR_NC")); | ||
| 402 | - switch_body.push_back( | ||
| 403 | - ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_TYPE_LOW_BAND_WIDTH", cfg.Addr()}))); | ||
| 404 | - switch_body.push_back(ast_.Case(Arg(nullptr))); | ||
| 405 | - switch_body.push_back( | ||
| 406 | - ast_.Return(ast_.Call("aclrtMallocWithCfg", {ptr, size, "ACL_MEM_TYPE_HIGH_BAND_WIDTH", cfg.Addr()}))); | ||
| 407 | - | ||
| 408 | - body.push_back(ast_.Switch(mem_type, switch_body)); | ||
| 409 | - | ||
| 410 | - items.push_back(ast_.DefineFunction("AclrtMalloc", {ptr, size, mem_type, module_id}, "aclError", ast_.Body(body))); | ||
| 411 | - return SUCCESS; | ||
| 412 | -} | ||
| 413 | - | ||
| 414 | Status LoadAndRunFileCodeGenerator::BuildCommonHelperFunctions(std::vector<DeclNode *> &items) const { | 373 | Status LoadAndRunFileCodeGenerator::BuildCommonHelperFunctions(std::vector<DeclNode *> &items) const { |
| 415 | - GE_ASSERT_SUCCESS(BuildAclrtMallocFunction(items)); | ||
| 416 | - | ||
| 417 | auto dev_ptr = ast_.Var("void *&", "dev_ptr"); | 374 | auto dev_ptr = ast_.Var("void *&", "dev_ptr"); |
| 418 | auto size = ast_.Var("const size_t", "size"); | 375 | auto size = ast_.Var("const size_t", "size"); |
| 419 | auto mem_type = ast_.Var("const uint32_t", "mem_type"); | 376 | auto mem_type = ast_.Var("const uint32_t", "mem_type"); |
| @@ -524,4 +481,89 @@ Status LoadAndRunFileCodeGenerator::BuildDispatchOp(std::vector<DeclNode *> &ite | |||
| 524 | 481 | ||
| 525 | return SUCCESS; | 482 | return SUCCESS; |
| 526 | } | 483 | } |
| 484 | + | ||
| 485 | +std::vector<DeclNode *> LoadAndRunFileCodeGenerator::BuildQueryResourceApis( | ||
| 486 | + const Om2CodegenModel &codegen_model) const { | ||
| 487 | + const auto &runtime = codegen_model.runtime; | ||
| 488 | + std::vector<DeclNode *> items; | ||
| 489 | + | ||
| 490 | + // GertModelGetStreamNum | ||
| 491 | + items.push_back(ast_.DefineFunction("GertModelGetStreamNum", {}, "uint64_t", | ||
| 492 | + {ast_.Return(ast_.UInt(static_cast<uint64_t>(runtime.stream_num)))})); | ||
| 493 | + | ||
| 494 | + // GertModelGetStreamDesc | ||
| 495 | + auto stream_flags = ast_.Var("uint32_t *", "stream_flags"); | ||
| 496 | + auto stream_num = ast_.Var("uint64_t", "stream_num"); | ||
| 497 | + auto stream_ext = ast_.Var("void *", "extended_attrs"); | ||
| 498 | + std::vector<BodyItem> stream_desc_body = { | ||
| 499 | + ast_.If((stream_flags == nullptr) || (stream_num != ast_.UInt(static_cast<uint64_t>(runtime.stream_num))), | ||
| 500 | + {ast_.Call("OM2_LOGE", | ||
| 501 | + {ast_.Str("GertModelGetStreamDesc failed, stream_flags is null or stream_num mismatch, " | ||
| 502 | + "expected %lu, got %lu"), | ||
| 503 | + ast_.UInt(static_cast<uint64_t>(runtime.stream_num)), stream_num}), | ||
| 504 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 505 | + }; | ||
| 506 | + for (uint32_t i = 0U; i < runtime.stream_num; ++i) { | ||
| 507 | + stream_desc_body.emplace_back( | ||
| 508 | + ast_.Assign(stream_flags[ast_.UInt(static_cast<uint64_t>(i))], runtime.stream_flag_values[i])); | ||
| 509 | + } | ||
| 510 | + stream_desc_body.emplace_back(ast_.Return(ast_.UInt(0U))); | ||
| 511 | + items.push_back(ast_.DefineFunction("GertModelGetStreamDesc", {stream_flags, stream_num, stream_ext}, "int32_t", | ||
| 512 | + ast_.Body(stream_desc_body))); | ||
| 513 | + | ||
| 514 | + // GertModelGetEventNum | ||
| 515 | + items.push_back(ast_.DefineFunction("GertModelGetEventNum", {}, "uint64_t", | ||
| 516 | + {ast_.Return(ast_.UInt(static_cast<uint64_t>(runtime.event_num)))})); | ||
| 517 | + | ||
| 518 | + // GertModelGetEventDesc | ||
| 519 | + auto event_flags = ast_.Var("uint32_t *", "event_flags"); | ||
| 520 | + auto event_num = ast_.Var("uint64_t", "event_num"); | ||
| 521 | + auto event_ext = ast_.Var("void *", "extended_attrs"); | ||
| 522 | + std::vector<BodyItem> event_desc_body = { | ||
| 523 | + ast_.If( | ||
| 524 | + (event_flags == nullptr) || (event_num != ast_.UInt(static_cast<uint64_t>(runtime.event_num))), | ||
| 525 | + {ast_.Call("OM2_LOGE", {ast_.Str("GertModelGetEventDesc failed, event_flags is null or event_num mismatch, " | ||
| 526 | + "expected %lu, got %lu"), | ||
| 527 | + ast_.UInt(static_cast<uint64_t>(runtime.event_num)), event_num}), | ||
| 528 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 529 | + }; | ||
| 530 | + for (uint32_t i = 0U; i < runtime.event_num; ++i) { | ||
| 531 | + event_desc_body.emplace_back( | ||
| 532 | + ast_.Assign(event_flags[ast_.UInt(static_cast<uint64_t>(i))], | ||
| 533 | + "ACL_EVENT_SYNC | ACL_EVENT_CAPTURE_STREAM_PROGRESS | ACL_EVENT_TIME_LINE")); | ||
| 534 | + } | ||
| 535 | + event_desc_body.emplace_back(ast_.Return(ast_.UInt(0U))); | ||
| 536 | + items.push_back(ast_.DefineFunction("GertModelGetEventDesc", {event_flags, event_num, event_ext}, "int32_t", | ||
| 537 | + ast_.Body(event_desc_body))); | ||
| 538 | + | ||
| 539 | + // GertModelGetLabelNum | ||
| 540 | + items.push_back(ast_.DefineFunction("GertModelGetLabelNum", {}, "uint64_t", | ||
| 541 | + {ast_.Return(ast_.UInt(static_cast<uint64_t>(runtime.label_num)))})); | ||
| 542 | + | ||
| 543 | + // GertModelGetNotifyNum | ||
| 544 | + items.push_back(ast_.DefineFunction("GertModelGetNotifyNum", {}, "uint64_t", | ||
| 545 | + {ast_.Return(ast_.UInt(static_cast<uint64_t>(runtime.notify_num)))})); | ||
| 546 | + | ||
| 547 | + // GertModelGetNotifyDesc | ||
| 548 | + auto notify_flags = ast_.Var("uint64_t *", "notify_flags"); | ||
| 549 | + auto notify_num = ast_.Var("uint64_t", "notify_num"); | ||
| 550 | + auto notify_ext = ast_.Var("void *", "extended_attrs"); | ||
| 551 | + std::vector<BodyItem> notify_desc_body = { | ||
| 552 | + ast_.If((notify_flags == nullptr) || (notify_num != ast_.UInt(static_cast<uint64_t>(runtime.notify_num))), | ||
| 553 | + {ast_.Call("OM2_LOGE", | ||
| 554 | + {ast_.Str("GertModelGetNotifyDesc failed, notify_flags is null or notify_num mismatch, " | ||
| 555 | + "expected %lu, got %lu"), | ||
| 556 | + ast_.UInt(static_cast<uint64_t>(runtime.notify_num)), notify_num}), | ||
| 557 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 558 | + }; | ||
| 559 | + for (uint32_t i = 0U; i < runtime.notify_num; ++i) { | ||
| 560 | + notify_desc_body.emplace_back( | ||
| 561 | + ast_.Assign(notify_flags[ast_.UInt(static_cast<uint64_t>(i))], "ACL_NOTIFY_DEVICE_USE_ONLY")); | ||
| 562 | + } | ||
| 563 | + notify_desc_body.emplace_back(ast_.Return(ast_.UInt(0U))); | ||
| 564 | + items.push_back(ast_.DefineFunction("GertModelGetNotifyDesc", {notify_flags, notify_num, notify_ext}, "int32_t", | ||
| 565 | + ast_.Body(notify_desc_body))); | ||
| 566 | + | ||
| 567 | + return items; | ||
| 568 | +} | ||
| 527 | } // namespace ge | 569 | } // namespace ge |
| @@ -27,6 +27,7 @@ class LoadAndRunFileCodeGenerator : public Om2ModelClassGeneratorBase { | |||
| 27 | MethodDef *BuildGetRtModelHandleMethod() const; | 27 | MethodDef *BuildGetRtModelHandleMethod() const; |
| 28 | MethodDef *BuildRunAsyncMethod(const Om2CodegenModel &codegen_model); | 28 | MethodDef *BuildRunAsyncMethod(const Om2CodegenModel &codegen_model); |
| 29 | MethodDef *BuildRunMethod(const Om2CodegenModel &codegen_model); | 29 | MethodDef *BuildRunMethod(const Om2CodegenModel &codegen_model); |
| 30 | + std::vector<DeclNode *> BuildQueryResourceApis(const Om2CodegenModel &codegen_model) const; | ||
| 30 | StructDecl *BuildLaunchKernelCfgHolder() const; | 31 | StructDecl *BuildLaunchKernelCfgHolder() const; |
| 31 | StructDecl *BuildLaunchKernelConfig() const; | 32 | StructDecl *BuildLaunchKernelConfig() const; |
| 32 | FunctionDef *BuildAssembleLaunchConfig() const; | 33 | FunctionDef *BuildAssembleLaunchConfig() const; |
| @@ -53,7 +54,6 @@ class LoadAndRunFileCodeGenerator : public Om2ModelClassGeneratorBase { | |||
| 53 | void BuildRunBodyCopyOutputs(std::vector<BodyItem> &body, const std::vector<ModelIoEntry> &entries, | 54 | void BuildRunBodyCopyOutputs(std::vector<BodyItem> &body, const std::vector<ModelIoEntry> &entries, |
| 54 | const VarRef &exe_stream, bool is_async); | 55 | const VarRef &exe_stream, bool is_async); |
| 55 | Status BuildCommonHelperFunctions(std::vector<DeclNode *> &items) const; | 56 | Status BuildCommonHelperFunctions(std::vector<DeclNode *> &items) const; |
| 56 | - Status BuildAclrtMallocFunction(std::vector<DeclNode *> &items) const; | ||
| 57 | Status BuildDispatchOp(std::vector<DeclNode *> &items, | 57 | Status BuildDispatchOp(std::vector<DeclNode *> &items, |
| 58 | const std::map<uint32_t, std::string> &type_to_func_name) const; | 58 | const std::map<uint32_t, std::string> &type_to_func_name) const; |
| 59 | bool has_custom_kernel_ = false; | 59 | bool has_custom_kernel_ = false; |
| @@ -51,16 +51,20 @@ MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelConstructor(const Om2Codegen | |||
| 51 | (void)body.emplace_back(label_list_.Resize(runtime.label_num)); | 51 | (void)body.emplace_back(label_list_.Resize(runtime.label_num)); |
| 52 | } | 52 | } |
| 53 | (void)body.emplace_back(ast_.Call("OM2_LOGD", {ast_.Str("Om2Model created")})); | 53 | (void)body.emplace_back(ast_.Call("OM2_LOGD", {ast_.Str("Om2Model created")})); |
| 54 | - return ast_.DefineMethod("Om2Model", "Om2Model", | 54 | + return ast_.DefineMethod( |
| 55 | - {bin_files, bin_data, bin_size, bin_num, constants, var_addrs, work_ptr, session_id, | 55 | + "Om2Model", "Om2Model", |
| 56 | - model_id, instance_handle, priority}, | 56 | + {bin_files, bin_data, bin_size, bin_num, constants, var_addrs, work_ptr, session_id, model_id, instance_handle, |
| 57 | - "", | 57 | + priority}, |
| 58 | - {ast_.MemberInit("constants_", constants), ast_.MemberInit("var_addrs_", var_addrs), | 58 | + "", |
| 59 | - ast_.MemberInit("total_dev_mem_ptr_", work_ptr), ast_.MemberInit("session_id_", session_id), | 59 | + {ast_.MemberInit("constants_", constants), ast_.MemberInit("var_addrs_", var_addrs), |
| 60 | - ast_.MemberInit("model_id_", model_id), | 60 | + ast_.MemberInit("total_dev_mem_ptr_", work_ptr), ast_.MemberInit("owns_total_dev_mem_", false), |
| 61 | - ast_.MemberInit("instance_handle_", instance_handle), ast_.MemberInit("kernel_id_", 0), | 61 | + ast_.MemberInit("session_id_", session_id), ast_.MemberInit("model_id_", model_id), |
| 62 | - ast_.MemberInit("session_scope_mem_ptr_", nullptr), ast_.MemberInit("priority_", priority)}, | 62 | + ast_.MemberInit("instance_handle_", instance_handle), ast_.MemberInit("kernel_id_", 0), |
| 63 | - body); | 63 | + ast_.MemberInit("session_scope_mem_ptr_", nullptr), ast_.MemberInit("priority_", priority), |
| 64 | + ast_.MemberInit("is_external_rt_model_", false), ast_.MemberInit("is_external_streams_", false), | ||
| 65 | + ast_.MemberInit("is_external_notifies_", false), ast_.MemberInit("is_external_events_", false), | ||
| 66 | + ast_.MemberInit("is_external_labels_", false)}, | ||
| 67 | + body); | ||
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelDestructor() const { | 70 | MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelDestructor() const { |
| @@ -73,10 +77,33 @@ MethodDef *ResourcesFileCodeGenerator::BuildOm2ModelDestructor() const { | |||
| 73 | 77 | ||
| 74 | MethodDef *ResourcesFileCodeGenerator::BuildInitResourcesMethod( | 78 | MethodDef *ResourcesFileCodeGenerator::BuildInitResourcesMethod( |
| 75 | const Om2CodegenModel &codegen_model, const std::vector<TaskCodeBuilderPtr> &task_code_builders) { | 79 | const Om2CodegenModel &codegen_model, const std::vector<TaskCodeBuilderPtr> &task_code_builders) { |
| 80 | + const auto reuse_zero_copy = ast_.Var("uint64_t", "reuse_zero_copy"); | ||
| 81 | + const auto required_work_size = ast_.Var("size_t", "required_work_size"); | ||
| 82 | + const auto model_work_size = ast_.Var("size_t", "kModelWorkSize"); | ||
| 83 | + const auto model_zero_copy_size = ast_.Var("size_t", "kModelZeroCopySize"); | ||
| 84 | + auto external_resources = ast_.Var("const GertModelExternalResources &", "external_resources"); | ||
| 85 | + | ||
| 76 | std::vector<BodyItem> body = { | 86 | std::vector<BodyItem> body = { |
| 77 | ast_.Call("OM2_LOGI", {ast_.Str("InitResources begin")}), | 87 | ast_.Call("OM2_LOGI", {ast_.Str("InitResources begin")}), |
| 88 | + ast_.Call("OM2_LOGI", {ast_.Str("model_id=%u, InitResources: work_ptr=%p, work_size=%zu, zero_copy_size=%zu"), | ||
| 89 | + model_id_, total_dev_mem_ptr_, model_work_size, model_zero_copy_size}), | ||
| 90 | + ast_.VarDecl(required_work_size, model_work_size), | ||
| 91 | + ast_.If(reuse_zero_copy != 0U, {ast_.Assign(required_work_size, model_work_size - model_zero_copy_size)}), | ||
| 92 | + ast_.If(total_dev_mem_ptr_ != nullptr, | ||
| 93 | + {ast_.Call("OM2_LOGI", {ast_.Str("model_id=%u, InitResources: use external work_ptr=%p"), model_id_, | ||
| 94 | + total_dev_mem_ptr_})}), | ||
| 95 | + ast_.If((total_dev_mem_ptr_ == nullptr) && (required_work_size != 0U), | ||
| 96 | + {ast_.Call("OM2_LOGI", {ast_.Str("model_id=%u, InitResources: prepare work_ptr allocation, " | ||
| 97 | + "work_size=%zu, zero_copy_size=%zu, malloc_size=%zu"), | ||
| 98 | + model_id_, model_work_size, model_zero_copy_size, required_work_size}), | ||
| 99 | + ChkStatus(AclrtMallocHelper(total_dev_mem_ptr_.Addr(), required_work_size, "RT_MEMORY_HBM", 0U)), | ||
| 100 | + ast_.Assign(owns_total_dev_mem_, true)}), | ||
| 101 | + ast_.BlankLine(), | ||
| 78 | ast_.Comment("1. 创建 model"), | 102 | ast_.Comment("1. 创建 model"), |
| 79 | - ChkStatus(AclmdlRIBuildBegin(model_handle_.Addr(), 0)), | 103 | + ast_.If(external_resources.Attr("external_rt_model") != nullptr, |
| 104 | + {ast_.Assign(model_handle_, external_resources.Attr("external_rt_model")), | ||
| 105 | + ast_.Assign(is_external_rt_model_, true)}, | ||
| 106 | + {ChkStatus(AclmdlRIBuildBegin(model_handle_.Addr(), 0))}), | ||
| 80 | ast_.BlankLine(), | 107 | ast_.BlankLine(), |
| 81 | ast_.Comment("2. 获取overflow地址"), | 108 | ast_.Comment("2. 获取overflow地址"), |
| 82 | ChkStatus(AclrtCtxGetFloatOverflowAddr(overflow_addr_.Addr())), | 109 | ChkStatus(AclrtCtxGetFloatOverflowAddr(overflow_addr_.Addr())), |
| @@ -84,10 +111,10 @@ MethodDef *ResourcesFileCodeGenerator::BuildInitResourcesMethod( | |||
| 84 | ast_.Comment("3. 创建其他资源"), | 111 | ast_.Comment("3. 创建其他资源"), |
| 85 | }; | 112 | }; |
| 86 | const auto &runtime = codegen_model.runtime; | 113 | const auto &runtime = codegen_model.runtime; |
| 87 | - BuildInitStreamResources(body, runtime); | 114 | + BuildInitStreamResources(body, runtime, external_resources); |
| 88 | - BuildInitNotifyResources(body, runtime); | 115 | + BuildInitNotifyResources(body, runtime, external_resources); |
| 89 | - BuildInitEventResources(body, runtime); | 116 | + BuildInitEventResources(body, runtime, external_resources); |
| 90 | - BuildInitLabelResources(body, runtime); | 117 | + BuildInitLabelResources(body, runtime, external_resources); |
| 91 | for (const auto &task_code_builder : task_code_builders) { | 118 | for (const auto &task_code_builder : task_code_builders) { |
| 92 | GE_ASSERT_NOTNULL(task_code_builder); | 119 | GE_ASSERT_NOTNULL(task_code_builder); |
| 93 | GE_ASSERT_SUCCESS(task_code_builder->RenderInitResource(body)); | 120 | GE_ASSERT_SUCCESS(task_code_builder->RenderInitResource(body)); |
| @@ -96,19 +123,36 @@ MethodDef *ResourcesFileCodeGenerator::BuildInitResourcesMethod( | |||
| 96 | (void)body.emplace_back(args_table_.Attr("Init")()); | 123 | (void)body.emplace_back(args_table_.Attr("Init")()); |
| 97 | (void)body.emplace_back(ast_.Call("OM2_LOGI", {ast_.Str("InitResources done")})); | 124 | (void)body.emplace_back(ast_.Call("OM2_LOGI", {ast_.Str("InitResources done")})); |
| 98 | (void)body.emplace_back(ast_.Return("ACL_SUCCESS")); | 125 | (void)body.emplace_back(ast_.Return("ACL_SUCCESS")); |
| 99 | - return ast_.DefineMethod("Om2Model", "InitResources", {}, "aclError", body); | 126 | + return ast_.DefineMethod("Om2Model", "InitResources", {reuse_zero_copy, external_resources}, "aclError", body); |
| 100 | } | 127 | } |
| 101 | 128 | ||
| 102 | void ResourcesFileCodeGenerator::BuildInitStreamResources(std::vector<BodyItem> &body, | 129 | void ResourcesFileCodeGenerator::BuildInitStreamResources(std::vector<BodyItem> &body, |
| 103 | - const RuntimeResourceSemantic &runtime) { | 130 | + const RuntimeResourceSemantic &runtime, |
| 131 | + const VarRef &external_resources) { | ||
| 104 | if (runtime.stream_num == 0U) { | 132 | if (runtime.stream_num == 0U) { |
| 105 | return; | 133 | return; |
| 106 | } | 134 | } |
| 107 | (void)body.emplace_back(ast_.Comment("创建下沉Stream并绑定模型")); | 135 | (void)body.emplace_back(ast_.Comment("创建下沉Stream并绑定模型")); |
| 136 | + auto ext_i = ast_.Var("size_t", "ext_i"); | ||
| 137 | + auto ext_streams = external_resources.Attr("external_streams"); | ||
| 138 | + auto ext_stream_num = external_resources.Attr("external_stream_num"); | ||
| 139 | + std::vector<BodyItem> ext_items = { | ||
| 140 | + ast_.If(ext_stream_num != stream_list_.Size(), | ||
| 141 | + {ast_.Call("OM2_LOGE", {ast_.Str("external_stream_num mismatch, expected %zu, got %lu"), | ||
| 142 | + stream_list_.Size(), ext_stream_num}), | ||
| 143 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 144 | + ast_.For(ast_.VarDecl(ext_i, 0), ext_i < ext_stream_num, ast_.PreInc(ext_i), | ||
| 145 | + {ast_.Assign(stream_list_[ext_i], ext_streams[ext_i])}), | ||
| 146 | + ast_.Assign(is_external_streams_, true), | ||
| 147 | + }; | ||
| 148 | + std::vector<BodyItem> create_items; | ||
| 108 | for (uint32_t i = 0U; i < runtime.stream_num; ++i) { | 149 | for (uint32_t i = 0U; i < runtime.stream_num; ++i) { |
| 109 | const auto stream_flag = ast_.Var("uint32_t", "stream" + std::to_string(i) + "_flag"); | 150 | const auto stream_flag = ast_.Var("uint32_t", "stream" + std::to_string(i) + "_flag"); |
| 110 | - (void)body.emplace_back(ast_.VarDecl(stream_flag, runtime.stream_flag_values[i])); | 151 | + create_items.emplace_back(ast_.VarDecl(stream_flag, runtime.stream_flag_values[i])); |
| 111 | - (void)body.emplace_back(ChkRt(RtStreamCreateWithFlags(stream_list_[i].Addr(), priority_, stream_flag))); | 152 | + create_items.emplace_back(ChkRt(RtStreamCreateWithFlags(stream_list_[i].Addr(), priority_, stream_flag))); |
| 153 | + } | ||
| 154 | + (void)body.emplace_back(ast_.If(ext_stream_num != ast_.UInt(0U), ext_items, create_items)); | ||
| 155 | + for (uint32_t i = 0U; i < runtime.stream_num; ++i) { | ||
| 112 | const auto bind_flag = ast_.Var("auto", "bind" + std::to_string(i) + "_flag"); | 156 | const auto bind_flag = ast_.Var("auto", "bind" + std::to_string(i) + "_flag"); |
| 113 | (void)body.emplace_back(ast_.VarDecl(bind_flag, runtime.bind_flag_values[i])); | 157 | (void)body.emplace_back(ast_.VarDecl(bind_flag, runtime.bind_flag_values[i])); |
| 114 | (void)body.emplace_back(ChkStatus(AclmdlRIBindStream(model_handle_, stream_list_[i], bind_flag))); | 158 | (void)body.emplace_back(ChkStatus(AclmdlRIBindStream(model_handle_, stream_list_[i], bind_flag))); |
| @@ -117,45 +161,86 @@ void ResourcesFileCodeGenerator::BuildInitStreamResources(std::vector<BodyItem> | |||
| 117 | } | 161 | } |
| 118 | 162 | ||
| 119 | void ResourcesFileCodeGenerator::BuildInitNotifyResources(std::vector<BodyItem> &body, | 163 | void ResourcesFileCodeGenerator::BuildInitNotifyResources(std::vector<BodyItem> &body, |
| 120 | - const RuntimeResourceSemantic &runtime) { | 164 | + const RuntimeResourceSemantic &runtime, |
| 165 | + const VarRef &external_resources) { | ||
| 121 | if (runtime.notify_num == 0U) { | 166 | if (runtime.notify_num == 0U) { |
| 122 | return; | 167 | return; |
| 123 | } | 168 | } |
| 124 | - auto i = ast_.Var("size_t", "i"); | ||
| 125 | (void)body.emplace_back(ast_.Comment("创建Notify")); | 169 | (void)body.emplace_back(ast_.Comment("创建Notify")); |
| 126 | - (void)body.emplace_back( | 170 | + auto ext_i = ast_.Var("size_t", "ext_i"); |
| 171 | + auto ext_notifies = external_resources.Attr("external_notifies"); | ||
| 172 | + auto ext_notify_num = external_resources.Attr("external_notify_num"); | ||
| 173 | + std::vector<BodyItem> ext_items = { | ||
| 174 | + ast_.If(ext_notify_num != notify_list_.Size(), | ||
| 175 | + {ast_.Call("OM2_LOGE", {ast_.Str("external_notify_num mismatch, expected %zu, got %lu"), | ||
| 176 | + notify_list_.Size(), ext_notify_num}), | ||
| 177 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 178 | + ast_.For(ast_.VarDecl(ext_i, 0), ext_i < ext_notify_num, ast_.PreInc(ext_i), | ||
| 179 | + {ast_.Assign(notify_list_[ext_i], ext_notifies[ext_i])}), | ||
| 180 | + ast_.Assign(is_external_notifies_, true), | ||
| 181 | + }; | ||
| 182 | + auto i = ast_.Var("size_t", "i"); | ||
| 183 | + std::vector<BodyItem> create_items = { | ||
| 127 | ast_.For(ast_.VarDecl(i, 0), i < runtime.notify_num, ast_.PreInc(i), | 184 | ast_.For(ast_.VarDecl(i, 0), i < runtime.notify_num, ast_.PreInc(i), |
| 128 | - { | 185 | + {ChkStatus(AclrtCreateNotify(notify_list_[i].Addr(), "ACL_NOTIFY_DEVICE_USE_ONLY"))}), |
| 129 | - ChkStatus(AclrtCreateNotify(notify_list_[i].Addr(), "ACL_NOTIFY_DEVICE_USE_ONLY")), | 186 | + }; |
| 130 | - })); | 187 | + (void)body.emplace_back(ast_.If(ext_notify_num != ast_.UInt(0U), ext_items, create_items)); |
| 131 | } | 188 | } |
| 132 | 189 | ||
| 133 | void ResourcesFileCodeGenerator::BuildInitEventResources(std::vector<BodyItem> &body, | 190 | void ResourcesFileCodeGenerator::BuildInitEventResources(std::vector<BodyItem> &body, |
| 134 | - const RuntimeResourceSemantic &runtime) { | 191 | + const RuntimeResourceSemantic &runtime, |
| 192 | + const VarRef &external_resources) { | ||
| 135 | if (runtime.event_num == 0U) { | 193 | if (runtime.event_num == 0U) { |
| 136 | return; | 194 | return; |
| 137 | } | 195 | } |
| 138 | - auto i = ast_.Var("size_t", "i"); | ||
| 139 | (void)body.emplace_back(ast_.Comment("创建Event")); | 196 | (void)body.emplace_back(ast_.Comment("创建Event")); |
| 140 | - (void)body.emplace_back(ast_.For( | 197 | + auto ext_i = ast_.Var("size_t", "ext_i"); |
| 141 | - ast_.VarDecl(i, 0), i < runtime.event_num, ast_.PreInc(i), | 198 | + auto ext_events = external_resources.Attr("external_events"); |
| 142 | - { | 199 | + auto ext_event_num = external_resources.Attr("external_event_num"); |
| 143 | - ChkStatus(AclrtCreateEventWithFlag( | 200 | + std::vector<BodyItem> ext_items = { |
| 144 | - event_list_[i].Addr(), "ACL_EVENT_SYNC | ACL_EVENT_CAPTURE_STREAM_PROGRESS | ACL_EVENT_TIME_LINE")), | 201 | + ast_.If(ext_event_num != event_list_.Size(), |
| 145 | - })); | 202 | + {ast_.Call("OM2_LOGE", {ast_.Str("external_event_num mismatch, expected %zu, got %lu"), |
| 203 | + event_list_.Size(), ext_event_num}), | ||
| 204 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 205 | + ast_.For(ast_.VarDecl(ext_i, 0), ext_i < ext_event_num, ast_.PreInc(ext_i), | ||
| 206 | + {ast_.Assign(event_list_[ext_i], ext_events[ext_i])}), | ||
| 207 | + ast_.Assign(is_external_events_, true), | ||
| 208 | + }; | ||
| 209 | + auto i = ast_.Var("size_t", "i"); | ||
| 210 | + std::vector<BodyItem> create_items = { | ||
| 211 | + ast_.For( | ||
| 212 | + ast_.VarDecl(i, 0), i < runtime.event_num, ast_.PreInc(i), | ||
| 213 | + {ChkStatus(AclrtCreateEventWithFlag( | ||
| 214 | + event_list_[i].Addr(), "ACL_EVENT_SYNC | ACL_EVENT_CAPTURE_STREAM_PROGRESS | ACL_EVENT_TIME_LINE"))}), | ||
| 215 | + }; | ||
| 216 | + (void)body.emplace_back(ast_.If(ext_event_num != ast_.UInt(0U), ext_items, create_items)); | ||
| 146 | } | 217 | } |
| 147 | 218 | ||
| 148 | void ResourcesFileCodeGenerator::BuildInitLabelResources(std::vector<BodyItem> &body, | 219 | void ResourcesFileCodeGenerator::BuildInitLabelResources(std::vector<BodyItem> &body, |
| 149 | - const RuntimeResourceSemantic &runtime) { | 220 | + const RuntimeResourceSemantic &runtime, |
| 221 | + const VarRef &external_resources) { | ||
| 150 | if (runtime.label_num == 0U) { | 222 | if (runtime.label_num == 0U) { |
| 151 | return; | 223 | return; |
| 152 | } | 224 | } |
| 153 | - auto i = ast_.Var("size_t", "i"); | ||
| 154 | (void)body.emplace_back(ast_.Comment("创建Label")); | 225 | (void)body.emplace_back(ast_.Comment("创建Label")); |
| 155 | - (void)body.emplace_back(ast_.For(ast_.VarDecl(i, 0), i < runtime.label_num, ast_.PreInc(i), | 226 | + auto ext_i = ast_.Var("size_t", "ext_i"); |
| 156 | - { | 227 | + auto ext_labels = external_resources.Attr("external_labels"); |
| 157 | - ChkStatus(AclrtCreateLabel(label_list_[i].Addr())), | 228 | + auto ext_label_num = external_resources.Attr("external_label_num"); |
| 158 | - })); | 229 | + std::vector<BodyItem> ext_items = { |
| 230 | + ast_.If(ext_label_num != label_list_.Size(), | ||
| 231 | + {ast_.Call("OM2_LOGE", {ast_.Str("external_label_num mismatch, expected %zu, got %lu"), | ||
| 232 | + label_list_.Size(), ext_label_num}), | ||
| 233 | + ast_.Return("ACL_ERROR_FAILURE")}), | ||
| 234 | + ast_.For(ast_.VarDecl(ext_i, 0), ext_i < ext_label_num, ast_.PreInc(ext_i), | ||
| 235 | + {ast_.Assign(label_list_[ext_i], ext_labels[ext_i])}), | ||
| 236 | + ast_.Assign(is_external_labels_, true), | ||
| 237 | + }; | ||
| 238 | + auto i = ast_.Var("size_t", "i"); | ||
| 239 | + std::vector<BodyItem> create_items = { | ||
| 240 | + ast_.For(ast_.VarDecl(i, 0), i < runtime.label_num, ast_.PreInc(i), | ||
| 241 | + {ChkStatus(AclrtCreateLabel(label_list_[i].Addr()))}), | ||
| 242 | + }; | ||
| 243 | + (void)body.emplace_back(ast_.If(ext_label_num != ast_.UInt(0U), ext_items, create_items)); | ||
| 159 | } | 244 | } |
| 160 | 245 | ||
| 161 | void ResourcesFileCodeGenerator::BuildInitSessionScopeMemory(std::vector<BodyItem> &body, | 246 | void ResourcesFileCodeGenerator::BuildInitSessionScopeMemory(std::vector<BodyItem> &body, |
| @@ -176,24 +261,30 @@ MethodDef *ResourcesFileCodeGenerator::BuildReleaseResourcesMethod(const Om2Code | |||
| 176 | const auto &runtime = codegen_model.runtime; | 261 | const auto &runtime = codegen_model.runtime; |
| 177 | if (runtime.label_num > 0U) { | 262 | if (runtime.label_num > 0U) { |
| 178 | auto label = ast_.Var("auto", "label"); | 263 | auto label = ast_.Var("auto", "label"); |
| 179 | - (void)body.emplace_back(ast_.RangeFor(label, label_list_, | 264 | + (void)body.emplace_back(ast_.If(!is_external_labels_, |
| 180 | - { | 265 | + {ast_.RangeFor(label, label_list_, |
| 181 | - ast_.If(label != nullptr, {ChkStatus(AclrtDestroyLabel(label))}), | 266 | + { |
| 182 | - })); | 267 | + ast_.If(label != nullptr, {ChkStatus(AclrtDestroyLabel(label))}), |
| 268 | + })}, | ||
| 269 | + {}, false)); | ||
| 183 | } | 270 | } |
| 184 | if (runtime.event_num > 0U) { | 271 | if (runtime.event_num > 0U) { |
| 185 | auto event = ast_.Var("auto", "event"); | 272 | auto event = ast_.Var("auto", "event"); |
| 186 | - (void)body.emplace_back(ast_.RangeFor(event, event_list_, | 273 | + (void)body.emplace_back(ast_.If(!is_external_events_, |
| 187 | - { | 274 | + {ast_.RangeFor(event, event_list_, |
| 188 | - ChkStatus(AclrtDestroyEvent(event)), | 275 | + { |
| 189 | - })); | 276 | + ChkStatus(AclrtDestroyEvent(event)), |
| 277 | + })}, | ||
| 278 | + {}, false)); | ||
| 190 | } | 279 | } |
| 191 | if (runtime.notify_num > 0U) { | 280 | if (runtime.notify_num > 0U) { |
| 192 | auto notify = ast_.Var("auto", "notify"); | 281 | auto notify = ast_.Var("auto", "notify"); |
| 193 | - (void)body.emplace_back(ast_.RangeFor(notify, notify_list_, | 282 | + (void)body.emplace_back(ast_.If(!is_external_notifies_, |
| 194 | - { | 283 | + {ast_.RangeFor(notify, notify_list_, |
| 195 | - ChkStatus(AclrtDestroyNotify(notify)), | 284 | + { |
| 196 | - })); | 285 | + ChkStatus(AclrtDestroyNotify(notify)), |
| 286 | + })}, | ||
| 287 | + {}, false)); | ||
| 197 | } | 288 | } |
| 198 | if (runtime.stream_num > 0U) { | 289 | if (runtime.stream_num > 0U) { |
| 199 | auto stream = ast_.Var("auto", "stream"); | 290 | auto stream = ast_.Var("auto", "stream"); |
| @@ -202,10 +293,12 @@ MethodDef *ResourcesFileCodeGenerator::BuildReleaseResourcesMethod(const Om2Code | |||
| 202 | { | 293 | { |
| 203 | ChkStatus(AclmdlRIUnbindStream(model_handle_, stream)), | 294 | ChkStatus(AclmdlRIUnbindStream(model_handle_, stream)), |
| 204 | })})); | 295 | })})); |
| 205 | - (void)body.emplace_back(ast_.RangeFor(stream, stream_list_, | 296 | + (void)body.emplace_back(ast_.If(!is_external_streams_, |
| 206 | - { | 297 | + {ast_.RangeFor(stream, stream_list_, |
| 207 | - ChkStatus(AclrtDestroyStream(stream)), | 298 | + { |
| 208 | - })); | 299 | + ChkStatus(AclrtDestroyStream(stream)), |
| 300 | + })}, | ||
| 301 | + {}, false)); | ||
| 209 | } | 302 | } |
| 210 | if (runtime.kernel_bin_num > 0U) { | 303 | if (runtime.kernel_bin_num > 0U) { |
| 211 | auto bin_handle = ast_.Var("auto", "bin_handle"); | 304 | auto bin_handle = ast_.Var("auto", "bin_handle"); |
| @@ -216,7 +309,7 @@ MethodDef *ResourcesFileCodeGenerator::BuildReleaseResourcesMethod(const Om2Code | |||
| 216 | } | 309 | } |
| 217 | BuildReleaseResourcesMethodForControlTask(body, runtime); | 310 | BuildReleaseResourcesMethodForControlTask(body, runtime); |
| 218 | auto i = ast_.Var("int", "i"); | 311 | auto i = ast_.Var("int", "i"); |
| 219 | - (void)body.emplace_back(ChkStatus(AclmdlRIDestroy(model_handle_))); | 312 | + (void)body.emplace_back(ast_.If(!is_external_rt_model_, {ChkStatus(AclmdlRIDestroy(model_handle_))}, {}, false)); |
| 220 | (void)body.emplace_back(ast_.If(session_scope_mem_ptr_ != nullptr, { | 313 | (void)body.emplace_back(ast_.If(session_scope_mem_ptr_ != nullptr, { |
| 221 | ChkStatus(AclrtFree(session_scope_mem_ptr_)), | 314 | ChkStatus(AclrtFree(session_scope_mem_ptr_)), |
| 222 | })); | 315 | })); |
| @@ -230,6 +323,10 @@ MethodDef *ResourcesFileCodeGenerator::BuildReleaseResourcesMethod(const Om2Code | |||
| 230 | { | 323 | { |
| 231 | ast_.If(dev_dynamic_mem_ptrs_[i] != nullptr, {ChkStatus(AclrtFree(dev_dynamic_mem_ptrs_[i]))}), | 324 | ast_.If(dev_dynamic_mem_ptrs_[i] != nullptr, {ChkStatus(AclrtFree(dev_dynamic_mem_ptrs_[i]))}), |
| 232 | })); | 325 | })); |
| 326 | + (void)body.emplace_back(ast_.If((owns_total_dev_mem_ == true) && (total_dev_mem_ptr_ != nullptr), | ||
| 327 | + {ChkStatus(AclrtFree(total_dev_mem_ptr_))})); | ||
| 328 | + (void)body.emplace_back(ast_.Assign(total_dev_mem_ptr_, nullptr)); | ||
| 329 | + (void)body.emplace_back(ast_.Assign(owns_total_dev_mem_, false)); | ||
| 233 | (void)body.emplace_back(ast_.Call("OM2_LOGI", {ast_.Str("ReleaseResources done")})); | 330 | (void)body.emplace_back(ast_.Call("OM2_LOGI", {ast_.Str("ReleaseResources done")})); |
| 234 | (void)body.emplace_back(ast_.Return("ACL_SUCCESS")); | 331 | (void)body.emplace_back(ast_.Return("ACL_SUCCESS")); |
| 235 | return ast_.DefineMethod("Om2Model", "ReleaseResources", {}, "aclError", body); | 332 | return ast_.DefineMethod("Om2Model", "ReleaseResources", {}, "aclError", body); |
| @@ -27,10 +27,14 @@ class ResourcesFileCodeGenerator : public Om2ModelClassGeneratorBase { | |||
| 27 | MethodDef *BuildReleaseResourcesMethod(const Om2CodegenModel &codegen_model); | 27 | MethodDef *BuildReleaseResourcesMethod(const Om2CodegenModel &codegen_model); |
| 28 | 28 | ||
| 29 | private: | 29 | private: |
| 30 | - void BuildInitStreamResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 30 | + void BuildInitStreamResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime, |
| 31 | - void BuildInitNotifyResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 31 | + const VarRef &external_resources); |
| 32 | - void BuildInitEventResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 32 | + void BuildInitNotifyResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime, |
| 33 | - void BuildInitLabelResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 33 | + const VarRef &external_resources); |
| 34 | + void BuildInitEventResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime, | ||
| 35 | + const VarRef &external_resources); | ||
| 36 | + void BuildInitLabelResources(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime, | ||
| 37 | + const VarRef &external_resources); | ||
| 34 | void BuildInitSessionScopeMemory(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 38 | void BuildInitSessionScopeMemory(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); |
| 35 | void BuildReleaseResourcesMethodForControlTask(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); | 39 | void BuildReleaseResourcesMethodForControlTask(std::vector<BodyItem> &body, const RuntimeResourceSemantic &runtime); |
| 36 | }; | 40 | }; |
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #include "common/om2/codegen/om2_codegen_model_builder.h" | 11 | #include "common/om2/codegen/om2_codegen_model_builder.h" |
| 12 | 12 | ||
| 13 | +#include <cinttypes> | ||
| 13 | #include <iterator> | 14 | #include <iterator> |
| 14 | #include <limits> | 15 | #include <limits> |
| 15 | #include <map> | 16 | #include <map> |
| @@ -298,6 +299,14 @@ std::vector<om2::MemInfo> Om2CodegenModelBuilder::GetAllMemoryTypeSize(const GeM | |||
| 298 | Status Om2CodegenModelBuilder::BuildRuntimeResource(const GeModelPtr &model, Om2CodegenModel &codegen_model) const { | 299 | Status Om2CodegenModelBuilder::BuildRuntimeResource(const GeModelPtr &model, Om2CodegenModel &codegen_model) const { |
| 299 | GE_ASSERT_NOTNULL(model); | 300 | GE_ASSERT_NOTNULL(model); |
| 300 | (void)AttrUtils::GetInt(model, ATTR_MODEL_MEMORY_SIZE, codegen_model.runtime.total_mem_size); | 301 | (void)AttrUtils::GetInt(model, ATTR_MODEL_MEMORY_SIZE, codegen_model.runtime.total_mem_size); |
| 302 | + (void)AttrUtils::GetInt(model, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, codegen_model.runtime.zero_copy_size); | ||
| 303 | + if (codegen_model.runtime.zero_copy_size > codegen_model.runtime.total_mem_size) { | ||
| 304 | + REPORT_INNER_ERR_MSG("E19999", "zero copy size[%" PRIu64 "] exceeds total memory size[%" PRIu64 "]", | ||
| 305 | + codegen_model.runtime.zero_copy_size, codegen_model.runtime.total_mem_size); | ||
| 306 | + GELOGE(PARAM_INVALID, "[OM2] zero copy size[%" PRIu64 "] exceeds total memory size[%" PRIu64 "]", | ||
| 307 | + codegen_model.runtime.zero_copy_size, codegen_model.runtime.total_mem_size); | ||
| 308 | + return PARAM_INVALID; | ||
| 309 | + } | ||
| 301 | (void)AttrUtils::GetInt(model, ATTR_MODEL_WEIGHT_SIZE, codegen_model.runtime.total_weight_size); | 310 | (void)AttrUtils::GetInt(model, ATTR_MODEL_WEIGHT_SIZE, codegen_model.runtime.total_weight_size); |
| 302 | (void)AttrUtils::GetInt(model, ATTR_MODEL_STREAM_NUM, codegen_model.runtime.stream_num); | 311 | (void)AttrUtils::GetInt(model, ATTR_MODEL_STREAM_NUM, codegen_model.runtime.stream_num); |
| 303 | (void)AttrUtils::GetInt(model, ATTR_MODEL_NOTIFY_NUM, codegen_model.runtime.notify_num); | 312 | (void)AttrUtils::GetInt(model, ATTR_MODEL_NOTIFY_NUM, codegen_model.runtime.notify_num); |
| @@ -61,6 +61,7 @@ struct OpInputEdges { | |||
| 61 | 61 | ||
| 62 | struct RuntimeResourceSemantic { | 62 | struct RuntimeResourceSemantic { |
| 63 | uint64_t total_mem_size{0U}; | 63 | uint64_t total_mem_size{0U}; |
| 64 | + uint64_t zero_copy_size{0U}; | ||
| 64 | uint64_t total_weight_size{0U}; | 65 | uint64_t total_weight_size{0U}; |
| 65 | uint32_t stream_num{0U}; | 66 | uint32_t stream_num{0U}; |
| 66 | uint32_t notify_num{0U}; | 67 | uint32_t notify_num{0U}; |
| @@ -24,6 +24,7 @@ Om2ModelClassGeneratorBase::Om2ModelClassGeneratorBase(AstBuildContext &ast) | |||
| 24 | label_list_(ast.Var("std::vector<aclrtLabel>", "label_list_")), | 24 | label_list_(ast.Var("std::vector<aclrtLabel>", "label_list_")), |
| 25 | aclrt_label_list_(ast.Var("aclrtLabelList", "aclrt_label_list_")), | 25 | aclrt_label_list_(ast.Var("aclrtLabelList", "aclrt_label_list_")), |
| 26 | total_dev_mem_ptr_(ast.Var("void *", "total_dev_mem_ptr_")), | 26 | total_dev_mem_ptr_(ast.Var("void *", "total_dev_mem_ptr_")), |
| 27 | + owns_total_dev_mem_(ast.Var("bool", "owns_total_dev_mem_")), | ||
| 27 | is_stream_list_bind_(ast.Var("bool", "is_stream_list_bind_")), | 28 | is_stream_list_bind_(ast.Var("bool", "is_stream_list_bind_")), |
| 28 | bin_info_map_(ast.Var("std::unordered_map<std::string, BinDataInfo>", "bin_info_map_")), | 29 | bin_info_map_(ast.Var("std::unordered_map<std::string, BinDataInfo>", "bin_info_map_")), |
| 29 | args_table_(ast.Var("Om2ArgsTable", "args_table_")), | 30 | args_table_(ast.Var("Om2ArgsTable", "args_table_")), |
| @@ -40,5 +41,10 @@ Om2ModelClassGeneratorBase::Om2ModelClassGeneratorBase(AstBuildContext &ast) | |||
| 40 | overflow_addr_(ast_.Var("void *", "overflow_addr_")), | 41 | overflow_addr_(ast_.Var("void *", "overflow_addr_")), |
| 41 | dev_dynamic_mem_ptrs_(ast_.Var("std::vector<void *>", "dev_dynamic_mem_ptrs_")), | 42 | dev_dynamic_mem_ptrs_(ast_.Var("std::vector<void *>", "dev_dynamic_mem_ptrs_")), |
| 42 | session_scope_mem_ptr_(ast_.Var("void *", "session_scope_mem_ptr_")), | 43 | session_scope_mem_ptr_(ast_.Var("void *", "session_scope_mem_ptr_")), |
| 43 | - priority_(ast_.Var("int32_t", "priority_")) {} | 44 | + priority_(ast_.Var("int32_t", "priority_")), |
| 45 | + is_external_rt_model_(ast_.Var("bool", "is_external_rt_model_")), | ||
| 46 | + is_external_streams_(ast_.Var("bool", "is_external_streams_")), | ||
| 47 | + is_external_notifies_(ast_.Var("bool", "is_external_notifies_")), | ||
| 48 | + is_external_events_(ast_.Var("bool", "is_external_events_")), | ||
| 49 | + is_external_labels_(ast_.Var("bool", "is_external_labels_")) {} | ||
| 44 | } // namespace ge | 50 | } // namespace ge |
| @@ -31,6 +31,7 @@ class Om2ModelClassGeneratorBase : public CodeGeneratorBase { | |||
| 31 | VarRef label_list_; | 31 | VarRef label_list_; |
| 32 | VarRef aclrt_label_list_; | 32 | VarRef aclrt_label_list_; |
| 33 | VarRef total_dev_mem_ptr_; | 33 | VarRef total_dev_mem_ptr_; |
| 34 | + VarRef owns_total_dev_mem_; | ||
| 34 | VarRef is_stream_list_bind_; | 35 | VarRef is_stream_list_bind_; |
| 35 | VarRef bin_info_map_; | 36 | VarRef bin_info_map_; |
| 36 | VarRef args_table_; | 37 | VarRef args_table_; |
| @@ -48,6 +49,11 @@ class Om2ModelClassGeneratorBase : public CodeGeneratorBase { | |||
| 48 | VarRef dev_dynamic_mem_ptrs_; | 49 | VarRef dev_dynamic_mem_ptrs_; |
| 49 | VarRef session_scope_mem_ptr_; | 50 | VarRef session_scope_mem_ptr_; |
| 50 | VarRef priority_; | 51 | VarRef priority_; |
| 52 | + VarRef is_external_rt_model_; | ||
| 53 | + VarRef is_external_streams_; | ||
| 54 | + VarRef is_external_notifies_; | ||
| 55 | + VarRef is_external_events_; | ||
| 56 | + VarRef is_external_labels_; | ||
| 51 | }; | 57 | }; |
| 52 | } // namespace ge | 58 | } // namespace ge |
| 53 | 59 | ||
| @@ -92,20 +92,24 @@ Status ProgramGenerator::GenerateInterfaceHeader(Om2CodePrinter &code_printer) { | |||
| 92 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceDumpApis)); | 92 | file_items.push_back(ast_.StablePart(StablePartId::kInterfaceDumpApis)); |
| 93 | 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()); |
| 94 | file_items.push_back(ast_.Namespace( | 94 | file_items.push_back(ast_.Namespace( |
| 95 | - "om2", { | 95 | + "om2", |
| 96 | - ast_.Field("constexpr int32_t", "INPUT_NUM", static_cast<int>(codegen_model_.model_io.input_count)), | 96 | + { |
| 97 | - ast_.Field("constexpr int32_t", "OUTPUT_NUM", static_cast<int>(codegen_model_.model_io.output_count)), | 97 | + ast_.Field("constexpr int32_t", "INPUT_NUM", static_cast<int>(codegen_model_.model_io.input_count)), |
| 98 | - interface_handler.BuildBinDataInfoStruct(), | 98 | + ast_.Field("constexpr int32_t", "OUTPUT_NUM", static_cast<int>(codegen_model_.model_io.output_count)), |
| 99 | - interface_handler.BuildAicpuParamHeadStruct(), | 99 | + ast_.Field("constexpr size_t", "kModelWorkSize", ast_.ULong(codegen_model_.runtime.total_mem_size)), |
| 100 | - interface_handler.BuildAicpuSessionInfoStruct(), | 100 | + ast_.Field("constexpr size_t", "kModelZeroCopySize", ast_.ULong(codegen_model_.runtime.zero_copy_size)), |
| 101 | - interface_handler.BuildArgsInfoStruct(), | 101 | + interface_handler.BuildAclrtMallocFunction(), |
| 102 | - interface_handler.BuildTfAiCpuExInfoStruct(), | 102 | + interface_handler.BuildBinDataInfoStruct(), |
| 103 | - interface_handler.BuildArgsRefreshInfoStruct(), | 103 | + interface_handler.BuildAicpuParamHeadStruct(), |
| 104 | - ast_.StablePart(StablePartId::kScopeGuard, StablePartPlacement::kNamespace), | 104 | + interface_handler.BuildAicpuSessionInfoStruct(), |
| 105 | - interface_handler.BuildOm2ArgsTableClass(), | 105 | + interface_handler.BuildArgsInfoStruct(), |
| 106 | - ast_.StablePart(StablePartId::kOpDefStructs, StablePartPlacement::kNamespace), | 106 | + interface_handler.BuildTfAiCpuExInfoStruct(), |
| 107 | - interface_handler.BuildOm2ModelClass(codegen_model_), | 107 | + interface_handler.BuildArgsRefreshInfoStruct(), |
| 108 | - })); | 108 | + ast_.StablePart(StablePartId::kScopeGuard, StablePartPlacement::kNamespace), |
| 109 | + interface_handler.BuildOm2ArgsTableClass(), | ||
| 110 | + ast_.StablePart(StablePartId::kOpDefStructs, StablePartPlacement::kNamespace), | ||
| 111 | + interface_handler.BuildOm2ModelClass(codegen_model_), | ||
| 112 | + })); | ||
| 109 | file_items.push_back(ast_.ExternBlock("C", external_api_decls)); | 113 | file_items.push_back(ast_.ExternBlock("C", external_api_decls)); |
| 110 | auto *translation_unit = ast_.File(file_items); | 114 | auto *translation_unit = ast_.File(file_items); |
| 111 | GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kInterfaceHeaderFile, translation_unit, code_printer)); | 115 | GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kInterfaceHeaderFile, translation_unit, code_printer)); |
| @@ -216,6 +220,7 @@ Status ProgramGenerator::GenerateLoadAndRunSource(Om2CodePrinter &code_printer) | |||
| 216 | load_and_run_handler.BuildRunMethod(codegen_model_), | 220 | load_and_run_handler.BuildRunMethod(codegen_model_), |
| 217 | })); | 221 | })); |
| 218 | body_items.emplace_back(ast_.StablePart(StablePartId::kLoadAndRunExternalApis)); | 222 | body_items.emplace_back(ast_.StablePart(StablePartId::kLoadAndRunExternalApis)); |
| 223 | + body_items.emplace_back(ast_.ExternBlock("C", load_and_run_handler.BuildQueryResourceApis(codegen_model_))); | ||
| 219 | auto *translation_unit = ast_.File(body_items); | 224 | auto *translation_unit = ast_.File(body_items); |
| 220 | GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kLoadingAndRunningFile, translation_unit, code_printer)); | 225 | GE_ASSERT_SUCCESS(EmitFile(GeneratedFileIndex::kLoadingAndRunningFile, translation_unit, code_printer)); |
| 221 | GELOGD("[OM2] Load and run source file code is generated."); | 226 | GELOGD("[OM2] Load and run source file code is generated."); |
| @@ -177,7 +177,7 @@ FunctionDef *KernelExTaskCodeBuilder::RenderTfAicpuKernelTaskDistribute() const | |||
| 177 | auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); | 177 | auto config = ast_.Var("aclrtLaunchKernelCfg *", "config"); |
| 178 | auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); | 178 | auto launch_func = ast_.Var("GertModelLaunchFunc", "launch_func"); |
| 179 | auto instance_handle = ast_.Var("void *", "instance_handle"); | 179 | auto instance_handle = ast_.Var("void *", "instance_handle"); |
| 180 | - auto task_info = ast_.Var("Om2TaskInfo *", "task_info"); | 180 | + auto task_info = ast_.Var("GertModelTaskDesc *", "task_info"); |
| 181 | auto kernel_params = ast_.Var("GertModelLaunchKernelV2Params", "launch_kernel_v2_params"); | 181 | auto kernel_params = ast_.Var("GertModelLaunchKernelV2Params", "launch_kernel_v2_params"); |
| 182 | auto launch_params = ast_.Var("GertModelTaskLaunchParams", "launch_params"); | 182 | auto launch_params = ast_.Var("GertModelTaskLaunchParams", "launch_params"); |
| 183 | auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "launch_info"); | 183 | auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "launch_info"); |
| @@ -531,9 +531,9 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncTaskInfo(std::vector<BodyItem> | |||
| 531 | auto io_tensors = ast_.Var("std::vector<gert::Tensor>", "io_tensors"); | 531 | auto io_tensors = ast_.Var("std::vector<gert::Tensor>", "io_tensors"); |
| 532 | (void)body.emplace_back(ast_.VarDecl(io_tensors)); | 532 | (void)body.emplace_back(ast_.VarDecl(io_tensors)); |
| 533 | (void)body.emplace_back(io_tensors.Attr("reserve")(ast_.Var("", "num_io"))); | 533 | (void)body.emplace_back(io_tensors.Attr("reserve")(ast_.Var("", "num_io"))); |
| 534 | - auto report_inputs = ast_.Var("std::vector<Om2TaskIoEntry>", "report_inputs"); | 534 | + auto report_inputs = ast_.Var("std::vector<GertModelTaskIoEntry>", "report_inputs"); |
| 535 | (void)body.emplace_back(ast_.VarDecl(report_inputs)); | 535 | (void)body.emplace_back(ast_.VarDecl(report_inputs)); |
| 536 | - auto report_outputs = ast_.Var("std::vector<Om2TaskIoEntry>", "report_outputs"); | 536 | + auto report_outputs = ast_.Var("std::vector<GertModelTaskIoEntry>", "report_outputs"); |
| 537 | (void)body.emplace_back(ast_.VarDecl(report_outputs)); | 537 | (void)body.emplace_back(ast_.VarDecl(report_outputs)); |
| 538 | 538 | ||
| 539 | auto kex = op.Arrow("dispatch_info").Attr("kernel_ex"); | 539 | auto kex = op.Arrow("dispatch_info").Attr("kernel_ex"); |
| @@ -548,13 +548,13 @@ Status KernelExTaskCodeBuilder::RenderDispatchFuncTaskInfo(std::vector<BodyItem> | |||
| 548 | "BuildTensor", | 548 | "BuildTensor", |
| 549 | {ast_.ReinterpretCast("void *", ast_.Var("", "iow_addr")[idx]), tensor.Attr("size"), | 549 | {ast_.ReinterpretCast("void *", ast_.Var("", "iow_addr")[idx]), tensor.Attr("size"), |
| 550 | tensor.Attr("data_type"), tensor.Attr("format"), tensor.Attr("shape"), tensor.Attr("shape_dims")})), | 550 | tensor.Attr("data_type"), tensor.Attr("format"), tensor.Attr("shape"), tensor.Attr("shape_dims")})), |
| 551 | - ast_.VarDecl(ast_.Var("Om2TaskIoEntry", "_entry"), | 551 | + ast_.VarDecl(ast_.Var("GertModelTaskIoEntry", "_entry"), |
| 552 | - ast_.InitList({ast_.Var("", "sizeof(Om2TaskIoEntry)"), | 552 | + ast_.InitList({ast_.Var("", "sizeof(GertModelTaskIoEntry)"), |
| 553 | ast_.Var("", "io_tensors").Attr("back")().Addr(), tensor.Attr("args_offset")})), | 553 | ast_.Var("", "io_tensors").Attr("back")().Addr(), tensor.Attr("args_offset")})), |
| 554 | ast_.If(item.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), {report_inputs.PushBack(ast_.Var("", "_entry"))}, | 554 | ast_.If(item.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), {report_inputs.PushBack(ast_.Var("", "_entry"))}, |
| 555 | {report_outputs.PushBack(ast_.Var("", "_entry"))})})); | 555 | {report_outputs.PushBack(ast_.Var("", "_entry"))})})); |
| 556 | 556 | ||
| 557 | - auto task_info = ast_.Var("Om2TaskInfo", "task_info"); | 557 | + auto task_info = ast_.Var("GertModelTaskDesc", "task_info"); |
| 558 | auto args_table_info = ctx.Attr("args_table").Attr("GetArgsInfo")(kex.Attr("args_table_idx")); | 558 | auto args_table_info = ctx.Attr("args_table").Attr("GetArgsInfo")(kex.Attr("args_table_idx")); |
| 559 | auto stream = ctx.Attr("stream_list")[kex.Attr("stream_id")]; | 559 | auto stream = ctx.Attr("stream_list")[kex.Attr("stream_id")]; |
| 560 | (void)body.emplace_back(ast_.VarDecl(task_info)); | 560 | (void)body.emplace_back(ast_.VarDecl(task_info)); |
| @@ -158,8 +158,8 @@ std::vector<BodyItem> CustomTaskCodeBuilder::RenderDispatchSetup(const VarRef &o | |||
| 158 | ast_.Call( | 158 | ast_.Call( |
| 159 | "", | 159 | "", |
| 160 | {ast_.Var("", "io_tensors").Attr("reserve")(op.Arrow("dispatch_info").Attr("custom").Attr("args_info_num"))}), | 160 | {ast_.Var("", "io_tensors").Attr("reserve")(op.Arrow("dispatch_info").Attr("custom").Attr("args_info_num"))}), |
| 161 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "report_inputs")), | 161 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "report_inputs")), |
| 162 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "report_outputs")), | 162 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "report_outputs")), |
| 163 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_addrs")), | 163 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_addrs")), |
| 164 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_sizes")), | 164 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_sizes")), |
| 165 | }; | 165 | }; |
| @@ -191,34 +191,12 @@ BodyItem CustomTaskCodeBuilder::RenderDispatchLoop(const VarRef &op, const VarRe | |||
| 191 | 191 | ||
| 192 | std::vector<BodyItem> CustomTaskCodeBuilder::RenderDistribution(const VarRef &op, const VarRef &ctx) { | 192 | std::vector<BodyItem> CustomTaskCodeBuilder::RenderDistribution(const VarRef &op, const VarRef &ctx) { |
| 193 | auto custom = op.Arrow("dispatch_info").Attr("custom"); | 193 | auto custom = op.Arrow("dispatch_info").Attr("custom"); |
| 194 | - auto dispatch_type = ast_.StaticCast("uint32_t", op.Arrow("dispatch_type")); | ||
| 195 | auto stream = ctx.Attr("stream_list")[custom.Attr("stream_id")]; | 194 | auto stream = ctx.Attr("stream_list")[custom.Attr("stream_id")]; |
| 196 | 195 | ||
| 197 | return { | 196 | return { |
| 198 | - ChkStatus(ast_.Call( | ||
| 199 | - "ReportOm2TaskPreprocess", | ||
| 200 | - {op.Arrow("op_name"), custom.Attr("op_type"), | ||
| 201 | - ast_.UInt(0), // op_desc_id | ||
| 202 | - ast_.ReinterpretCast("uintptr_t", ast_.Var("", "args_info").Arrow("dev_addr")), | ||
| 203 | - ast_.Var("", "args_info").Arrow("size"), ast_.Var("", "report_inputs"), ast_.Var("", "report_outputs"), | ||
| 204 | - ast_.Var("", "report_workspace_addrs"), ast_.Var("", "report_workspace_sizes"), dispatch_type, | ||
| 205 | - ast_.Var("", "0"), stream, ast_.Var("", "nullptr"), ctx.Attr("model_id"), ctx.Attr("instance_handle")})), | ||
| 206 | - ast_.VarDecl(ast_.Var("uint64_t", "_launch_begin"), ast_.Call("MsprofSysCycleTime", {})), | ||
| 207 | ChkStatus(ast_.Call("KernelCustTaskDistribute", | 197 | ChkStatus(ast_.Call("KernelCustTaskDistribute", |
| 208 | - {ast_.Var("", "op->op_name"), ast_.Var("", "op->dispatch_info.custom.op_type"), | 198 | + {op.Arrow("op_name"), op.Arrow("dispatch_info").Attr("custom").Attr("op_type"), |
| 209 | ast_.Var("", "input_tensors"), ast_.Var("", "output_tensors"), stream})), | 199 | ast_.Var("", "input_tensors"), ast_.Var("", "output_tensors"), stream})), |
| 210 | - ChkStatus(ast_.Call( | ||
| 211 | - "ReportLaunchedOm2Task", | ||
| 212 | - {op.Arrow("op_name"), custom.Attr("op_type"), | ||
| 213 | - ast_.UInt(0), // op_desc_id | ||
| 214 | - ast_.ReinterpretCast("uintptr_t", ast_.Var("", "args_info").Arrow("dev_addr")), | ||
| 215 | - ast_.Var("", "args_info").Arrow("size"), ast_.Var("", "report_inputs").Data(), | ||
| 216 | - ast_.StaticCast("uint64_t", ast_.Var("", "report_inputs").Size()), ast_.Var("", "report_outputs").Data(), | ||
| 217 | - ast_.StaticCast("uint32_t", ast_.Var("", "report_outputs").Size()), | ||
| 218 | - ast_.Var("", "report_workspace_addrs").Data(), ast_.Var("", "report_workspace_sizes").Data(), | ||
| 219 | - ast_.StaticCast("uint32_t", ast_.Var("", "report_workspace_sizes").Size()), dispatch_type, ast_.Var("", "0"), | ||
| 220 | - stream, ctx.Attr("model_id"), ctx.Attr("instance_handle"), ast_.UInt(0U), | ||
| 221 | - ast_.Var("uint64_t", "_launch_begin")})), | ||
| 222 | }; | 200 | }; |
| 223 | } | 201 | } |
| 224 | 202 | ||
| @@ -238,8 +216,8 @@ std::vector<BodyItem> CustomTaskCodeBuilder::HandleInputOutputArg(const VarRef & | |||
| 238 | a.Attr("data").Attr("tensor").Attr("data_type"), a.Attr("data").Attr("tensor").Attr("format"), | 216 | a.Attr("data").Attr("tensor").Attr("data_type"), a.Attr("data").Attr("tensor").Attr("format"), |
| 239 | a.Attr("data").Attr("tensor").Attr("shape"), a.Attr("data").Attr("tensor").Attr("shape_dims")})), | 217 | a.Attr("data").Attr("tensor").Attr("shape"), a.Attr("data").Attr("tensor").Attr("shape_dims")})), |
| 240 | ast_.VarDecl( | 218 | ast_.VarDecl( |
| 241 | - ast_.Var("Om2TaskIoEntry", "_entry"), | 219 | + ast_.Var("GertModelTaskIoEntry", "_entry"), |
| 242 | - ast_.InitList({ast_.Var("", "sizeof(Om2TaskIoEntry)"), ast_.Var("", "io_tensors").Attr("back")().Addr(), | 220 | + ast_.InitList({ast_.Var("", "sizeof(GertModelTaskIoEntry)"), ast_.Var("", "io_tensors").Attr("back")().Addr(), |
| 243 | a.Attr("data").Attr("tensor").Attr("args_offset")})), | 221 | a.Attr("data").Attr("tensor").Attr("args_offset")})), |
| 244 | ast_.If(a.Attr("type") == ast_.Var("", "OP_ARG_INPUT") || a.Attr("type") == ast_.Var("", "OP_ARG_CONST_TENSOR"), | 222 | ast_.If(a.Attr("type") == ast_.Var("", "OP_ARG_INPUT") || a.Attr("type") == ast_.Var("", "OP_ARG_CONST_TENSOR"), |
| 245 | { | 223 | { |
| @@ -364,9 +364,9 @@ Status DSATaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, | |||
| 364 | auto dsa_io_tensors = ast_.Var("std::vector<gert::Tensor>", "dsa_io_tensors"); | 364 | auto dsa_io_tensors = ast_.Var("std::vector<gert::Tensor>", "dsa_io_tensors"); |
| 365 | (void)body.push_back(ast_.VarDecl(dsa_io_tensors)); | 365 | (void)body.push_back(ast_.VarDecl(dsa_io_tensors)); |
| 366 | (void)body.push_back(ast_.Call("", {dsa_io_tensors.Attr("reserve")(dsa_data.Attr("num_args"))})); | 366 | (void)body.push_back(ast_.Call("", {dsa_io_tensors.Attr("reserve")(dsa_data.Attr("num_args"))})); |
| 367 | - auto dsa_report_inputs = ast_.Var("std::vector<Om2TaskIoEntry>", "dsa_report_inputs"); | 367 | + auto dsa_report_inputs = ast_.Var("std::vector<GertModelTaskIoEntry>", "dsa_report_inputs"); |
| 368 | (void)body.push_back(ast_.VarDecl(dsa_report_inputs)); | 368 | (void)body.push_back(ast_.VarDecl(dsa_report_inputs)); |
| 369 | - auto dsa_report_outputs = ast_.Var("std::vector<Om2TaskIoEntry>", "dsa_report_outputs"); | 369 | + auto dsa_report_outputs = ast_.Var("std::vector<GertModelTaskIoEntry>", "dsa_report_outputs"); |
| 370 | (void)body.push_back(ast_.VarDecl(dsa_report_outputs)); | 370 | (void)body.push_back(ast_.VarDecl(dsa_report_outputs)); |
| 371 | auto dsa_report_ws_addrs = ast_.Var("std::vector<uint64_t>", "dsa_report_ws_addrs"); | 371 | auto dsa_report_ws_addrs = ast_.Var("std::vector<uint64_t>", "dsa_report_ws_addrs"); |
| 372 | (void)body.push_back(ast_.VarDecl(dsa_report_ws_addrs)); | 372 | (void)body.push_back(ast_.VarDecl(dsa_report_ws_addrs)); |
| @@ -378,7 +378,7 @@ Status DSATaskCodeBuilder::RenderDispatchFuncReport(std::vector<BodyItem> &body, | |||
| 378 | auto hbm_ai = ast_.Var("ArgsInfo *", "hbm_ai"); | 378 | auto hbm_ai = ast_.Var("ArgsInfo *", "hbm_ai"); |
| 379 | (void)body.push_back( | 379 | (void)body.push_back( |
| 380 | ast_.VarDecl(hbm_ai, ctx.Attr("args_table").Attr("GetArgsInfo")(dsa_data.Attr("hbm_table_index")))); | 380 | ast_.VarDecl(hbm_ai, ctx.Attr("args_table").Attr("GetArgsInfo")(dsa_data.Attr("hbm_table_index")))); |
| 381 | - auto task_info = ast_.Var("Om2TaskInfo", "task_info"); | 381 | + auto task_info = ast_.Var("GertModelTaskDesc", "task_info"); |
| 382 | (void)body.push_back(ast_.VarDecl(task_info)); | 382 | (void)body.push_back(ast_.VarDecl(task_info)); |
| 383 | (void)body.push_back( | 383 | (void)body.push_back( |
| 384 | ChkStatus(ast_.Call("AssembleOm2TaskInfo", {task_info.Addr(), | 384 | ChkStatus(ast_.Call("AssembleOm2TaskInfo", {task_info.Addr(), |
| @@ -444,8 +444,8 @@ Status DSATaskCodeBuilder::RenderDispatchFuncReportIo(std::vector<BodyItem> &bod | |||
| 444 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr("shape"), | 444 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr("shape"), |
| 445 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr("shape_dims")})), | 445 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr("shape_dims")})), |
| 446 | ast_.VarDecl( | 446 | ast_.VarDecl( |
| 447 | - ast_.Var("Om2TaskIoEntry", "_entry"), | 447 | + ast_.Var("GertModelTaskIoEntry", "_entry"), |
| 448 | - ast_.InitList({ast_.Var("", "sizeof(Om2TaskIoEntry)"), dsa_io_tensors.Attr("back")().Addr(), | 448 | + ast_.InitList({ast_.Var("", "sizeof(GertModelTaskIoEntry)"), dsa_io_tensors.Attr("back")().Addr(), |
| 449 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr( | 449 | dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("data").Attr("tensor").Attr( |
| 450 | "args_offset")})), | 450 | "args_offset")})), |
| 451 | ast_.If((dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("type") == ast_.Var("", "OP_ARG_INPUT")) || | 451 | ast_.If((dsa_data.Attr("args_info")[ast_.Var("", "_i")].Attr("type") == ast_.Var("", "OP_ARG_INPUT")) || |
| @@ -1543,8 +1543,8 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuDispatchSetup(const VarR | |||
| 1543 | ast_.If(v_a.Attr("type") == ast_.Var("", "OP_ARG_OPTIONAL_EMPTY"), {ast_.Assign(v_addr, ast_.UInt(0))}, | 1543 | ast_.If(v_a.Attr("type") == ast_.Var("", "OP_ARG_OPTIONAL_EMPTY"), {ast_.Assign(v_addr, ast_.UInt(0))}, |
| 1544 | {ast_.Assign(v_addr, resolve_addr), ast_.Var("", "aicpu_io_tensors").PushBack(build_tensor), | 1544 | {ast_.Assign(v_addr, resolve_addr), ast_.Var("", "aicpu_io_tensors").PushBack(build_tensor), |
| 1545 | ast_.VarDecl( | 1545 | ast_.VarDecl( |
| 1546 | - ast_.Var("Om2TaskIoEntry", "_entry"), | 1546 | + ast_.Var("GertModelTaskIoEntry", "_entry"), |
| 1547 | - ast_.InitList({ast_.Var("", "sizeof(Om2TaskIoEntry)"), | 1547 | + ast_.InitList({ast_.Var("", "sizeof(GertModelTaskIoEntry)"), |
| 1548 | ast_.Var("", "aicpu_io_tensors").Attr("back")().Addr(), data_t.Attr("args_offset")})), | 1548 | ast_.Var("", "aicpu_io_tensors").Attr("back")().Addr(), data_t.Attr("args_offset")})), |
| 1549 | ast_.If(v_a.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), | 1549 | ast_.If(v_a.Attr("type") != ast_.Var("", "OP_ARG_OUTPUT"), |
| 1550 | {ast_.Var("", "aicpu_report_inputs").PushBack(ast_.Var("", "_entry"))}, | 1550 | {ast_.Var("", "aicpu_report_inputs").PushBack(ast_.Var("", "_entry"))}, |
| @@ -1562,8 +1562,8 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuDispatchSetup(const VarR | |||
| 1562 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "iow_addr")), | 1562 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "iow_addr")), |
| 1563 | ast_.VarDecl(ast_.Var("std::vector<gert::Tensor>", "aicpu_io_tensors")), | 1563 | ast_.VarDecl(ast_.Var("std::vector<gert::Tensor>", "aicpu_io_tensors")), |
| 1564 | ast_.Call("", {ast_.Var("", "aicpu_io_tensors").Attr("reserve")(ast_.Var("", "num_io"))}), | 1564 | ast_.Call("", {ast_.Var("", "aicpu_io_tensors").Attr("reserve")(ast_.Var("", "num_io"))}), |
| 1565 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "aicpu_report_inputs")), | 1565 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "aicpu_report_inputs")), |
| 1566 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "aicpu_report_outputs")), | 1566 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "aicpu_report_outputs")), |
| 1567 | ast_.For(ast_.VarDecl("uint32_t", "i", ast_.UInt(0U)), ast_.Var("", "i") < ast_.Var("", "num_io"), | 1567 | ast_.For(ast_.VarDecl("uint32_t", "i", ast_.UInt(0U)), ast_.Var("", "i") < ast_.Var("", "num_io"), |
| 1568 | ast_.PostInc(ast_.Var("", "i")), loop_body), | 1568 | ast_.PostInc(ast_.Var("", "i")), loop_body), |
| 1569 | }; | 1569 | }; |
| @@ -1605,7 +1605,7 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderAicpuLaunchAndReport(const Va | |||
| 1605 | auto aicpu = op.Arrow("dispatch_info").Attr("aicpu"); | 1605 | auto aicpu = op.Arrow("dispatch_info").Attr("aicpu"); |
| 1606 | auto args_info = ast_.Var("ArgsInfo *", "aicpu_args_info"); | 1606 | auto args_info = ast_.Var("ArgsInfo *", "aicpu_args_info"); |
| 1607 | auto stream = ctx.Attr("stream_list")[aicpu.Attr("stream_id")]; | 1607 | auto stream = ctx.Attr("stream_list")[aicpu.Attr("stream_id")]; |
| 1608 | - auto task_info = ast_.Var("Om2TaskInfo", "aicpu_task_info"); | 1608 | + auto task_info = ast_.Var("GertModelTaskDesc", "aicpu_task_info"); |
| 1609 | auto launch_kernel_v2_params = ast_.Var("GertModelLaunchKernelV2Params", "aicpu_launch_kernel_v2_params"); | 1609 | auto launch_kernel_v2_params = ast_.Var("GertModelLaunchKernelV2Params", "aicpu_launch_kernel_v2_params"); |
| 1610 | auto launch_params = ast_.Var("GertModelTaskLaunchParams", "aicpu_launch_params"); | 1610 | auto launch_params = ast_.Var("GertModelTaskLaunchParams", "aicpu_launch_params"); |
| 1611 | auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "aicpu_launch_info"); | 1611 | auto launch_info = ast_.Var("GertModelTaskLaunchInfo", "aicpu_launch_info"); |
| @@ -1678,8 +1678,8 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderDispatchSetup(const VarRef &o | |||
| 1678 | ast_.Call( | 1678 | ast_.Call( |
| 1679 | "", | 1679 | "", |
| 1680 | {ast_.Var("", "io_tensors").Attr("reserve")(op.Arrow("dispatch_info").Attr("aicore").Attr("args_info_num"))}), | 1680 | {ast_.Var("", "io_tensors").Attr("reserve")(op.Arrow("dispatch_info").Attr("aicore").Attr("args_info_num"))}), |
| 1681 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "report_inputs")), | 1681 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "report_inputs")), |
| 1682 | - ast_.VarDecl(ast_.Var("std::vector<Om2TaskIoEntry>", "report_outputs")), | 1682 | + ast_.VarDecl(ast_.Var("std::vector<GertModelTaskIoEntry>", "report_outputs")), |
| 1683 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_addrs")), | 1683 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_addrs")), |
| 1684 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_sizes")), | 1684 | ast_.VarDecl(ast_.Var("std::vector<uint64_t>", "report_workspace_sizes")), |
| 1685 | }; | 1685 | }; |
| @@ -1743,10 +1743,10 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderDistribution(const VarRef &op | |||
| 1743 | 1743 | ||
| 1744 | return { | 1744 | return { |
| 1745 | ast_.VarDecl( | 1745 | ast_.VarDecl( |
| 1746 | - ast_.Var("Om2L0TaskRawInfo", "l0_info"), | 1746 | + ast_.Var("GertModelTaskRawInfo", "task_raw_info"), |
| 1747 | ast_.InitList({ast_.UInt(1U), slot_args.Attr("need_assert_or_printf"), | 1747 | ast_.InitList({ast_.UInt(1U), slot_args.Attr("need_assert_or_printf"), |
| 1748 | ast_.StaticCast("uint64_t", slot_args.Attr("slots_num")), slot_args.Attr("slot_info")})), | 1748 | ast_.StaticCast("uint64_t", slot_args.Attr("slots_num")), slot_args.Attr("slot_info")})), |
| 1749 | - ast_.VarDecl(ast_.Var("Om2TaskInfo", "task_info")), | 1749 | + ast_.VarDecl(ast_.Var("GertModelTaskDesc", "task_info")), |
| 1750 | ChkStatus(ast_.Call("AssembleOm2TaskInfo", | 1750 | ChkStatus(ast_.Call("AssembleOm2TaskInfo", |
| 1751 | {ast_.Var("", "task_info").Addr(), | 1751 | {ast_.Var("", "task_info").Addr(), |
| 1752 | op.Arrow("op_name"), | 1752 | op.Arrow("op_name"), |
| @@ -1777,7 +1777,7 @@ std::vector<BodyItem> KernelTaskCodeBuilder::RenderDistribution(const VarRef &op | |||
| 1777 | {ast_.Var("", "task_info").Attr("stream"), | 1777 | {ast_.Var("", "task_info").Attr("stream"), |
| 1778 | ast_.ReinterpretCast("int32_t *", ast_.Var("", "task_info").Attr("stream_id").Addr())})), | 1778 | ast_.ReinterpretCast("int32_t *", ast_.Var("", "task_info").Attr("stream_id").Addr())})), |
| 1779 | ast_.Assign(ast_.Var("", "task_info").Attr("kernel_type"), aicore.Attr("kernel_type")), | 1779 | ast_.Assign(ast_.Var("", "task_info").Attr("kernel_type"), aicore.Attr("kernel_type")), |
| 1780 | - ast_.Assign(ast_.Var("", "task_info").Attr("l0_exception_dump_info"), ast_.Var("", "l0_info").Addr()), | 1780 | + ast_.Assign(ast_.Var("", "task_info").Attr("task_raw_info"), ast_.Var("", "task_raw_info").Addr()), |
| 1781 | ast_.VarDecl(ast_.Var("GertModelLaunchKernelV2Params", "kernel_params"), | 1781 | ast_.VarDecl(ast_.Var("GertModelLaunchKernelV2Params", "kernel_params"), |
| 1782 | ast_.DesignatedInit({{"func_handle", ctx.Attr("func_handles")[aicore.Attr("func_idx")]}, | 1782 | ast_.DesignatedInit({{"func_handle", ctx.Attr("func_handles")[aicore.Attr("func_idx")]}, |
| 1783 | {"block_dim", aicore.Attr("block_dim")}, | 1783 | {"block_dim", aicore.Attr("block_dim")}, |
| @@ -1813,8 +1813,8 @@ std::vector<BodyItem> KernelTaskCodeBuilder::HandleInputOutputArg(const VarRef & | |||
| 1813 | a.Attr("data").Attr("tensor").Attr("data_type"), a.Attr("data").Attr("tensor").Attr("format"), | 1813 | a.Attr("data").Attr("tensor").Attr("data_type"), a.Attr("data").Attr("tensor").Attr("format"), |
| 1814 | a.Attr("data").Attr("tensor").Attr("shape"), a.Attr("data").Attr("tensor").Attr("shape_dims")})), | 1814 | a.Attr("data").Attr("tensor").Attr("shape"), a.Attr("data").Attr("tensor").Attr("shape_dims")})), |
| 1815 | ast_.VarDecl( | 1815 | ast_.VarDecl( |
| 1816 | - ast_.Var("Om2TaskIoEntry", "_entry"), | 1816 | + ast_.Var("GertModelTaskIoEntry", "_entry"), |
| 1817 | - ast_.InitList({ast_.Var("", "sizeof(Om2TaskIoEntry)"), ast_.Var("", "io_tensors").Attr("back")().Addr(), | 1817 | + ast_.InitList({ast_.Var("", "sizeof(GertModelTaskIoEntry)"), ast_.Var("", "io_tensors").Attr("back")().Addr(), |
| 1818 | a.Attr("data").Attr("tensor").Attr("args_offset")})), | 1818 | a.Attr("data").Attr("tensor").Attr("args_offset")})), |
| 1819 | ast_.If(a.Attr("type") == ast_.Var("", "OP_ARG_INPUT") || a.Attr("type") == ast_.Var("", "OP_ARG_CONST_TENSOR"), | 1819 | ast_.If(a.Attr("type") == ast_.Var("", "OP_ARG_INPUT") || a.Attr("type") == ast_.Var("", "OP_ARG_CONST_TENSOR"), |
| 1820 | {ast_.Var("", "report_inputs").PushBack(ast_.Var("", "_entry"))}, | 1820 | {ast_.Var("", "report_inputs").PushBack(ast_.Var("", "_entry"))}, |
| @@ -1936,7 +1936,7 @@ Arg KernelTaskCodeBuilder::RenderAicoreOpDefFields(const AicoreTaskData &data) { | |||
| 1936 | auto l0_values = std::vector<Arg>{ | 1936 | auto l0_values = std::vector<Arg>{ |
| 1937 | static_cast<int64_t>(data.need_assert_or_printf), | 1937 | static_cast<int64_t>(data.need_assert_or_printf), |
| 1938 | static_cast<int64_t>(build_data_.semantic.ordered_arg_values.size()), | 1938 | static_cast<int64_t>(build_data_.semantic.ordered_arg_values.size()), |
| 1939 | - ast_.CCast("const Om2L0ArgSlotInfo[]", | 1939 | + ast_.CCast("const GertModelArgSlotInfo[]", |
| 1940 | TaskCodeBuilderUtil::BuildL0ArgSlotEntries(ast_, build_data_.semantic.ordered_arg_values)), | 1940 | TaskCodeBuilderUtil::BuildL0ArgSlotEntries(ast_, build_data_.semantic.ordered_arg_values)), |
| 1941 | }; | 1941 | }; |
| 1942 | // 融合算子字段:从 semantic 直接读取,编译期嵌入 kOpDefs[] | 1942 | // 融合算子字段:从 semantic 直接读取,编译期嵌入 kOpDefs[] |
| @@ -26,36 +26,36 @@ Status TaskCodeBuilderUtil::RenderDispatchFunc(AstBuildContext &ast, const std:: | |||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | namespace { | 28 | namespace { |
| 29 | -const char *ToOm2L0ArgKind(AddrValueKind kind) { | 29 | +const char *ToGertModelArgKind(AddrValueKind kind) { |
| 30 | switch (kind) { | 30 | switch (kind) { |
| 31 | case AddrValueKind::kInputInstance: | 31 | case AddrValueKind::kInputInstance: |
| 32 | case AddrValueKind::kConstTensor: | 32 | case AddrValueKind::kConstTensor: |
| 33 | - return "OM2_L0_ARG_INPUT"; | 33 | + return "GERT_MODEL_ARG_INPUT"; |
| 34 | case AddrValueKind::kOutputInstance: | 34 | case AddrValueKind::kOutputInstance: |
| 35 | - return "OM2_L0_ARG_OUTPUT"; | 35 | + return "GERT_MODEL_ARG_OUTPUT"; |
| 36 | case AddrValueKind::kWorkspace: | 36 | case AddrValueKind::kWorkspace: |
| 37 | - return "OM2_L0_ARG_WORKSPACE"; | 37 | + return "GERT_MODEL_ARG_WORKSPACE"; |
| 38 | case AddrValueKind::kTiling: | 38 | case AddrValueKind::kTiling: |
| 39 | - return "OM2_L0_ARG_TILING"; | 39 | + return "GERT_MODEL_ARG_TILING"; |
| 40 | case AddrValueKind::kShapeInfoBuffer: | 40 | case AddrValueKind::kShapeInfoBuffer: |
| 41 | - return "OM2_L0_ARG_SHAPE_INFO"; | 41 | + return "GERT_MODEL_ARG_SHAPE_INFO"; |
| 42 | case AddrValueKind::kLevel1DescPtr: | 42 | case AddrValueKind::kLevel1DescPtr: |
| 43 | - return "OM2_L0_ARG_LEVEL1_DESC"; | 43 | + return "GERT_MODEL_ARG_LEVEL1_DESC"; |
| 44 | case AddrValueKind::kPlaceholder: | 44 | case AddrValueKind::kPlaceholder: |
| 45 | - return "OM2_L0_ARG_PLACEHOLDER"; | 45 | + return "GERT_MODEL_ARG_PLACEHOLDER"; |
| 46 | case AddrValueKind::kCustomValue: | 46 | case AddrValueKind::kCustomValue: |
| 47 | - return "OM2_L0_ARG_CUSTOM_VALUE"; | 47 | + return "GERT_MODEL_ARG_CUSTOM_VALUE"; |
| 48 | case AddrValueKind::kFftsAddr: | 48 | case AddrValueKind::kFftsAddr: |
| 49 | - return "OM2_L0_ARG_FFTS_ADDR"; | 49 | + return "GERT_MODEL_ARG_FFTS_ADDR"; |
| 50 | case AddrValueKind::kEventAddr: | 50 | case AddrValueKind::kEventAddr: |
| 51 | - return "OM2_L0_ARG_EVENT_ADDR"; | 51 | + return "GERT_MODEL_ARG_EVENT_ADDR"; |
| 52 | case AddrValueKind::kOverflowAddr: | 52 | case AddrValueKind::kOverflowAddr: |
| 53 | - return "OM2_L0_ARG_OVERFLOW_ADDR"; | 53 | + return "GERT_MODEL_ARG_OVERFLOW_ADDR"; |
| 54 | case AddrValueKind::kOptionalEmpty: | 54 | case AddrValueKind::kOptionalEmpty: |
| 55 | case AddrValueKind::kEmptyAddr: | 55 | case AddrValueKind::kEmptyAddr: |
| 56 | - return "OM2_L0_ARG_EMPTY_ADDR"; | 56 | + return "GERT_MODEL_ARG_EMPTY_ADDR"; |
| 57 | default: | 57 | default: |
| 58 | - return "OM2_L0_ARG_EMPTY_ADDR"; | 58 | + return "GERT_MODEL_ARG_EMPTY_ADDR"; |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -125,7 +125,7 @@ Expr *TaskCodeBuilderUtil::BuildTaskIoEntries(AstBuildContext &ast, const std::v | |||
| 125 | if (!addr.tensor_info.has_value()) { | 125 | if (!addr.tensor_info.has_value()) { |
| 126 | continue; | 126 | continue; |
| 127 | } | 127 | } |
| 128 | - (void)entries.emplace_back(std::vector<Arg>{ast.Var("", "sizeof(Om2TaskIoEntry)"), | 128 | + (void)entries.emplace_back(std::vector<Arg>{ast.Var("", "sizeof(GertModelTaskIoEntry)"), |
| 129 | ast.Var("gert::Tensor", addr.symbol_hint).Addr(), | 129 | ast.Var("gert::Tensor", addr.symbol_hint).Addr(), |
| 130 | std::to_string(addr.tensor_info->args_offset) + "U"}); | 130 | std::to_string(addr.tensor_info->args_offset) + "U"}); |
| 131 | } | 131 | } |
| @@ -163,7 +163,8 @@ Expr *TaskCodeBuilderUtil::BuildL0ArgSlotEntries(AstBuildContext &ast, const std | |||
| 163 | ? Arg(std::to_string(addr.tensor_info->args_offset / sizeof(uint64_t)) + "U") | 163 | ? Arg(std::to_string(addr.tensor_info->args_offset / sizeof(uint64_t)) + "U") |
| 164 | : Arg("0U")); | 164 | : Arg("0U")); |
| 165 | (void)entries.emplace_back(std::vector<Arg>{ | 165 | (void)entries.emplace_back(std::vector<Arg>{ |
| 166 | - ToOm2L0ArgKind(addr.kind), "0U", std::to_string(args_offset) + "U", std::to_string(value) + "UL", related_index, | 166 | + ast.Var("", "sizeof(GertModelArgSlotInfo)"), ToGertModelArgKind(addr.kind), "0U", |
| 167 | + std::to_string(args_offset) + "U", std::to_string(value) + "UL", related_index, | ||
| 167 | std::to_string(addr.event_id) + "U", std::to_string(addr.level1_target_offset.value_or(0U)) + "U"}); | 168 | std::to_string(addr.event_id) + "U", std::to_string(addr.level1_target_offset.value_or(0U)) + "U"}); |
| 168 | args_offset += GetOrderedArgByteSizeForL0(addr); | 169 | args_offset += GetOrderedArgByteSizeForL0(addr); |
| 169 | } | 170 | } |
| @@ -211,14 +212,14 @@ Status TaskCodeBuilderUtil::AppendReportLaunchedTaskCall( | |||
| 211 | const auto output_num = count_report_tensors(output_addrs); | 212 | const auto output_num = count_report_tensors(output_addrs); |
| 212 | const auto workspace_num = workspace_addrs.size(); | 213 | const auto workspace_num = workspace_addrs.size(); |
| 213 | if (input_num > 0U) { | 214 | if (input_num > 0U) { |
| 214 | - (void)items.emplace_back(ast.VarDecl("const Om2TaskIoEntry", inputs_var + "[]", input_entries)); | 215 | + (void)items.emplace_back(ast.VarDecl("const GertModelTaskIoEntry", inputs_var + "[]", input_entries)); |
| 215 | (void)args.emplace_back(inputs_var); | 216 | (void)args.emplace_back(inputs_var); |
| 216 | } else { | 217 | } else { |
| 217 | (void)args.emplace_back("nullptr"); | 218 | (void)args.emplace_back("nullptr"); |
| 218 | } | 219 | } |
| 219 | (void)args.emplace_back(ast.ULong(input_num)); | 220 | (void)args.emplace_back(ast.ULong(input_num)); |
| 220 | if (output_num > 0U) { | 221 | if (output_num > 0U) { |
| 221 | - (void)items.emplace_back(ast.VarDecl("const Om2TaskIoEntry", outputs_var + "[]", output_entries)); | 222 | + (void)items.emplace_back(ast.VarDecl("const GertModelTaskIoEntry", outputs_var + "[]", output_entries)); |
| 222 | (void)args.emplace_back(outputs_var); | 223 | (void)args.emplace_back(outputs_var); |
| 223 | } else { | 224 | } else { |
| 224 | (void)args.emplace_back("nullptr"); | 225 | (void)args.emplace_back("nullptr"); |
| @@ -29,7 +29,7 @@ class DataDumpImpl { | |||
| 29 | DataDumpImpl(); | 29 | DataDumpImpl(); |
| 30 | ~DataDumpImpl(); | 30 | ~DataDumpImpl(); |
| 31 | 31 | ||
| 32 | - Status SaveTask(const Om2TaskInfo &task_info, ModelTaskType task_type, rtStream_t stream, bool is_op_debug); | 32 | + Status SaveTask(const GertModelTaskDesc &task_info, ModelTaskType task_type, rtStream_t stream, bool is_op_debug); |
| 33 | 33 | ||
| 34 | Status BuildAndLoadOpMappingInfo(const ModelDumpInfo &model_info); | 34 | Status BuildAndLoadOpMappingInfo(const ModelDumpInfo &model_info); |
| 35 | 35 | ||
| @@ -31,9 +31,9 @@ class ExceptionDumpImpl { | |||
| 31 | explicit ExceptionDumpImpl(uint32_t device_id = 0U); | 31 | explicit ExceptionDumpImpl(uint32_t device_id = 0U); |
| 32 | ~ExceptionDumpImpl(); | 32 | ~ExceptionDumpImpl(); |
| 33 | 33 | ||
| 34 | - Status SaveOpInfo(const Om2TaskInfo &task_info); | 34 | + Status SaveOpInfo(const GertModelTaskDesc &task_info); |
| 35 | 35 | ||
| 36 | - Status ReportL0ExceptionDumpInfo(const Om2TaskInfo &task_info) const; | 36 | + Status ReportL0ExceptionDumpInfo(const GertModelTaskDesc &task_info) const; |
| 37 | 37 | ||
| 38 | bool GetOpDescInfo(const OpDescInfoId &op_id, OpDescInfo &op_info) const; | 38 | bool GetOpDescInfo(const OpDescInfoId &op_id, OpDescInfo &op_info) const; |
| 39 | 39 | ||
| @@ -44,13 +44,13 @@ class ExceptionDumpImpl { | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | private: | 46 | private: |
| 47 | - Status ReportL1ExceptionDumpInfo(const Om2TaskInfo &task_info, const OpDescInfo &op_info) const; | 47 | + Status ReportL1ExceptionDumpInfo(const GertModelTaskDesc &task_info, const OpDescInfo &op_info) const; |
| 48 | 48 | ||
| 49 | void FillAdumpOpInfoBuilder(const OpDescInfo &op_info, std::vector<Adx::TensorInfoV2> &input_infos, | 49 | void FillAdumpOpInfoBuilder(const OpDescInfo &op_info, std::vector<Adx::TensorInfoV2> &input_infos, |
| 50 | std::vector<Adx::TensorInfoV2> &output_infos, | 50 | std::vector<Adx::TensorInfoV2> &output_infos, |
| 51 | std::vector<Adx::TensorInfoV2> &workspace_infos, AdumpOpInfoBuilder &builder) const; | 51 | std::vector<Adx::TensorInfoV2> &workspace_infos, AdumpOpInfoBuilder &builder) const; |
| 52 | 52 | ||
| 53 | - Status SubmitToAdump(const char *op_name, const Om2TaskInfo &task_info, const OpDescInfo &op_info, | 53 | + Status SubmitToAdump(const char *op_name, const GertModelTaskDesc &task_info, const OpDescInfo &op_info, |
| 54 | std::vector<Adx::TensorInfoV2> &input_infos, std::vector<Adx::TensorInfoV2> &output_infos, | 54 | std::vector<Adx::TensorInfoV2> &input_infos, std::vector<Adx::TensorInfoV2> &output_infos, |
| 55 | std::vector<Adx::TensorInfoV2> &workspace_infos, const AdumpOpInfoBuilder &builder) const; | 55 | std::vector<Adx::TensorInfoV2> &workspace_infos, const AdumpOpInfoBuilder &builder) const; |
| 56 | 56 | ||
| @@ -24,110 +24,110 @@ | |||
| 24 | #define OM2_C_API_EXPORT __attribute__((visibility("default"))) | 24 | #define OM2_C_API_EXPORT __attribute__((visibility("default"))) |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | -#ifdef __cplusplus | ||
| 28 | -extern "C" { | ||
| 29 | -#endif | ||
| 30 | - | ||
| 31 | // ============ Tensor信息 ============ | 27 | // ============ Tensor信息 ============ |
| 32 | /** | 28 | /** |
| 33 | * @brief OM2 算子单个输入或输出 Tensor 与 args buffer 地址槽位的映射信息。 | 29 | * @brief OM2 算子单个输入或输出 Tensor 与 args buffer 地址槽位的映射信息。 |
| 34 | */ | 30 | */ |
| 35 | -struct Om2TaskIoEntry { | 31 | +struct GertModelTaskIoEntry { |
| 36 | - uint64_t struct_size = sizeof(Om2TaskIoEntry); // 布局变化时更新 | 32 | + uint64_t struct_size = sizeof(GertModelTaskIoEntry); // 布局变化时更新 |
| 37 | - const gert::Tensor *tensor = nullptr; // 输入,Tensor 基础信息指针,不允许为空。 | 33 | + const gert::Tensor *tensor = nullptr; // 输入,Tensor 基础信息指针,不允许为空。 |
| 38 | - uint64_t offset = 0; // 输入,Tensor 地址在 args buffer 中的偏移,单位为字节。 | 34 | + uint64_t offset = 0; // 输入,Tensor 地址在 args buffer 中的偏移,单位为字节。 |
| 39 | }; | 35 | }; |
| 40 | 36 | ||
| 41 | /** | 37 | /** |
| 42 | * @brief L0 异常 dump 的 kernel 参数槽位类型。 | 38 | * @brief L0 异常 dump 的 kernel 参数槽位类型。 |
| 43 | */ | 39 | */ |
| 44 | -enum Om2L0ArgKind { | 40 | +enum GertModelArgKind : uint64_t { |
| 45 | - OM2_L0_ARG_INPUT = 0, // 输入 Tensor 地址槽位。 | 41 | + GERT_MODEL_ARG_INPUT = 0, // 输入 Tensor 地址槽位。 |
| 46 | - OM2_L0_ARG_OUTPUT = 1, // 输出 Tensor 地址槽位。 | 42 | + GERT_MODEL_ARG_OUTPUT = 1, // 输出 Tensor 地址槽位。 |
| 47 | - OM2_L0_ARG_WORKSPACE = 2, // Workspace 地址槽位。 | 43 | + GERT_MODEL_ARG_WORKSPACE = 2, // Workspace 地址槽位。 |
| 48 | - OM2_L0_ARG_TILING = 3, // Tiling 数据地址槽位。 | 44 | + GERT_MODEL_ARG_TILING = 3, // Tiling 数据地址槽位。 |
| 49 | - OM2_L0_ARG_SHAPE_INFO = 4, // Shape 信息地址槽位。 | 45 | + GERT_MODEL_ARG_SHAPE_INFO = 4, // Shape 信息地址槽位。 |
| 50 | - OM2_L0_ARG_LEVEL1_DESC = 5, // 一级描述信息地址槽位。 | 46 | + GERT_MODEL_ARG_LEVEL1_DESC = 5, // 一级描述信息地址槽位。 |
| 51 | - OM2_L0_ARG_PLACEHOLDER = 6, // 占位地址槽位。 | 47 | + GERT_MODEL_ARG_PLACEHOLDER = 6, // 占位地址槽位。 |
| 52 | - OM2_L0_ARG_CUSTOM_VALUE = 7, // 自定义立即数槽位。 | 48 | + GERT_MODEL_ARG_CUSTOM_VALUE = 7, // 自定义立即数槽位。 |
| 53 | - OM2_L0_ARG_FFTS_ADDR = 8, // FFTS 地址槽位。 | 49 | + GERT_MODEL_ARG_FFTS_ADDR = 8, // FFTS 地址槽位。 |
| 54 | - OM2_L0_ARG_EVENT_ADDR = 9, // Event 地址槽位。 | 50 | + GERT_MODEL_ARG_EVENT_ADDR = 9, // Event 地址槽位。 |
| 55 | - OM2_L0_ARG_OVERFLOW_ADDR = 10, // Overflow 地址槽位。 | 51 | + GERT_MODEL_ARG_OVERFLOW_ADDR = 10, // Overflow 地址槽位。 |
| 56 | - OM2_L0_ARG_EMPTY_ADDR = 11 // 空地址槽位。 | 52 | + GERT_MODEL_ARG_EMPTY_ADDR = 11, // 空地址槽位。 |
| 53 | + GERT_MODEL_ARG_INVALID_KIND = 0xFFFFU | ||
| 57 | }; | 54 | }; |
| 58 | 55 | ||
| 59 | /** | 56 | /** |
| 60 | * @brief L0 异常 dump 的单个 kernel 参数槽位原始信息。 | 57 | * @brief L0 异常 dump 的单个 kernel 参数槽位原始信息。 |
| 61 | */ | 58 | */ |
| 62 | -struct Om2L0ArgSlotInfo { | 59 | +struct GertModelArgSlotInfo { |
| 63 | - uint32_t kind; // 输入,槽位类型,取值见 Om2L0ArgKind。 | 60 | + uint64_t struct_size = sizeof(GertModelArgSlotInfo); // 结构体版本号,布局变化时更新 |
| 64 | - uint32_t flags; // 输入,预留标志位,当前填 0。 | 61 | + GertModelArgKind kind = GERT_MODEL_ARG_INVALID_KIND; // 输入,槽位类型,取值见 GertModelArgKind。 |
| 65 | - uint64_t args_offset; // 输入,槽位在 args buffer 中的偏移,单位为字节。 | 62 | + uint64_t flags = 0; // 输入,预留标志位,当前填 0。 |
| 66 | - uint64_t value; // 输入,槽位附加值。Tiling 或 Shape 信息场景表示数据大小,其他场景按 kind 解释。 | 63 | + uint64_t args_offset = 0; // 输入,槽位在 args buffer 中的偏移,单位为字节。 |
| 67 | - uint32_t related_index; // 输入,关联索引。输入、输出或 Workspace 场景表示对应数组下标。 | 64 | + uint64_t value = 0; // 输入,槽位附加值。Tiling 或 Shape 信息场景表示数据大小,其他场景按 kind 解释。 |
| 68 | - uint32_t event_id; // 输入,Event 场景的事件 ID,非 Event 场景填 0。 | 65 | + uint64_t related_index = 0; // 输入,关联索引。输入、输出或 Workspace 场景表示对应数组下标。 |
| 69 | - uint64_t level1_target_offset; // 输入,一级描述信息指向的目标槽位偏移,单位为字节。 | 66 | + uint64_t event_id = 0; // 输入,Event 场景的事件 ID,非 Event 场景填 0。 |
| 67 | + uint64_t level1_target_offset = 0; // 输入,一级描述信息指向的目标槽位偏移,单位为字节。 | ||
| 70 | }; | 68 | }; |
| 71 | 69 | ||
| 72 | /** | 70 | /** |
| 73 | * @brief L0 异常 dump 的 kernel 参数原始信息列表。 | 71 | * @brief L0 异常 dump 的 kernel 参数原始信息列表。 |
| 74 | */ | 72 | */ |
| 75 | -struct Om2L0TaskRawInfo { | 73 | +struct GertModelTaskRawInfo { |
| 76 | - uint32_t version; // 输入,结构体版本号,当前为 1。 | 74 | + uint64_t struct_size = sizeof(GertModelTaskRawInfo); // 结构体版本号,布局变化时更新 |
| 77 | // 输入,是否需要 assert 或 printf 相关异常 dump,0 表示不需要,非 0 表示需要。 | 75 | // 输入,是否需要 assert 或 printf 相关异常 dump,0 表示不需要,非 0 表示需要。 |
| 78 | - uint32_t need_assert_or_printf; | 76 | + uint64_t need_assert_or_printf = 0; |
| 79 | - uint64_t arg_num; // 输入,args 指向的槽位个数。 | 77 | + uint64_t arg_num = 0; // 输入,args 指向的槽位个数。 |
| 80 | // 输入,槽位信息数组首地址。arg_num 为 0 时可以为空指针。 | 78 | // 输入,槽位信息数组首地址。arg_num 为 0 时可以为空指针。 |
| 81 | - const struct Om2L0ArgSlotInfo *args; | 79 | + const struct GertModelArgSlotInfo *args = nullptr; |
| 82 | }; | 80 | }; |
| 83 | 81 | ||
| 84 | // ============ Task Dump 信息 ============ | 82 | // ============ Task Dump 信息 ============ |
| 85 | /** | 83 | /** |
| 86 | * @brief OM2 算子任务 dump 信息。 | 84 | * @brief OM2 算子任务 dump 信息。 |
| 87 | */ | 85 | */ |
| 88 | -struct Om2TaskInfo { | 86 | +struct GertModelTaskDesc { |
| 87 | + uint64_t struct_size = sizeof(GertModelTaskDesc); // 结构体版本号,布局变化时更新 | ||
| 89 | // 基础信息 | 88 | // 基础信息 |
| 90 | - const char *op_name; // 输入,算子名称,不允许为空。 | 89 | + const char *op_name = nullptr; // 输入,算子名称,不允许为空。 |
| 91 | - const char *op_type; // 输入,算子类型,不允许为空。 | 90 | + const char *op_type = nullptr; // 输入,算子类型,不允许为空。 |
| 92 | - uint32_t task_id; // 输入,运行时 task ID。 | 91 | + uint64_t task_id = 0; // 输入,运行时 task ID。 |
| 93 | - uint32_t stream_id; // 输入,运行时 stream ID。 | 92 | + uint64_t stream_id = 0; // 输入,运行时 stream ID。 |
| 94 | - uint32_t context_id; // 输入,运行时 context ID。 | 93 | + uint64_t context_id = 0; // 输入,运行时 context ID。 |
| 95 | - uint32_t thread_id; // 输入,运行时 thread ID。 | 94 | + uint64_t thread_id = 0; // 输入,运行时 thread ID。 |
| 96 | - uint32_t block_dim; // 输入,Kernel launch block dim,非 Kernel 任务填 0。 | 95 | + uint64_t block_dim = 0; // 输入,Kernel launch block dim,非 Kernel 任务填 0。 |
| 97 | - uint64_t op_desc_id; // 输入,OpDesc ID。 | 96 | + uint64_t op_desc_id = 0; // 输入,OpDesc ID。 |
| 98 | - uintptr_t args_base; // 输入,args buffer 基地址。 | 97 | + uintptr_t args_base = 0; // 输入,args buffer 基地址。 |
| 99 | - uint64_t args_size; // 输入,args buffer 大小,单位为字节。 | 98 | + uint64_t args_size = 0; // 输入,args buffer 大小,单位为字节。 |
| 100 | 99 | ||
| 101 | // 输入输出 | 100 | // 输入输出 |
| 102 | - uint64_t input_num; // 输入,inputs 指向的输入 Tensor 个数。 | 101 | + uint64_t input_num = 0; // 输入,inputs 指向的输入 Tensor 个数。 |
| 103 | // 输入,输入 Tensor 映射数组首地址。input_num 为 0 时可以为空指针。 | 102 | // 输入,输入 Tensor 映射数组首地址。input_num 为 0 时可以为空指针。 |
| 104 | - const struct Om2TaskIoEntry *inputs; | 103 | + const struct GertModelTaskIoEntry *inputs = nullptr; |
| 105 | - uint32_t output_num; // 输入,outputs 指向的输出 Tensor 个数。 | 104 | + uint64_t output_num = 0; // 输入,outputs 指向的输出 Tensor 个数。 |
| 106 | // 输入,输出 Tensor 映射数组首地址。output_num 为 0 时可以为空指针。 | 105 | // 输入,输出 Tensor 映射数组首地址。output_num 为 0 时可以为空指针。 |
| 107 | - const struct Om2TaskIoEntry *outputs; | 106 | + const struct GertModelTaskIoEntry *outputs = nullptr; |
| 108 | 107 | ||
| 109 | // Workspace | 108 | // Workspace |
| 110 | - uint32_t workspace_num; // 输入,Workspace 个数。 | 109 | + uint64_t workspace_num = 0; // 输入,Workspace 个数。 |
| 111 | - const uint64_t *workspace_addrs; // 输入,Workspace 地址数组首地址。workspace_num 为 0 时可以为空指针。 | 110 | + const uint64_t *workspace_addrs = nullptr; // 输入,Workspace 地址数组首地址。workspace_num 为 0 时可以为空指针。 |
| 112 | - const uint64_t *workspace_sizes; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。 | 111 | + const uint64_t *workspace_sizes = |
| 112 | + nullptr; // 输入,Workspace 大小数组首地址,单位为字节。workspace_num 为 0 时可以为空指针。 | ||
| 113 | 113 | ||
| 114 | // 其他 | 114 | // 其他 |
| 115 | - uint32_t task_type; // 输入,任务类型,取值与 ModelTaskType 保持一致。 | 115 | + uint64_t task_type = 0; // 输入,任务类型,取值与 ModelTaskType 保持一致。 |
| 116 | uint64_t kernel_type = 10000U; // 输入,kernel 类型,取值与 ge::ccKernelType 保持一致,默认 INVALID。 | 116 | uint64_t kernel_type = 10000U; // 输入,kernel 类型,取值与 ge::ccKernelType 保持一致,默认 INVALID。 |
| 117 | - void *stream; // 输入,rtStream_t 运行时流句柄。 | 117 | + void *stream = nullptr; // 输入,rtStream_t 运行时流句柄。 |
| 118 | - uint32_t is_raw_address; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。 | 118 | + uint64_t is_raw_address = 0; // 输入,是否为 raw address 模式,0 表示否,非 0 表示是。 |
| 119 | // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。 | 119 | // 输入,L0 异常 dump 原始信息指针。不需要 L0 异常 dump 时可以为空指针。 |
| 120 | - const struct Om2L0TaskRawInfo *l0_exception_dump_info; | 120 | + const struct GertModelTaskRawInfo *task_raw_info = nullptr; |
| 121 | 121 | ||
| 122 | // kernel launch 计时 | 122 | // kernel launch 计时 |
| 123 | - uint64_t launch_begin; // 输入,kernel launch 开始时间戳 | 123 | + uint64_t launch_begin = 0; // 输入,kernel launch 开始时间戳 |
| 124 | 124 | ||
| 125 | // 融合算子信息 | 125 | // 融合算子信息 |
| 126 | - const char *original_op_names; // 输入,分号分隔的原始算子名称列表。非融合算子为 nullptr。 | 126 | + const char *original_op_names = nullptr; // 输入,分号分隔的原始算子名称列表。非融合算子为 nullptr。 |
| 127 | - uint64_t input_mem_size; // 输入,输入内存大小,单位为字节。 | 127 | + uint64_t input_mem_size = 0; // 输入,输入内存大小,单位为字节。 |
| 128 | - uint64_t output_mem_size; // 输入,输出内存大小,单位为字节。 | 128 | + uint64_t output_mem_size = 0; // 输入,输出内存大小,单位为字节。 |
| 129 | - uint64_t workspace_mem_size; // 输入,workspace 内存大小,单位为字节。 | 129 | + uint64_t workspace_mem_size = 0; // 输入,workspace 内存大小,单位为字节。 |
| 130 | - uint64_t weight_mem_size; // 输入,权重内存大小,单位为字节。 | 130 | + uint64_t weight_mem_size = 0; // 输入,权重内存大小,单位为字节。 |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | // ============ Run 阶段回调函数类型定义 ============ | 133 | // ============ Run 阶段回调函数类型定义 ============ |
| @@ -149,21 +149,12 @@ struct GertModelRunCallbacks { | |||
| 149 | 149 | ||
| 150 | // ============ Dump 回调函数入参 struct 的类型定义 ============ | 150 | // ============ Dump 回调函数入参 struct 的类型定义 ============ |
| 151 | 151 | ||
| 152 | -// get_data_dump_enabled 回调入参 | ||
| 153 | -struct GertModelDumpEnabledInfo { | ||
| 154 | - uint64_t struct_size = sizeof(GertModelDumpEnabledInfo); // 布局变化时更新 | ||
| 155 | - const char *op_name = nullptr; // 算子名 | ||
| 156 | - uint64_t enabled = 0; // 输出:是否使能 dump | ||
| 157 | -}; | ||
| 158 | - | ||
| 159 | // GertModelBaseInfo: report_model_base_info 回调入参(codegen → executor 传递 rt_model_handle) | 152 | // GertModelBaseInfo: report_model_base_info 回调入参(codegen → executor 传递 rt_model_handle) |
| 160 | struct GertModelBaseInfo { | 153 | struct GertModelBaseInfo { |
| 161 | uint64_t struct_size = sizeof(GertModelBaseInfo); // 布局变化时更新 | 154 | uint64_t struct_size = sizeof(GertModelBaseInfo); // 布局变化时更新 |
| 162 | const void *rt_model_handle = nullptr; // 输入:codegen 创建的 aclmdlRI*(InitResources 后即可获得) | 155 | const void *rt_model_handle = nullptr; // 输入:codegen 创建的 aclmdlRI*(InitResources 后即可获得) |
| 163 | }; | 156 | }; |
| 164 | 157 | ||
| 165 | -using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info); | ||
| 166 | -using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | ||
| 167 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | 158 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); |
| 168 | 159 | ||
| 169 | // ============ 弱符号接口 ============ | 160 | // ============ 弱符号接口 ============ |
| @@ -176,9 +167,8 @@ using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct | |||
| 176 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 | 167 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 |
| 177 | * @return 返回 0 表示成功,返回其他值表示失败。 | 168 | * @return 返回 0 表示成功,返回其他值表示失败。 |
| 178 | */ | 169 | */ |
| 179 | -int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, | 170 | +int32_t ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info, |
| 180 | - const struct Om2TaskInfo *task_info, const void *extended_attrs, | 171 | + const void *extended_attrs, size_t extended_attrs_size); |
| 181 | - size_t extended_attrs_size); | ||
| 182 | 172 | ||
| 183 | /** | 173 | /** |
| 184 | * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。 | 174 | * @brief 在 OM2 算子任务 launch 后保存 DFX 任务信息。 |
| @@ -189,9 +179,8 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instan | |||
| 189 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 | 179 | * @param extended_attrs_size 输入,预留扩展属性大小,单位为字节,当前必须为 0。 |
| 190 | * @return 返回 0 表示成功,返回其他值表示失败。 | 180 | * @return 返回 0 表示成功,返回其他值表示失败。 |
| 191 | */ | 181 | */ |
| 192 | -int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, | 182 | +int32_t ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info, |
| 193 | - const struct Om2TaskInfo *task_info, const void *extended_attrs, | 183 | + const void *extended_attrs, size_t extended_attrs_size); |
| 194 | - size_t extended_attrs_size); | ||
| 195 | 184 | ||
| 196 | /** | 185 | /** |
| 197 | * @brief 查询指定算子是否需要 Data Dump。 | 186 | * @brief 查询指定算子是否需要 Data Dump。 |
| @@ -201,15 +190,11 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *insta | |||
| 201 | * @param is_data_dump 输出,该算子是否需要 Data Dump,0 表示不需要,1 表示需要。 | 190 | * @param is_data_dump 输出,该算子是否需要 Data Dump,0 表示不需要,1 表示需要。 |
| 202 | * @return 返回 0 表示成功,返回其他值表示失败。 | 191 | * @return 返回 0 表示成功,返回其他值表示失败。 |
| 203 | */ | 192 | */ |
| 204 | -int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, | 193 | +int32_t IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, uint8_t *is_data_dump); |
| 205 | - uint8_t *is_data_dump); | ||
| 206 | 194 | ||
| 207 | -int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info); | 195 | +int32_t ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info); |
| 208 | 196 | ||
| 209 | int32_t ReportRunInfoPreprocess(void *instance_handle, const struct GertModelRunReportInfo *info); | 197 | int32_t ReportRunInfoPreprocess(void *instance_handle, const struct GertModelRunReportInfo *info); |
| 210 | int32_t ReportRunInfoPostprocess(void *instance_handle, const struct GertModelRunReportInfo *info); | 198 | int32_t ReportRunInfoPostprocess(void *instance_handle, const struct GertModelRunReportInfo *info); |
| 211 | -#ifdef __cplusplus | ||
| 212 | -} | ||
| 213 | -#endif | ||
| 214 | 199 | ||
| 215 | #endif // GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_ | 200 | #endif // GE_FRAMEWORK_RUNTIME_DUMP_MODEL_DUMP_C_API_H_ |
| @@ -32,8 +32,8 @@ class ProfilingImpl; | |||
| 32 | // ============================================================ | 32 | // ============================================================ |
| 33 | // 复用 C API 中的结构体定义 | 33 | // 复用 C API 中的结构体定义 |
| 34 | // ============================================================ | 34 | // ============================================================ |
| 35 | -using Om2TaskIoEntry = ::Om2TaskIoEntry; | 35 | +using GertModelTaskIoEntry = ::GertModelTaskIoEntry; |
| 36 | -using Om2TaskInfo = ::Om2TaskInfo; | 36 | +using GertModelTaskDesc = ::GertModelTaskDesc; |
| 37 | 37 | ||
| 38 | // ============================================================ | 38 | // ============================================================ |
| 39 | // ModelDumpManager 内部结构体 | 39 | // ModelDumpManager 内部结构体 |
| @@ -87,9 +87,9 @@ class VISIBILITY_EXPORT ModelDumpManager { | |||
| 87 | // ======================================================================== | 87 | // ======================================================================== |
| 88 | // Task 级信息接口 | 88 | // Task 级信息接口 |
| 89 | // ======================================================================== | 89 | // ======================================================================== |
| 90 | - Status AddOm2TaskInfo(const Om2TaskInfo &task_info); | 90 | + Status AddOm2TaskInfo(const GertModelTaskDesc &task_info); |
| 91 | 91 | ||
| 92 | - Status PreprocessOm2TaskInfo(const Om2TaskInfo &task_info); | 92 | + Status PreprocessOm2TaskInfo(const GertModelTaskDesc &task_info); |
| 93 | 93 | ||
| 94 | Status IsDataDumpEnabled(const char *op_name, uint8_t *is_data_dump) const; | 94 | Status IsDataDumpEnabled(const char *op_name, uint8_t *is_data_dump) const; |
| 95 | 95 | ||
| @@ -24,19 +24,19 @@ class ProfilingImpl { | |||
| 24 | Status ReportModelLoadEnd(const ModelDumpInfo &model_info) const; | 24 | Status ReportModelLoadEnd(const ModelDumpInfo &model_info) const; |
| 25 | Status ReportRunInfoPreprocessImpl(uint64_t model_id, uint64_t step_id, aclrtStream stream) const; | 25 | Status ReportRunInfoPreprocessImpl(uint64_t model_id, uint64_t step_id, aclrtStream stream) const; |
| 26 | Status ReportRunInfoPostprocessImpl(uint64_t model_id, uint64_t step_id, aclrtStream stream) const; | 26 | Status ReportRunInfoPostprocessImpl(uint64_t model_id, uint64_t step_id, aclrtStream stream) const; |
| 27 | - Status SaveTaskInfo(const Om2TaskInfo &task_info, const ModelDumpInfo &model_info) const; | 27 | + Status SaveTaskInfo(const GertModelTaskDesc &task_info, const ModelDumpInfo &model_info) const; |
| 28 | 28 | ||
| 29 | Status RegisterModelToProfilingRuntime(const ModelDumpInfo &model_info) const; | 29 | Status RegisterModelToProfilingRuntime(const ModelDumpInfo &model_info) const; |
| 30 | Status UnregisterModelFromProfilingRuntime(uint32_t model_id) const; | 30 | Status UnregisterModelFromProfilingRuntime(uint32_t model_id) const; |
| 31 | 31 | ||
| 32 | private: | 32 | private: |
| 33 | - Status BuildTaskDescInfo(const Om2TaskInfo &task_info, const ModelDumpInfo &model_info, TaskDescInfo &task_desc_info, | 33 | + Status BuildTaskDescInfo(const GertModelTaskDesc &task_info, const ModelDumpInfo &model_info, |
| 34 | - uint32_t &prof_task_type) const; | 34 | + TaskDescInfo &task_desc_info, uint32_t &prof_task_type) const; |
| 35 | Status ReportTaskDescInfo(const TaskDescInfo &task_desc_info, uint32_t prof_task_type, uint32_t tid) const; | 35 | Status ReportTaskDescInfo(const TaskDescInfo &task_desc_info, uint32_t prof_task_type, uint32_t tid) const; |
| 36 | Status ReportTensorInfo(const TaskDescInfo &task_desc_info, uint32_t tid) const; | 36 | Status ReportTensorInfo(const TaskDescInfo &task_desc_info, uint32_t tid) const; |
| 37 | Status ReportContextIdInfo(const TaskDescInfo &task_desc_info, uint32_t tid) const; | 37 | Status ReportContextIdInfo(const TaskDescInfo &task_desc_info, uint32_t tid) const; |
| 38 | - Status ReportFusionOpInfo(const Om2TaskInfo &task_info, uint32_t model_id) const; | 38 | + Status ReportFusionOpInfo(const GertModelTaskDesc &task_info, uint32_t model_id) const; |
| 39 | - Status ReportLaunchInfo(const Om2TaskInfo &task_info, uint64_t prof_time) const; | 39 | + Status ReportLaunchInfo(const GertModelTaskDesc &task_info, uint64_t prof_time) const; |
| 40 | std::vector<std::string> SplitFusionOpNames(const char *names_str) const; | 40 | std::vector<std::string> SplitFusionOpNames(const char *names_str) const; |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| @@ -53,7 +53,7 @@ struct GertModelTaskLaunchInfo { | |||
| 53 | uint64_t struct_size = sizeof(GertModelTaskLaunchInfo); | 53 | uint64_t struct_size = sizeof(GertModelTaskLaunchInfo); |
| 54 | 54 | ||
| 55 | GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2; | 55 | GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2; |
| 56 | - Om2TaskInfo *task_info = nullptr; | 56 | + GertModelTaskDesc *task_info = nullptr; |
| 57 | const GertModelTaskLaunchParams *launch_params = nullptr; | 57 | const GertModelTaskLaunchParams *launch_params = nullptr; |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| @@ -67,8 +67,8 @@ typedef int32_t (*GertModelLaunchFunc)(void *instance_handle, GertModelTaskLaunc | |||
| 67 | } | 67 | } |
| 68 | #endif | 68 | #endif |
| 69 | 69 | ||
| 70 | -struct GertModelCallbacks { | 70 | +struct GertModelLoadCallbacks { |
| 71 | - uint64_t struct_size = sizeof(GertModelCallbacks); // 布局变化时更新 | 71 | + uint64_t struct_size = sizeof(GertModelLoadCallbacks); // 布局变化时更新 |
| 72 | 72 | ||
| 73 | // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调; | 73 | // codegen 在 InitResources 创建 rt_model_handle 后、Load 前回调; |
| 74 | // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo) | 74 | // executor 收到后完成 ReportModelBaseInfo(组装 ModelDumpInfo → SetModelDumpInfo) |
| @@ -32,7 +32,7 @@ DataDumpImpl::~DataDumpImpl() { | |||
| 32 | Clear(); | 32 | Clear(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -Status DataDumpImpl::SaveTask(const Om2TaskInfo &task_info, ModelTaskType task_type, rtStream_t stream, | 35 | +Status DataDumpImpl::SaveTask(const GertModelTaskDesc &task_info, ModelTaskType task_type, rtStream_t stream, |
| 36 | bool is_op_debug) { | 36 | bool is_op_debug) { |
| 37 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 37 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 38 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; | 38 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; |
| @@ -53,7 +53,7 @@ Status DataDumpImpl::SaveTask(const Om2TaskInfo &task_info, ModelTaskType task_t | |||
| 53 | dump_info.op_type = op_type; | 53 | dump_info.op_type = op_type; |
| 54 | dump_info.is_raw_address = task_info.is_raw_address; | 54 | dump_info.is_raw_address = task_info.is_raw_address; |
| 55 | 55 | ||
| 56 | - const auto copy_io_entries = [](const Om2TaskIoEntry *entries, const uint32_t entry_num, | 56 | + const auto copy_io_entries = [](const GertModelTaskIoEntry *entries, const uint32_t entry_num, |
| 57 | std::vector<InnerTensorInfo> &inner_tensors) -> Status { | 57 | std::vector<InnerTensorInfo> &inner_tensors) -> Status { |
| 58 | if ((entry_num > 0U) && (entries == nullptr)) { | 58 | if ((entry_num > 0U) && (entries == nullptr)) { |
| 59 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task io entries is null, entry_num=%u.", entry_num); | 59 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task io entries is null, entry_num=%u.", entry_num); |
| @@ -36,7 +36,7 @@ uint64_t EncodeL0ArgDesc(uint8_t type, uint64_t value) { | |||
| 36 | return (static_cast<uint64_t>(type) << kBit8Shift) | (value & kL0ArgDescValueMask); | 36 | return (static_cast<uint64_t>(type) << kBit8Shift) | (value & kL0ArgDescValueMask); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -bool IsL0ExceptionDumpEnabled(const Om2L0TaskRawInfo &l0_info) { | 39 | +bool IsL0ExceptionDumpEnabled(const GertModelTaskRawInfo &l0_info) { |
| 40 | return (DumpConfig::Instance().GetDumpScene() == GE_DUMP_EXCEPTION_AIC_ERR_BRIEF) || | 40 | return (DumpConfig::Instance().GetDumpScene() == GE_DUMP_EXCEPTION_AIC_ERR_BRIEF) || |
| 41 | (l0_info.need_assert_or_printf != 0U); | 41 | (l0_info.need_assert_or_printf != 0U); |
| 42 | } | 42 | } |
| @@ -45,7 +45,7 @@ bool IsL1ExceptionDumpEnabled() { | |||
| 45 | return DumpConfig::Instance().GetDumpScene() == GE_DUMP_EXCEPTION_AIC_ERR_NORM; | 45 | return DumpConfig::Instance().GetDumpScene() == GE_DUMP_EXCEPTION_AIC_ERR_NORM; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -Status GetL0InputSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slot, uint64_t &size) { | 48 | +Status GetL0InputSize(const GertModelTaskDesc &task_info, const GertModelArgSlotInfo &slot, uint64_t &size) { |
| 49 | if ((task_info.input_num > 0U) && (task_info.inputs == nullptr)) { | 49 | if ((task_info.input_num > 0U) && (task_info.inputs == nullptr)) { |
| 50 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task input entries is null, input_num=%u.", task_info.input_num); | 50 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task input entries is null, input_num=%u.", task_info.input_num); |
| 51 | return PARAM_INVALID; | 51 | return PARAM_INVALID; |
| @@ -61,7 +61,7 @@ Status GetL0InputSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slot | |||
| 61 | return PARAM_INVALID; | 61 | return PARAM_INVALID; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | -Status GetL0OutputSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slot, uint64_t &size) { | 64 | +Status GetL0OutputSize(const GertModelTaskDesc &task_info, const GertModelArgSlotInfo &slot, uint64_t &size) { |
| 65 | if ((task_info.output_num > 0U) && (task_info.outputs == nullptr)) { | 65 | if ((task_info.output_num > 0U) && (task_info.outputs == nullptr)) { |
| 66 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task output entries is null, output_num=%u.", task_info.output_num); | 66 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 task output entries is null, output_num=%u.", task_info.output_num); |
| 67 | return PARAM_INVALID; | 67 | return PARAM_INVALID; |
| @@ -77,7 +77,7 @@ Status GetL0OutputSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slo | |||
| 77 | return PARAM_INVALID; | 77 | return PARAM_INVALID; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | -Status GetL0WorkspaceSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slot, uint64_t &size) { | 80 | +Status GetL0WorkspaceSize(const GertModelTaskDesc &task_info, const GertModelArgSlotInfo &slot, uint64_t &size) { |
| 81 | if ((task_info.workspace_sizes == nullptr) || (slot.related_index >= task_info.workspace_num)) { | 81 | if ((task_info.workspace_sizes == nullptr) || (slot.related_index >= task_info.workspace_num)) { |
| 82 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 L0 workspace slot index=%u is invalid, workspace_num=%u.", | 82 | GELOGE(PARAM_INVALID, "[Check][Param] OM2 L0 workspace slot index=%u is invalid, workspace_num=%u.", |
| 83 | slot.related_index, task_info.workspace_num); | 83 | slot.related_index, task_info.workspace_num); |
| @@ -87,22 +87,23 @@ Status GetL0WorkspaceSize(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo & | |||
| 87 | return SUCCESS; | 87 | return SUCCESS; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | -Status AppendL0SizeFromRawSlot(const Om2TaskInfo &task_info, const Om2L0ArgSlotInfo &slot, bool need_assert_or_printf, | 90 | +Status AppendL0SizeFromRawSlot(const GertModelTaskDesc &task_info, const GertModelArgSlotInfo &slot, |
| 91 | - bool &has_assert_workspace, std::vector<uint64_t> &l0_size_list) { | 91 | + bool need_assert_or_printf, bool &has_assert_workspace, |
| 92 | + std::vector<uint64_t> &l0_size_list) { | ||
| 92 | switch (slot.kind) { | 93 | switch (slot.kind) { |
| 93 | - case OM2_L0_ARG_INPUT: { | 94 | + case GERT_MODEL_ARG_INPUT: { |
| 94 | uint64_t input_size = 0U; | 95 | uint64_t input_size = 0U; |
| 95 | GE_CHK_STATUS_RET(GetL0InputSize(task_info, slot, input_size)); | 96 | GE_CHK_STATUS_RET(GetL0InputSize(task_info, slot, input_size)); |
| 96 | l0_size_list.emplace_back(input_size); | 97 | l0_size_list.emplace_back(input_size); |
| 97 | return SUCCESS; | 98 | return SUCCESS; |
| 98 | } | 99 | } |
| 99 | - case OM2_L0_ARG_OUTPUT: { | 100 | + case GERT_MODEL_ARG_OUTPUT: { |
| 100 | uint64_t output_size = 0U; | 101 | uint64_t output_size = 0U; |
| 101 | GE_CHK_STATUS_RET(GetL0OutputSize(task_info, slot, output_size)); | 102 | GE_CHK_STATUS_RET(GetL0OutputSize(task_info, slot, output_size)); |
| 102 | l0_size_list.emplace_back(output_size); | 103 | l0_size_list.emplace_back(output_size); |
| 103 | return SUCCESS; | 104 | return SUCCESS; |
| 104 | } | 105 | } |
| 105 | - case OM2_L0_ARG_WORKSPACE: { | 106 | + case GERT_MODEL_ARG_WORKSPACE: { |
| 106 | uint64_t workspace_size = 0U; | 107 | uint64_t workspace_size = 0U; |
| 107 | GE_CHK_STATUS_RET(GetL0WorkspaceSize(task_info, slot, workspace_size)); | 108 | GE_CHK_STATUS_RET(GetL0WorkspaceSize(task_info, slot, workspace_size)); |
| 108 | if (need_assert_or_printf && !has_assert_workspace) { | 109 | if (need_assert_or_printf && !has_assert_workspace) { |
| @@ -112,19 +113,19 @@ Status AppendL0SizeFromRawSlot(const Om2TaskInfo &task_info, const Om2L0ArgSlotI | |||
| 112 | l0_size_list.emplace_back(workspace_size); | 113 | l0_size_list.emplace_back(workspace_size); |
| 113 | return SUCCESS; | 114 | return SUCCESS; |
| 114 | } | 115 | } |
| 115 | - case OM2_L0_ARG_SHAPE_INFO: | 116 | + case GERT_MODEL_ARG_SHAPE_INFO: |
| 116 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeShapeInfo, slot.value)); | 117 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeShapeInfo, slot.value)); |
| 117 | return SUCCESS; | 118 | return SUCCESS; |
| 118 | - case OM2_L0_ARG_TILING: | 119 | + case GERT_MODEL_ARG_TILING: |
| 119 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeTiling, slot.value)); | 120 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeTiling, slot.value)); |
| 120 | return SUCCESS; | 121 | return SUCCESS; |
| 121 | - case OM2_L0_ARG_LEVEL1_DESC: | 122 | + case GERT_MODEL_ARG_LEVEL1_DESC: |
| 122 | - case OM2_L0_ARG_PLACEHOLDER: | 123 | + case GERT_MODEL_ARG_PLACEHOLDER: |
| 123 | - case OM2_L0_ARG_CUSTOM_VALUE: | 124 | + case GERT_MODEL_ARG_CUSTOM_VALUE: |
| 124 | - case OM2_L0_ARG_FFTS_ADDR: | 125 | + case GERT_MODEL_ARG_FFTS_ADDR: |
| 125 | - case OM2_L0_ARG_EVENT_ADDR: | 126 | + case GERT_MODEL_ARG_EVENT_ADDR: |
| 126 | - case OM2_L0_ARG_OVERFLOW_ADDR: | 127 | + case GERT_MODEL_ARG_OVERFLOW_ADDR: |
| 127 | - case OM2_L0_ARG_EMPTY_ADDR: | 128 | + case GERT_MODEL_ARG_EMPTY_ADDR: |
| 128 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeIgnored, 0U)); | 129 | l0_size_list.emplace_back(EncodeL0ArgDesc(kL0ArgDescTypeIgnored, 0U)); |
| 129 | return SUCCESS; | 130 | return SUCCESS; |
| 130 | default: | 131 | default: |
| @@ -133,8 +134,8 @@ Status AppendL0SizeFromRawSlot(const Om2TaskInfo &task_info, const Om2L0ArgSlotI | |||
| 133 | } | 134 | } |
| 134 | } | 135 | } |
| 135 | 136 | ||
| 136 | -Status BuildL0SizeListFromRawInfo(const Om2TaskInfo &task_info, std::vector<uint64_t> &l0_size_list) { | 137 | +Status BuildL0SizeListFromRawInfo(const GertModelTaskDesc &task_info, std::vector<uint64_t> &l0_size_list) { |
| 137 | - const auto *raw_info = task_info.l0_exception_dump_info; | 138 | + const auto *raw_info = task_info.task_raw_info; |
| 138 | if (raw_info == nullptr) { | 139 | if (raw_info == nullptr) { |
| 139 | return SUCCESS; | 140 | return SUCCESS; |
| 140 | } | 141 | } |
| @@ -167,7 +168,7 @@ std::string ToString(const std::vector<T> &vec) { | |||
| 167 | return ss.str(); | 168 | return ss.str(); |
| 168 | } | 169 | } |
| 169 | 170 | ||
| 170 | -void BuildInputTensorInfos(const Om2TaskInfo &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { | 171 | +void BuildInputTensorInfos(const GertModelTaskDesc &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { |
| 171 | for (uint32_t i = 0; i < task_info.input_num; ++i) { | 172 | for (uint32_t i = 0; i < task_info.input_num; ++i) { |
| 172 | if (task_info.inputs != nullptr && task_info.inputs[i].tensor != nullptr) { | 173 | if (task_info.inputs != nullptr && task_info.inputs[i].tensor != nullptr) { |
| 173 | Adx::TensorInfoV2 tensor_info{}; | 174 | Adx::TensorInfoV2 tensor_info{}; |
| @@ -184,7 +185,7 @@ void BuildInputTensorInfos(const Om2TaskInfo &task_info, std::vector<Adx::Tensor | |||
| 184 | } | 185 | } |
| 185 | } | 186 | } |
| 186 | 187 | ||
| 187 | -void BuildOutputTensorInfos(const Om2TaskInfo &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { | 188 | +void BuildOutputTensorInfos(const GertModelTaskDesc &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { |
| 188 | for (uint32_t i = 0; i < task_info.output_num; ++i) { | 189 | for (uint32_t i = 0; i < task_info.output_num; ++i) { |
| 189 | if (task_info.outputs != nullptr && task_info.outputs[i].tensor != nullptr) { | 190 | if (task_info.outputs != nullptr && task_info.outputs[i].tensor != nullptr) { |
| 190 | Adx::TensorInfoV2 tensor_info{}; | 191 | Adx::TensorInfoV2 tensor_info{}; |
| @@ -201,7 +202,7 @@ void BuildOutputTensorInfos(const Om2TaskInfo &task_info, std::vector<Adx::Tenso | |||
| 201 | } | 202 | } |
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | -void BuildWorkspaceTensorInfos(const Om2TaskInfo &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { | 205 | +void BuildWorkspaceTensorInfos(const GertModelTaskDesc &task_info, std::vector<Adx::TensorInfoV2> &tensor_infos) { |
| 205 | for (uint32_t i = 0; i < task_info.workspace_num; ++i) { | 206 | for (uint32_t i = 0; i < task_info.workspace_num; ++i) { |
| 206 | if (task_info.workspace_sizes != nullptr) { | 207 | if (task_info.workspace_sizes != nullptr) { |
| 207 | Adx::TensorInfoV2 tensor_info{}; | 208 | Adx::TensorInfoV2 tensor_info{}; |
| @@ -223,9 +224,9 @@ ExceptionDumpImpl::ExceptionDumpImpl(uint32_t device_id) : device_id_(device_id) | |||
| 223 | 224 | ||
| 224 | ExceptionDumpImpl::~ExceptionDumpImpl() = default; | 225 | ExceptionDumpImpl::~ExceptionDumpImpl() = default; |
| 225 | 226 | ||
| 226 | -Status ExceptionDumpImpl::ReportL0ExceptionDumpInfo(const Om2TaskInfo &task_info) const { | 227 | +Status ExceptionDumpImpl::ReportL0ExceptionDumpInfo(const GertModelTaskDesc &task_info) const { |
| 227 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 228 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 228 | - const auto *raw_info = task_info.l0_exception_dump_info; | 229 | + const auto *raw_info = task_info.task_raw_info; |
| 229 | if (raw_info == nullptr) { | 230 | if (raw_info == nullptr) { |
| 230 | GELOGD("OM2 L0 exception dump raw info is null, skip op=%s", op_name); | 231 | GELOGD("OM2 L0 exception dump raw info is null, skip op=%s", op_name); |
| 231 | return SUCCESS; | 232 | return SUCCESS; |
| @@ -268,7 +269,7 @@ Status ExceptionDumpImpl::ReportL0ExceptionDumpInfo(const Om2TaskInfo &task_info | |||
| 268 | return SUCCESS; | 269 | return SUCCESS; |
| 269 | } | 270 | } |
| 270 | 271 | ||
| 271 | -Status ExceptionDumpImpl::SaveOpInfo(const Om2TaskInfo &task_info) { | 272 | +Status ExceptionDumpImpl::SaveOpInfo(const GertModelTaskDesc &task_info) { |
| 272 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 273 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 273 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; | 274 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; |
| 274 | GELOGD("SaveOpInfo: op_name=%s, task_id=%u, stream_id=%u, context_id=%u, device_id=%u, thread_id=%u", op_name, | 275 | GELOGD("SaveOpInfo: op_name=%s, task_id=%u, stream_id=%u, context_id=%u, device_id=%u, thread_id=%u", op_name, |
| @@ -376,7 +377,7 @@ bool ExceptionDumpImpl::GetOpDescInfo(const OpDescInfoId &op_id, OpDescInfo &op_ | |||
| 376 | op_id.device_id); | 377 | op_id.device_id); |
| 377 | op_info = dump_op_info; | 378 | op_info = dump_op_info; |
| 378 | // Note: OM2 doesn't need RefreshAddrs because device_address is already a real device | 379 | // Note: OM2 doesn't need RefreshAddrs because device_address is already a real device |
| 379 | - // address passed in by Runtime through Om2TaskInfo, not a pointer offset that needs | 380 | + // address passed in by Runtime through GertModelTaskDesc, not a pointer offset that needs |
| 380 | // to be resolved from args. | 381 | // to be resolved from args. |
| 381 | return true; | 382 | return true; |
| 382 | } | 383 | } |
| @@ -384,7 +385,8 @@ bool ExceptionDumpImpl::GetOpDescInfo(const OpDescInfoId &op_id, OpDescInfo &op_ | |||
| 384 | return false; | 385 | return false; |
| 385 | } | 386 | } |
| 386 | 387 | ||
| 387 | -Status ExceptionDumpImpl::ReportL1ExceptionDumpInfo(const Om2TaskInfo &task_info, const OpDescInfo &op_info) const { | 388 | +Status ExceptionDumpImpl::ReportL1ExceptionDumpInfo(const GertModelTaskDesc &task_info, |
| 389 | + const OpDescInfo &op_info) const { | ||
| 388 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 390 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 389 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; | 391 | const char *op_type = (task_info.op_type != nullptr) ? task_info.op_type : ""; |
| 390 | GELOGD("ReportL1ExceptionDumpInfo: op_name=%s, task_id=%u", op_name, task_info.task_id); | 392 | GELOGD("ReportL1ExceptionDumpInfo: op_name=%s, task_id=%u", op_name, task_info.task_id); |
| @@ -432,8 +434,8 @@ void ExceptionDumpImpl::FillAdumpOpInfoBuilder(const OpDescInfo &op_info, std::v | |||
| 432 | .DeviceInfo(Adx::DEVICE_INFO_NAME_ARGS, reinterpret_cast<void *>(op_info.args), op_info.args_size); | 434 | .DeviceInfo(Adx::DEVICE_INFO_NAME_ARGS, reinterpret_cast<void *>(op_info.args), op_info.args_size); |
| 433 | } | 435 | } |
| 434 | 436 | ||
| 435 | -Status ExceptionDumpImpl::SubmitToAdump(const char *op_name, const Om2TaskInfo &task_info, const OpDescInfo &op_info, | 437 | +Status ExceptionDumpImpl::SubmitToAdump(const char *op_name, const GertModelTaskDesc &task_info, |
| 436 | - std::vector<Adx::TensorInfoV2> &input_infos, | 438 | + const OpDescInfo &op_info, std::vector<Adx::TensorInfoV2> &input_infos, |
| 437 | std::vector<Adx::TensorInfoV2> &output_infos, | 439 | std::vector<Adx::TensorInfoV2> &output_infos, |
| 438 | std::vector<Adx::TensorInfoV2> &workspace_infos, | 440 | std::vector<Adx::TensorInfoV2> &workspace_infos, |
| 439 | const AdumpOpInfoBuilder &builder) const { | 441 | const AdumpOpInfoBuilder &builder) const { |
| @@ -27,11 +27,8 @@ ge::dump::ModelDumpManager *GetDumpManager(void *instance_handle) { | |||
| 27 | } | 27 | } |
| 28 | } // namespace | 28 | } // namespace |
| 29 | 29 | ||
| 30 | -// 对外暴露的 C API 函数,需要 extern "C" 确保 C 链接 | 30 | +int32_t ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info, |
| 31 | -extern "C" { | 31 | + const void *extended_attrs, size_t extended_attrs_size) { |
| 32 | -int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instance_handle, | ||
| 33 | - const struct Om2TaskInfo *task_info, const void *extended_attrs, | ||
| 34 | - size_t extended_attrs_size) { | ||
| 35 | (void)model_id; | 32 | (void)model_id; |
| 36 | 33 | ||
| 37 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { | 34 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { |
| @@ -51,9 +48,8 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPreprocess(uint32_t model_id, void *instan | |||
| 51 | return static_cast<int32_t>(manager->PreprocessOm2TaskInfo(*task_info)); | 48 | return static_cast<int32_t>(manager->PreprocessOm2TaskInfo(*task_info)); |
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | -int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, | 51 | +int32_t ReportDfxTaskPostprocess(uint32_t model_id, void *instance_handle, const struct GertModelTaskDesc *task_info, |
| 55 | - const struct Om2TaskInfo *task_info, const void *extended_attrs, | 52 | + const void *extended_attrs, size_t extended_attrs_size) { |
| 56 | - size_t extended_attrs_size) { | ||
| 57 | (void)model_id; | 53 | (void)model_id; |
| 58 | 54 | ||
| 59 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { | 55 | if ((extended_attrs != nullptr) || (extended_attrs_size != 0U)) { |
| @@ -73,8 +69,7 @@ int32_t OM2_C_API_EXPORT ReportDfxTaskPostprocess(uint32_t model_id, void *insta | |||
| 73 | return static_cast<int32_t>(manager->AddOm2TaskInfo(*task_info)); | 69 | return static_cast<int32_t>(manager->AddOm2TaskInfo(*task_info)); |
| 74 | } | 70 | } |
| 75 | 71 | ||
| 76 | -int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, | 72 | +int32_t IsDataDumpEnabled(uint32_t model_id, void *instance_handle, const char *op_name, uint8_t *is_data_dump) { |
| 77 | - uint8_t *is_data_dump) { | ||
| 78 | (void)model_id; | 73 | (void)model_id; |
| 79 | 74 | ||
| 80 | if ((instance_handle == nullptr) || (is_data_dump == nullptr)) { | 75 | if ((instance_handle == nullptr) || (is_data_dump == nullptr)) { |
| @@ -90,8 +85,8 @@ int32_t OM2_C_API_EXPORT IsDataDumpEnabled(uint32_t model_id, void *instance_han | |||
| 90 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); | 85 | return static_cast<int32_t>(manager->IsDataDumpEnabled(op_name, is_data_dump)); |
| 91 | } | 86 | } |
| 92 | 87 | ||
| 93 | -int32_t OM2_C_API_EXPORT ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info) { | 88 | +int32_t ReportModelBaseInfo(void *instance_handle, const struct GertModelBaseInfo *info) { |
| 94 | - if ((instance_handle == nullptr)) { | 89 | + if (instance_handle == nullptr) { |
| 95 | GELOGW("ModelExecutor handle is null, skip"); | 90 | GELOGW("ModelExecutor handle is null, skip"); |
| 96 | return ge::SUCCESS; | 91 | return ge::SUCCESS; |
| 97 | } | 92 | } |
| @@ -143,5 +138,3 @@ int32_t ReportRunInfoPostprocess(void *instance_handle, const struct GertModelRu | |||
| 143 | mgr->ReportRunInfoPostprocess(info->model_id, step_id, stream); | 138 | mgr->ReportRunInfoPostprocess(info->model_id, step_id, stream); |
| 144 | return 0; | 139 | return 0; |
| 145 | } | 140 | } |
| 146 | - | ||
| 147 | -} // extern "C" | ||
| @@ -130,11 +130,11 @@ Status ModelDumpManager::IsDataDumpEnabled(const char *op_name, uint8_t *is_data | |||
| 130 | return SUCCESS; | 130 | return SUCCESS; |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | -Status ModelDumpManager::PreprocessOm2TaskInfo(const Om2TaskInfo &task_info) { | 133 | +Status ModelDumpManager::PreprocessOm2TaskInfo(const GertModelTaskDesc &task_info) { |
| 134 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 134 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 135 | GELOGD("PreprocessOm2TaskInfo: op_name=%s, stream_id=%u", op_name, task_info.stream_id); | 135 | GELOGD("PreprocessOm2TaskInfo: op_name=%s, stream_id=%u", op_name, task_info.stream_id); |
| 136 | 136 | ||
| 137 | - if (task_info.l0_exception_dump_info == nullptr) { | 137 | + if (task_info.task_raw_info == nullptr) { |
| 138 | return SUCCESS; | 138 | return SUCCESS; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| @@ -146,7 +146,7 @@ Status ModelDumpManager::PreprocessOm2TaskInfo(const Om2TaskInfo &task_info) { | |||
| 146 | return SUCCESS; | 146 | return SUCCESS; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | -Status ModelDumpManager::AddOm2TaskInfo(const Om2TaskInfo &task_info) { | 149 | +Status ModelDumpManager::AddOm2TaskInfo(const GertModelTaskDesc &task_info) { |
| 150 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 150 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 151 | GELOGD("AddOm2TaskInfo: op_name=%s, task_id=%u, stream_id=%u", op_name, task_info.task_id, task_info.stream_id); | 151 | GELOGD("AddOm2TaskInfo: op_name=%s, task_id=%u, stream_id=%u", op_name, task_info.task_id, task_info.stream_id); |
| 152 | 152 | ||
| @@ -108,7 +108,7 @@ void BuildSingleTensorInfo(const TaskDescInfo &task_desc_info, uint32_t tid, siz | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | -void AppendTensorInfo(const Om2TaskIoEntry *entries, uint64_t entry_num, const char *op_name, | 111 | +void AppendTensorInfo(const GertModelTaskIoEntry *entries, uint64_t entry_num, const char *op_name, |
| 112 | std::vector<Format> &formats, std::vector<DataType> &data_types, | 112 | std::vector<Format> &formats, std::vector<DataType> &data_types, |
| 113 | std::vector<std::vector<int64_t>> &shapes) { | 113 | std::vector<std::vector<int64_t>> &shapes) { |
| 114 | if (entries == nullptr) { | 114 | if (entries == nullptr) { |
| @@ -212,7 +212,7 @@ Status ProfilingImpl::ReportModelLoadEnd(const ModelDumpInfo &model_info) const | |||
| 212 | return CheckMsprofRet(MsprofReportEvent(kNonAgingFlag, &model_load_event), "Report model load end", model_name); | 212 | return CheckMsprofRet(MsprofReportEvent(kNonAgingFlag, &model_load_event), "Report model load end", model_name); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | -Status ProfilingImpl::SaveTaskInfo(const Om2TaskInfo &task_info, const ModelDumpInfo &model_info) const { | 215 | +Status ProfilingImpl::SaveTaskInfo(const GertModelTaskDesc &task_info, const ModelDumpInfo &model_info) const { |
| 216 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; | 216 | const char *op_name = (task_info.op_name != nullptr) ? task_info.op_name : ""; |
| 217 | if (!ProfilingConfig::Instance().IsTaskReportEnabled()) { | 217 | if (!ProfilingConfig::Instance().IsTaskReportEnabled()) { |
| 218 | GELOGD("Skip saving OM2 profiling task info, task profiling disabled, op_name=%s, task_type=%u", op_name, | 218 | GELOGD("Skip saving OM2 profiling task info, task profiling disabled, op_name=%s, task_type=%u", op_name, |
| @@ -240,7 +240,7 @@ Status ProfilingImpl::SaveTaskInfo(const Om2TaskInfo &task_info, const ModelDump | |||
| 240 | return SUCCESS; | 240 | return SUCCESS; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | -Status ProfilingImpl::BuildTaskDescInfo(const Om2TaskInfo &task_info, const ModelDumpInfo &model_info, | 243 | +Status ProfilingImpl::BuildTaskDescInfo(const GertModelTaskDesc &task_info, const ModelDumpInfo &model_info, |
| 244 | TaskDescInfo &task_desc_info, uint32_t &prof_task_type) const { | 244 | TaskDescInfo &task_desc_info, uint32_t &prof_task_type) const { |
| 245 | const auto model_task_type = static_cast<ModelTaskType>(task_info.task_type); | 245 | const auto model_task_type = static_cast<ModelTaskType>(task_info.task_type); |
| 246 | const auto iter = kModelTaskTypeToProfTaskType.find(model_task_type); | 246 | const auto iter = kModelTaskTypeToProfTaskType.find(model_task_type); |
| @@ -440,7 +440,7 @@ Status ProfilingImpl::ReportRunInfoPostprocessImpl(uint64_t model_id, uint64_t s | |||
| 440 | return SUCCESS; | 440 | return SUCCESS; |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | -Status ProfilingImpl::ReportLaunchInfo(const Om2TaskInfo &task_info, uint64_t prof_time) const { | 443 | +Status ProfilingImpl::ReportLaunchInfo(const GertModelTaskDesc &task_info, uint64_t prof_time) const { |
| 444 | if (task_info.launch_begin == 0U) { | 444 | if (task_info.launch_begin == 0U) { |
| 445 | if (task_info.op_name != nullptr) { | 445 | if (task_info.op_name != nullptr) { |
| 446 | GELOGD("[OM2][Prof] Launch timing not recorded, op_name=%s", task_info.op_name); | 446 | GELOGD("[OM2][Prof] Launch timing not recorded, op_name=%s", task_info.op_name); |
| @@ -462,7 +462,7 @@ Status ProfilingImpl::ReportLaunchInfo(const Om2TaskInfo &task_info, uint64_t pr | |||
| 462 | return CheckMsprofRet(MsprofReportApi(kNonAgingFlag, &api), "ReportLaunchInfo", op_name); | 462 | return CheckMsprofRet(MsprofReportApi(kNonAgingFlag, &api), "ReportLaunchInfo", op_name); |
| 463 | } | 463 | } |
| 464 | 464 | ||
| 465 | -Status ProfilingImpl::ReportFusionOpInfo(const Om2TaskInfo &task_info, uint32_t model_id) const { | 465 | +Status ProfilingImpl::ReportFusionOpInfo(const GertModelTaskDesc &task_info, uint32_t model_id) const { |
| 466 | if (task_info.original_op_names == nullptr) { | 466 | if (task_info.original_op_names == nullptr) { |
| 467 | return SUCCESS; // 非融合算子,跳过 | 467 | return SUCCESS; // 非融合算子,跳过 |
| 468 | } | 468 | } |
| @@ -27,11 +27,11 @@ | |||
| 27 | 27 | ||
| 28 | namespace { | 28 | namespace { |
| 29 | 29 | ||
| 30 | -const char *GetTaskOpName(const Om2TaskInfo *task_info) { | 30 | +const char *GetTaskOpName(const GertModelTaskDesc *task_info) { |
| 31 | return (task_info != nullptr) && (task_info->op_name != nullptr) ? task_info->op_name : ""; | 31 | return (task_info != nullptr) && (task_info->op_name != nullptr) ? task_info->op_name : ""; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | -const char *GetTaskOpType(const Om2TaskInfo *task_info) { | 34 | +const char *GetTaskOpType(const GertModelTaskDesc *task_info) { |
| 35 | return (task_info != nullptr) && (task_info->op_type != nullptr) ? task_info->op_type : ""; | 35 | return (task_info != nullptr) && (task_info->op_type != nullptr) ? task_info->op_type : ""; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -42,7 +42,7 @@ uint32_t GetModelId(void *instance_handle) { | |||
| 42 | return static_cast<gert::Om2ModelExecutor *>(instance_handle)->GetModelId(); | 42 | return static_cast<gert::Om2ModelExecutor *>(instance_handle)->GetModelId(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | -int32_t GetDataDumpEnabled(const Om2TaskInfo &task_info, void *instance_handle, uint8_t &is_data_dump) { | 45 | +int32_t GetDataDumpEnabled(const GertModelTaskDesc &task_info, void *instance_handle, uint8_t &is_data_dump) { |
| 46 | if (instance_handle == nullptr) { | 46 | if (instance_handle == nullptr) { |
| 47 | return ge::SUCCESS; | 47 | return ge::SUCCESS; |
| 48 | } | 48 | } |
| @@ -69,7 +69,7 @@ void SetDataDumpAttr(aclrtLaunchKernelCfg *config, uint8_t is_data_dump) { | |||
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | -bool IsAicoreTask(const Om2TaskInfo &task_info) { | 72 | +bool IsAicoreTask(const GertModelTaskDesc &task_info) { |
| 73 | const auto task_type = static_cast<ge::ModelTaskType>(task_info.task_type); | 73 | const auto task_type = static_cast<ge::ModelTaskType>(task_info.task_type); |
| 74 | const auto kernel_type = static_cast<ge::ccKernelType>(task_info.kernel_type); | 74 | const auto kernel_type = static_cast<ge::ccKernelType>(task_info.kernel_type); |
| 75 | const bool is_all_kernel = (task_type == ge::ModelTaskType::MODEL_TASK_ALL_KERNEL) || | 75 | const bool is_all_kernel = (task_type == ge::ModelTaskType::MODEL_TASK_ALL_KERNEL) || |
| @@ -80,7 +80,7 @@ bool IsAicoreTask(const Om2TaskInfo &task_info) { | |||
| 80 | return is_all_kernel || is_aicore_kernel; | 80 | return is_all_kernel || is_aicore_kernel; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | -int32_t ReportTaskPreprocess(void *instance_handle, Om2TaskInfo *task_info) { | 83 | +int32_t ReportTaskPreprocess(void *instance_handle, GertModelTaskDesc *task_info) { |
| 84 | const auto kernel_type = static_cast<ge::ccKernelType>(task_info->kernel_type); | 84 | const auto kernel_type = static_cast<ge::ccKernelType>(task_info->kernel_type); |
| 85 | if (instance_handle == nullptr) { | 85 | if (instance_handle == nullptr) { |
| 86 | GELOGW("[OM2] ModelExecutor handle is null, skip preprocess."); | 86 | GELOGW("[OM2] ModelExecutor handle is null, skip preprocess."); |
| @@ -124,12 +124,14 @@ int32_t LaunchKernelV2Task(void *instance_handle, GertModelTaskLaunchInfo *launc | |||
| 124 | return ge::SUCCESS; | 124 | return ge::SUCCESS; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | -int32_t ReportTaskPostprocess(void *instance_handle, Om2TaskInfo *task_info) { | 127 | +int32_t ReportTaskPostprocess(void *instance_handle, GertModelTaskDesc *task_info) { |
| 128 | - const auto task_id_ret = aclrtGetThreadLastTaskId(&task_info->task_id); | 128 | + uint32_t task_id; |
| 129 | + const auto task_id_ret = aclrtGetThreadLastTaskId(&task_id); | ||
| 129 | GE_RETURN_WITH_LOG_IF_ERROR( | 130 | GE_RETURN_WITH_LOG_IF_ERROR( |
| 130 | task_id_ret, "[OM2] aclrtGetThreadLastTaskId failed, model_id=%u, op_name=%s, op_type=%s, thread_id=%u, ret=%d.", | 131 | task_id_ret, "[OM2] aclrtGetThreadLastTaskId failed, model_id=%u, op_name=%s, op_type=%s, thread_id=%u, ret=%d.", |
| 131 | GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), task_info->thread_id, | 132 | GetModelId(instance_handle), GetTaskOpName(task_info), GetTaskOpType(task_info), task_info->thread_id, |
| 132 | task_id_ret); | 133 | task_id_ret); |
| 134 | + task_info->task_id = task_id; | ||
| 133 | 135 | ||
| 134 | if (instance_handle == nullptr) { | 136 | if (instance_handle == nullptr) { |
| 135 | GELOGW("[OM2] ModelExecutor handle is null, skip postprocess."); | 137 | GELOGW("[OM2] ModelExecutor handle is null, skip postprocess."); |
| @@ -57,20 +57,30 @@ constexpr uint8_t OM2_MAGIC[] = {0x50, 0x4B, 0x03, 0x04}; | |||
| 57 | using GertModelHandle = void *; | 57 | using GertModelHandle = void *; |
| 58 | 58 | ||
| 59 | // 入参合并为结构体:首字段 struct_size 版本号,新字段只能追加;整数类型统一 uint64_t | 59 | // 入参合并为结构体:首字段 struct_size 版本号,新字段只能追加;整数类型统一 uint64_t |
| 60 | -struct GertModelLoadConfig { // 合并 Create+Load:容纳原 Om2ModelCreate 全部参数 | 60 | +struct GertModelLoadConfig { // 合并 Create+Load:容纳原 Om2ModelCreate 全部参数 |
| 61 | - uint64_t struct_size = sizeof(GertModelLoadConfig); // 布局变化时更新 | 61 | + uint64_t struct_size = sizeof(GertModelLoadConfig); // 布局变化时更新 |
| 62 | - const char **bin_files = nullptr; // 输入:bin 文件路径列表 | 62 | + const char **bin_files = nullptr; // 输入:bin 文件路径列表 |
| 63 | - const void **bin_data = nullptr; // 输入:bin 内存数据列表 | 63 | + const void **bin_data = nullptr; // 输入:bin 内存数据列表 |
| 64 | - uint64_t *bin_size = nullptr; // 输入:bin 大小列表 | 64 | + uint64_t *bin_size = nullptr; // 输入:bin 大小列表 |
| 65 | - uint64_t bin_num = 0; // 输入:bin 数量 | 65 | + uint64_t bin_num = 0; // 输入:bin 数量 |
| 66 | - void **constants = nullptr; // 输入:常量 | 66 | + void **constants = nullptr; // 输入:常量 |
| 67 | - void **var_addrs = nullptr; // 输入:vars | 67 | + void **var_addrs = nullptr; // 输入:vars |
| 68 | - void *work_ptr = nullptr; // 输入:工作内存指针 | 68 | + void *work_ptr = nullptr; // 输入:工作内存指针 |
| 69 | - uint64_t *session_id = nullptr; // 输入:session id | 69 | + uint64_t *session_id = nullptr; // 输入:session id |
| 70 | - uint64_t model_id = 0; // 输入:model id,打印日志用 | 70 | + uint64_t model_id = 0; // 输入:model id,打印日志用 |
| 71 | - void *instance_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数 | 71 | + void *instance_handle = nullptr; // Om2ModelExecutor*,回调函数的首参数 |
| 72 | - const struct GertModelCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump) | 72 | + const struct GertModelLoadCallbacks *callbacks = nullptr; // 输入:dump 回调表,可空(nullptr = 不使能 dump) |
| 73 | - int64_t priority = 0; // 输入:优先级 | 73 | + int64_t priority = 0; // 输入:优先级 |
| 74 | + uint64_t reuse_zero_copy = 0; // 输入:是否复用零拷贝内存 | ||
| 75 | + aclmdlRI external_rt_model = nullptr; // 输入:外部创建的 rtModel,可空(nullptr = pbody 自行创建) | ||
| 76 | + aclrtStream *external_streams = nullptr; // 输入:外部创建的 stream 数组,可空 | ||
| 77 | + uint64_t external_stream_num = 0; // 输入:外部 stream 数量 | ||
| 78 | + aclrtEvent *external_events = nullptr; // 输入:外部创建的 event 数组,可空 | ||
| 79 | + uint64_t external_event_num = 0; // 输入:外部 event 数量 | ||
| 80 | + aclrtLabel *external_labels = nullptr; // 输入:外部创建的 label 数组,可空 | ||
| 81 | + uint64_t external_label_num = 0; // 输入:外部 label 数量 | ||
| 82 | + aclrtNotify *external_notifies = nullptr; // 输入:外部创建的 notify 数组,可空 | ||
| 83 | + uint64_t external_notify_num = 0; // 输入:外部 notify 数量 | ||
| 74 | }; | 84 | }; |
| 75 | 85 | ||
| 76 | struct GertModelRunConfig { | 86 | struct GertModelRunConfig { |
| @@ -1144,14 +1154,12 @@ class Om2ModelExecutor::Impl { | |||
| 1144 | std::vector<const char *> bin_files(kernel_bin_info.size()); | 1154 | std::vector<const char *> bin_files(kernel_bin_info.size()); |
| 1145 | std::vector<const void *> bin_data(kernel_bin_info.size()); | 1155 | std::vector<const void *> bin_data(kernel_bin_info.size()); |
| 1146 | std::vector<uint64_t> bin_sizes(kernel_bin_info.size()); | 1156 | std::vector<uint64_t> bin_sizes(kernel_bin_info.size()); |
| 1147 | - void *work_ptr = nullptr; | ||
| 1148 | for (auto i = 0U; i < kernel_bin_info.size(); ++i) { | 1157 | for (auto i = 0U; i < kernel_bin_info.size(); ++i) { |
| 1149 | bin_files[i] = kernel_bin_info[i].file.c_str(); | 1158 | bin_files[i] = kernel_bin_info[i].file.c_str(); |
| 1150 | bin_data[i] = kernel_bin_info[i].data.get(); | 1159 | bin_data[i] = kernel_bin_info[i].data.get(); |
| 1151 | bin_sizes[i] = kernel_bin_info[i].data_size; | 1160 | bin_sizes[i] = kernel_bin_info[i].data_size; |
| 1152 | } | 1161 | } |
| 1153 | session_id_ = session_id; | 1162 | session_id_ = session_id; |
| 1154 | - GE_ASSERT_SUCCESS(PrepareWorkPtr(load_arg, work_ptr)); | ||
| 1155 | GE_ASSERT_SUCCESS(PrepareConstantsFromStruct(model_data.constants_data, weight_buf, load_arg, constants)); | 1163 | GE_ASSERT_SUCCESS(PrepareConstantsFromStruct(model_data.constants_data, weight_buf, load_arg, constants)); |
| 1156 | if (model_data.rt_var_resource != nullptr) { | 1164 | if (model_data.rt_var_resource != nullptr) { |
| 1157 | auto var_manager = Om2RTVarManagerPool::Instance().GetManager(session_id); | 1165 | auto var_manager = Om2RTVarManagerPool::Instance().GetManager(session_id); |
| @@ -1170,9 +1178,9 @@ class Om2ModelExecutor::Impl { | |||
| 1170 | GE_ASSERT_SUCCESS(PrepareVarAddrs(model_data, static_cast<uint32_t>(load_arg.device_id), var_addrs)); | 1178 | GE_ASSERT_SUCCESS(PrepareVarAddrs(model_data, static_cast<uint32_t>(load_arg.device_id), var_addrs)); |
| 1171 | 1179 | ||
| 1172 | GE_ASSERT_NOTNULL(run_model_info_.load_func); | 1180 | GE_ASSERT_NOTNULL(run_model_info_.load_func); |
| 1173 | - GertModelCallbacks callbacks = {.struct_size = sizeof(GertModelCallbacks), | 1181 | + GertModelLoadCallbacks callbacks = {.struct_size = sizeof(GertModelLoadCallbacks), |
| 1174 | - .report_model_base_info = ReportModelBaseInfo, | 1182 | + .report_model_base_info = ReportModelBaseInfo, |
| 1175 | - .launch_func = GertModelLaunchTask}; | 1183 | + .launch_func = GertModelLaunchTask}; |
| 1176 | struct GertModelLoadConfig config = {.struct_size = sizeof(GertModelLoadConfig), | 1184 | struct GertModelLoadConfig config = {.struct_size = sizeof(GertModelLoadConfig), |
| 1177 | .bin_files = bin_files.data(), | 1185 | .bin_files = bin_files.data(), |
| 1178 | .bin_data = bin_data.data(), | 1186 | .bin_data = bin_data.data(), |
| @@ -1180,12 +1188,13 @@ class Om2ModelExecutor::Impl { | |||
| 1180 | .bin_num = bin_data.size(), | 1188 | .bin_num = bin_data.size(), |
| 1181 | .constants = constants.empty() ? nullptr : constants.data(), | 1189 | .constants = constants.empty() ? nullptr : constants.data(), |
| 1182 | .var_addrs = var_addrs.empty() ? nullptr : var_addrs.data(), | 1190 | .var_addrs = var_addrs.empty() ? nullptr : var_addrs.data(), |
| 1183 | - .work_ptr = work_ptr, | 1191 | + .work_ptr = load_arg.work_ptr, |
| 1184 | .session_id = &session_id_, | 1192 | .session_id = &session_id_, |
| 1185 | .model_id = load_arg.model_id, | 1193 | .model_id = load_arg.model_id, |
| 1186 | .instance_handle = static_cast<void *>(owner_), | 1194 | .instance_handle = static_cast<void *>(owner_), |
| 1187 | .callbacks = &callbacks, | 1195 | .callbacks = &callbacks, |
| 1188 | - .priority = load_arg.priority}; | 1196 | + .priority = load_arg.priority, |
| 1197 | + .reuse_zero_copy = load_arg.reuse_zero_copy ? 1U : 0U}; | ||
| 1189 | GE_ASSERT_SUCCESS(run_model_info_.load_func(&config, &run_model_info_.model_handle, nullptr)); | 1198 | GE_ASSERT_SUCCESS(run_model_info_.load_func(&config, &run_model_info_.model_handle, nullptr)); |
| 1190 | GE_ASSERT_NOTNULL(run_model_info_.model_handle); | 1199 | GE_ASSERT_NOTNULL(run_model_info_.model_handle); |
| 1191 | 1200 | ||
| @@ -1577,23 +1586,6 @@ class Om2ModelExecutor::Impl { | |||
| 1577 | } | 1586 | } |
| 1578 | 1587 | ||
| 1579 | private: | 1588 | private: |
| 1580 | - ge::Status PrepareWorkPtr(const Om2ModelLoadArg &load_arg, void *&work_ptr) { | ||
| 1581 | - const size_t required_work_size = load_arg.reuse_zero_copy | ||
| 1582 | - ? model_meta_info_.work_size - model_meta_info_.zero_copy_size | ||
| 1583 | - : model_meta_info_.work_size; | ||
| 1584 | - if (load_arg.work_ptr != nullptr) { | ||
| 1585 | - work_ptr = load_arg.work_ptr; | ||
| 1586 | - return ge::SUCCESS; | ||
| 1587 | - } | ||
| 1588 | - void *inner_work_ptr = nullptr; | ||
| 1589 | - GE_ASSERT_SUCCESS(RtMallocBuffer(required_work_size, inner_work_ptr)); | ||
| 1590 | - if (inner_work_ptr != nullptr) { | ||
| 1591 | - owned_buffers_.push_back(inner_work_ptr); | ||
| 1592 | - } | ||
| 1593 | - work_ptr = inner_work_ptr; | ||
| 1594 | - return ge::SUCCESS; | ||
| 1595 | - } | ||
| 1596 | - | ||
| 1597 | ge::Status PrepareInternalConsts(const ge::ReadonlyByteBuffer &weight_buf, const Om2ModelLoadArg &load_arg, | 1589 | ge::Status PrepareInternalConsts(const ge::ReadonlyByteBuffer &weight_buf, const Om2ModelLoadArg &load_arg, |
| 1598 | const std::vector<Om2ConstItem> &const_items, size_t internal_weight_size, | 1590 | const std::vector<Om2ConstItem> &const_items, size_t internal_weight_size, |
| 1599 | std::vector<void *> &constants) { | 1591 | std::vector<void *> &constants) { |
| @@ -79,8 +79,8 @@ int32_t Om2CallbackProbe(void *, GertModelTaskLaunchInfo *info) { | |||
| 79 | 79 | ||
| 80 | class CallbackProbeModel { | 80 | class CallbackProbeModel { |
| 81 | public: | 81 | public: |
| 82 | - int32_t Load(const GertModelCallbacks *callbacks) { | 82 | + int32_t Load(const GertModelLoadCallbacks *callbacks) { |
| 83 | - callbacks_ = (callbacks == nullptr) ? GertModelCallbacks{} : *callbacks; | 83 | + callbacks_ = (callbacks == nullptr) ? GertModelLoadCallbacks{} : *callbacks; |
| 84 | return SUCCESS; | 84 | return SUCCESS; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| @@ -98,12 +98,12 @@ class CallbackProbeModel { | |||
| 98 | return callback_used_; | 98 | return callback_used_; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | - const GertModelCallbacks &Callbacks() const { | 101 | + const GertModelLoadCallbacks &Callbacks() const { |
| 102 | return callbacks_; | 102 | return callbacks_; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | private: | 105 | private: |
| 106 | - GertModelCallbacks callbacks_{}; | 106 | + GertModelLoadCallbacks callbacks_{}; |
| 107 | gert::Om2ModelExecutor executor_; | 107 | gert::Om2ModelExecutor executor_; |
| 108 | bool callback_used_ = false; | 108 | bool callback_used_ = false; |
| 109 | }; | 109 | }; |
| @@ -847,6 +847,12 @@ const std::string fake_interface_header_src = R"(#pragma once | |||
| 847 | #include <cstddef> | 847 | #include <cstddef> |
| 848 | #include <cstdint> | 848 | #include <cstdint> |
| 849 | 849 | ||
| 850 | +typedef void* aclmdlRI; | ||
| 851 | +typedef void* aclrtStream; | ||
| 852 | +typedef void* aclrtEvent; | ||
| 853 | +typedef void* aclrtLabel; | ||
| 854 | +typedef void* aclrtNotify; | ||
| 855 | + | ||
| 850 | namespace gert { | 856 | namespace gert { |
| 851 | class Tensor; | 857 | class Tensor; |
| 852 | } | 858 | } |
| @@ -864,8 +870,17 @@ struct GertModelLoadConfig { | |||
| 864 | uint64_t model_id = 0; // used for logging | 870 | uint64_t model_id = 0; // used for logging |
| 865 | void *instance_handle = nullptr; | 871 | void *instance_handle = nullptr; |
| 866 | void *executor_handle = nullptr; | 872 | void *executor_handle = nullptr; |
| 867 | - const struct GertModelCallbacks *callbacks = nullptr; | 873 | + const struct GertModelLoadCallbacks *callbacks = nullptr; |
| 868 | int64_t priority = 0; | 874 | int64_t priority = 0; |
| 875 | + aclmdlRI external_rt_model = nullptr; | ||
| 876 | + aclrtStream *external_streams = nullptr; | ||
| 877 | + uint64_t external_stream_num = 0; | ||
| 878 | + aclrtEvent *external_events = nullptr; | ||
| 879 | + uint64_t external_event_num = 0; | ||
| 880 | + aclrtLabel *external_labels = nullptr; | ||
| 881 | + uint64_t external_label_num = 0; | ||
| 882 | + aclrtNotify *external_notifies = nullptr; | ||
| 883 | + uint64_t external_notify_num = 0; | ||
| 869 | }; | 884 | }; |
| 870 | 885 | ||
| 871 | struct GertModelRunConfig { | 886 | struct GertModelRunConfig { |
| @@ -923,7 +938,7 @@ struct FakeModel { | |||
| 923 | } | 938 | } |
| 924 | 939 | ||
| 925 | extern "C" int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output) { | 940 | extern "C" int GertModelLoad(const struct GertModelLoadConfig *config, GertModelHandle *model_handle, struct GertModelLoadOutput *output) { |
| 926 | - if ((model_handle == nullptr) || (config == nullptr) || (config->work_ptr == nullptr) || (config->constants == nullptr) || (config->constants[0] == nullptr)) { | 941 | + if ((model_handle == nullptr) || (config == nullptr) || (config->constants == nullptr) || (config->constants[0] == nullptr)) { |
| 927 | return 1; | 942 | return 1; |
| 928 | } | 943 | } |
| 929 | auto *model = new (std::nothrow) FakeModel(); | 944 | auto *model = new (std::nothrow) FakeModel(); |
| @@ -980,6 +995,8 @@ set(CMAKE_CXX_STANDARD 17) | |||
| 980 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | 995 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 981 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) | 996 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 982 | 997 | ||
| 998 | +include_directories($ENV{ASCEND_HOME_PATH}/include) | ||
| 999 | + | ||
| 983 | add_library(g1_om2 SHARED | 1000 | add_library(g1_om2 SHARED |
| 984 | g1_resources.cpp | 1001 | g1_resources.cpp |
| 985 | g1_kernel_reg.cpp | 1002 | g1_kernel_reg.cpp |
| @@ -3865,7 +3882,7 @@ TEST_F(Om2St, ConvertOm2Model_Ok_GenOm2WithCustomOp) { | |||
| 3865 | 3882 | ||
| 3866 | TEST_F(Om2CallbackSt, KernelLaunchThroughExecutor) { | 3883 | TEST_F(Om2CallbackSt, KernelLaunchThroughExecutor) { |
| 3867 | g_om2_callback_probe_count = 0; | 3884 | g_om2_callback_probe_count = 0; |
| 3868 | - GertModelCallbacks callbacks{}; | 3885 | + GertModelLoadCallbacks callbacks{}; |
| 3869 | callbacks.launch_func = Om2CallbackProbe; | 3886 | callbacks.launch_func = Om2CallbackProbe; |
| 3870 | CallbackProbeModel model; | 3887 | CallbackProbeModel model; |
| 3871 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); | 3888 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); |
| @@ -3876,7 +3893,7 @@ TEST_F(Om2CallbackSt, KernelLaunchThroughExecutor) { | |||
| 3876 | 3893 | ||
| 3877 | TEST_F(Om2CallbackSt, DsaLaunchThroughExecutor) { | 3894 | TEST_F(Om2CallbackSt, DsaLaunchThroughExecutor) { |
| 3878 | g_om2_callback_probe_count = 0; | 3895 | g_om2_callback_probe_count = 0; |
| 3879 | - GertModelCallbacks callbacks{}; | 3896 | + GertModelLoadCallbacks callbacks{}; |
| 3880 | callbacks.launch_func = Om2CallbackProbe; | 3897 | callbacks.launch_func = Om2CallbackProbe; |
| 3881 | CallbackProbeModel model; | 3898 | CallbackProbeModel model; |
| 3882 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); | 3899 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); |
| @@ -3885,13 +3902,13 @@ TEST_F(Om2CallbackSt, DsaLaunchThroughExecutor) { | |||
| 3885 | } | 3902 | } |
| 3886 | 3903 | ||
| 3887 | TEST_F(Om2CallbackSt, CallbackErrorPropagates) { | 3904 | TEST_F(Om2CallbackSt, CallbackErrorPropagates) { |
| 3888 | - GertModelCallbacks callbacks{}; | 3905 | + GertModelLoadCallbacks callbacks{}; |
| 3889 | callbacks.launch_func = Om2CallbackProbe; | 3906 | callbacks.launch_func = Om2CallbackProbe; |
| 3890 | EXPECT_EQ(callbacks.launch_func(nullptr, nullptr), PARAM_INVALID); | 3907 | EXPECT_EQ(callbacks.launch_func(nullptr, nullptr), PARAM_INVALID); |
| 3891 | } | 3908 | } |
| 3892 | 3909 | ||
| 3893 | TEST_F(Om2CallbackSt, FallbackLaunchWithoutCallback) { | 3910 | TEST_F(Om2CallbackSt, FallbackLaunchWithoutCallback) { |
| 3894 | - GertModelCallbacks callbacks{}; | 3911 | + GertModelLoadCallbacks callbacks{}; |
| 3895 | EXPECT_EQ(callbacks.launch_func, nullptr); | 3912 | EXPECT_EQ(callbacks.launch_func, nullptr); |
| 3896 | GertModelTaskLaunchInfo info{}; | 3913 | GertModelTaskLaunchInfo info{}; |
| 3897 | // GE_ASSERT_NOTNULL records invalid task_info and keeps the callback return value successful. | 3914 | // GE_ASSERT_NOTNULL records invalid task_info and keeps the callback return value successful. |
| @@ -3899,7 +3916,7 @@ TEST_F(Om2CallbackSt, FallbackLaunchWithoutCallback) { | |||
| 3899 | } | 3916 | } |
| 3900 | 3917 | ||
| 3901 | TEST_F(Om2CallbackSt, TfTwoLaunches) { | 3918 | TEST_F(Om2CallbackSt, TfTwoLaunches) { |
| 3902 | - GertModelCallbacks callbacks{}; | 3919 | + GertModelLoadCallbacks callbacks{}; |
| 3903 | callbacks.launch_func = Om2CallbackProbe; | 3920 | callbacks.launch_func = Om2CallbackProbe; |
| 3904 | CallbackProbeModel model; | 3921 | CallbackProbeModel model; |
| 3905 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); | 3922 | ASSERT_EQ(model.Load(&callbacks), SUCCESS); |
| @@ -272,6 +272,12 @@ static const std::string fake_om2_so_src = R"( | |||
| 272 | #include <cstddef> | 272 | #include <cstddef> |
| 273 | #include <cstdint> | 273 | #include <cstdint> |
| 274 | 274 | ||
| 275 | +typedef void* aclmdlRI; | ||
| 276 | +typedef void* aclrtStream; | ||
| 277 | +typedef void* aclrtEvent; | ||
| 278 | +typedef void* aclrtLabel; | ||
| 279 | +typedef void* aclrtNotify; | ||
| 280 | + | ||
| 275 | struct GertModelLoadConfig { | 281 | struct GertModelLoadConfig { |
| 276 | uint64_t struct_size; | 282 | uint64_t struct_size; |
| 277 | const char **bin_files; | 283 | const char **bin_files; |
| @@ -285,8 +291,17 @@ struct GertModelLoadConfig { | |||
| 285 | uint64_t model_id; | 291 | uint64_t model_id; |
| 286 | void *instance_handle; | 292 | void *instance_handle; |
| 287 | void *executor_handle; | 293 | void *executor_handle; |
| 288 | - const struct GertModelCallbacks *callbacks; | 294 | + const struct GertModelLoadCallbacks *callbacks; |
| 289 | int64_t priority; | 295 | int64_t priority; |
| 296 | + aclmdlRI external_rt_model = nullptr; | ||
| 297 | + aclrtStream *external_streams = nullptr; | ||
| 298 | + uint64_t external_stream_num = 0; | ||
| 299 | + aclrtEvent *external_events = nullptr; | ||
| 300 | + uint64_t external_event_num = 0; | ||
| 301 | + aclrtLabel *external_labels = nullptr; | ||
| 302 | + uint64_t external_label_num = 0; | ||
| 303 | + aclrtNotify *external_notifies = nullptr; | ||
| 304 | + uint64_t external_notify_num = 0; | ||
| 290 | }; | 305 | }; |
| 291 | 306 | ||
| 292 | struct GertModelRunConfig { | 307 | struct GertModelRunConfig { |
| @@ -210,27 +210,27 @@ class ControlTaskCodeGeneratorUt : public testing::Test { | |||
| 210 | 210 | ||
| 211 | std::string GetInterfaceDumpApisExpected() { | 211 | std::string GetInterfaceDumpApisExpected() { |
| 212 | return R"( | 212 | return R"( |
| 213 | -struct Om2TaskIoEntry { | 213 | +struct GertModelTaskIoEntry { |
| 214 | const struct Om2Tensor *tensor; | 214 | const struct Om2Tensor *tensor; |
| 215 | uint64_t offset; | 215 | uint64_t offset; |
| 216 | }; | 216 | }; |
| 217 | 217 | ||
| 218 | -enum Om2L0ArgKind { | 218 | +enum GertModelArgKind { |
| 219 | - OM2_L0_ARG_INPUT = 0, | 219 | + GERT_MODEL_ARG_INPUT = 0, |
| 220 | - OM2_L0_ARG_OUTPUT = 1, | 220 | + GERT_MODEL_ARG_OUTPUT = 1, |
| 221 | - OM2_L0_ARG_WORKSPACE = 2, | 221 | + GERT_MODEL_ARG_WORKSPACE = 2, |
| 222 | - OM2_L0_ARG_TILING = 3, | 222 | + GERT_MODEL_ARG_TILING = 3, |
| 223 | - OM2_L0_ARG_SHAPE_INFO = 4, | 223 | + GERT_MODEL_ARG_SHAPE_INFO = 4, |
| 224 | - OM2_L0_ARG_LEVEL1_DESC = 5, | 224 | + GERT_MODEL_ARG_LEVEL1_DESC = 5, |
| 225 | - OM2_L0_ARG_PLACEHOLDER = 6, | 225 | + GERT_MODEL_ARG_PLACEHOLDER = 6, |
| 226 | - OM2_L0_ARG_CUSTOM_VALUE = 7, | 226 | + GERT_MODEL_ARG_CUSTOM_VALUE = 7, |
| 227 | - OM2_L0_ARG_FFTS_ADDR = 8, | 227 | + GERT_MODEL_ARG_FFTS_ADDR = 8, |
| 228 | - OM2_L0_ARG_EVENT_ADDR = 9, | 228 | + GERT_MODEL_ARG_EVENT_ADDR = 9, |
| 229 | - OM2_L0_ARG_OVERFLOW_ADDR = 10, | 229 | + GERT_MODEL_ARG_OVERFLOW_ADDR = 10, |
| 230 | - OM2_L0_ARG_EMPTY_ADDR = 11 | 230 | + GERT_MODEL_ARG_EMPTY_ADDR = 11 |
| 231 | }; | 231 | }; |
| 232 | 232 | ||
| 233 | -struct Om2L0ArgSlotInfo { | 233 | +struct GertModelArgSlotInfo { |
| 234 | uint32_t kind; | 234 | uint32_t kind; |
| 235 | uint32_t flags; | 235 | uint32_t flags; |
| 236 | uint64_t args_offset; | 236 | uint64_t args_offset; |
| @@ -240,14 +240,14 @@ struct Om2L0ArgSlotInfo { | |||
| 240 | uint64_t level1_target_offset; | 240 | uint64_t level1_target_offset; |
| 241 | }; | 241 | }; |
| 242 | 242 | ||
| 243 | -struct Om2L0TaskRawInfo { | 243 | +struct GertModelTaskRawInfo { |
| 244 | uint32_t version; | 244 | uint32_t version; |
| 245 | uint32_t need_assert_or_printf; | 245 | uint32_t need_assert_or_printf; |
| 246 | uint64_t arg_num; | 246 | uint64_t arg_num; |
| 247 | - const struct Om2L0ArgSlotInfo* args; | 247 | + const struct GertModelArgSlotInfo* args; |
| 248 | }; | 248 | }; |
| 249 | 249 | ||
| 250 | -struct Om2TaskInfo { | 250 | +struct GertModelTaskDesc { |
| 251 | const char* op_name; | 251 | const char* op_name; |
| 252 | const char* op_type; | 252 | const char* op_type; |
| 253 | uint32_t task_id; | 253 | uint32_t task_id; |
| @@ -259,28 +259,28 @@ struct Om2TaskInfo { | |||
| 259 | uintptr_t args_base; | 259 | uintptr_t args_base; |
| 260 | uint64_t args_size; | 260 | uint64_t args_size; |
| 261 | uint64_t input_num; | 261 | uint64_t input_num; |
| 262 | - const struct Om2TaskIoEntry* inputs; | 262 | + const struct GertModelTaskIoEntry* inputs; |
| 263 | uint32_t output_num; | 263 | uint32_t output_num; |
| 264 | - const struct Om2TaskIoEntry* outputs; | 264 | + const struct GertModelTaskIoEntry* outputs; |
| 265 | uint32_t workspace_num; | 265 | uint32_t workspace_num; |
| 266 | const uint64_t* workspace_addrs; | 266 | const uint64_t* workspace_addrs; |
| 267 | const uint64_t* workspace_sizes; | 267 | const uint64_t* workspace_sizes; |
| 268 | uint32_t task_type; | 268 | uint32_t task_type; |
| 269 | void* stream; | 269 | void* stream; |
| 270 | uint32_t is_raw_address; | 270 | uint32_t is_raw_address; |
| 271 | - const struct Om2L0TaskRawInfo* l0_exception_dump_info; | 271 | + const struct GertModelTaskRawInfo* task_raw_info; |
| 272 | }; | 272 | }; |
| 273 | 273 | ||
| 274 | extern "C" { | 274 | extern "C" { |
| 275 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, | 275 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, |
| 276 | void* instance_handle, | 276 | void* instance_handle, |
| 277 | - const struct Om2TaskInfo* task_info, | 277 | + const struct GertModelTaskDesc* task_info, |
| 278 | const void* extended_attrs, | 278 | const void* extended_attrs, |
| 279 | size_t extended_attrs_size); | 279 | size_t extended_attrs_size); |
| 280 | 280 | ||
| 281 | __attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id, | 281 | __attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id, |
| 282 | void* instance_handle, | 282 | void* instance_handle, |
| 283 | - const struct Om2TaskInfo* task_info, | 283 | + const struct GertModelTaskDesc* task_info, |
| 284 | const void* extended_attrs, | 284 | const void* extended_attrs, |
| 285 | size_t extended_attrs_size); | 285 | size_t extended_attrs_size); |
| 286 | 286 | ||
| @@ -520,28 +520,28 @@ inline std::vector<uint64_t> FlattenHostArgs(Args&&... args) { | |||
| 520 | return buf; | 520 | return buf; |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | -struct Om2TaskIoEntry { | 523 | +struct GertModelTaskIoEntry { |
| 524 | - uint64_t struct_size = sizeof(Om2TaskIoEntry); | 524 | + uint64_t struct_size = sizeof(GertModelTaskIoEntry); |
| 525 | const gert::Tensor *tensor = nullptr; | 525 | const gert::Tensor *tensor = nullptr; |
| 526 | uint64_t offset = 0; | 526 | uint64_t offset = 0; |
| 527 | }; | 527 | }; |
| 528 | 528 | ||
| 529 | -enum Om2L0ArgKind { | 529 | +enum GertModelArgKind { |
| 530 | - OM2_L0_ARG_INPUT = 0, | 530 | + GERT_MODEL_ARG_INPUT = 0, |
| 531 | - OM2_L0_ARG_OUTPUT = 1, | 531 | + GERT_MODEL_ARG_OUTPUT = 1, |
| 532 | - OM2_L0_ARG_WORKSPACE = 2, | 532 | + GERT_MODEL_ARG_WORKSPACE = 2, |
| 533 | - OM2_L0_ARG_TILING = 3, | 533 | + GERT_MODEL_ARG_TILING = 3, |
| 534 | - OM2_L0_ARG_SHAPE_INFO = 4, | 534 | + GERT_MODEL_ARG_SHAPE_INFO = 4, |
| 535 | - OM2_L0_ARG_LEVEL1_DESC = 5, | 535 | + GERT_MODEL_ARG_LEVEL1_DESC = 5, |
| 536 | - OM2_L0_ARG_PLACEHOLDER = 6, | 536 | + GERT_MODEL_ARG_PLACEHOLDER = 6, |
| 537 | - OM2_L0_ARG_CUSTOM_VALUE = 7, | 537 | + GERT_MODEL_ARG_CUSTOM_VALUE = 7, |
| 538 | - OM2_L0_ARG_FFTS_ADDR = 8, | 538 | + GERT_MODEL_ARG_FFTS_ADDR = 8, |
| 539 | - OM2_L0_ARG_EVENT_ADDR = 9, | 539 | + GERT_MODEL_ARG_EVENT_ADDR = 9, |
| 540 | - OM2_L0_ARG_OVERFLOW_ADDR = 10, | 540 | + GERT_MODEL_ARG_OVERFLOW_ADDR = 10, |
| 541 | - OM2_L0_ARG_EMPTY_ADDR = 11 | 541 | + GERT_MODEL_ARG_EMPTY_ADDR = 11 |
| 542 | }; | 542 | }; |
| 543 | 543 | ||
| 544 | -struct Om2L0ArgSlotInfo { | 544 | +struct GertModelArgSlotInfo { |
| 545 | uint32_t kind; | 545 | uint32_t kind; |
| 546 | uint32_t flags; | 546 | uint32_t flags; |
| 547 | uint64_t args_offset; | 547 | uint64_t args_offset; |
| @@ -551,14 +551,14 @@ struct Om2L0ArgSlotInfo { | |||
| 551 | uint64_t level1_target_offset; | 551 | uint64_t level1_target_offset; |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | -struct Om2L0TaskRawInfo { | 554 | +struct GertModelTaskRawInfo { |
| 555 | uint32_t version; | 555 | uint32_t version; |
| 556 | uint32_t need_assert_or_printf; | 556 | uint32_t need_assert_or_printf; |
| 557 | uint64_t arg_num; | 557 | uint64_t arg_num; |
| 558 | - const struct Om2L0ArgSlotInfo* args; | 558 | + const struct GertModelArgSlotInfo* args; |
| 559 | }; | 559 | }; |
| 560 | 560 | ||
| 561 | -struct Om2TaskInfo { | 561 | +struct GertModelTaskDesc { |
| 562 | const char* op_name; | 562 | const char* op_name; |
| 563 | const char* op_type; | 563 | const char* op_type; |
| 564 | uint32_t task_id; | 564 | uint32_t task_id; |
| @@ -570,16 +570,16 @@ struct Om2TaskInfo { | |||
| 570 | uintptr_t args_base; | 570 | uintptr_t args_base; |
| 571 | uint64_t args_size; | 571 | uint64_t args_size; |
| 572 | uint64_t input_num; | 572 | uint64_t input_num; |
| 573 | - const struct Om2TaskIoEntry* inputs; | 573 | + const struct GertModelTaskIoEntry* inputs; |
| 574 | uint32_t output_num; | 574 | uint32_t output_num; |
| 575 | - const struct Om2TaskIoEntry* outputs; | 575 | + const struct GertModelTaskIoEntry* outputs; |
| 576 | uint32_t workspace_num; | 576 | uint32_t workspace_num; |
| 577 | const uint64_t* workspace_addrs; | 577 | const uint64_t* workspace_addrs; |
| 578 | const uint64_t* workspace_sizes; | 578 | const uint64_t* workspace_sizes; |
| 579 | uint32_t task_type; | 579 | uint32_t task_type; |
| 580 | void* stream; | 580 | void* stream; |
| 581 | uint32_t is_raw_address; | 581 | uint32_t is_raw_address; |
| 582 | - const struct Om2L0TaskRawInfo* l0_exception_dump_info; | 582 | + const struct GertModelTaskRawInfo* task_raw_info; |
| 583 | uint64_t launch_begin; | 583 | uint64_t launch_begin; |
| 584 | const char *original_op_names; | 584 | const char *original_op_names; |
| 585 | uint64_t input_mem_size; | 585 | uint64_t input_mem_size; |
| @@ -599,16 +599,60 @@ struct GertModelBaseInfo { | |||
| 599 | const void *rt_model_handle = nullptr; | 599 | const void *rt_model_handle = nullptr; |
| 600 | }; | 600 | }; |
| 601 | 601 | ||
| 602 | -using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct Om2TaskInfo *info); | 602 | +using ReportTaskProcessFunc = int32_t (*)(void *instance_handle, const struct GertModelTaskDesc *info); |
| 603 | using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); | 603 | using GetDataDumpEnabledInfoFunc = int32_t (*)(void *instance_handle, struct GertModelDumpEnabledInfo *info); |
| 604 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); | 604 | using ReportModelBaseInfoFunc = int32_t (*)(void *instance_handle, const struct GertModelBaseInfo *info); |
| 605 | 605 | ||
| 606 | -struct GertModelCallbacks { | 606 | +enum GertModelTaskLaunchType : uint64_t { |
| 607 | - uint64_t struct_size = sizeof(GertModelCallbacks); | 607 | + ACL_RT_LAUNCH_KERNEL_V2 = 0, |
| 608 | + RT_STARS_TASK_LAUNCH_WITH_FLAG = 1, | ||
| 609 | +}; | ||
| 610 | + | ||
| 611 | +struct GertModelLaunchKernelV2Params { | ||
| 612 | + uint64_t struct_size = sizeof(GertModelLaunchKernelV2Params); | ||
| 613 | + aclrtFuncHandle func_handle = nullptr; | ||
| 614 | + uint32_t block_dim = 0; | ||
| 615 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 616 | + uint32_t reserved_1 = 0; | ||
| 617 | + const void *args_data = nullptr; | ||
| 618 | + size_t args_size = 0; | ||
| 619 | + aclrtLaunchKernelCfg *config = nullptr; | ||
| 620 | + aclrtStream stream = nullptr; | ||
| 621 | +}; | ||
| 622 | + | ||
| 623 | +struct GertModelLaunchStarsTaskWithFlagParams { | ||
| 624 | + uint64_t struct_size = sizeof(GertModelLaunchStarsTaskWithFlagParams); | ||
| 625 | + const void *task_sqe = nullptr; | ||
| 626 | + uint32_t sqe_len = 0; | ||
| 627 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 628 | + uint32_t reserved_1 = 0; | ||
| 629 | + aclrtStream stream = nullptr; | ||
| 630 | + uint32_t flag = 0; | ||
| 631 | + // 用于填充空洞,保持结构体布局与 ACL 接口一致。 | ||
| 632 | + uint32_t reserved_2 = 0; | ||
| 633 | +}; | ||
| 634 | + | ||
| 635 | +union GertModelTaskLaunchParams { | ||
| 636 | + GertModelLaunchKernelV2Params launch_kernel_v2_params; | ||
| 637 | + GertModelLaunchStarsTaskWithFlagParams launch_stars_task_params; | ||
| 638 | +}; | ||
| 639 | + | ||
| 640 | +struct GertModelTaskLaunchInfo { | ||
| 641 | + uint64_t struct_size = sizeof(GertModelTaskLaunchInfo); | ||
| 642 | + GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2; | ||
| 643 | + GertModelTaskDesc *task_info = nullptr; | ||
| 644 | + const GertModelTaskLaunchParams *launch_params = nullptr; | ||
| 645 | +}; | ||
| 646 | + | ||
| 647 | +using GertModelLaunchFunc = int32_t (*)(void *instance_handle, GertModelTaskLaunchInfo *launch_info); | ||
| 648 | + | ||
| 649 | +struct GertModelLoadCallbacks { | ||
| 650 | + uint64_t struct_size = sizeof(GertModelLoadCallbacks); | ||
| 608 | ReportTaskProcessFunc report_task_preprocess = nullptr; | 651 | ReportTaskProcessFunc report_task_preprocess = nullptr; |
| 609 | ReportTaskProcessFunc report_task_postprocess = nullptr; | 652 | ReportTaskProcessFunc report_task_postprocess = nullptr; |
| 610 | GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; | 653 | GetDataDumpEnabledInfoFunc get_data_dump_enabled = nullptr; |
| 611 | ReportModelBaseInfoFunc report_model_base_info = nullptr; | 654 | ReportModelBaseInfoFunc report_model_base_info = nullptr; |
| 655 | + GertModelLaunchFunc launch_func = nullptr; | ||
| 612 | }; | 656 | }; |
| 613 | 657 | ||
| 614 | using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo *info); | 658 | using ReportModelRunFunc = int32_t (*)(void *instance_handle, const struct GertModelRunReportInfo *info); |
| @@ -639,8 +683,30 @@ struct GertModelLoadConfig { | |||
| 639 | uint64_t model_id = 0; // used for logging | 683 | uint64_t model_id = 0; // used for logging |
| 640 | void *instance_handle = nullptr; | 684 | void *instance_handle = nullptr; |
| 641 | void *executor_handle = nullptr; | 685 | void *executor_handle = nullptr; |
| 642 | - const struct GertModelCallbacks *callbacks = nullptr; | 686 | + const struct GertModelLoadCallbacks *callbacks = nullptr; |
| 643 | int64_t priority = 0; | 687 | int64_t priority = 0; |
| 688 | + aclmdlRI external_rt_model = nullptr; | ||
| 689 | + aclrtStream *external_streams = nullptr; | ||
| 690 | + uint64_t external_stream_num = 0; | ||
| 691 | + aclrtEvent *external_events = nullptr; | ||
| 692 | + uint64_t external_event_num = 0; | ||
| 693 | + aclrtLabel *external_labels = nullptr; | ||
| 694 | + uint64_t external_label_num = 0; | ||
| 695 | + aclrtNotify *external_notifies = nullptr; | ||
| 696 | + uint64_t external_notify_num = 0; | ||
| 697 | +}; | ||
| 698 | + | ||
| 699 | +struct GertModelExternalResources { | ||
| 700 | + uint64_t struct_size = sizeof(GertModelExternalResources); | ||
| 701 | + aclmdlRI external_rt_model = nullptr; | ||
| 702 | + aclrtStream *external_streams = nullptr; | ||
| 703 | + uint64_t external_stream_num = 0; | ||
| 704 | + aclrtNotify *external_notifies = nullptr; | ||
| 705 | + uint64_t external_notify_num = 0; | ||
| 706 | + aclrtEvent *external_events = nullptr; | ||
| 707 | + uint64_t external_event_num = 0; | ||
| 708 | + aclrtLabel *external_labels = nullptr; | ||
| 709 | + uint64_t external_label_num = 0; | ||
| 644 | }; | 710 | }; |
| 645 | 711 | ||
| 646 | struct GertModelRunConfig { | 712 | struct GertModelRunConfig { |
| @@ -672,20 +738,15 @@ struct GertModelUnloadOutput { | |||
| 672 | extern "C" { | 738 | extern "C" { |
| 673 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, | 739 | __attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id, |
| 674 | void* instance_handle, | 740 | void* instance_handle, |
| 675 | - const struct Om2TaskInfo* task_info, | 741 | + const struct GertModelTaskDesc* task_info, |
| 676 | const void* extended_attrs, | 742 | const void* extended_attrs, |
| 677 | size_t extended_attrs_size); | 743 | size_t extended_attrs_size); |
| 678 | 744 | ||
| 679 | __attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id, | 745 | __attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id, |
| 680 | void* instance_handle, | 746 | void* instance_handle, |
| 681 | - const struct Om2TaskInfo* task_info, | 747 | + const struct GertModelTaskDesc* task_info, |
| 682 | const void* extended_attrs, | 748 | const void* extended_attrs, |
| 683 | - size_t extended_attrs_size); | 749 | + size_t extended_attrs_size); |
| 684 | - | ||
| 685 | -__attribute__((weak)) int32_t IsDataDumpEnabled(uint32_t model_id, | ||
| 686 | - void* instance_handle, | ||
| 687 | - const char* op_name, | ||
| 688 | - uint8_t* is_data_dump); | ||
| 689 | } | 750 | } |
| 690 | 751 | ||
| 691 | struct rtLabelDevInfo { | 752 | struct rtLabelDevInfo { |
| @@ -894,10 +955,10 @@ struct AicoreDispatchInfo { | |||
| 894 | uint16_t time_out; // 超时时间 | 955 | uint16_t time_out; // 超时时间 |
| 895 | uint32_t local_memory_size; // 本地内存大小 | 956 | uint32_t local_memory_size; // 本地内存大小 |
| 896 | } launch; | 957 | } launch; |
| 897 | - struct { // L0 信息,构建 Om2L0TaskRawInfo | 958 | + struct { // L0 信息,构建 GertModelTaskRawInfo |
| 898 | uint32_t need_assert_or_printf; // 是否需要 assert/printf | 959 | uint32_t need_assert_or_printf; // 是否需要 assert/printf |
| 899 | uint32_t slots_num; // L0 slot 数量 | 960 | uint32_t slots_num; // L0 slot 数量 |
| 900 | - const Om2L0ArgSlotInfo *slot_info; // L0 slot 信息数组 | 961 | + const GertModelArgSlotInfo *slot_info; // L0 slot 信息数组 |
| 901 | } slot_args; | 962 | } slot_args; |
| 902 | struct { // 融合算子信息,非融合全为 0/nullptr | 963 | struct { // 融合算子信息,非融合全为 0/nullptr |
| 903 | const char *original_op_names; // 原始算子名称(分号分隔) | 964 | const char *original_op_names; // 原始算子名称(分号分隔) |
| @@ -1091,11 +1152,11 @@ struct DispatchOpContext { | |||
| 1091 | 1152 | ||
| 1092 | class Om2Model { | 1153 | class Om2Model { |
| 1093 | public: | 1154 | public: |
| 1094 | - Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, void *executor_handle, int32_t priority); | 1155 | + Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority); |
| 1095 | ~Om2Model(); | 1156 | ~Om2Model(); |
| 1096 | - aclError InitResources(); | 1157 | + aclError InitResources(const GertModelExternalResources &external_resources); |
| 1097 | aclError RegisterKernels(); | 1158 | aclError RegisterKernels(); |
| 1098 | - aclError Load(const GertModelCallbacks *callbacks); | 1159 | + aclError Load(const GertModelLoadCallbacks *callbacks); |
| 1099 | aclmdlRI GetRtModelHandle(); | 1160 | aclmdlRI GetRtModelHandle(); |
| 1100 | aclError Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, const GertModelRunCallbacks *run_callbacks); | 1161 | aclError Run(size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, int32_t stream_sync_timeout, const GertModelRunCallbacks *run_callbacks); |
| 1101 | aclError RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, const GertModelRunCallbacks *run_callbacks); | 1162 | aclError RunAsync(aclrtStream &exe_stream, size_t input_count, gert::Tensor **input_data, size_t output_count, gert::Tensor **output_data, const GertModelRunCallbacks *run_callbacks); |
| @@ -1124,7 +1185,6 @@ class Om2Model { | |||
| 1124 | uint64_t *session_id_; | 1185 | uint64_t *session_id_; |
| 1125 | uint32_t model_id_; | 1186 | uint32_t model_id_; |
| 1126 | void *instance_handle_; | 1187 | void *instance_handle_; |
| 1127 | - void *executor_handle_; | ||
| 1128 | uint64_t kernel_id_; | 1188 | uint64_t kernel_id_; |
| 1129 | std::vector<void *> dev_ext_info_mem_ptrs_; | 1189 | std::vector<void *> dev_ext_info_mem_ptrs_; |
| 1130 | std::map<uint32_t, void *> mem_event_id_mem_map_; | 1190 | std::map<uint32_t, void *> mem_event_id_mem_map_; |
| @@ -1132,6 +1192,11 @@ class Om2Model { | |||
| 1132 | std::vector<void *> dev_dynamic_mem_ptrs_; | 1192 | std::vector<void *> dev_dynamic_mem_ptrs_; |
| 1133 | void *session_scope_mem_ptr_; | 1193 | void *session_scope_mem_ptr_; |
| 1134 | int32_t priority_; | 1194 | int32_t priority_; |
| 1195 | + bool is_external_rt_model_; | ||
| 1196 | + bool is_external_streams_; | ||
| 1197 | + bool is_external_notifies_; | ||
| 1198 | + bool is_external_events_; | ||
| 1199 | + bool is_external_labels_; | ||
| 1135 | }; | 1200 | }; |
| 1136 | } // namespace om2 | 1201 | } // namespace om2 |
| 1137 | #ifdef __cplusplus | 1202 | #ifdef __cplusplus |
| @@ -1155,8 +1220,8 @@ int GertModelUnload(GertModelHandle model_handle, const struct GertModelUnloadCo | |||
| 1155 | #include "_interface.h" | 1220 | #include "_interface.h" |
| 1156 | 1221 | ||
| 1157 | namespace om2 { | 1222 | namespace om2 { |
| 1158 | -Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, void *executor_handle, int32_t priority) | 1223 | +Om2Model::Om2Model(const char **bin_files, const void **bin_data, uint64_t *bin_size, size_t bin_num, void **constants, void **var_addrs, void *work_ptr, uint64_t *session_id, uint32_t model_id, void *instance_handle, int32_t priority) |
| 1159 | - : constants_(constants), var_addrs_(var_addrs), total_dev_mem_ptr_(work_ptr), session_id_(session_id), model_id_(model_id), instance_handle_(instance_handle), executor_handle_(executor_handle), kernel_id_(0), session_scope_mem_ptr_(nullptr), priority_(priority) { | 1224 | + : constants_(constants), var_addrs_(var_addrs), total_dev_mem_ptr_(work_ptr), session_id_(session_id), model_id_(model_id), instance_handle_(instance_handle), kernel_id_(0), session_scope_mem_ptr_(nullptr), priority_(priority), is_external_rt_model_(false), is_external_streams_(false), is_external_notifies_(false), is_external_events_(false), is_external_labels_(false) { |
| 1160 | for (size_t i = 0; (i < bin_num); ++i) { | 1225 | for (size_t i = 0; (i < bin_num); ++i) { |
| 1161 | bin_info_map_[std::string(bin_files[i])] = {bin_data[i], bin_size[i]}; | 1226 | bin_info_map_[std::string(bin_files[i])] = {bin_data[i], bin_size[i]}; |
| 1162 | } | 1227 | } |
| @@ -1172,40 +1237,89 @@ Om2Model::~Om2Model() { | |||
| 1172 | (void)ReleaseResources(); | 1237 | (void)ReleaseResources(); |
| 1173 | } | 1238 | } |
| 1174 | 1239 | ||
| 1175 | -aclError Om2Model::InitResources() { | 1240 | +aclError Om2Model::InitResources(const GertModelExternalResources &external_resources) { |
| 1176 | OM2_LOGI("InitResources begin"); | 1241 | OM2_LOGI("InitResources begin"); |
| 1177 | // 1. 创建 model | 1242 | // 1. 创建 model |
| 1178 | - OM2_CHK_STATUS(aclmdlRIBuildBegin(&model_handle_, 0)); | 1243 | + if ((external_resources.external_rt_model != nullptr)) { |
| 1244 | + model_handle_ = external_resources.external_rt_model; | ||
| 1245 | + is_external_rt_model_ = true; | ||
| 1246 | + } else { | ||
| 1247 | + OM2_CHK_STATUS(aclmdlRIBuildBegin(&model_handle_, 0)); | ||
| 1248 | + } | ||
| 1179 | 1249 | ||
| 1180 | // 2. 获取overflow地址 | 1250 | // 2. 获取overflow地址 |
| 1181 | OM2_CHK_STATUS(aclrtCtxGetFloatOverflowAddr(&overflow_addr_)); | 1251 | OM2_CHK_STATUS(aclrtCtxGetFloatOverflowAddr(&overflow_addr_)); |
| 1182 | 1252 | ||
| 1183 | // 3. 创建其他资源 | 1253 | // 3. 创建其他资源 |
| 1184 | // 创建下沉Stream并绑定模型 | 1254 | // 创建下沉Stream并绑定模型 |
| 1185 | - uint32_t stream0_flag = RT_STREAM_PERSISTENT; | 1255 | + if ((external_resources.external_stream_num != 0U)) { |
| 1186 | - OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[0], priority_, stream0_flag)); | 1256 | + if ((external_resources.external_stream_num != stream_list_.size())) { |
| 1257 | + OM2_LOGE("external_stream_num mismatch, expected %zu, got %lu", stream_list_.size(), external_resources.external_stream_num); | ||
| 1258 | + return ACL_ERROR_FAILURE; | ||
| 1259 | + } | ||
| 1260 | + for (size_t ext_i = 0; (ext_i < external_resources.external_stream_num); ++ext_i) { | ||
| 1261 | + stream_list_[ext_i] = external_resources.external_streams[ext_i]; | ||
| 1262 | + } | ||
| 1263 | + is_external_streams_ = true; | ||
| 1264 | + } else { | ||
| 1265 | + uint32_t stream0_flag = RT_STREAM_PERSISTENT; | ||
| 1266 | + OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[0], priority_, stream0_flag)); | ||
| 1267 | + uint32_t stream1_flag = RT_STREAM_PERSISTENT; | ||
| 1268 | + OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[1], priority_, stream1_flag)); | ||
| 1269 | + uint32_t stream2_flag = RT_STREAM_PERSISTENT; | ||
| 1270 | + OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[2], priority_, stream2_flag)); | ||
| 1271 | + } | ||
| 1187 | auto bind0_flag = RT_HEAD_STREAM; | 1272 | auto bind0_flag = RT_HEAD_STREAM; |
| 1188 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[0], bind0_flag)); | 1273 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[0], bind0_flag)); |
| 1189 | - uint32_t stream1_flag = RT_STREAM_PERSISTENT; | ||
| 1190 | - OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[1], priority_, stream1_flag)); | ||
| 1191 | auto bind1_flag = RT_HEAD_STREAM; | 1274 | auto bind1_flag = RT_HEAD_STREAM; |
| 1192 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[1], bind1_flag)); | 1275 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[1], bind1_flag)); |
| 1193 | - uint32_t stream2_flag = RT_STREAM_PERSISTENT; | ||
| 1194 | - OM2_CHK_RT(rtStreamCreateWithFlags(&stream_list_[2], priority_, stream2_flag)); | ||
| 1195 | auto bind2_flag = RT_HEAD_STREAM; | 1276 | auto bind2_flag = RT_HEAD_STREAM; |
| 1196 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[2], bind2_flag)); | 1277 | OM2_CHK_STATUS(aclmdlRIBindStream(model_handle_, stream_list_[2], bind2_flag)); |
| 1197 | is_stream_list_bind_ = true; | 1278 | is_stream_list_bind_ = true; |
| 1198 | // 创建Notify | 1279 | // 创建Notify |
| 1199 | - for (size_t i = 0; (i < 1); ++i) { | 1280 | + if ((external_resources.external_notify_num != 0U)) { |
| 1200 | - OM2_CHK_STATUS(aclrtCreateNotify(¬ify_list_[i], ACL_NOTIFY_DEVICE_USE_ONLY)); | 1281 | + if ((external_resources.external_notify_num != notify_list_.size())) { |
| 1282 | + OM2_LOGE("external_notify_num mismatch, expected %zu, got %lu", notify_list_.size(), external_resources.external_notify_num); | ||
| 1283 | + return ACL_ERROR_FAILURE; | ||
| 1284 | + } | ||
| 1285 | + for (size_t ext_i = 0; (ext_i < external_resources.external_notify_num); ++ext_i) { | ||
| 1286 | + notify_list_[ext_i] = external_resources.external_notifies[ext_i]; | ||
| 1287 | + } | ||
| 1288 | + is_external_notifies_ = true; | ||
| 1289 | + } else { | ||
| 1290 | + for (size_t i = 0; (i < 1); ++i) { | ||
| 1291 | + OM2_CHK_STATUS(aclrtCreateNotify(¬ify_list_[i], ACL_NOTIFY_DEVICE_USE_ONLY)); | ||
| 1292 | + } | ||
| 1201 | } | 1293 | } |
| 1202 | // 创建Event | 1294 | // 创建Event |
| 1203 | - for (size_t i = 0; (i < 1); ++i) { | 1295 | + if ((external_resources.external_event_num != 0U)) { |
| 1204 | - OM2_CHK_STATUS(aclrtCreateEventWithFlag(&event_list_[i], ACL_EVENT_SYNC | ACL_EVENT_CAPTURE_STREAM_PROGRESS | ACL_EVENT_TIME_LINE)); | 1296 | + if ((external_resources.external_event_num != event_list_.size())) { |
| 1297 | + OM2_LOGE("external_event_num mismatch, expected %zu, got %lu", event_list_.size(), external_resources.external_event_num); | ||
| 1298 | + return ACL_ERROR_FAILURE; | ||
| 1299 | + } | ||
| 1300 | + for (size_t ext_i = 0; (ext_i < external_resources.external_event_num); ++ext_i) { | ||
| 1301 | + event_list_[ext_i] = external_resources.external_events[ext_i]; | ||
| 1302 | + } | ||
| 1303 | + is_external_events_ = true; | ||
| 1304 | + } else { | ||
| 1305 | + for (size_t i = 0; (i < 1); ++i) { | ||
| 1306 | + OM2_CHK_STATUS(aclrtCreateEventWithFlag(&event_list_[i], ACL_EVENT_SYNC | ACL_EVENT_CAPTURE_STREAM_PROGRESS | ACL_EVENT_TIME_LINE)); | ||
| 1307 | + } | ||
| 1205 | } | 1308 | } |
| 1206 | // 创建Label | 1309 | // 创建Label |
| 1207 | - for (size_t i = 0; (i < 3); ++i) { | 1310 | + if ((external_resources.external_label_num != 0U)) { |
| 1208 | - OM2_CHK_STATUS(aclrtCreateLabel(&label_list_[i])); | 1311 | + if ((external_resources.external_label_num != label_list_.size())) { |
| 1312 | + OM2_LOGE("external_label_num mismatch, expected %zu, got %lu", label_list_.size(), external_resources.external_label_num); | ||
| 1313 | + return ACL_ERROR_FAILURE; | ||
| 1314 | + } | ||
| 1315 | + for (size_t ext_i = 0; (ext_i < external_resources.external_label_num); ++ext_i) { | ||
| 1316 | + label_list_[ext_i] = external_resources.external_labels[ext_i]; | ||
| 1317 | + } | ||
| 1318 | + is_external_labels_ = true; | ||
| 1319 | + } else { | ||
| 1320 | + for (size_t i = 0; (i < 3); ++i) { | ||
| 1321 | + OM2_CHK_STATUS(aclrtCreateLabel(&label_list_[i])); | ||
| 1322 | + } | ||
| 1209 | } | 1323 | } |
| 1210 | OM2_CHK_STATUS(CreateLabelListForLabelSwitch(6, {1, 2})); | 1324 | OM2_CHK_STATUS(CreateLabelListForLabelSwitch(6, {1, 2})); |
| 1211 | OM2_CHK_STATUS(CreateLabelListForLabelGotoEx(11, 0)); | 1325 | OM2_CHK_STATUS(CreateLabelListForLabelGotoEx(11, 0)); |
| @@ -1216,24 +1330,32 @@ aclError Om2Model::InitResources() { | |||
| 1216 | 1330 | ||
| 1217 | aclError Om2Model::ReleaseResources() { | 1331 | aclError Om2Model::ReleaseResources() { |
| 1218 | OM2_LOGI("ReleaseResources begin"); | 1332 | OM2_LOGI("ReleaseResources begin"); |
| 1219 | - for (auto label : label_list_) { | 1333 | + if (!is_external_labels_) { |
| 1220 | - if ((label != nullptr)) { | 1334 | + for (auto label : label_list_) { |
| 1221 | - OM2_CHK_STATUS(aclrtDestroyLabel(label)); | 1335 | + if ((label != nullptr)) { |
| 1336 | + OM2_CHK_STATUS(aclrtDestroyLabel(label)); | ||
| 1337 | + } | ||
| 1222 | } | 1338 | } |
| 1223 | } | 1339 | } |
| 1224 | - for (auto event : event_list_) { | 1340 | + if (!is_external_events_) { |
| 1225 | - OM2_CHK_STATUS(aclrtDestroyEvent(event)); | 1341 | + for (auto event : event_list_) { |
| 1342 | + OM2_CHK_STATUS(aclrtDestroyEvent(event)); | ||
| 1343 | + } | ||
| 1226 | } | 1344 | } |
| 1227 | - for (auto notify : notify_list_) { | 1345 | + if (!is_external_notifies_) { |
| 1228 | - OM2_CHK_STATUS(aclrtDestroyNotify(notify)); | 1346 | + for (auto notify : notify_list_) { |
| 1347 | + OM2_CHK_STATUS(aclrtDestroyNotify(notify)); | ||
| 1348 | + } | ||
| 1229 | } | 1349 | } |
| 1230 | if (is_stream_list_bind_) { | 1350 | if (is_stream_list_bind_) { |
| 1231 | for (auto stream : stream_list_) { | 1351 | for (auto stream : stream_list_) { |
| 1232 | OM2_CHK_STATUS(aclmdlRIUnbindStream(model_handle_, stream)); | 1352 | OM2_CHK_STATUS(aclmdlRIUnbindStream(model_handle_, stream)); |
| 1233 | } | 1353 | } |
| 1234 | } | 1354 | } |
| 1235 | - for (auto stream : stream_list_) { | 1355 | + if (!is_external_streams_) { |
| 1236 | - OM2_CHK_STATUS(aclrtDestroyStream(stream)); | 1356 | + for (auto stream : stream_list_) { |
| 1357 | + OM2_CHK_STATUS(aclrtDestroyStream(stream)); | ||
| 1358 | + } | ||
| 1237 | } | 1359 | } |
| 1238 | for (auto &label : label_switch_label_list_) { | 1360 | for (auto &label : label_switch_label_list_) { |
| 1239 | if ((label.second != nullptr)) { | 1361 | if ((label.second != nullptr)) { |
| @@ -1250,7 +1372,9 @@ aclError Om2Model::ReleaseResources() { | |||
| 1250 | } | 1372 | } |
| 1251 | } | 1373 | } |
| 1252 | label_goto_args_.clear(); | 1374 | label_goto_args_.clear(); |
| 1253 | - OM2_CHK_STATUS(aclmdlRIDestroy(model_handle_)); | 1375 | + if (!is_external_rt_model_) { |
| 1376 | + OM2_CHK_STATUS(aclmdlRIDestroy(model_handle_)); | ||
| 1377 | + } | ||
| 1254 | if ((session_scope_mem_ptr_ != nullptr)) { | 1378 | if ((session_scope_mem_ptr_ != nullptr)) { |
| 1255 | OM2_CHK_STATUS(aclrtFree(session_scope_mem_ptr_)); | 1379 | OM2_CHK_STATUS(aclrtFree(session_scope_mem_ptr_)); |
| 1256 | } | 1380 | } |
| @@ -1104,6 +1104,32 @@ TEST_F(Om2CodegenModelBuilderUt, BuildRuntimeSemantic_WithNotifyEventLabel_Ok) { | |||
| 1104 | EXPECT_EQ(doc.runtime.stream_flag_values[0], "RT_STREAM_PERSISTENT"); | 1104 | EXPECT_EQ(doc.runtime.stream_flag_values[0], "RT_STREAM_PERSISTENT"); |
| 1105 | } | 1105 | } |
| 1106 | 1106 | ||
| 1107 | +TEST_F(Om2CodegenModelBuilderUt, BuildRuntimeSemantic_ReadsZeroCopySize) { | ||
| 1108 | + GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp(); | ||
| 1109 | + ASSERT_NE(ge_root_model, nullptr); | ||
| 1110 | + const auto &subgraph_models = ge_root_model->GetSubgraphInstanceNameToModel(); | ||
| 1111 | + ASSERT_FALSE(subgraph_models.empty()); | ||
| 1112 | + const auto ge_model = subgraph_models.begin()->second; | ||
| 1113 | + ASSERT_TRUE(AttrUtils::SetInt(ge_model, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, 512)); | ||
| 1114 | + | ||
| 1115 | + Om2CodegenModel doc; | ||
| 1116 | + ASSERT_EQ(BuildCodegenModel(ge_root_model, doc), SUCCESS); | ||
| 1117 | + EXPECT_EQ(doc.runtime.total_mem_size, 2048U); | ||
| 1118 | + EXPECT_EQ(doc.runtime.zero_copy_size, 512U); | ||
| 1119 | +} | ||
| 1120 | + | ||
| 1121 | +TEST_F(Om2CodegenModelBuilderUt, BuildRuntimeSemantic_RejectsOversizedZeroCopyMemory) { | ||
| 1122 | + GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp(); | ||
| 1123 | + ASSERT_NE(ge_root_model, nullptr); | ||
| 1124 | + const auto &subgraph_models = ge_root_model->GetSubgraphInstanceNameToModel(); | ||
| 1125 | + ASSERT_FALSE(subgraph_models.empty()); | ||
| 1126 | + const auto ge_model = subgraph_models.begin()->second; | ||
| 1127 | + ASSERT_TRUE(AttrUtils::SetInt(ge_model, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, 4096)); | ||
| 1128 | + | ||
| 1129 | + Om2CodegenModel doc; | ||
| 1130 | + EXPECT_EQ(BuildCodegenModel(ge_root_model, doc), PARAM_INVALID); | ||
| 1131 | +} | ||
| 1132 | + | ||
| 1107 | TEST_F(Om2CodegenModelBuilderUt, BuildModelIoSemantic_Aicore_Ok) { | 1133 | TEST_F(Om2CodegenModelBuilderUt, BuildModelIoSemantic_Aicore_Ok) { |
| 1108 | GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp(); | 1134 | GeRootModelPtr ge_root_model = CreateGeRootModelWithAicoreOp(); |
| 1109 | ASSERT_NE(ge_root_model, nullptr); | 1135 | ASSERT_NE(ge_root_model, nullptr); |
| @@ -883,10 +883,10 @@ TEST_F(Om2CodegenUt, InterfaceDumpApis_EmitInCLinkageAndPtrToU64Outside_Ok) { | |||
| 883 | "inline void *ValueToPtr(const uint64_t value) {\n", | 883 | "inline void *ValueToPtr(const uint64_t value) {\n", |
| 884 | "inline uint64_t PtrToU64(const void *ptr) {\n", | 884 | "inline uint64_t PtrToU64(const void *ptr) {\n", |
| 885 | "extern \"C\" {\n", | 885 | "extern \"C\" {\n", |
| 886 | - "enum Om2L0ArgKind {\n", | 886 | + "enum GertModelArgKind : uint64_t {\n", |
| 887 | - "struct Om2L0ArgSlotInfo {\n", | 887 | + "struct GertModelArgSlotInfo {\n", |
| 888 | - "struct Om2L0TaskRawInfo {\n", | 888 | + "struct GertModelTaskRawInfo {\n", |
| 889 | - "const struct Om2L0TaskRawInfo* l0_exception_dump_info;\n", | 889 | + "const struct GertModelTaskRawInfo *task_raw_info = nullptr;\n", |
| 890 | " uint64_t kernel_type = 10000U;\n", | 890 | " uint64_t kernel_type = 10000U;\n", |
| 891 | "enum GertModelTaskLaunchType : uint64_t", | 891 | "enum GertModelTaskLaunchType : uint64_t", |
| 892 | "struct GertModelLaunchKernelV2Params {\n", | 892 | "struct GertModelLaunchKernelV2Params {\n", |
| @@ -910,10 +910,8 @@ TEST_F(Om2CodegenUt, InterfaceDumpApis_EmitInCLinkageAndPtrToU64Outside_Ok) { | |||
| 910 | " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n", | 910 | " uint64_t struct_size = sizeof(GertModelTaskLaunchInfo);\n", |
| 911 | " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n", | 911 | " GertModelTaskLaunchType launch_type = ACL_RT_LAUNCH_KERNEL_V2;\n", |
| 912 | "GertModelLaunchFunc launch_func = nullptr;", | 912 | "GertModelLaunchFunc launch_func = nullptr;", |
| 913 | - "__attribute__((weak)) int32_t ReportDfxTaskPreprocess(uint32_t model_id,\n", | ||
| 914 | - "__attribute__((weak)) int32_t ReportDfxTaskPostprocess(uint32_t model_id,\n", | ||
| 915 | }); | 913 | }); |
| 916 | - EXPECT_LT(output.find(" uint32_t task_type;\n"), output.find(" uint64_t kernel_type = 10000U;\n")); | 914 | + EXPECT_LT(output.find(" uint64_t task_type = 0;\n"), output.find(" uint64_t kernel_type = 10000U;\n")); |
| 917 | EXPECT_EQ(output.find("report_task_preprocess"), std::string::npos); | 915 | EXPECT_EQ(output.find("report_task_preprocess"), std::string::npos); |
| 918 | EXPECT_EQ(output.find("report_task_postprocess"), std::string::npos); | 916 | EXPECT_EQ(output.find("report_task_postprocess"), std::string::npos); |
| 919 | EXPECT_EQ(output.find("get_data_dump_enabled"), std::string::npos); | 917 | EXPECT_EQ(output.find("get_data_dump_enabled"), std::string::npos); |
| @@ -940,10 +938,6 @@ TEST_F(Om2CodegenUt, LoadAndRunDumpHelpers_EmitInAnonymousNamespace_Ok) { | |||
| 940 | "namespace {\n", | 938 | "namespace {\n", |
| 941 | "gert::Tensor BuildTensor(void *device_address, uint64_t size, int32_t data_type, int32_t format,\n", | 939 | "gert::Tensor BuildTensor(void *device_address, uint64_t size, int32_t data_type, int32_t format,\n", |
| 942 | "const int64_t *shape_dims, uint64_t shape_dims_num) {\n", | 940 | "const int64_t *shape_dims, uint64_t shape_dims_num) {\n", |
| 943 | - "aclError ReportLaunchedOm2Task(const char *op_name, const char *op_type, uint64_t op_desc_id,\n", | ||
| 944 | - "const uint64_t *workspace_addrs, const uint64_t *workspace_sizes,\n", | ||
| 945 | - "uint32_t workspace_num,\n", | ||
| 946 | - "uint32_t task_type, uint32_t block_dim, void *stream,\n", | ||
| 947 | }); | 941 | }); |
| 948 | EXPECT_EQ(output.find("GetIsDataDump("), std::string::npos); | 942 | EXPECT_EQ(output.find("GetIsDataDump("), std::string::npos); |
| 949 | } | 943 | } |
| @@ -970,9 +964,9 @@ TEST_F(Om2CodegenUt, BuildL0ArgSlotEntries_EmitsTensorWorkspaceAndIgnoredKinds) | |||
| 970 | ASSERT_NE(entries, nullptr); | 964 | ASSERT_NE(entries, nullptr); |
| 971 | auto output = EmitNode(*entries); | 965 | auto output = EmitNode(*entries); |
| 972 | ExpectContainsAll(output, { | 966 | ExpectContainsAll(output, { |
| 973 | - "{OM2_L0_ARG_INPUT, 0U, 0U, 0UL, 0U, 0U, 0U}", | 967 | + "{sizeof(GertModelArgSlotInfo), GERT_MODEL_ARG_INPUT, 0U, 0U, 0UL, 0U, 0U, 0U}", |
| 974 | - "{OM2_L0_ARG_WORKSPACE, 0U, 8U, 0UL, 0U, 0U, 0U}", | 968 | + "{sizeof(GertModelArgSlotInfo), GERT_MODEL_ARG_WORKSPACE, 0U, 8U, 0UL, 0U, 0U, 0U}", |
| 975 | - "{OM2_L0_ARG_PLACEHOLDER, 0U, 16U, 0UL, 0U, 0U, 0U}", | 969 | + "{sizeof(GertModelArgSlotInfo), GERT_MODEL_ARG_PLACEHOLDER, 0U, 16U, 0UL, 0U, 0U, 0U}", |
| 976 | }); | 970 | }); |
| 977 | } | 971 | } |
| 978 | 972 | ||
| @@ -1510,8 +1504,7 @@ TEST_F(Om2CodegenUt, StablePartProvider_AllIds_Ok) { | |||
| 1510 | {StablePartId::kScopeGuard, "class ScopeGuard"}, | 1504 | {StablePartId::kScopeGuard, "class ScopeGuard"}, |
| 1511 | {StablePartId::kReadBinaryFileToBuffer, "BinaryBuffer ReadBinaryFileToBuffer"}, | 1505 | {StablePartId::kReadBinaryFileToBuffer, "BinaryBuffer ReadBinaryFileToBuffer"}, |
| 1512 | {StablePartId::kGenerateJsonFile, "aclError GenerateJsonFile"}, | 1506 | {StablePartId::kGenerateJsonFile, "aclError GenerateJsonFile"}, |
| 1513 | - {StablePartId::kInterfaceDumpApis, "struct Om2TaskInfo"}, | 1507 | + {StablePartId::kInterfaceDumpApis, "struct GertModelTaskDesc"}, |
| 1514 | - {StablePartId::kLoadAndRunDumpHelpers, "aclError ReportLaunchedOm2Task"}, | ||
| 1515 | {StablePartId::kOm2LogMacros, "#define OM2_LOGD"}, | 1508 | {StablePartId::kOm2LogMacros, "#define OM2_LOGD"}, |
| 1516 | }; | 1509 | }; |
| 1517 | 1510 | ||
| @@ -1734,18 +1727,18 @@ TEST_F(Om2CodegenUt, TaskCodeBuilderUtil_BuildL0ArgSlotEntries_AllKinds) { | |||
| 1734 | ASSERT_NE(entries, nullptr); | 1727 | ASSERT_NE(entries, nullptr); |
| 1735 | auto output = EmitNode(*entries); | 1728 | auto output = EmitNode(*entries); |
| 1736 | ExpectContainsAll(output, { | 1729 | ExpectContainsAll(output, { |
| 1737 | - "OM2_L0_ARG_INPUT", | 1730 | + "GERT_MODEL_ARG_INPUT", |
| 1738 | - "OM2_L0_ARG_OUTPUT", | 1731 | + "GERT_MODEL_ARG_OUTPUT", |
| 1739 | - "OM2_L0_ARG_WORKSPACE", | 1732 | + "GERT_MODEL_ARG_WORKSPACE", |
| 1740 | - "OM2_L0_ARG_TILING", | 1733 | + "GERT_MODEL_ARG_TILING", |
| 1741 | - "OM2_L0_ARG_CUSTOM_VALUE", | 1734 | + "GERT_MODEL_ARG_CUSTOM_VALUE", |
| 1742 | - "OM2_L0_ARG_PLACEHOLDER", | 1735 | + "GERT_MODEL_ARG_PLACEHOLDER", |
| 1743 | - "OM2_L0_ARG_LEVEL1_DESC", | 1736 | + "GERT_MODEL_ARG_LEVEL1_DESC", |
| 1744 | - "OM2_L0_ARG_SHAPE_INFO", | 1737 | + "GERT_MODEL_ARG_SHAPE_INFO", |
| 1745 | - "OM2_L0_ARG_FFTS_ADDR", | 1738 | + "GERT_MODEL_ARG_FFTS_ADDR", |
| 1746 | - "OM2_L0_ARG_EVENT_ADDR", | 1739 | + "GERT_MODEL_ARG_EVENT_ADDR", |
| 1747 | - "OM2_L0_ARG_OVERFLOW_ADDR", | 1740 | + "GERT_MODEL_ARG_OVERFLOW_ADDR", |
| 1748 | - "OM2_L0_ARG_EMPTY_ADDR", | 1741 | + "GERT_MODEL_ARG_EMPTY_ADDR", |
| 1749 | }); | 1742 | }); |
| 1750 | } | 1743 | } |
| 1751 | 1744 | ||
| @@ -1986,26 +1979,26 @@ TEST(Om2CodegenTypesUt, PublicTypesHaveStableDefaultsAndCallbacks) { | |||
| 1986 | GertModelLaunchKernelV2Params kernel{}; | 1979 | GertModelLaunchKernelV2Params kernel{}; |
| 1987 | GertModelLaunchStarsTaskWithFlagParams dsa{}; | 1980 | GertModelLaunchStarsTaskWithFlagParams dsa{}; |
| 1988 | GertModelTaskLaunchInfo launch{}; | 1981 | GertModelTaskLaunchInfo launch{}; |
| 1989 | - GertModelCallbacks callbacks{}; | 1982 | + GertModelLoadCallbacks callbacks{}; |
| 1990 | - Om2TaskInfo task{}; | 1983 | + GertModelTaskDesc task{}; |
| 1991 | 1984 | ||
| 1992 | EXPECT_EQ(kernel.struct_size, sizeof(GertModelLaunchKernelV2Params)); | 1985 | EXPECT_EQ(kernel.struct_size, sizeof(GertModelLaunchKernelV2Params)); |
| 1993 | EXPECT_EQ(dsa.struct_size, sizeof(GertModelLaunchStarsTaskWithFlagParams)); | 1986 | EXPECT_EQ(dsa.struct_size, sizeof(GertModelLaunchStarsTaskWithFlagParams)); |
| 1994 | EXPECT_EQ(launch.struct_size, sizeof(GertModelTaskLaunchInfo)); | 1987 | EXPECT_EQ(launch.struct_size, sizeof(GertModelTaskLaunchInfo)); |
| 1995 | - EXPECT_EQ(callbacks.struct_size, sizeof(GertModelCallbacks)); | 1988 | + EXPECT_EQ(callbacks.struct_size, sizeof(GertModelLoadCallbacks)); |
| 1996 | EXPECT_EQ(launch.launch_type, ACL_RT_LAUNCH_KERNEL_V2); | 1989 | EXPECT_EQ(launch.launch_type, ACL_RT_LAUNCH_KERNEL_V2); |
| 1997 | EXPECT_EQ(task.kernel_type, static_cast<uint64_t>(ccKernelType::INVALID)); | 1990 | EXPECT_EQ(task.kernel_type, static_cast<uint64_t>(ccKernelType::INVALID)); |
| 1998 | static_assert(std::is_same<decltype(task.kernel_type), uint64_t>::value); | 1991 | static_assert(std::is_same<decltype(task.kernel_type), uint64_t>::value); |
| 1999 | - static_assert(offsetof(Om2TaskInfo, task_type) < offsetof(Om2TaskInfo, kernel_type)); | 1992 | + static_assert(offsetof(GertModelTaskDesc, task_type) < offsetof(GertModelTaskDesc, kernel_type)); |
| 2000 | - static_assert(offsetof(Om2TaskInfo, kernel_type) < offsetof(Om2TaskInfo, stream)); | 1993 | + static_assert(offsetof(GertModelTaskDesc, kernel_type) < offsetof(GertModelTaskDesc, stream)); |
| 2001 | EXPECT_EQ(kernel.reserved_1, 0U); | 1994 | EXPECT_EQ(kernel.reserved_1, 0U); |
| 2002 | EXPECT_EQ(dsa.reserved_1, 0U); | 1995 | EXPECT_EQ(dsa.reserved_1, 0U); |
| 2003 | EXPECT_EQ(dsa.reserved_2, 0U); | 1996 | EXPECT_EQ(dsa.reserved_2, 0U); |
| 2004 | EXPECT_EQ(callbacks.report_model_base_info, nullptr); | 1997 | EXPECT_EQ(callbacks.report_model_base_info, nullptr); |
| 2005 | EXPECT_EQ(callbacks.launch_func, nullptr); | 1998 | EXPECT_EQ(callbacks.launch_func, nullptr); |
| 2006 | - EXPECT_FALSE(HasLegacyLaunchCallback<GertModelCallbacks>::value); | 1999 | + EXPECT_FALSE(HasLegacyLaunchCallback<GertModelLoadCallbacks>::value); |
| 2007 | - EXPECT_FALSE(HasLegacyPostCallback<GertModelCallbacks>::value); | 2000 | + EXPECT_FALSE(HasLegacyPostCallback<GertModelLoadCallbacks>::value); |
| 2008 | - EXPECT_FALSE(HasLegacyDataDumpCallback<GertModelCallbacks>::value); | 2001 | + EXPECT_FALSE(HasLegacyDataDumpCallback<GertModelLoadCallbacks>::value); |
| 2009 | } | 2002 | } |
| 2010 | 2003 | ||
| 2011 | TEST(Om2CodegenTypesUt, LaunchTypeValuesAndUnionLayoutAreStable) { | 2004 | TEST(Om2CodegenTypesUt, LaunchTypeValuesAndUnionLayoutAreStable) { |
| @@ -2465,6 +2458,57 @@ TEST_F(Om2CodegenUt, CppEmitter_EmptyTypeNameSeparator) { | |||
| 2465 | EXPECT_NE(output.find("EmptyTypeAlias"), std::string::npos); | 2458 | EXPECT_NE(output.find("EmptyTypeAlias"), std::string::npos); |
| 2466 | } | 2459 | } |
| 2467 | 2460 | ||
| 2461 | +TEST_F(Om2CodegenUt, CppEmitter_SwitchCaseBodyIndentation) { | ||
| 2462 | + AstContext ctx; | ||
| 2463 | + AstBuildContext ast(ctx); | ||
| 2464 | + | ||
| 2465 | + const auto *switch_stmt = ast.Switch("value", { | ||
| 2466 | + ast.Case("CASE_A"), | ||
| 2467 | + ast.Return("result_a"), | ||
| 2468 | + ast.Case("CASE_B"), | ||
| 2469 | + ast.Return("result_b"), | ||
| 2470 | + ast.Case(nullptr), | ||
| 2471 | + ast.Return("default_result"), | ||
| 2472 | + }); | ||
| 2473 | + | ||
| 2474 | + EXPECT_EQ(EmitNode(*switch_stmt), | ||
| 2475 | + "switch (value) {\n" | ||
| 2476 | + " case CASE_A:\n" | ||
| 2477 | + " return result_a;\n" | ||
| 2478 | + " case CASE_B:\n" | ||
| 2479 | + " return result_b;\n" | ||
| 2480 | + " default:\n" | ||
| 2481 | + " return default_result;\n" | ||
| 2482 | + "}\n"); | ||
| 2483 | +} | ||
| 2484 | + | ||
| 2485 | +TEST_F(Om2CodegenUt, CppEmitter_NestedSwitchCaseBodyIndentation) { | ||
| 2486 | + AstContext ctx; | ||
| 2487 | + AstBuildContext ast(ctx); | ||
| 2488 | + | ||
| 2489 | + const auto *switch_stmt = ast.Switch("outer", { | ||
| 2490 | + ast.Case("OUTER_CASE"), | ||
| 2491 | + ast.Switch("inner", | ||
| 2492 | + { | ||
| 2493 | + ast.Case("INNER_CASE"), | ||
| 2494 | + ast.Return("inner_result"), | ||
| 2495 | + }), | ||
| 2496 | + ast.Case(nullptr), | ||
| 2497 | + ast.Return("outer_default_result"), | ||
| 2498 | + }); | ||
| 2499 | + | ||
| 2500 | + EXPECT_EQ(EmitNode(*switch_stmt), | ||
| 2501 | + "switch (outer) {\n" | ||
| 2502 | + " case OUTER_CASE:\n" | ||
| 2503 | + " switch (inner) {\n" | ||
| 2504 | + " case INNER_CASE:\n" | ||
| 2505 | + " return inner_result;\n" | ||
| 2506 | + " }\n" | ||
| 2507 | + " default:\n" | ||
| 2508 | + " return outer_default_result;\n" | ||
| 2509 | + "}\n"); | ||
| 2510 | +} | ||
| 2511 | + | ||
| 2468 | class RTVarResourceCoverageTest : public testing::Test { | 2512 | class RTVarResourceCoverageTest : public testing::Test { |
| 2469 | protected: | 2513 | protected: |
| 2470 | gert::RTVarEntry MakeEntry(const std::string &var_name, int format, int dtype) { | 2514 | gert::RTVarEntry MakeEntry(const std::string &var_name, int format, int dtype) { |
| @@ -386,6 +386,12 @@ static std::string interface_header_src = R"(#pragma once | |||
| 386 | #include <cstddef> | 386 | #include <cstddef> |
| 387 | #include <cstdint> | 387 | #include <cstdint> |
| 388 | 388 | ||
| 389 | +typedef void* aclmdlRI; | ||
| 390 | +typedef void* aclrtStream; | ||
| 391 | +typedef void* aclrtEvent; | ||
| 392 | +typedef void* aclrtLabel; | ||
| 393 | +typedef void* aclrtNotify; | ||
| 394 | + | ||
| 389 | namespace gert { | 395 | namespace gert { |
| 390 | class Tensor; | 396 | class Tensor; |
| 391 | } | 397 | } |
| @@ -408,8 +414,9 @@ struct GertModelLoadConfig { | |||
| 408 | uint64_t model_id = 0; // used for logging | 414 | uint64_t model_id = 0; // used for logging |
| 409 | void *instance_handle = nullptr; | 415 | void *instance_handle = nullptr; |
| 410 | void *executor_handle = nullptr; | 416 | void *executor_handle = nullptr; |
| 411 | - const struct GertModelCallbacks *callbacks = nullptr; | 417 | + const struct GertModelLoadCallbacks *callbacks = nullptr; |
| 412 | int64_t priority = 0; | 418 | int64_t priority = 0; |
| 419 | + uint64_t reuse_zero_copy = 0; | ||
| 413 | }; | 420 | }; |
| 414 | 421 | ||
| 415 | struct GertModelRunConfig { | 422 | struct GertModelRunConfig { |
| @@ -475,6 +482,9 @@ bool CheckWorkPtr(void *work_ptr) { | |||
| 475 | if (mode_str == "NON_NULL") { | 482 | if (mode_str == "NON_NULL") { |
| 476 | return work_ptr != nullptr; | 483 | return work_ptr != nullptr; |
| 477 | } | 484 | } |
| 485 | + if (mode_str == "NULL") { | ||
| 486 | + return work_ptr == nullptr; | ||
| 487 | + } | ||
| 478 | if (mode_str == "EQUAL") { | 488 | if (mode_str == "EQUAL") { |
| 479 | const char *value = std::getenv("OM2_EXPECT_WORK_PTR_VALUE"); | 489 | const char *value = std::getenv("OM2_EXPECT_WORK_PTR_VALUE"); |
| 480 | if (value == nullptr) { | 490 | if (value == nullptr) { |
| @@ -651,6 +661,8 @@ set(CMAKE_CXX_STANDARD 17) | |||
| 651 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | 661 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 652 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) | 662 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 653 | 663 | ||
| 664 | +include_directories($ENV{ASCEND_HOME_PATH}/include) | ||
| 665 | + | ||
| 654 | add_library(g1_om2 SHARED | 666 | add_library(g1_om2 SHARED |
| 655 | g1_resources.cpp | 667 | g1_resources.cpp |
| 656 | g1_kernel_reg.cpp | 668 | g1_kernel_reg.cpp |
| @@ -1671,7 +1683,7 @@ TEST_F(Om2ModelExecutorUt, load_ok_with_internal_work_ptr_and_external_device_we | |||
| 1671 | auto load_arg = MakeOm2LoadArg(); | 1683 | auto load_arg = MakeOm2LoadArg(); |
| 1672 | load_arg.weight_ptr = device_weight.data(); | 1684 | load_arg.weight_ptr = device_weight.data(); |
| 1673 | load_arg.weight_size = device_weight.size(); | 1685 | load_arg.weight_size = device_weight.size(); |
| 1674 | - ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NON_NULL", 1), 0); | 1686 | + ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NULL", 1), 0); |
| 1675 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_MODE", "NON_NULL", 1), 0); | 1687 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_MODE", "NON_NULL", 1), 0); |
| 1676 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_FIRST_BYTE", "1", 1), 0); | 1688 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_FIRST_BYTE", "1", 1), 0); |
| 1677 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_PTR_MODE", "EQUAL", 1), 0); | 1689 | ASSERT_EQ(setenv("OM2_EXPECT_CONST0_PTR_MODE", "EQUAL", 1), 0); |
| @@ -3195,26 +3207,26 @@ TEST_F(Om2ModelExecutorUt, make_om2_load_arg_has_reuse_zero_copy_false_by_defaul | |||
| 3195 | EXPECT_FALSE(load_arg.reuse_zero_copy); | 3207 | EXPECT_FALSE(load_arg.reuse_zero_copy); |
| 3196 | } | 3208 | } |
| 3197 | 3209 | ||
| 3198 | -TEST_F(Om2ModelExecutorUt, load_with_reuse_zero_copy_true_and_internal_work_allocation) { | 3210 | +TEST_F(Om2ModelExecutorUt, load_with_reuse_zero_copy_true_passes_null_work_ptr_to_pbody) { |
| 3199 | auto model_data_holder = LoadValidModelData(); | 3211 | auto model_data_holder = LoadValidModelData(); |
| 3200 | gert::Om2ModelExecutor executor; | 3212 | gert::Om2ModelExecutor executor; |
| 3201 | auto load_arg = MakeOm2LoadArg(); | 3213 | auto load_arg = MakeOm2LoadArg(); |
| 3202 | load_arg.reuse_zero_copy = true; | 3214 | load_arg.reuse_zero_copy = true; |
| 3203 | 3215 | ||
| 3204 | EnvValueGuard guard_mode("OM2_EXPECT_WORK_PTR_MODE"); | 3216 | EnvValueGuard guard_mode("OM2_EXPECT_WORK_PTR_MODE"); |
| 3205 | - ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NON_NULL", 1), 0); | 3217 | + ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NULL", 1), 0); |
| 3206 | 3218 | ||
| 3207 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); | 3219 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); |
| 3208 | } | 3220 | } |
| 3209 | 3221 | ||
| 3210 | -TEST_F(Om2ModelExecutorUt, load_with_reuse_zero_copy_false_and_internal_work_allocation) { | 3222 | +TEST_F(Om2ModelExecutorUt, load_with_reuse_zero_copy_false_passes_null_work_ptr_to_pbody) { |
| 3211 | auto model_data_holder = LoadValidModelData(); | 3223 | auto model_data_holder = LoadValidModelData(); |
| 3212 | gert::Om2ModelExecutor executor; | 3224 | gert::Om2ModelExecutor executor; |
| 3213 | auto load_arg = MakeOm2LoadArg(); | 3225 | auto load_arg = MakeOm2LoadArg(); |
| 3214 | load_arg.reuse_zero_copy = false; | 3226 | load_arg.reuse_zero_copy = false; |
| 3215 | 3227 | ||
| 3216 | EnvValueGuard guard_mode("OM2_EXPECT_WORK_PTR_MODE"); | 3228 | EnvValueGuard guard_mode("OM2_EXPECT_WORK_PTR_MODE"); |
| 3217 | - ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NON_NULL", 1), 0); | 3229 | + ASSERT_EQ(setenv("OM2_EXPECT_WORK_PTR_MODE", "NULL", 1), 0); |
| 3218 | 3230 | ||
| 3219 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); | 3231 | EXPECT_EQ(executor.Load(model_data_holder.model_data, load_arg, 1U), SUCCESS); |
| 3220 | } | 3232 | } |
| @@ -44,6 +44,12 @@ static const std::string fake_om2_so_src = R"( | |||
| 44 | #include <cstddef> | 44 | #include <cstddef> |
| 45 | #include <cstdint> | 45 | #include <cstdint> |
| 46 | 46 | ||
| 47 | +typedef void* aclmdlRI; | ||
| 48 | +typedef void* aclrtStream; | ||
| 49 | +typedef void* aclrtEvent; | ||
| 50 | +typedef void* aclrtLabel; | ||
| 51 | +typedef void* aclrtNotify; | ||
| 52 | + | ||
| 47 | struct GertModelLoadConfig { | 53 | struct GertModelLoadConfig { |
| 48 | uint64_t struct_size; | 54 | uint64_t struct_size; |
| 49 | const char **bin_files; | 55 | const char **bin_files; |
| @@ -57,8 +63,17 @@ struct GertModelLoadConfig { | |||
| 57 | uint64_t model_id; | 63 | uint64_t model_id; |
| 58 | void *instance_handle; | 64 | void *instance_handle; |
| 59 | void *executor_handle = nullptr; | 65 | void *executor_handle = nullptr; |
| 60 | - const struct GertModelCallbacks *callbacks; | 66 | + const struct GertModelLoadCallbacks *callbacks; |
| 61 | int64_t priority; | 67 | int64_t priority; |
| 68 | + aclmdlRI external_rt_model = nullptr; | ||
| 69 | + aclrtStream *external_streams = nullptr; | ||
| 70 | + uint64_t external_stream_num = 0; | ||
| 71 | + aclrtEvent *external_events = nullptr; | ||
| 72 | + uint64_t external_event_num = 0; | ||
| 73 | + aclrtLabel *external_labels = nullptr; | ||
| 74 | + uint64_t external_label_num = 0; | ||
| 75 | + aclrtNotify *external_notifies = nullptr; | ||
| 76 | + uint64_t external_notify_num = 0; | ||
| 62 | }; | 77 | }; |
| 63 | 78 | ||
| 64 | struct GertModelRunConfig { | 79 | struct GertModelRunConfig { |
| @@ -78,7 +78,7 @@ class CallbackRuntimeUt : public testing::Test { | |||
| 78 | AclRuntimeStub::UnInstall(&acl_); | 78 | AclRuntimeStub::UnInstall(&acl_); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | - GertModelTaskLaunchInfo MakeKernelInfo(Om2TaskInfo &task, GertModelTaskLaunchParams ¶ms, | 81 | + GertModelTaskLaunchInfo MakeKernelInfo(GertModelTaskDesc &task, GertModelTaskLaunchParams ¶ms, |
| 82 | aclrtLaunchKernelCfg *cfg = nullptr) { | 82 | aclrtLaunchKernelCfg *cfg = nullptr) { |
| 83 | task.op_name = "op"; | 83 | task.op_name = "op"; |
| 84 | task.op_type = "Type"; | 84 | task.op_type = "Type"; |
| @@ -101,7 +101,7 @@ class CallbackRuntimeUt : public testing::Test { | |||
| 101 | }; | 101 | }; |
| 102 | 102 | ||
| 103 | TEST_F(CallbackRuntimeUt, KernelLaunchUsesAclAndPostprocesses) { | 103 | TEST_F(CallbackRuntimeUt, KernelLaunchUsesAclAndPostprocesses) { |
| 104 | - Om2TaskInfo task{}; | 104 | + GertModelTaskDesc task{}; |
| 105 | GertModelTaskLaunchParams params{}; | 105 | GertModelTaskLaunchParams params{}; |
| 106 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | 106 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); |
| 107 | 107 | ||
| @@ -118,7 +118,7 @@ TEST_F(CallbackRuntimeUt, KernelLaunchSetsDataDumpAttribute) { | |||
| 118 | aclrtLaunchKernelCfg cfg{}; | 118 | aclrtLaunchKernelCfg cfg{}; |
| 119 | cfg.attrs = &attr; | 119 | cfg.attrs = &attr; |
| 120 | cfg.numAttrs = 1U; | 120 | cfg.numAttrs = 1U; |
| 121 | - Om2TaskInfo task{}; | 121 | + GertModelTaskDesc task{}; |
| 122 | GertModelTaskLaunchParams params{}; | 122 | GertModelTaskLaunchParams params{}; |
| 123 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params, &cfg); | 123 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params, &cfg); |
| 124 | 124 | ||
| @@ -128,7 +128,7 @@ TEST_F(CallbackRuntimeUt, KernelLaunchSetsDataDumpAttribute) { | |||
| 128 | 128 | ||
| 129 | TEST_F(CallbackRuntimeUt, KernelLaunchErrorPropagates) { | 129 | TEST_F(CallbackRuntimeUt, KernelLaunchErrorPropagates) { |
| 130 | acl_.launch_ret = ACL_ERROR_RT_INTERNAL_ERROR; | 130 | acl_.launch_ret = ACL_ERROR_RT_INTERNAL_ERROR; |
| 131 | - Om2TaskInfo task{}; | 131 | + GertModelTaskDesc task{}; |
| 132 | GertModelTaskLaunchParams params{}; | 132 | GertModelTaskLaunchParams params{}; |
| 133 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | 133 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); |
| 134 | 134 | ||
| @@ -138,7 +138,7 @@ TEST_F(CallbackRuntimeUt, KernelLaunchErrorPropagates) { | |||
| 138 | 138 | ||
| 139 | TEST_F(CallbackRuntimeUt, PostprocessTaskIdErrorPropagates) { | 139 | TEST_F(CallbackRuntimeUt, PostprocessTaskIdErrorPropagates) { |
| 140 | acl_.task_id_ret = ACL_ERROR_RT_INTERNAL_ERROR; | 140 | acl_.task_id_ret = ACL_ERROR_RT_INTERNAL_ERROR; |
| 141 | - Om2TaskInfo task{}; | 141 | + GertModelTaskDesc task{}; |
| 142 | GertModelTaskLaunchParams params{}; | 142 | GertModelTaskLaunchParams params{}; |
| 143 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | 143 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); |
| 144 | 144 | ||
| @@ -149,7 +149,7 @@ TEST_F(CallbackRuntimeUt, PostprocessTaskIdErrorPropagates) { | |||
| 149 | TEST_F(CallbackRuntimeUt, NonAicoreKernelTypesStillLaunch) { | 149 | TEST_F(CallbackRuntimeUt, NonAicoreKernelTypesStillLaunch) { |
| 150 | for (const auto kernel_type : | 150 | for (const auto kernel_type : |
| 151 | {ccKernelType::AI_CPU, ccKernelType::CUSTOMIZED, ccKernelType::HOST_CPU, ccKernelType::AI_CPU_KFC}) { | 151 | {ccKernelType::AI_CPU, ccKernelType::CUSTOMIZED, ccKernelType::HOST_CPU, ccKernelType::AI_CPU_KFC}) { |
| 152 | - Om2TaskInfo task{}; | 152 | + GertModelTaskDesc task{}; |
| 153 | task.kernel_type = static_cast<uint64_t>(kernel_type); | 153 | task.kernel_type = static_cast<uint64_t>(kernel_type); |
| 154 | GertModelTaskLaunchParams params{}; | 154 | GertModelTaskLaunchParams params{}; |
| 155 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); | 155 | GertModelTaskLaunchInfo info = MakeKernelInfo(task, params); |
| @@ -163,7 +163,7 @@ TEST_F(CallbackRuntimeUt, KernelInvalidArgumentsAreHandled) { | |||
| 163 | info.launch_type = ACL_RT_LAUNCH_KERNEL_V2; | 163 | info.launch_type = ACL_RT_LAUNCH_KERNEL_V2; |
| 164 | EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | 164 | EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); |
| 165 | 165 | ||
| 166 | - Om2TaskInfo task{}; | 166 | + GertModelTaskDesc task{}; |
| 167 | info.task_info = &task; | 167 | info.task_info = &task; |
| 168 | EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); | 168 | EXPECT_EQ(GertModelLaunchTask(nullptr, &info), SUCCESS); |
| 169 | } | 169 | } |
| @@ -179,7 +179,7 @@ TEST_F(CallbackRuntimeUt, UnsupportedLaunchTypeReturnsUnsupported) { | |||
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | TEST_F(CallbackRuntimeUt, DsaLaunchMergesDataDumpFlagAndCallsRuntime) { | 181 | TEST_F(CallbackRuntimeUt, DsaLaunchMergesDataDumpFlagAndCallsRuntime) { |
| 182 | - Om2TaskInfo task{}; | 182 | + GertModelTaskDesc task{}; |
| 183 | task.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_DSA); | 183 | task.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_DSA); |
| 184 | GertModelTaskLaunchParams params{}; | 184 | GertModelTaskLaunchParams params{}; |
| 185 | params.launch_stars_task_params.task_sqe = reinterpret_cast<void *>(0x44); | 185 | params.launch_stars_task_params.task_sqe = reinterpret_cast<void *>(0x44); |
| @@ -201,7 +201,7 @@ TEST_F(CallbackRuntimeUt, DsaLaunchMergesDataDumpFlagAndCallsRuntime) { | |||
| 201 | 201 | ||
| 202 | TEST_F(CallbackRuntimeUt, DsaRuntimeErrorPropagates) { | 202 | TEST_F(CallbackRuntimeUt, DsaRuntimeErrorPropagates) { |
| 203 | runtime_.general_ctrl_ret = ACL_ERROR_RT_INTERNAL_ERROR; | 203 | runtime_.general_ctrl_ret = ACL_ERROR_RT_INTERNAL_ERROR; |
| 204 | - Om2TaskInfo task{}; | 204 | + GertModelTaskDesc task{}; |
| 205 | GertModelTaskLaunchParams params{}; | 205 | GertModelTaskLaunchParams params{}; |
| 206 | GertModelTaskLaunchInfo info{}; | 206 | GertModelTaskLaunchInfo info{}; |
| 207 | info.launch_type = RT_STARS_TASK_LAUNCH_WITH_FLAG; | 207 | info.launch_type = RT_STARS_TASK_LAUNCH_WITH_FLAG; |
| @@ -214,8 +214,8 @@ TEST(GertModelExecutorTypesUt, DefaultsAndLayoutAreStable) { | |||
| 214 | GertModelLaunchKernelV2Params kernel{}; | 214 | GertModelLaunchKernelV2Params kernel{}; |
| 215 | GertModelLaunchStarsTaskWithFlagParams dsa{}; | 215 | GertModelLaunchStarsTaskWithFlagParams dsa{}; |
| 216 | GertModelTaskLaunchInfo info{}; | 216 | GertModelTaskLaunchInfo info{}; |
| 217 | - GertModelCallbacks callbacks{}; | 217 | + GertModelLoadCallbacks callbacks{}; |
| 218 | - Om2TaskInfo task{}; | 218 | + GertModelTaskDesc task{}; |
| 219 | 219 | ||
| 220 | EXPECT_EQ(kernel.struct_size, sizeof(kernel)); | 220 | EXPECT_EQ(kernel.struct_size, sizeof(kernel)); |
| 221 | EXPECT_EQ(dsa.struct_size, sizeof(dsa)); | 221 | EXPECT_EQ(dsa.struct_size, sizeof(dsa)); |
| @@ -379,7 +379,7 @@ TEST_F(ModelDumpManagerTest, SetModelDumpInfoWithoutOverflowTest) { | |||
| 379 | // 测试 AddOm2TaskInfo - 无 Dump 启用场景 | 379 | // 测试 AddOm2TaskInfo - 无 Dump 启用场景 |
| 380 | TEST_F(ModelDumpManagerTest, AddOm2TaskInfoNoDumpEnabledTest) { | 380 | TEST_F(ModelDumpManagerTest, AddOm2TaskInfoNoDumpEnabledTest) { |
| 381 | ModelDumpManager manager(1); | 381 | ModelDumpManager manager(1); |
| 382 | - Om2TaskInfo info{}; | 382 | + GertModelTaskDesc info{}; |
| 383 | info.op_name = "test_op"; | 383 | info.op_name = "test_op"; |
| 384 | info.task_id = 1; | 384 | info.task_id = 1; |
| 385 | info.stream_id = 1; | 385 | info.stream_id = 1; |
| @@ -390,7 +390,7 @@ TEST_F(ModelDumpManagerTest, AddOm2TaskInfoNoDumpEnabledTest) { | |||
| 390 | 390 | ||
| 391 | TEST_F(ModelDumpManagerTest, PreprocessOm2TaskInfoNoL0InfoReturnsSuccess) { | 391 | TEST_F(ModelDumpManagerTest, PreprocessOm2TaskInfoNoL0InfoReturnsSuccess) { |
| 392 | ModelDumpManager manager(1); | 392 | ModelDumpManager manager(1); |
| 393 | - Om2TaskInfo info{}; | 393 | + GertModelTaskDesc info{}; |
| 394 | info.op_name = "test_op"; | 394 | info.op_name = "test_op"; |
| 395 | info.stream_id = 1; | 395 | info.stream_id = 1; |
| 396 | 396 | ||
| @@ -400,7 +400,7 @@ TEST_F(ModelDumpManagerTest, PreprocessOm2TaskInfoNoL0InfoReturnsSuccess) { | |||
| 400 | 400 | ||
| 401 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessNullParamReturnsSuccess) { | 401 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessNullParamReturnsSuccess) { |
| 402 | gert::Om2ModelExecutor executor; | 402 | gert::Om2ModelExecutor executor; |
| 403 | - Om2TaskInfo info{}; | 403 | + GertModelTaskDesc info{}; |
| 404 | 404 | ||
| 405 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, nullptr, 0U), ge::SUCCESS); | 405 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, nullptr, 0U), ge::SUCCESS); |
| 406 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, nullptr, nullptr, 0U), ge::SUCCESS); | 406 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, nullptr, nullptr, 0U), ge::SUCCESS); |
| @@ -408,7 +408,7 @@ TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessNullParamReturnsSuccess) { | |||
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessReservedParamReturnsSuccess) { | 410 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessReservedParamReturnsSuccess) { |
| 411 | - Om2TaskInfo info{}; | 411 | + GertModelTaskDesc info{}; |
| 412 | uint32_t reserved = 0U; | 412 | uint32_t reserved = 0U; |
| 413 | 413 | ||
| 414 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); | 414 | EXPECT_EQ(ReportDfxTaskPreprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); |
| @@ -416,7 +416,7 @@ TEST_F(ModelDumpManagerTest, ReportDfxTaskPreprocessReservedParamReturnsSuccess) | |||
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessReservedParamReturnsSuccess) { | 418 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessReservedParamReturnsSuccess) { |
| 419 | - Om2TaskInfo info{}; | 419 | + GertModelTaskDesc info{}; |
| 420 | uint32_t reserved = 0U; | 420 | uint32_t reserved = 0U; |
| 421 | 421 | ||
| 422 | EXPECT_EQ(ReportDfxTaskPostprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); | 422 | EXPECT_EQ(ReportDfxTaskPostprocess(1U, nullptr, &info, &reserved, 0U), ge::SUCCESS); |
| @@ -425,7 +425,7 @@ TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessReservedParamReturnsSuccess | |||
| 425 | 425 | ||
| 426 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessWithoutDumpManagerReturnsSuccess) { | 426 | TEST_F(ModelDumpManagerTest, ReportDfxTaskPostprocessWithoutDumpManagerReturnsSuccess) { |
| 427 | gert::Om2ModelExecutor executor; | 427 | gert::Om2ModelExecutor executor; |
| 428 | - Om2TaskInfo info{}; | 428 | + GertModelTaskDesc info{}; |
| 429 | info.op_name = "test_op"; | 429 | info.op_name = "test_op"; |
| 430 | info.task_id = 1; | 430 | info.task_id = 1; |
| 431 | info.stream_id = 1; | 431 | info.stream_id = 1; |
| @@ -457,7 +457,7 @@ TEST_F(ModelDumpManagerTest, AddOm2TaskInfoDataDumpEnabledTest) { | |||
| 457 | DumpConfig::Instance().SetDataDumpEnabled(true); | 457 | DumpConfig::Instance().SetDataDumpEnabled(true); |
| 458 | 458 | ||
| 459 | ModelDumpManager manager(1); | 459 | ModelDumpManager manager(1); |
| 460 | - Om2TaskInfo info{}; | 460 | + GertModelTaskDesc info{}; |
| 461 | info.op_name = "test_op"; | 461 | info.op_name = "test_op"; |
| 462 | info.task_id = 1; | 462 | info.task_id = 1; |
| 463 | info.stream_id = 1; | 463 | info.stream_id = 1; |
| @@ -472,7 +472,7 @@ TEST_F(ModelDumpManagerTest, AddOm2TaskInfoExceptionDumpEnabledTest) { | |||
| 472 | DumpConfig::Instance().SetExceptionDumpEnabled(true); | 472 | DumpConfig::Instance().SetExceptionDumpEnabled(true); |
| 473 | 473 | ||
| 474 | ModelDumpManager manager(1); | 474 | ModelDumpManager manager(1); |
| 475 | - Om2TaskInfo info{}; | 475 | + GertModelTaskDesc info{}; |
| 476 | info.op_name = "test_op"; | 476 | info.op_name = "test_op"; |
| 477 | info.task_id = 1; | 477 | info.task_id = 1; |
| 478 | info.stream_id = 1; | 478 | info.stream_id = 1; |
| @@ -511,7 +511,7 @@ TEST_F(ModelDumpManagerTest, DispatchDumpInfoDataDumpEnabledTest) { | |||
| 511 | modelInfo.model_id = 1; | 511 | modelInfo.model_id = 1; |
| 512 | manager.SetModelDumpInfo(modelInfo); | 512 | manager.SetModelDumpInfo(modelInfo); |
| 513 | 513 | ||
| 514 | - Om2TaskInfo taskInfo{}; | 514 | + GertModelTaskDesc taskInfo{}; |
| 515 | taskInfo.op_name = "test_op"; | 515 | taskInfo.op_name = "test_op"; |
| 516 | taskInfo.task_id = 1; | 516 | taskInfo.task_id = 1; |
| 517 | taskInfo.stream_id = 1; | 517 | taskInfo.stream_id = 1; |
| @@ -524,7 +524,7 @@ TEST_F(ModelDumpManagerTest, DispatchDumpInfoDataDumpEnabledTest) { | |||
| 524 | // ExceptionDumpImpl 测试 | 524 | // ExceptionDumpImpl 测试 |
| 525 | TEST(ExceptionDumpImplTest, BasicTest) { | 525 | TEST(ExceptionDumpImplTest, BasicTest) { |
| 526 | ExceptionDumpImpl impl; | 526 | ExceptionDumpImpl impl; |
| 527 | - Om2TaskInfo info{}; | 527 | + GertModelTaskDesc info{}; |
| 528 | info.op_name = "test_op"; | 528 | info.op_name = "test_op"; |
| 529 | info.task_id = 1; | 529 | info.task_id = 1; |
| 530 | info.stream_id = 1; | 530 | info.stream_id = 1; |
| @@ -545,7 +545,7 @@ TEST(ExceptionDumpImplTest, SaveOpInfoLiteExceptionDoesNotReportL1Info) { | |||
| 545 | SUCCESS); | 545 | SUCCESS); |
| 546 | 546 | ||
| 547 | ExceptionDumpImpl impl; | 547 | ExceptionDumpImpl impl; |
| 548 | - Om2TaskInfo info{}; | 548 | + GertModelTaskDesc info{}; |
| 549 | info.op_name = "test_op"; | 549 | info.op_name = "test_op"; |
| 550 | info.op_type = "Add"; | 550 | info.op_type = "Add"; |
| 551 | info.task_id = 1U; | 551 | info.task_id = 1U; |
| @@ -563,7 +563,7 @@ TEST(ExceptionDumpImplTest, SaveOpInfoAicErrNormReportsL1Info) { | |||
| 563 | SUCCESS); | 563 | SUCCESS); |
| 564 | 564 | ||
| 565 | ExceptionDumpImpl impl; | 565 | ExceptionDumpImpl impl; |
| 566 | - Om2TaskInfo info{}; | 566 | + GertModelTaskDesc info{}; |
| 567 | info.op_name = "test_op"; | 567 | info.op_name = "test_op"; |
| 568 | info.op_type = "Add"; | 568 | info.op_type = "Add"; |
| 569 | info.task_id = 1U; | 569 | info.task_id = 1U; |
| @@ -575,7 +575,7 @@ TEST(ExceptionDumpImplTest, SaveOpInfoAicErrNormReportsL1Info) { | |||
| 575 | 575 | ||
| 576 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoNoInfoReturnsSuccess) { | 576 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoNoInfoReturnsSuccess) { |
| 577 | ExceptionDumpImpl impl; | 577 | ExceptionDumpImpl impl; |
| 578 | - Om2TaskInfo info{}; | 578 | + GertModelTaskDesc info{}; |
| 579 | info.op_name = "test_op"; | 579 | info.op_name = "test_op"; |
| 580 | 580 | ||
| 581 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); | 581 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); |
| @@ -583,14 +583,14 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoNoInfoReturnsSuccess) { | |||
| 583 | 583 | ||
| 584 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoArgNumWithoutArgsReturnsInvalid) { | 584 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoArgNumWithoutArgsReturnsInvalid) { |
| 585 | ExceptionDumpImpl impl; | 585 | ExceptionDumpImpl impl; |
| 586 | - Om2L0TaskRawInfo l0Info{}; | 586 | + GertModelTaskRawInfo l0Info{}; |
| 587 | - l0Info.version = 1U; | 587 | + l0Info.struct_size = 1U; |
| 588 | l0Info.arg_num = 1U; | 588 | l0Info.arg_num = 1U; |
| 589 | l0Info.args = nullptr; | 589 | l0Info.args = nullptr; |
| 590 | 590 | ||
| 591 | - Om2TaskInfo info{}; | 591 | + GertModelTaskDesc info{}; |
| 592 | info.op_name = "test_op"; | 592 | info.op_name = "test_op"; |
| 593 | - info.l0_exception_dump_info = &l0Info; | 593 | + info.task_raw_info = &l0Info; |
| 594 | 594 | ||
| 595 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), PARAM_INVALID); | 595 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), PARAM_INVALID); |
| 596 | } | 596 | } |
| @@ -600,17 +600,17 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoLiteDumpDisabledReturnsSucc | |||
| 600 | DumpStub::GetInstance().Clear(); | 600 | DumpStub::GetInstance().Clear(); |
| 601 | 601 | ||
| 602 | ExceptionDumpImpl impl; | 602 | ExceptionDumpImpl impl; |
| 603 | - Om2L0ArgSlotInfo slot{}; | 603 | + GertModelArgSlotInfo slot{}; |
| 604 | - slot.kind = OM2_L0_ARG_INPUT; | 604 | + slot.kind = GERT_MODEL_ARG_INPUT; |
| 605 | slot.value = 32U; | 605 | slot.value = 32U; |
| 606 | - Om2L0TaskRawInfo l0Info{}; | 606 | + GertModelTaskRawInfo l0Info{}; |
| 607 | - l0Info.version = 1U; | 607 | + l0Info.struct_size = 1U; |
| 608 | l0Info.arg_num = 1U; | 608 | l0Info.arg_num = 1U; |
| 609 | l0Info.args = &slot; | 609 | l0Info.args = &slot; |
| 610 | 610 | ||
| 611 | - Om2TaskInfo info{}; | 611 | + GertModelTaskDesc info{}; |
| 612 | info.op_name = "test_op"; | 612 | info.op_name = "test_op"; |
| 613 | - info.l0_exception_dump_info = &l0Info; | 613 | + info.task_raw_info = &l0Info; |
| 614 | 614 | ||
| 615 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); | 615 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); |
| 616 | EXPECT_TRUE(DumpStub::GetInstance().GetUnits().empty()); | 616 | EXPECT_TRUE(DumpStub::GetInstance().GetUnits().empty()); |
| @@ -619,28 +619,28 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoLiteDumpDisabledReturnsSucc | |||
| 619 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoConvertsSlotKinds) { | 619 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoConvertsSlotKinds) { |
| 620 | DumpStub::GetInstance().Clear(); | 620 | DumpStub::GetInstance().Clear(); |
| 621 | 621 | ||
| 622 | - Om2L0ArgSlotInfo slots[12]{}; | 622 | + GertModelArgSlotInfo slots[12]{}; |
| 623 | - slots[0].kind = OM2_L0_ARG_INPUT; | 623 | + slots[0].kind = GERT_MODEL_ARG_INPUT; |
| 624 | slots[0].args_offset = 0U; | 624 | slots[0].args_offset = 0U; |
| 625 | - slots[1].kind = OM2_L0_ARG_OUTPUT; | 625 | + slots[1].kind = GERT_MODEL_ARG_OUTPUT; |
| 626 | slots[1].args_offset = 8U; | 626 | slots[1].args_offset = 8U; |
| 627 | - slots[2].kind = OM2_L0_ARG_WORKSPACE; | 627 | + slots[2].kind = GERT_MODEL_ARG_WORKSPACE; |
| 628 | slots[2].related_index = 0U; | 628 | slots[2].related_index = 0U; |
| 629 | - slots[3].kind = OM2_L0_ARG_SHAPE_INFO; | 629 | + slots[3].kind = GERT_MODEL_ARG_SHAPE_INFO; |
| 630 | slots[3].value = 4U; | 630 | slots[3].value = 4U; |
| 631 | - slots[4].kind = OM2_L0_ARG_TILING; | 631 | + slots[4].kind = GERT_MODEL_ARG_TILING; |
| 632 | slots[4].value = 256U; | 632 | slots[4].value = 256U; |
| 633 | - slots[5].kind = OM2_L0_ARG_LEVEL1_DESC; | 633 | + slots[5].kind = GERT_MODEL_ARG_LEVEL1_DESC; |
| 634 | - slots[6].kind = OM2_L0_ARG_PLACEHOLDER; | 634 | + slots[6].kind = GERT_MODEL_ARG_PLACEHOLDER; |
| 635 | - slots[7].kind = OM2_L0_ARG_CUSTOM_VALUE; | 635 | + slots[7].kind = GERT_MODEL_ARG_CUSTOM_VALUE; |
| 636 | slots[7].value = 9U; | 636 | slots[7].value = 9U; |
| 637 | - slots[8].kind = OM2_L0_ARG_FFTS_ADDR; | 637 | + slots[8].kind = GERT_MODEL_ARG_FFTS_ADDR; |
| 638 | - slots[9].kind = OM2_L0_ARG_EVENT_ADDR; | 638 | + slots[9].kind = GERT_MODEL_ARG_EVENT_ADDR; |
| 639 | - slots[10].kind = OM2_L0_ARG_OVERFLOW_ADDR; | 639 | + slots[10].kind = GERT_MODEL_ARG_OVERFLOW_ADDR; |
| 640 | - slots[11].kind = OM2_L0_ARG_EMPTY_ADDR; | 640 | + slots[11].kind = GERT_MODEL_ARG_EMPTY_ADDR; |
| 641 | 641 | ||
| 642 | - Om2L0TaskRawInfo l0Info{}; | 642 | + GertModelTaskRawInfo l0Info{}; |
| 643 | - l0Info.version = 1U; | 643 | + l0Info.struct_size = 1U; |
| 644 | l0Info.need_assert_or_printf = 1U; | 644 | l0Info.need_assert_or_printf = 1U; |
| 645 | l0Info.arg_num = 12U; | 645 | l0Info.arg_num = 12U; |
| 646 | l0Info.args = slots; | 646 | l0Info.args = slots; |
| @@ -649,11 +649,11 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoConvertsSlotKinds) { | |||
| 649 | inputTensor.SetSize(32U); | 649 | inputTensor.SetSize(32U); |
| 650 | gert::Tensor outputTensor{}; | 650 | gert::Tensor outputTensor{}; |
| 651 | outputTensor.SetSize(64U); | 651 | outputTensor.SetSize(64U); |
| 652 | - Om2TaskIoEntry inputEntry{sizeof(Om2TaskIoEntry), &inputTensor, 0U}; | 652 | + GertModelTaskIoEntry inputEntry{sizeof(GertModelTaskIoEntry), &inputTensor, 0U}; |
| 653 | - Om2TaskIoEntry outputEntry{sizeof(Om2TaskIoEntry), &outputTensor, 8U}; | 653 | + GertModelTaskIoEntry outputEntry{sizeof(GertModelTaskIoEntry), &outputTensor, 8U}; |
| 654 | uint64_t workspaceSize = 128U; | 654 | uint64_t workspaceSize = 128U; |
| 655 | 655 | ||
| 656 | - Om2TaskInfo info{}; | 656 | + GertModelTaskDesc info{}; |
| 657 | info.op_name = "test_op"; | 657 | info.op_name = "test_op"; |
| 658 | info.input_num = 1U; | 658 | info.input_num = 1U; |
| 659 | info.inputs = &inputEntry; | 659 | info.inputs = &inputEntry; |
| @@ -661,7 +661,7 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoConvertsSlotKinds) { | |||
| 661 | info.outputs = &outputEntry; | 661 | info.outputs = &outputEntry; |
| 662 | info.workspace_num = 1U; | 662 | info.workspace_num = 1U; |
| 663 | info.workspace_sizes = &workspaceSize; | 663 | info.workspace_sizes = &workspaceSize; |
| 664 | - info.l0_exception_dump_info = &l0Info; | 664 | + info.task_raw_info = &l0Info; |
| 665 | 665 | ||
| 666 | ExceptionDumpImpl impl; | 666 | ExceptionDumpImpl impl; |
| 667 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); | 667 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), SUCCESS); |
| @@ -681,17 +681,17 @@ TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoConvertsSlotKinds) { | |||
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoUnsupportedKindReturnsInvalid) { | 683 | TEST(ExceptionDumpImplTest, ReportL0ExceptionDumpInfoUnsupportedKindReturnsInvalid) { |
| 684 | - Om2L0ArgSlotInfo slot{}; | 684 | + GertModelArgSlotInfo slot{}; |
| 685 | - slot.kind = 999U; | 685 | + slot.kind = static_cast<GertModelArgKind>(999U); |
| 686 | - Om2L0TaskRawInfo l0Info{}; | 686 | + GertModelTaskRawInfo l0Info{}; |
| 687 | - l0Info.version = 1U; | 687 | + l0Info.struct_size = 1U; |
| 688 | l0Info.need_assert_or_printf = 1U; | 688 | l0Info.need_assert_or_printf = 1U; |
| 689 | l0Info.arg_num = 1U; | 689 | l0Info.arg_num = 1U; |
| 690 | l0Info.args = &slot; | 690 | l0Info.args = &slot; |
| 691 | 691 | ||
| 692 | - Om2TaskInfo info{}; | 692 | + GertModelTaskDesc info{}; |
| 693 | info.op_name = "test_op"; | 693 | info.op_name = "test_op"; |
| 694 | - info.l0_exception_dump_info = &l0Info; | 694 | + info.task_raw_info = &l0Info; |
| 695 | 695 | ||
| 696 | ExceptionDumpImpl impl; | 696 | ExceptionDumpImpl impl; |
| 697 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), PARAM_INVALID); | 697 | EXPECT_EQ(impl.ReportL0ExceptionDumpInfo(info), PARAM_INVALID); |
| @@ -705,7 +705,7 @@ TEST(ExceptionDumpImplTest, GetOpDescInfoNotFoundTest) { | |||
| 705 | 705 | ||
| 706 | TEST(ExceptionDumpImplTest, ClearTest) { | 706 | TEST(ExceptionDumpImplTest, ClearTest) { |
| 707 | ExceptionDumpImpl impl; | 707 | ExceptionDumpImpl impl; |
| 708 | - Om2TaskInfo info{}; | 708 | + GertModelTaskDesc info{}; |
| 709 | info.op_name = "test_op"; | 709 | info.op_name = "test_op"; |
| 710 | info.task_id = 1; | 710 | info.task_id = 1; |
| 711 | info.stream_id = 1; | 711 | info.stream_id = 1; |
| @@ -725,7 +725,7 @@ TEST(DataDumpImplTest, ConstructorDestructorTest) { | |||
| 725 | 725 | ||
| 726 | TEST(DataDumpImplTest, SaveTaskTest) { | 726 | TEST(DataDumpImplTest, SaveTaskTest) { |
| 727 | DataDumpImpl impl; | 727 | DataDumpImpl impl; |
| 728 | - Om2TaskInfo info{}; | 728 | + GertModelTaskDesc info{}; |
| 729 | info.op_name = "test_op"; | 729 | info.op_name = "test_op"; |
| 730 | info.task_id = 1; | 730 | info.task_id = 1; |
| 731 | info.stream_id = 1; | 731 | info.stream_id = 1; |
| @@ -940,7 +940,7 @@ TEST_F(ProfilingImplTest, ReportModelLoadEnd_ProfilingEnabled_ReturnsSuccess) { | |||
| 940 | 940 | ||
| 941 | TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginZero_ReturnsSuccess) { | 941 | TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginZero_ReturnsSuccess) { |
| 942 | ProfilingImpl impl; | 942 | ProfilingImpl impl; |
| 943 | - Om2TaskInfo task_info = {}; | 943 | + GertModelTaskDesc task_info = {}; |
| 944 | task_info.op_name = "test_op"; | 944 | task_info.op_name = "test_op"; |
| 945 | task_info.launch_begin = 0U; | 945 | task_info.launch_begin = 0U; |
| 946 | Status ret = impl.ReportLaunchInfo(task_info, 1000U); | 946 | Status ret = impl.ReportLaunchInfo(task_info, 1000U); |
| @@ -949,7 +949,7 @@ TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginZero_ReturnsSuccess) { | |||
| 949 | 949 | ||
| 950 | TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginNonZero_ReturnsSuccess) { | 950 | TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginNonZero_ReturnsSuccess) { |
| 951 | ProfilingImpl impl; | 951 | ProfilingImpl impl; |
| 952 | - Om2TaskInfo task_info = {}; | 952 | + GertModelTaskDesc task_info = {}; |
| 953 | task_info.op_name = "test_op"; | 953 | task_info.op_name = "test_op"; |
| 954 | task_info.op_type = "Add"; | 954 | task_info.op_type = "Add"; |
| 955 | task_info.launch_begin = 500U; | 955 | task_info.launch_begin = 500U; |
| @@ -960,7 +960,7 @@ TEST_F(ProfilingImplTest, ReportLaunchInfo_LaunchBeginNonZero_ReturnsSuccess) { | |||
| 960 | 960 | ||
| 961 | TEST_F(ProfilingImplTest, ReportLaunchInfo_NullOpName_ReturnsSuccess) { | 961 | TEST_F(ProfilingImplTest, ReportLaunchInfo_NullOpName_ReturnsSuccess) { |
| 962 | ProfilingImpl impl; | 962 | ProfilingImpl impl; |
| 963 | - Om2TaskInfo task_info = {}; | 963 | + GertModelTaskDesc task_info = {}; |
| 964 | task_info.op_name = nullptr; | 964 | task_info.op_name = nullptr; |
| 965 | task_info.launch_begin = 500U; | 965 | task_info.launch_begin = 500U; |
| 966 | task_info.thread_id = 1U; | 966 | task_info.thread_id = 1U; |
| @@ -987,7 +987,7 @@ TEST_F(ProfilingImplTest, ReportLaunchInfo_CapturesMsprofApiWithoutTruncation) { | |||
| 987 | ProfilingTestUtil::Instance().SetProfFunc(check_func); | 987 | ProfilingTestUtil::Instance().SetProfFunc(check_func); |
| 988 | 988 | ||
| 989 | ProfilingImpl impl; | 989 | ProfilingImpl impl; |
| 990 | - Om2TaskInfo task_info = {}; | 990 | + GertModelTaskDesc task_info = {}; |
| 991 | task_info.op_name = "test_op"; | 991 | task_info.op_name = "test_op"; |
| 992 | task_info.launch_begin = 500UL; | 992 | task_info.launch_begin = 500UL; |
| 993 | task_info.thread_id = 1U; | 993 | task_info.thread_id = 1U; |
| @@ -1028,7 +1028,7 @@ TEST_F(ProfilingImplTest, ReportModelLoadEnd_CapturesMsprofEventFields) { | |||
| 1028 | 1028 | ||
| 1029 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_OriginalOpNamesNull_ReturnsSuccess) { | 1029 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_OriginalOpNamesNull_ReturnsSuccess) { |
| 1030 | ProfilingImpl impl; | 1030 | ProfilingImpl impl; |
| 1031 | - Om2TaskInfo task_info = {}; | 1031 | + GertModelTaskDesc task_info = {}; |
| 1032 | task_info.op_name = "fusion_op"; | 1032 | task_info.op_name = "fusion_op"; |
| 1033 | task_info.original_op_names = nullptr; | 1033 | task_info.original_op_names = nullptr; |
| 1034 | Status ret = impl.ReportFusionOpInfo(task_info, 42U); | 1034 | Status ret = impl.ReportFusionOpInfo(task_info, 42U); |
| @@ -1037,7 +1037,7 @@ TEST_F(ProfilingImplTest, ReportFusionOpInfo_OriginalOpNamesNull_ReturnsSuccess) | |||
| 1037 | 1037 | ||
| 1038 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_SingleOpName_ReturnsSuccess) { | 1038 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_SingleOpName_ReturnsSuccess) { |
| 1039 | ProfilingImpl impl; | 1039 | ProfilingImpl impl; |
| 1040 | - Om2TaskInfo task_info = {}; | 1040 | + GertModelTaskDesc task_info = {}; |
| 1041 | task_info.op_name = "fusion_op"; | 1041 | task_info.op_name = "fusion_op"; |
| 1042 | task_info.original_op_names = "MatMul"; | 1042 | task_info.original_op_names = "MatMul"; |
| 1043 | task_info.input_mem_size = 1024U; | 1043 | task_info.input_mem_size = 1024U; |
| @@ -1051,7 +1051,7 @@ TEST_F(ProfilingImplTest, ReportFusionOpInfo_SingleOpName_ReturnsSuccess) { | |||
| 1051 | 1051 | ||
| 1052 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_MultipleOpNames_ReturnsSuccess) { | 1052 | TEST_F(ProfilingImplTest, ReportFusionOpInfo_MultipleOpNames_ReturnsSuccess) { |
| 1053 | ProfilingImpl impl; | 1053 | ProfilingImpl impl; |
| 1054 | - Om2TaskInfo task_info = {}; | 1054 | + GertModelTaskDesc task_info = {}; |
| 1055 | task_info.op_name = "fusion_op"; | 1055 | task_info.op_name = "fusion_op"; |
| 1056 | task_info.original_op_names = "MatMul;Add;Relu"; | 1056 | task_info.original_op_names = "MatMul;Add;Relu"; |
| 1057 | task_info.input_mem_size = 1024U; | 1057 | task_info.input_mem_size = 1024U; |
| @@ -1092,7 +1092,7 @@ TEST_F(ProfilingImplTest, UnregisterModelFromProfilingRuntime_ReturnsSuccess) { | |||
| 1092 | 1092 | ||
| 1093 | TEST_F(ProfilingImplTest, SaveTaskInfo_TaskReportDisabled_ReturnsSuccess) { | 1093 | TEST_F(ProfilingImplTest, SaveTaskInfo_TaskReportDisabled_ReturnsSuccess) { |
| 1094 | ProfilingImpl impl; | 1094 | ProfilingImpl impl; |
| 1095 | - Om2TaskInfo task_info = {}; | 1095 | + GertModelTaskDesc task_info = {}; |
| 1096 | task_info.op_name = "test_op"; | 1096 | task_info.op_name = "test_op"; |
| 1097 | task_info.op_type = "Add"; | 1097 | task_info.op_type = "Add"; |
| 1098 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1098 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1108,7 +1108,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_TaskReportEnabled_ReturnsSuccess) { | |||
| 1108 | EXPECT_TRUE(ProfilingConfig::Instance().IsTaskReportEnabled()); | 1108 | EXPECT_TRUE(ProfilingConfig::Instance().IsTaskReportEnabled()); |
| 1109 | 1109 | ||
| 1110 | ProfilingImpl impl; | 1110 | ProfilingImpl impl; |
| 1111 | - Om2TaskInfo task_info = {}; | 1111 | + GertModelTaskDesc task_info = {}; |
| 1112 | task_info.op_name = "test_op"; | 1112 | task_info.op_name = "test_op"; |
| 1113 | task_info.op_type = "Add"; | 1113 | task_info.op_type = "Add"; |
| 1114 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1114 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1124,7 +1124,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_InvalidTaskType_ReturnsSuccess) { | |||
| 1124 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1124 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1125 | 1125 | ||
| 1126 | ProfilingImpl impl; | 1126 | ProfilingImpl impl; |
| 1127 | - Om2TaskInfo task_info = {}; | 1127 | + GertModelTaskDesc task_info = {}; |
| 1128 | task_info.op_name = "test_op"; | 1128 | task_info.op_name = "test_op"; |
| 1129 | task_info.op_type = "Unknown"; | 1129 | task_info.op_type = "Unknown"; |
| 1130 | task_info.task_type = 0xFFU; // invalid task type | 1130 | task_info.task_type = 0xFFU; // invalid task type |
| @@ -1148,18 +1148,18 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_WithInputTensors_ReturnsSuccess) { | |||
| 1148 | } | 1148 | } |
| 1149 | tensor.MutableStorageShape().SetDimNum(4U); | 1149 | tensor.MutableStorageShape().SetDimNum(4U); |
| 1150 | 1150 | ||
| 1151 | - Om2TaskIoEntry inputs[2] = {}; | 1151 | + GertModelTaskIoEntry inputs[2] = {}; |
| 1152 | inputs[0U].tensor = &tensor; | 1152 | inputs[0U].tensor = &tensor; |
| 1153 | inputs[0U].offset = 0U; | 1153 | inputs[0U].offset = 0U; |
| 1154 | inputs[1U].tensor = &tensor; | 1154 | inputs[1U].tensor = &tensor; |
| 1155 | inputs[1U].offset = 1024U; | 1155 | inputs[1U].offset = 1024U; |
| 1156 | 1156 | ||
| 1157 | - Om2TaskIoEntry outputs[1] = {}; | 1157 | + GertModelTaskIoEntry outputs[1] = {}; |
| 1158 | outputs[0U].tensor = &tensor; | 1158 | outputs[0U].tensor = &tensor; |
| 1159 | outputs[0U].offset = 2048U; | 1159 | outputs[0U].offset = 2048U; |
| 1160 | 1160 | ||
| 1161 | ProfilingImpl impl; | 1161 | ProfilingImpl impl; |
| 1162 | - Om2TaskInfo task_info = {}; | 1162 | + GertModelTaskDesc task_info = {}; |
| 1163 | task_info.op_name = "test_op"; | 1163 | task_info.op_name = "test_op"; |
| 1164 | task_info.op_type = "Add"; | 1164 | task_info.op_type = "Add"; |
| 1165 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1165 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1184,12 +1184,12 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_NullTensor_ReturnsSuccess) { | |||
| 1184 | tensor.SetStorageFormat(static_cast<ge::Format>(0U)); // FORMAT_NCHW | 1184 | tensor.SetStorageFormat(static_cast<ge::Format>(0U)); // FORMAT_NCHW |
| 1185 | tensor.MutableStorageShape().SetDimNum(4U); | 1185 | tensor.MutableStorageShape().SetDimNum(4U); |
| 1186 | 1186 | ||
| 1187 | - Om2TaskIoEntry inputs[1] = {}; | 1187 | + GertModelTaskIoEntry inputs[1] = {}; |
| 1188 | inputs[0U].tensor = &tensor; | 1188 | inputs[0U].tensor = &tensor; |
| 1189 | inputs[0U].offset = 0U; | 1189 | inputs[0U].offset = 0U; |
| 1190 | 1190 | ||
| 1191 | ProfilingImpl impl; | 1191 | ProfilingImpl impl; |
| 1192 | - Om2TaskInfo task_info = {}; | 1192 | + GertModelTaskDesc task_info = {}; |
| 1193 | task_info.op_name = "test_op"; | 1193 | task_info.op_name = "test_op"; |
| 1194 | task_info.op_type = "Add"; | 1194 | task_info.op_type = "Add"; |
| 1195 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1195 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1206,7 +1206,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_NullIoEntries_ReturnsSuccess) { | |||
| 1206 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1206 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1207 | 1207 | ||
| 1208 | ProfilingImpl impl; | 1208 | ProfilingImpl impl; |
| 1209 | - Om2TaskInfo task_info = {}; | 1209 | + GertModelTaskDesc task_info = {}; |
| 1210 | task_info.op_name = "test_op"; | 1210 | task_info.op_name = "test_op"; |
| 1211 | task_info.op_type = "Add"; | 1211 | task_info.op_type = "Add"; |
| 1212 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1212 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1225,7 +1225,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_WithNullOpName_ReturnsSuccess) { | |||
| 1225 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1225 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1226 | 1226 | ||
| 1227 | ProfilingImpl impl; | 1227 | ProfilingImpl impl; |
| 1228 | - Om2TaskInfo task_info = {}; | 1228 | + GertModelTaskDesc task_info = {}; |
| 1229 | task_info.op_name = nullptr; | 1229 | task_info.op_name = nullptr; |
| 1230 | task_info.op_type = "Add"; | 1230 | task_info.op_type = "Add"; |
| 1231 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); | 1231 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL); |
| @@ -1242,7 +1242,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_AicpuTaskType_ReturnsSuccess) { | |||
| 1242 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1242 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1243 | 1243 | ||
| 1244 | ProfilingImpl impl; | 1244 | ProfilingImpl impl; |
| 1245 | - Om2TaskInfo task_info = {}; | 1245 | + GertModelTaskDesc task_info = {}; |
| 1246 | task_info.op_name = "aicpu_op"; | 1246 | task_info.op_name = "aicpu_op"; |
| 1247 | task_info.op_type = "KernelEx"; | 1247 | task_info.op_type = "KernelEx"; |
| 1248 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL_EX); // AICPU | 1248 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_KERNEL_EX); // AICPU |
| @@ -1258,7 +1258,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_DsaTaskType_ReturnsSuccess) { | |||
| 1258 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1258 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1259 | 1259 | ||
| 1260 | ProfilingImpl impl; | 1260 | ProfilingImpl impl; |
| 1261 | - Om2TaskInfo task_info = {}; | 1261 | + GertModelTaskDesc task_info = {}; |
| 1262 | task_info.op_name = "dsa_op"; | 1262 | task_info.op_name = "dsa_op"; |
| 1263 | task_info.op_type = "DSA"; | 1263 | task_info.op_type = "DSA"; |
| 1264 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_DSA); | 1264 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_DSA); |
| @@ -1273,7 +1273,7 @@ TEST_F(ProfilingImplTest, SaveTaskInfo_HcclTaskType_ReturnsSuccess) { | |||
| 1273 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); | 1273 | ASSERT_EQ(ProfilingConfig::Instance().Enable(options), SUCCESS); |
| 1274 | 1274 | ||
| 1275 | ProfilingImpl impl; | 1275 | ProfilingImpl impl; |
| 1276 | - Om2TaskInfo task_info = {}; | 1276 | + GertModelTaskDesc task_info = {}; |
| 1277 | task_info.op_name = "hccl_op"; | 1277 | task_info.op_name = "hccl_op"; |
| 1278 | task_info.op_type = "HCCL"; | 1278 | task_info.op_type = "HCCL"; |
| 1279 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_HCCL); | 1279 | task_info.task_type = static_cast<uint32_t>(ModelTaskType::MODEL_TASK_HCCL); |
| @@ -30,8 +30,8 @@ class Om2WithoutGraphDumpTest : public testing::Test { | |||
| 30 | } | 30 | } |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | -Om2TaskInfo MakeTaskInfo() { | 33 | +GertModelTaskDesc MakeTaskInfo() { |
| 34 | - Om2TaskInfo info{}; | 34 | + GertModelTaskDesc info{}; |
| 35 | info.op_name = "test_op"; | 35 | info.op_name = "test_op"; |
| 36 | info.task_id = 1U; | 36 | info.task_id = 1U; |
| 37 | info.stream_id = 1U; | 37 | info.stream_id = 1U; |
| @@ -75,6 +75,12 @@ static const std::string fake_om2_so_src = R"( | |||
| 75 | #include <cstddef> | 75 | #include <cstddef> |
| 76 | #include <cstdint> | 76 | #include <cstdint> |
| 77 | 77 | ||
| 78 | +typedef void* aclmdlRI; | ||
| 79 | +typedef void* aclrtStream; | ||
| 80 | +typedef void* aclrtEvent; | ||
| 81 | +typedef void* aclrtLabel; | ||
| 82 | +typedef void* aclrtNotify; | ||
| 83 | + | ||
| 78 | struct GertModelLoadConfig { | 84 | struct GertModelLoadConfig { |
| 79 | uint64_t struct_size; | 85 | uint64_t struct_size; |
| 80 | const char **bin_files; | 86 | const char **bin_files; |
| @@ -88,8 +94,17 @@ struct GertModelLoadConfig { | |||
| 88 | uint64_t model_id; | 94 | uint64_t model_id; |
| 89 | void *instance_handle; | 95 | void *instance_handle; |
| 90 | void *executor_handle = nullptr; | 96 | void *executor_handle = nullptr; |
| 91 | - const struct GertModelCallbacks *callbacks; | 97 | + const struct GertModelLoadCallbacks *callbacks; |
| 92 | int64_t priority; | 98 | int64_t priority; |
| 99 | + aclmdlRI external_rt_model = nullptr; | ||
| 100 | + aclrtStream *external_streams = nullptr; | ||
| 101 | + uint64_t external_stream_num = 0; | ||
| 102 | + aclrtEvent *external_events = nullptr; | ||
| 103 | + uint64_t external_event_num = 0; | ||
| 104 | + aclrtLabel *external_labels = nullptr; | ||
| 105 | + uint64_t external_label_num = 0; | ||
| 106 | + aclrtNotify *external_notifies = nullptr; | ||
| 107 | + uint64_t external_notify_num = 0; | ||
| 93 | }; | 108 | }; |
| 94 | 109 | ||
| 95 | struct GertModelRunConfig { | 110 | struct GertModelRunConfig { |