Skip to content

Commit df84945

Browse files
committed
Fix: assert/LOG paths failing when pto2_current_runtime() is null on AICPU
Problem: assert_impl and related code in orchestration/common.cpp use LOG_* macros that dereference pto2_current_runtime()->ops. On the device path, pto2_submit_mixed_task and other runtime code run in libaicpu_kernel.so, but only the orchestration plugin (libdevice_orch_*.so) had g_pto2_current_runtime set via dlsym(pto2_framework_bind_runtime). Each .so carries its own copy of common.cpp, so the AICPU image's g_ stayed nullptr and assertion reporting could crash or misbehave. Fix: In AicpuExecutor, call the link-resolved pto2_framework_bind_runtime(rt) for this DSO before orch_bind_runtime_, and pto2_framework_bind_runtime(nullptr) before pto2_runtime_destroy, mirroring the orchestration SO bind. Same change for a5 tensormap_and_ringbuffer.
1 parent d18163c commit df84945

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/a2a3/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ typedef void (*DeviceOrchestrationBindRuntimeFunc)(PTO2Runtime *rt);
7373
// Config function exported by orchestration .so
7474
typedef PTO2OrchestrationConfig (*DeviceOrchestrationConfigFunc)(const ChipStorageTaskArgs &orch_args);
7575

76+
// From orchestration/common.cpp linked into this DSO — updates g_pto2_current_runtime here (distinct from
77+
// pto2_framework_bind_runtime in the dlopen'd libdevice_orch_*.so).
78+
extern "C" void pto2_framework_bind_runtime(PTO2Runtime *rt);
79+
7680
constexpr int32_t MAX_AICPU_THREADS = PLATFORM_MAX_AICPU_THREADS;
7781
constexpr int32_t MAX_CORES_PER_THREAD = PLATFORM_MAX_CORES_PER_THREAD;
7882

@@ -2112,6 +2116,7 @@ int32_t AicpuExecutor::run(Runtime *runtime) {
21122116
#if PTO2_PROFILING
21132117
orch_cycle_start = get_sys_cnt_aicpu();
21142118
#endif
2119+
pto2_framework_bind_runtime(rt);
21152120
if (orch_bind_runtime_ != nullptr) {
21162121
orch_bind_runtime_(rt);
21172122
}
@@ -2353,8 +2358,8 @@ int32_t AicpuExecutor::run(Runtime *runtime) {
23532358
finished_.store(true, std::memory_order_release);
23542359
// Destroy PTO2 runtime and close orchestration SO (moved from orchestrator path)
23552360
if (!runtime->get_orch_built_on_host() && orch_so_handle_ != nullptr) {
2356-
// Clear the borrowed pointer in the orchestration SO before destroying
2357-
// rt, so g_pto2_current_runtime never points to freed memory.
2361+
// Clear g_pto2_current_runtime in this DSO and in the orchestration SO before destroying rt.
2362+
pto2_framework_bind_runtime(nullptr);
23582363
if (orch_bind_runtime_ != nullptr) {
23592364
orch_bind_runtime_(nullptr);
23602365
}

src/a5/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ typedef void (*DeviceOrchestrationBindRuntimeFunc)(PTO2Runtime *rt);
7373
// Config function exported by orchestration .so
7474
typedef PTO2OrchestrationConfig (*DeviceOrchestrationConfigFunc)(const ChipStorageTaskArgs &orch_args);
7575

76+
// From orchestration/common.cpp linked into this DSO — updates g_pto2_current_runtime here (distinct from
77+
// pto2_framework_bind_runtime in the dlopen'd libdevice_orch_*.so).
78+
extern "C" void pto2_framework_bind_runtime(PTO2Runtime *rt);
79+
7680
constexpr int32_t MAX_AICPU_THREADS = PLATFORM_MAX_AICPU_THREADS;
7781
constexpr int32_t MAX_CORES_PER_THREAD = PLATFORM_MAX_CORES_PER_THREAD;
7882

@@ -2091,6 +2095,7 @@ int32_t AicpuExecutor::run(Runtime *runtime) {
20912095
#if PTO2_PROFILING
20922096
orch_cycle_start = get_sys_cnt_aicpu();
20932097
#endif
2098+
pto2_framework_bind_runtime(rt);
20942099
if (orch_bind_runtime_ != nullptr) {
20952100
orch_bind_runtime_(rt);
20962101
}
@@ -2330,8 +2335,8 @@ int32_t AicpuExecutor::run(Runtime *runtime) {
23302335
finished_.store(true, std::memory_order_release);
23312336
// Destroy PTO2 runtime and close orchestration SO (moved from orchestrator path)
23322337
if (!runtime->get_orch_built_on_host() && orch_so_handle_ != nullptr) {
2333-
// Clear the borrowed pointer in the orchestration SO before destroying
2334-
// rt, so g_pto2_current_runtime never points to freed memory.
2338+
// Clear g_pto2_current_runtime in this DSO and in the orchestration SO before destroying rt.
2339+
pto2_framework_bind_runtime(nullptr);
23352340
if (orch_bind_runtime_ != nullptr) {
23362341
orch_bind_runtime_(nullptr);
23372342
}

0 commit comments

Comments
 (0)