From 66170bfceff693337d172761ca2fe76b1e8766e9 Mon Sep 17 00:00:00 2001 From: iperov Date: Wed, 9 Jun 2021 00:02:12 +0400 Subject: [PATCH] Python with DmlExecutionProvider : choose device_id in SessionOptions (#7964) --- onnxruntime/python/onnxruntime_pybind_state.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/onnxruntime/python/onnxruntime_pybind_state.cc b/onnxruntime/python/onnxruntime_pybind_state.cc index 4d0515563d..254d4b317b 100644 --- a/onnxruntime/python/onnxruntime_pybind_state.cc +++ b/onnxruntime/python/onnxruntime_pybind_state.cc @@ -622,7 +622,18 @@ static void RegisterExecutionProviders(InferenceSession* sess, const std::vector #endif } else if (type == kDmlExecutionProvider) { #ifdef USE_DML - RegisterExecutionProvider(sess, *onnxruntime::CreateExecutionProviderFactory_DML(0)); + int device_id = 0; + auto it = provider_options_map.find(type); + if (it != provider_options_map.end()) { + for (auto option : it->second) { + if (option.first == "device_id") { + if (!option.second.empty()) { + device_id = std::stoi(option.second); + } + } + } + } + RegisterExecutionProvider(sess, *onnxruntime::CreateExecutionProviderFactory_DML(device_id)); #endif } else if (type == kNnapiExecutionProvider) { #if defined(USE_NNAPI)