[CANN] Fix deadlock during parallel execution#29740
Open
abeclowicz wants to merge 6 commits into
Open
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a CANN GE GraphEngine deadlock in ORT_PARALLEL by ensuring ge::aclgrphBuildInitialize and ge::aclgrphBuildFinalize execute on the same dedicated thread, and synchronizing init/finalize with std::promise/std::future.
Changes:
- Introduce a dedicated background thread to run
aclgrphBuildInitializeand lateraclgrphBuildFinalizein the same thread context. - Add promise/future synchronization to block callers until initialization completes and to trigger finalization during provider shutdown.
- Update CANN provider shutdown to signal the finalize path and join the background thread.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cann/cann_graph.cc | Adds GE init/finalize background thread plus init/final synchronization primitives. |
| onnxruntime/core/providers/cann/cann_execution_provider.cc | Signals GE finalize via promise and joins the background thread during DeleteRegistry(). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Motivation and Context
During parallel execution (
ORT_PARALLEL), graph partitioning and compilation may be distributed across different worker threads. However, the GraphEngine functionaclgrphBuildFinalizeis thread-sensitive and must be executed by the exact same thread that initialized the engine (aclgrphBuildInitialize) - otherwise, this cross-thread mismatch results in a deadlock.Description
g_ge_thread), synchronized viastd::promiseandstd::futureto ensure proper execution flow.Reproduce the Issue
Below is the simplified C++ reproduction code. The
inference()function is the C/C++ sample taken directly from the ONNX Runtime documentation, withORT_PARALLELmode enabled.