Skip to content

Fix(device_runner): add host-side stream sync timeout watchdog with best-effort reset#688

Open
indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
indigo1973:prof_0425
Open

Fix(device_runner): add host-side stream sync timeout watchdog with best-effort reset#688
indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
indigo1973:prof_0425

Conversation

@indigo1973
Copy link
Copy Markdown
Contributor

Problem: rtStreamSynchronize may block indefinitely when device execution stalls, leaving host-side execution without a timeout recovery path.

Solution: run rtStreamSynchronize in a worker thread and monitor it with a condvar-based watchdog (1s timeout via PLATFORM_STREAM_SYNC_TIMEOUT_MS).

Timeout handling:

Log diagnostics (stream, device_id, block_dim, worker_count) Attempt aclrtResetDevice to unblock the stuck sync Wait one grace window for worker exit
If still blocked, detach worker to avoid permanent host hang On reset success, invalidate stream pointers and acl_ready_; on reset-fail+detach, clear stream pointers to avoid finalize-time UAF (with leak risk) In pto_runtime_c_api, detect timeout via last_run_timed_out() and trigger DeviceRunner::finalize() for best-effort cleanup Files:

platform_config.h: add PLATFORM_STREAM_SYNC_TIMEOUT_MS
device_runner.h/.cpp: add synchronize_stream_with_timeout() and last_run_timed_out_
pto_runtime_c_api.cpp: add timeout-triggered finalize path

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a host-side watchdog for stream synchronization to prevent permanent hangs. It introduces the synchronize_stream_with_timeout method, which executes synchronization in a separate thread and handles timeouts by resetting the device or detaching the worker thread. A review comment identifies a potential resource leak where clearing the acl_ready_ flag prematurely prevents aclFinalize() from being called during the subsequent cleanup process.

Comment thread src/a2a3/platform/onboard/host/device_runner.cpp Outdated
…est-effort reset

Problem: rtStreamSynchronize may block indefinitely when device execution stalls, leaving host-side execution without a timeout recovery path.

Solution: run rtStreamSynchronize in a worker thread and monitor it with a condvar-based watchdog (1s timeout via PLATFORM_STREAM_SYNC_TIMEOUT_MS).

Timeout handling:

Log diagnostics (stream, device_id, block_dim, worker_count)
Attempt aclrtResetDevice to unblock the stuck sync
Wait one grace window for worker exit
If still blocked, detach worker to avoid permanent host hang
On reset success, clear stream pointers (acl_ready_ stays true for finalize); on reset-fail+detach, clear stream pointers to avoid finalize-time UAF (with leak risk)
In pto_runtime_c_api, detect timeout via last_run_timed_out() and trigger DeviceRunner::finalize() for best-effort cleanup

Files:

platform_config.h: add PLATFORM_STREAM_SYNC_TIMEOUT_MS
device_runner.h/.cpp: add synchronize_stream_with_timeout() and last_run_timed_out_
pto_runtime_c_api.cpp: add timeout-triggered finalize path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant