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
Open
Fix(device_runner): add host-side stream sync timeout watchdog with best-effort reset#688indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
Conversation
There was a problem hiding this comment.
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.
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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