Skip to main content

Options

Struct Options 

Source
pub struct Options { /* private fields */ }
Expand description

Native CPU option storage. Net::configure applies it to an unloaded network.

§Choosing between Options and NetBuilder

Both reach the same native option block. Use Net::builder with threads, flag and option while a network is being created: those calls consume the builder and report a configuration failure before any model is read. Use Options when an option set is shared or prepared elsewhere, then hand it to Net::configure once, before loading parameters.

Implementations§

Source§

impl Options

Source

pub fn vulkan_precision(&mut self, precision: Precision) -> Result<&mut Self>

Applies a convenience preset, not a hardware capability restriction.

FP16 toggles packed, storage, and arithmetic together; FP32 clears all three. Both presets clear BF16 storage. Later set_flag overrides win, so mixed precision preferences remain independently configurable. Native ncnn selects supported kernels and performs runtime capability dispatch.

Source

pub fn new() -> Result<Self>

Retains the backward-compatible CPU, non-lightmode convenience preset.

Source

pub fn native_defaults() -> Result<Self>

Allocates unchanged native defaults. Safe networks select CPU unless a tracked Vulkan device is explicitly attached, independently of these flags.

Source

pub fn set_flag(&mut self, flag: OptionFlag, enabled: bool) -> Result<&mut Self>

Overrides one independent native boolean without changing other preferences.

The flag maps to the same native field as the matching CpuOption, so mixing the two forms for one field is allowed and the later write wins.

Source

pub fn flag(&self, flag: OptionFlag) -> Result<bool>

Reads one boolean option.

Source

pub fn set(&mut self, key: CpuOption, value: i32) -> Result<&mut Self>

Writes one integer option after validating its range.

CpuOption::Threads must be positive, CpuOption::FlushDenormals stays within 0..=3, CpuOption::OpenmpBlocktime and CpuOption::KvCacheSequenceHint accept zero, and the remaining keys accept 0 or 1. The value reaches the native option block only after those checks, so a rejected write leaves the block unchanged.

Source

pub unsafe fn set_blob_allocator(&mut self, allocator: &Pool) -> Result<()>

Attaches a pool allocator for intermediate blobs.

§Safety

The allocator stays alive and usable until every network configured from this option block is dropped, and no other network may claim the same pool at the same time. The native option block stores the handle without taking ownership.

Source

pub unsafe fn set_workspace_allocator(&mut self, allocator: &Pool) -> Result<()>

Attaches a pool allocator for layer workspace.

§Safety

The same lifetime and exclusivity rules as set_blob_allocator apply.

Source

pub unsafe fn set_kvcache_allocator(&mut self, allocator: &Pool) -> Result<()>

Attaches the allocator that keeps an attention KV cache.

The cache allocator must differ from the blob allocator, and CpuOption::KvCacheSequenceHint sizes the cache for the longest sequence.

§Safety

The same lifetime and exclusivity rules as set_blob_allocator apply.

Source

pub fn get(&self, key: CpuOption) -> Result<i32>

Reads one integer option.

Reads come from the native block, so a value written through a raw handle is visible here.

Source

pub unsafe fn as_raw(&self) -> ncnn_option_t

Exposes advanced configuration and disables low-copy output eligibility for networks subsequently configured with these options.

§Safety

The caller keeps these options alive while any network uses them and restores fields the adapter does not model.

Trait Implementations§

Source§

impl Drop for Options

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.