From 2507a172f8b3d301b712a448ad4d4e8a5089af72 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 20 Nov 2024 14:37:26 +0800 Subject: [PATCH 1/2] feat: select adapter id for DirectML --- fastdeploy/runtime/backends/ort/ort_backend.cc | 2 +- fastdeploy/runtime/runtime_option.cc | 5 ++++- fastdeploy/runtime/runtime_option.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fastdeploy/runtime/backends/ort/ort_backend.cc b/fastdeploy/runtime/backends/ort/ort_backend.cc index db1f03e40b..46bf01e9c3 100644 --- a/fastdeploy/runtime/backends/ort/ort_backend.cc +++ b/fastdeploy/runtime/backends/ort/ort_backend.cc @@ -98,7 +98,7 @@ bool OrtBackend::BuildOption(const OrtBackendOption& option) { "DML", ORT_API_VERSION, reinterpret_cast(&ortDmlApi)); OrtStatus* onnx_dml_status = ortDmlApi->SessionOptionsAppendExecutionProvider_DML(session_options_, - 0); + option_.device_id); if (onnx_dml_status != nullptr) { FDERROR << "DirectML is not support in your machine, the program will exit." diff --git a/fastdeploy/runtime/runtime_option.cc b/fastdeploy/runtime/runtime_option.cc index a2a232cedc..3552ef6259 100644 --- a/fastdeploy/runtime/runtime_option.cc +++ b/fastdeploy/runtime/runtime_option.cc @@ -141,7 +141,10 @@ void RuntimeOption::UseAscend() { paddle_lite_option.device = device; } -void RuntimeOption::UseDirectML() { device = Device::DIRECTML; } +void RuntimeOption::UseDirectML(int adapter_id) { + device = Device::DIRECTML; + device_id = adapter_id; +} void RuntimeOption::UseSophgo() { device = Device::SOPHGOTPUD; diff --git a/fastdeploy/runtime/runtime_option.h b/fastdeploy/runtime/runtime_option.h index 205a2184c0..0e43d9fb57 100755 --- a/fastdeploy/runtime/runtime_option.h +++ b/fastdeploy/runtime/runtime_option.h @@ -82,7 +82,7 @@ struct FASTDEPLOY_DECL RuntimeOption { void UseAscend(); /// Use onnxruntime DirectML to inference - void UseDirectML(); + void UseDirectML(int adapter_id = 0); /// Use Sophgo to inference void UseSophgo(); From ec3d4c714c14c0142afaf632306336b2e1af9356 Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 21 Nov 2024 16:46:53 +0800 Subject: [PATCH 2/2] fix: valid_directml_backends --- fastdeploy/fastdeploy_model.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h index 1d7dd58ef5..8bb12b91fe 100755 --- a/fastdeploy/fastdeploy_model.h +++ b/fastdeploy/fastdeploy_model.h @@ -47,7 +47,7 @@ class FASTDEPLOY_DECL FastDeployModel { std::vector valid_timvx_backends = {}; /** Model's valid directml backends. This member defined all the onnxruntime directml backends have successfully tested for the model */ - std::vector valid_directml_backends = {}; + std::vector valid_directml_backends = {Backend::ORT}; /** Model's valid ascend backends. This member defined all the cann backends have successfully tested for the model */ std::vector valid_ascend_backends = {};