Skip to content

[MIGraphX EP] Add support for user-provided HIP streams - #32870

Open
Andrea Bocci (fwyzard) wants to merge 3 commits into
microsoft:mainfrom
fwyzard:migraphx-user-compute-stream
Open

Andrea Bocci (fwyzard) wants to merge 3 commits into
microsoft:mainfrom
fwyzard:migraphx-user-compute-stream

Conversation

@fwyzard

@fwyzard Andrea Bocci (fwyzard) commented Sep 28, 2026 •

Copy link
Copy Markdown

Description

Add the "has_user_compute_stream" and "user_compute_stream" provider options to the MIGraphX execution provider, with the same names and semantics as in the CUDA execution provider: the address of a HIP stream provided by the user, that the execution provider should use instead of creating its own streams.

When the "user_compute_stream" option is set, use the HIP stream provided by the user for all the work submitted by the MIGraphX execution provider, instead of creating a new stream for each DeviceStreamCollection:

  • pass the user stream to RegisterMIGraphXStreamHandles(), resolving the TODO in
    RegisterStreamHandlers();
  • mark the MIGraphXStream that wraps it as not owned, so that the user stream is neither
    synchronised by Flush() nor destroyed together with the session;
  • check that the user stream belongs to the device used by the execution provider;
  • synchronise the user stream in OnRunEnd() only if sync_stream is set, so that the
    "disable_synchronize_execution_providers" run option lets the user keep submitting work asynchronously;
  • synchronise the user stream in Sync(), because a non-blocking stream is not synchronised
    together with the null stream.

The behaviour without a user compute stream is unchanged.

Implement a new unit test for the "has_user_compute_stream" and "user_compute_stream" options and user-provided HIP streams.

Motivation and Context

Implements #32850 .

Copilot AI balanced review requested due to automatic review settings September 28, 2026 07:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The new user-stream behavior lacks regression tests for parsing, synchronization, ownership, and device validation.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds user-provided HIP stream support to the MIGraphX execution provider.

Changes:

  • Adds and parses user stream provider options.
  • Validates stream device ownership.
  • Integrates external streams with execution, synchronization, and lifecycle handling.
File Description
migraphx_stream_handle.h Adds configurable stream ownership.
migraphx_stream_handle.cc Prevents destruction or flushing of external streams.
migraphx_execution_provider.h Stores and reports external-stream state.
migraphx_execution_provider.cc Uses, validates, and synchronizes user streams.
migraphx_execution_provider_info.h Defines and hashes the new options.
migraphx_execution_provider_info.cc Parses and serializes the new options.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime/core/providers/migraphx/migraphx_execution_provider.cc
… options

Add the "has_user_compute_stream" and "user_compute_stream" provider options to the MIGraphX
execution provider, with the same names and semantics as in the CUDA execution provider: the
address of a HIP stream provided by the user, that the execution provider should use instead of
creating its own streams.

Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
@fwyzard
Andrea Bocci (fwyzard) force-pushed the migraphx-user-compute-stream branch 2 times, most recently from 7ced9b8 to c486891 Compare September 28, 2026 08:35
Andrea Bocci (fwyzard) added a commit to fwyzard/cmsdist that referenced this pull request Sep 28, 2026
Add support for user-provided HIP streams to the ONNXRuntime MIGraphX
execution provider, using the same syntax and sematic as the CUDA EP.
See microsoft/onnxruntime#32850 for more details and
microsoft/onnxruntime#32870 for the upstream implementation.
@xadupre
Xavier Dupré (xadupre) requested a balanced review from Copilot September 28, 2026 10:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation is consistent with existing stream infrastructure and has comprehensive regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

External-stream execution does not reliably select the HIP device on calling threads, and the new Sync() path lacks coverage.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)

Comment thread onnxruntime/core/providers/migraphx/migraphx_stream_handle.cc
Comment thread onnxruntime/core/providers/migraphx/migraphx_execution_provider.cc
When the "user_compute_stream" option is set, use the HIP stream provided by the user for all the
work submitted by the MIGraphX execution provider, instead of creating a new stream for each
DeviceStreamCollection:
  - pass the user stream to RegisterMIGraphXStreamHandles(), resolving the TODO in
    RegisterStreamHandlers();
  - mark the MIGraphXStream that wraps it as not owned, so that the user stream is neither
    synchronised by Flush() nor destroyed together with the session;
  - check that the user stream belongs to the device used by the execution provider at creation;
  - select the device of the stream on every execution thread;
  - synchronise the user stream in OnRunEnd() only if sync_stream is set, so that the
    "disable_synchronize_execution_providers" run option lets the user keep submitting work
    asynchronously;
  - synchronise the user stream in Sync(), because a non-blocking stream is not synchronised
    together with the null stream.

Fix the behaviour without a user compute stream, and select the device of the internal stream on
every execution thread.

Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
Test that the "has_user_compute_stream" and "user_compute_stream" options are parsed and reported
back by the execution provider, and that the reported options round-trip.

Test that, with the "user_compute_stream" option, the MIGraphX execution provider
  - runs the inference in the user stream, ordered after the work already queued in it;
  - does not synchronise the host with the user stream when the synchronisation of the execution
    providers is disabled, and does synchronise it otherwise;
  - does not take ownership of the user stream, which stays valid after the session is destroyed;
  - supports several sessions, each with its own user stream, running concurrently;
  - handles a missing, null or invalid stream address;
  - rejects a user stream that belongs to a different device;
  - checks for a session running from a thread with a different current device;
  - validates the behaviour of the input/output synchronisation.

Link the HIP runtime to the unit tests when the MIGraphX execution provider is enabled, because
the tests create and manage the HIP streams and buffers themselves.

Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>

This branch has not been deployed

No deployments
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.

2 participants