Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add XNNPACK EP and do regular cpu as last resort

laurenspriem519ef44827c3
diff --git a/mobile/apps/photos/rust/Cargo.toml b/mobile/apps/photos/rust/Cargo.toml
index c76128e16a..e096af1805 100644
--- a/mobile/apps/photos/rust/Cargo.toml
+++ b/mobile/apps/photos/rust/Cargo.toml
@@ -20,10 +20,10 @@ once_cell = "1.20.2"
thiserror = "2.0.11"
[target.'cfg(target_os = "ios")'.dependencies]
-ort = { version = "=2.0.0-rc.4", default-features = false, features = ["ndarray", "coreml"] }
+ort = { version = "=2.0.0-rc.4", default-features = false, features = ["ndarray", "coreml", "xnnpack"] }
[target.'cfg(not(target_os = "ios"))'.dependencies]
-ort = { version = "=2.0.0-rc.4", default-features = false, features = ["ndarray", "load-dynamic", "copy-dylibs", "coreml", "nnapi"] }
+ort = { version = "=2.0.0-rc.4", default-features = false, features = ["ndarray", "load-dynamic", "copy-dylibs", "coreml", "nnapi", "xnnpack"] }
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] }
diff --git a/mobile/apps/photos/rust/src/ml/onnx.rs b/mobile/apps/photos/rust/src/ml/onnx.rs
index 09c784b602..8e12c5be61 100644
--- a/mobile/apps/photos/rust/src/ml/onnx.rs
+++ b/mobile/apps/photos/rust/src/ml/onnx.rs
@@ -1,5 +1,6 @@
use ort::{
CPUExecutionProvider, ExecutionProviderDispatch, GraphOptimizationLevel, Session, Tensor,
+ XNNPACKExecutionProvider,
};
#[cfg(target_vendor = "apple")]
@@ -27,11 +28,14 @@ pub fn build_session(model_path: &str, policy: &ExecutionProviderPolicy) -> MlRe
#[cfg(target_os = "android")]
if policy.prefer_nnapi {
- providers.push(NNAPIExecutionProvider::default().build());
+ // Prefer NNAPI accelerators and let ORT handle CPU fallback via XNNPACK/CPU EP.
+ providers.push(NNAPIExecutionProvider::default().with_disable_cpu().build());
}
if policy.allow_cpu_fallback {
- providers.push(CPUExecutionProvider::default().build());
+ // XNNPACK is generally a faster CPU path on mobile; keep plain CPU EP as last fallback.
+ providers.push(XNNPACKExecutionProvider::default().build());
+ providers.push(CPUExecutionProvider::default().with_arena_allocator().build());
}
if providers.is_empty() {