pub struct Pool { /* private fields */ }Expand description
Owns a native pool allocator and releases it after its allocations.
A pool serves the intermediate blobs, workspace or attention KV cache that a network or an
extractor allocates. Options and the per-extractor setters store the native
handle without taking ownership, so the pool must outlive every network and extractor configured
from it and must not be shared with one that runs concurrently. The type is thread-affine, like
the objects that use it.
let mut pool = ncnn_rust::alloc::Pool::new()?;
pool.configure(0.5, 1024 * 1024)?;
let mut options = ncnn_rust::Options::new()?;
// SAFETY: `pool` outlives these options and every network configured from them.
unsafe { options.set_blob_allocator(&pool)? };
let net = ncnn_rust::NetBuilder::with_options(options).load_bytes(
"7767517\n2 2\nInput input 0 1 input\nReLU relu 1 1 input output\n",
&[],
)?;
assert_eq!(
net.infer([("input", ncnn_rust::Mat::from_f32(&[-1.0, 2.0], &[2])?)], &["output"])?[0].values,
[0.0, 2.0]
);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !Send for Pool
impl !Sync for Pool
impl Freeze for Pool
impl RefUnwindSafe for Pool
impl Unpin for Pool
impl UnsafeUnpin for Pool
impl UnwindSafe for Pool
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