refactor: remove redundant *_if_available EP functions

This commit is contained in:
Carson M
2023-01-17 11:41:43 -06:00
parent 1ebefceb0b
commit ad5ba9b42e

View File

@@ -33,20 +33,6 @@ macro_rules! ep_providers {
}
}
macro_rules! ep_if_available {
($($fn_name:ident($original:ident): $name:expr),*) => {
$(
/// Creates a new
#[doc = $name]
#[doc = " execution provider if available, otherwise falling back to CPU."]
pub fn $fn_name() -> Self {
let o = Self::$original();
if o.is_available() { o } else { Self::cpu() }
}
)*
}
}
macro_rules! ep_options {
($(
$(#[$meta:meta])*
@@ -92,22 +78,15 @@ impl ExecutionProvider {
.to_string_lossy()
.into_owned();
if self.provider == avail {
let _ = ortsys![unsafe ReleaseAvailableProviders(providers, num_providers)];
return true;
}
}
let _ = ortsys![unsafe ReleaseAvailableProviders(providers, num_providers)];
false
}
ep_if_available! {
cuda_if_available(cuda): "CUDA",
tensorrt_if_available(tensorrt): "TensorRT",
acl_if_available(acl): "ACL",
dnnl_if_available(dnnl): "oneDNN",
onednn_if_available(dnnl): "oneDNN",
coreml_if_available(coreml): "CoreML"
}
/// Configure this execution provider with the given option.
pub fn with(mut self, k: impl Into<String>, v: impl Into<String>) -> Self {
self.options.insert(k.into(), v.into());
@@ -126,7 +105,7 @@ impl ExecutionProvider {
pub(crate) fn apply_execution_providers(options: *mut sys::OrtSessionOptions, execution_providers: impl AsRef<[ExecutionProvider]>) {
let status_to_result_and_log = |ep: &'static str, status: *mut sys::OrtStatus| {
let result = status_to_result(status);
tracing::debug!("{ep} execution provider registration {status:?}");
tracing::debug!("{ep} execution provider registration {result:?}");
result
};
for ep in execution_providers.as_ref() {