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
impl Options
Sourcepub fn vulkan_precision(&mut self, precision: Precision) -> Result<&mut Self>
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.
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Retains the backward-compatible CPU, non-lightmode convenience preset.
Sourcepub fn native_defaults() -> Result<Self>
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.
Sourcepub fn set_flag(&mut self, flag: OptionFlag, enabled: bool) -> Result<&mut Self>
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.
Sourcepub fn flag(&self, flag: OptionFlag) -> Result<bool>
pub fn flag(&self, flag: OptionFlag) -> Result<bool>
Reads one boolean option.
Sourcepub fn set(&mut self, key: CpuOption, value: i32) -> Result<&mut Self>
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.
Sourcepub unsafe fn set_blob_allocator(&mut self, allocator: &Pool) -> Result<()>
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.
Sourcepub unsafe fn set_workspace_allocator(&mut self, allocator: &Pool) -> Result<()>
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.
Sourcepub unsafe fn set_kvcache_allocator(&mut self, allocator: &Pool) -> Result<()>
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.