Skip to main content

BackendOptions

Struct BackendOptions 

Source
pub struct BackendOptions {
    pub opt_level: u8,
    pub symbolic_extent: Option<u32>,
    pub precision: PrecisionPolicy,
    pub memory_plan: Option<MemoryPlan>,
    pub quantization_params: Vec<QuantParam>,
    pub per_channel_params: Vec<PerChannelParam>,
    pub tiling_plans: Vec<TilingPlanInfo>,
    pub vectorization_hints: Vec<VectorizationHintInfo>,
    pub constant_tensors: Vec<ConstantTensor>,
}
Expand description

Options passed to a backend during compilation.

The precision field controls the target quantization precision. In the typical workflow, the caller (e.g. nxpu-cli) applies the appropriate quantization pass (F32ToF16, F32ToBf16, F32ToInt8, or MixedPrecisionPass) to the IR module before calling Backend::compile. The precision field is informational — backends can read it to emit diagnostics or choose format-specific options, but the IR has already been rewritten by the quantization pass.

Fields§

§opt_level: u8

Optimization level (0 = none, 1 = basic, 2 = aggressive).

§symbolic_extent: Option<u32>

Concrete extent to substitute for tensor dimensions the kernel leaves symbolic.

A WGSL kernel over array<f32> carries no length, so the emitted graph has no size for most dimensions. Formats differ on what to do about that: ONNX names them and resolves later, while TFLite requires a concrete extent and cannot load a model without one. None means the caller did not say, and the backend picks the smallest valid extent.

The type forbids a negative value on purpose: writing -1 here is the bug that made every TFLite model this project emitted unloadable.

§precision: PrecisionPolicy

Precision policy for quantization.

The CLI applies the corresponding quantization pass to the IR before compilation. Backends may use this to emit precision-related diagnostics or metadata, but should not re-quantize the IR.

§memory_plan: Option<MemoryPlan>

Optional memory plan computed by the memory planning pass.

When present, backends can use this to emit buffer allocation metadata (e.g. ONNX metadata_props, TFLite buffer info). Backends that do not support memory plan metadata may ignore this field.

§quantization_params: Vec<QuantParam>

Optional per-tensor quantization parameters from calibration.

When present, backends embed these parameters in the compiled output (e.g. ONNX metadata_props, TFLite companion JSON) so downstream tools can correctly dequantize tensors.

§per_channel_params: Vec<PerChannelParam>

Per-channel quantization parameters for weight tensors.

When present, backends emit per-channel quantization metadata: ONNX backends inject QuantizeLinear/DequantizeLinear (QDQ) nodes, TFLite backends include them in the companion JSON.

§tiling_plans: Vec<TilingPlanInfo>

Tiling plans computed by the tiling pass.

Backends may use these to emit cache-blocking metadata or generate tiled loop structures.

§vectorization_hints: Vec<VectorizationHintInfo>

Vectorization hints computed by the vectorization pass.

Backends may use these to emit SIMD annotations or select vector instruction widths.

§constant_tensors: Vec<ConstantTensor>

Contents for tensors the kernel receives as buffers, by name.

A WGSL kernel takes its weights through var<storage, read> and there is nothing in the source to say what they are — the host binds them per dispatch. An NNAPI driver will not accept a convolution on those terms: measured on a MediaTek MT6899, mtk-neuron_shim accelerates a convolution whose filter is a compile-time constant and refuses the identical convolution, at the same shapes, whose filter is a graph input.

A tensor named here is emitted as a constant and stops being a graph input. Empty is not “fill it with zeros”: a model that accelerated because its weights were invented would run, be attributed to the accelerator, and compute the wrong thing.

Trait Implementations§

Source§

impl Clone for BackendOptions

Source§

fn clone(&self) -> BackendOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BackendOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BackendOptions

Source§

fn default() -> BackendOptions

Returns the “default value” for a type. Read more
Source§

impl Display for BackendOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.