Skip to content

Commit 87f1499

Browse files
authored
[MIGraphX EP] Fix compilation after cherry-picking from win-onnxruntime (microsoft#25516)
After cherry-picking from win-onnxruntime (microsoft#25481), the MIGraphX EP stopped compiling on the main branch.
1 parent 6ee4ea3 commit 87f1499

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

onnxruntime/core/providers/migraphx/migraphx_allocator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void MIGraphXAllocator::CheckDevice() const {
1818
int current_device;
1919
auto hip_err = hipGetDevice(&current_device);
2020
if (hip_err == hipSuccess) {
21-
ORT_ENFORCE(current_device == Info().id);
21+
ORT_ENFORCE(current_device == Info().device.Id());
2222
}
2323
#endif
2424
}

onnxruntime/core/providers/migraphx/migraphx_provider_factory.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ struct MIGraphX_Provider : Provider {
151151
const OrtSessionOptions& session_options,
152152
const OrtLogger& logger,
153153
std::unique_ptr<IExecutionProvider>& ep) override {
154+
ORT_UNUSED_PARAMETER(num_devices);
154155
const ConfigOptions* config_options = &session_options.GetConfigOptions();
155156

156157
std::array<const void*, 2> configs_array = {&provider_options, config_options};
157-
const void* arg = reinterpret_cast<const void*>(&configs_array);
158158
auto ep_factory = CreateExecutionProviderFactory(&provider_options);
159159
ep = ep_factory->CreateProvider(session_options, logger);
160160

@@ -181,7 +181,7 @@ struct MigraphXEpFactory : OrtEpFactory {
181181
const char* ep_name,
182182
OrtHardwareDeviceType hw_type,
183183
const OrtLogger& default_logger_in)
184-
: ort_api{ort_api_in}, ep_name{ep_name}, ort_hw_device_type{hw_type}, default_logger{default_logger_in} {
184+
: ort_api{ort_api_in}, default_logger{default_logger_in}, ep_name{ep_name}, ort_hw_device_type{hw_type} {
185185
GetName = GetNameImpl;
186186
GetVendor = GetVendorImpl;
187187
GetSupportedDevices = GetSupportedDevicesImpl;
@@ -191,12 +191,12 @@ struct MigraphXEpFactory : OrtEpFactory {
191191

192192
// Returns the name for the EP. Each unique factory configuration must have a unique name.
193193
// Ex: a factory that supports NPU should have a different than a factory that supports GPU.
194-
static const char* GetNameImpl(const OrtEpFactory* this_ptr) {
194+
static const char* GetNameImpl(const OrtEpFactory* this_ptr) noexcept {
195195
const auto* factory = static_cast<const MigraphXEpFactory*>(this_ptr);
196196
return factory->ep_name.c_str();
197197
}
198198

199-
static const char* GetVendorImpl(const OrtEpFactory* this_ptr) {
199+
static const char* GetVendorImpl(const OrtEpFactory* this_ptr) noexcept {
200200
const auto* factory = static_cast<const MigraphXEpFactory*>(this_ptr);
201201
return factory->vendor.c_str();
202202
}
@@ -212,7 +212,7 @@ struct MigraphXEpFactory : OrtEpFactory {
212212
size_t num_devices,
213213
OrtEpDevice** ep_devices,
214214
size_t max_ep_devices,
215-
size_t* p_num_ep_devices) {
215+
size_t* p_num_ep_devices) noexcept {
216216
size_t& num_ep_devices = *p_num_ep_devices;
217217
auto* factory = static_cast<MigraphXEpFactory*>(this_ptr);
218218

@@ -237,11 +237,11 @@ struct MigraphXEpFactory : OrtEpFactory {
237237
_In_ size_t /*num_devices*/,
238238
_In_ const OrtSessionOptions* /*session_options*/,
239239
_In_ const OrtLogger* /*logger*/,
240-
_Out_ OrtEp** /*ep*/) {
240+
_Out_ OrtEp** /*ep*/) noexcept {
241241
return onnxruntime::CreateStatus(ORT_INVALID_ARGUMENT, "[MigraphX/AMDGPU EP] EP factory does not support this method.");
242242
}
243243

244-
static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) {
244+
static void ReleaseEpImpl(OrtEpFactory* /*this_ptr*/, OrtEp* /*ep*/) noexcept {
245245
// no-op as we never create an EP here.
246246
}
247247

onnxruntime/test/providers/migraphx/migraphx_basic_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ TEST(MIGraphXExecutionProviderTest, canEvalArgument) {
188188
ASSERT_EQ(canEvalNodeArgument(gv, node2, {1}, input_nodes), true);
189189
}
190190

191+
static bool SessionHasEp(Ort::Session& session, const char* ep_name) {
192+
// Access the underlying InferenceSession.
193+
const OrtSession* ort_session = session;
194+
const InferenceSession* s = reinterpret_cast<const InferenceSession*>(ort_session);
195+
bool has_ep = false;
196+
197+
for (const auto& provider : s->GetRegisteredProviderTypes()) {
198+
if (provider == ep_name) {
199+
has_ep = true;
200+
break;
201+
}
202+
}
203+
return has_ep;
204+
}
205+
206+
#if defined(WIN32)
207+
// Tests autoEP feature to automatically select an EP that supports the GPU.
208+
// Currently only works on Windows.
191209
TEST(MIGraphXExecutionProviderTest, AutoEp_PreferGpu) {
192210
PathString model_name = ORT_TSTR("migraphx_basic_test.onnx");
193211

@@ -212,6 +230,7 @@ TEST(MIGraphXExecutionProviderTest, AutoEp_PreferGpu) {
212230

213231
env.UnregisterExecutionProviderLibrary(kMIGraphXExecutionProvider);
214232
}
233+
#endif
215234

216235
} // namespace test
217236
} // namespace onnxruntime

0 commit comments

Comments
 (0)