pub struct AsyncSession { /* private fields */ }Expand description
Async wrapper for inference sessions.
Provides non-blocking inference operations using Tokio runtime. Ideal for web services, concurrent request handling, and high-throughput scenarios.
§Example
ⓘ
use ronn_api::AsyncSession;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let session = AsyncSession::from_file("model.onnx").await?;
let inputs = HashMap::new(); // Add your inputs here
let outputs = session.run(inputs).await?;
Ok(())
}Implementations§
Source§impl AsyncSession
impl AsyncSession
Sourcepub async fn with_options(
path: impl AsRef<Path> + Send + 'static,
options: SessionOptions,
) -> Result<Self>
pub async fn with_options( path: impl AsRef<Path> + Send + 'static, options: SessionOptions, ) -> Result<Self>
Sourcepub async fn run(
&self,
inputs: HashMap<String, Tensor>,
) -> Result<HashMap<String, Tensor>>
pub async fn run( &self, inputs: HashMap<String, Tensor>, ) -> Result<HashMap<String, Tensor>>
Sourcepub async fn run_concurrent(
&self,
inputs: HashMap<String, Tensor>,
) -> Result<HashMap<String, Tensor>>
pub async fn run_concurrent( &self, inputs: HashMap<String, Tensor>, ) -> Result<HashMap<String, Tensor>>
Run inference with read lock (allows concurrent reads if session supports it).
§Note
This is the same as run() for now, but could be optimized for
concurrent inference in the future.
Sourcepub fn clone_handle(&self) -> Self
pub fn clone_handle(&self) -> Self
Clone the async session for sharing across tasks.
This is cheap (only clones the Arc), allowing multiple tasks to share the same session.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AsyncSession
impl RefUnwindSafe for AsyncSession
impl Send for AsyncSession
impl Sync for AsyncSession
impl Unpin for AsyncSession
impl UnwindSafe for AsyncSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more