From fc7a6c61d0f3a7976cf86b93c98290fbfac5414c Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 23 Jul 2025 22:23:33 +0200 Subject: [PATCH 1/3] fix compilation after cherry-pick --- .../core/providers/migraphx/migraphx_allocator.cc | 2 +- .../migraphx/migraphx_provider_factory.cc | 14 +++++++------- .../providers/migraphx/migraphx_basic_test.cc | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/onnxruntime/core/providers/migraphx/migraphx_allocator.cc b/onnxruntime/core/providers/migraphx/migraphx_allocator.cc index cf9f44f4cd8f0..1cac133ab0c2c 100644 --- a/onnxruntime/core/providers/migraphx/migraphx_allocator.cc +++ b/onnxruntime/core/providers/migraphx/migraphx_allocator.cc @@ -18,7 +18,7 @@ void MIGraphXAllocator::CheckDevice() const { int current_device; auto hip_err = hipGetDevice(¤t_device); if (hip_err == hipSuccess) { - ORT_ENFORCE(current_device == Info().id); + ORT_ENFORCE(current_device == Info().device.Id()); } #endif } diff --git a/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc b/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc index 84c7fe3e4d4ab..e818d44211cd2 100644 --- a/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc +++ b/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc @@ -151,10 +151,10 @@ struct MIGraphX_Provider : Provider { const OrtSessionOptions& session_options, const OrtLogger& logger, std::unique_ptr& ep) override { + ORT_UNUSED_PARAMETER(num_devices); const ConfigOptions* config_options = &session_options.GetConfigOptions(); std::array configs_array = {&provider_options, config_options}; - const void* arg = reinterpret_cast(&configs_array); auto ep_factory = CreateExecutionProviderFactory(&provider_options); ep = ep_factory->CreateProvider(session_options, logger); @@ -181,7 +181,7 @@ struct MigraphXEpFactory : OrtEpFactory { const char* ep_name, OrtHardwareDeviceType hw_type, const OrtLogger& default_logger_in) - : ort_api{ort_api_in}, ep_name{ep_name}, ort_hw_device_type{hw_type}, default_logger{default_logger_in} { + : ort_api{ort_api_in}, default_logger{default_logger_in}, ep_name{ep_name}, ort_hw_device_type{hw_type} { GetName = GetNameImpl; GetVendor = GetVendorImpl; GetSupportedDevices = GetSupportedDevicesImpl; @@ -191,12 +191,12 @@ struct MigraphXEpFactory : OrtEpFactory { // Returns the name for the EP. Each unique factory configuration must have a unique name. // Ex: a factory that supports NPU should have a different than a factory that supports GPU. - static const char* GetNameImpl(const OrtEpFactory* this_ptr) { + static const char* GetNameImpl(const OrtEpFactory* this_ptr) noexcept { const auto* factory = static_cast(this_ptr); return factory->ep_name.c_str(); } - static const char* GetVendorImpl(const OrtEpFactory* this_ptr) { + static const char* GetVendorImpl(const OrtEpFactory* this_ptr) noexcept{ const auto* factory = static_cast(this_ptr); return factory->vendor.c_str(); } @@ -212,7 +212,7 @@ struct MigraphXEpFactory : OrtEpFactory { size_t num_devices, OrtEpDevice** ep_devices, size_t max_ep_devices, - size_t* p_num_ep_devices) { + size_t* p_num_ep_devices) noexcept{ size_t& num_ep_devices = *p_num_ep_devices; auto* factory = static_cast(this_ptr); @@ -237,11 +237,11 @@ struct MigraphXEpFactory : OrtEpFactory { _In_ size_t /*num_devices*/, _In_ const OrtSessionOptions* /*session_options*/, _In_ const OrtLogger* /*logger*/, - _Out_ OrtEp** /*ep*/) { + _Out_ OrtEp** /*ep*/) noexcept{ return onnxruntime::CreateStatus(ORT_INVALID_ARGUMENT, "[MigraphX/AMDGPU EP] EP factory does not support this method."); } - static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) { + static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) noexcept{ // no-op as we never create an EP here. } diff --git a/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc b/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc index 5de7885a9452a..1d6b3f12c7280 100644 --- a/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc +++ b/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc @@ -188,6 +188,21 @@ TEST(MIGraphXExecutionProviderTest, canEvalArgument) { ASSERT_EQ(canEvalNodeArgument(gv, node2, {1}, input_nodes), true); } +static bool SessionHasEp(Ort::Session& session, const char* ep_name) { + // Access the underlying InferenceSession. + const OrtSession* ort_session = session; + const InferenceSession* s = reinterpret_cast(ort_session); + bool has_ep = false; + + for (const auto& provider : s->GetRegisteredProviderTypes()) { + if (provider == ep_name) { + has_ep = true; + break; + } + } + return has_ep; +} + TEST(MIGraphXExecutionProviderTest, AutoEp_PreferGpu) { PathString model_name = ORT_TSTR("migraphx_basic_test.onnx"); From 3855787b0197aac096d84fbb854f9333d7e48f28 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 23 Jul 2025 22:31:13 +0200 Subject: [PATCH 2/3] lintrunner --- .../core/providers/migraphx/migraphx_provider_factory.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc b/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc index e818d44211cd2..f10ba87e88002 100644 --- a/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc +++ b/onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc @@ -196,7 +196,7 @@ struct MigraphXEpFactory : OrtEpFactory { return factory->ep_name.c_str(); } - static const char* GetVendorImpl(const OrtEpFactory* this_ptr) noexcept{ + static const char* GetVendorImpl(const OrtEpFactory* this_ptr) noexcept { const auto* factory = static_cast(this_ptr); return factory->vendor.c_str(); } @@ -212,7 +212,7 @@ struct MigraphXEpFactory : OrtEpFactory { size_t num_devices, OrtEpDevice** ep_devices, size_t max_ep_devices, - size_t* p_num_ep_devices) noexcept{ + size_t* p_num_ep_devices) noexcept { size_t& num_ep_devices = *p_num_ep_devices; auto* factory = static_cast(this_ptr); @@ -237,11 +237,11 @@ struct MigraphXEpFactory : OrtEpFactory { _In_ size_t /*num_devices*/, _In_ const OrtSessionOptions* /*session_options*/, _In_ const OrtLogger* /*logger*/, - _Out_ OrtEp** /*ep*/) noexcept{ + _Out_ OrtEp** /*ep*/) noexcept { return onnxruntime::CreateStatus(ORT_INVALID_ARGUMENT, "[MigraphX/AMDGPU EP] EP factory does not support this method."); } - static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) noexcept{ + static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) noexcept { // no-op as we never create an EP here. } From 8e0c43f2f9b00e08ecf32503ade19c1e86d63c93 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 24 Jul 2025 15:29:27 +0200 Subject: [PATCH 3/3] enable AutoEp test only for Windows --- onnxruntime/test/providers/migraphx/migraphx_basic_test.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc b/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc index 1d6b3f12c7280..761ddf1975d15 100644 --- a/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc +++ b/onnxruntime/test/providers/migraphx/migraphx_basic_test.cc @@ -203,6 +203,9 @@ static bool SessionHasEp(Ort::Session& session, const char* ep_name) { return has_ep; } +#if defined(WIN32) +// Tests autoEP feature to automatically select an EP that supports the GPU. +// Currently only works on Windows. TEST(MIGraphXExecutionProviderTest, AutoEp_PreferGpu) { PathString model_name = ORT_TSTR("migraphx_basic_test.onnx"); @@ -227,6 +230,7 @@ TEST(MIGraphXExecutionProviderTest, AutoEp_PreferGpu) { env.UnregisterExecutionProviderLibrary(kMIGraphXExecutionProvider); } +#endif } // namespace test } // namespace onnxruntime