use super::{ExecutionProvider, RegisterError};
use crate::{error::Result, session::builder::SessionBuilder};
#[derive(Debug, Default, Clone)]
pub struct NNAPI {
use_fp16: bool,
use_nchw: bool,
disable_cpu: bool,
cpu_only: bool
}
super::impl_ep!(NNAPI);
impl NNAPI {
#[must_use]
pub fn with_fp16(mut self, enable: bool) -> Self {
self.use_fp16 = enable;
self
}
#[must_use]
pub fn with_nchw(mut self, enable: bool) -> Self {
self.use_nchw = enable;
self
}
#[must_use]
pub fn with_disable_cpu(mut self, enable: bool) -> Self {
self.disable_cpu = enable;
self
}
#[must_use]
pub fn with_cpu_only(mut self, enable: bool) -> Self {
self.cpu_only = enable;
self
}
}
impl ExecutionProvider for NNAPI {
fn name(&self) -> &'static str {
"NnapiExecutionProvider"
}
fn supported_by_platform(&self) -> bool {
cfg!(target_os = "android")
}
#[allow(unused, unreachable_code)]
fn register(&self, session_builder: &mut SessionBuilder) -> Result<(), RegisterError> {
#[cfg(any(feature = "load-dynamic", feature = "nnapi"))]
{
use crate::AsPointer;
super::define_ep_register!(OrtSessionOptionsAppendExecutionProvider_Nnapi(options: *mut ort_sys::OrtSessionOptions, flags: u32) -> ort_sys::OrtStatusPtr);
let mut flags = 0;
if self.use_fp16 {
flags |= 0x001;
}
if self.use_nchw {
flags |= 0x002;
}
if self.disable_cpu {
flags |= 0x004;
}
if self.cpu_only {
flags |= 0x008;
}
return Ok(unsafe { crate::error::Error::result_from_status(OrtSessionOptionsAppendExecutionProvider_Nnapi(session_builder.ptr_mut(), flags)) }?);
}
Err(RegisterError::MissingFeature)
}
}