Skip to main content

ComputeBackend

Enum ComputeBackend 

Source
pub enum ComputeBackend {
    Serial,
    CpuMulti,
    Gpu,
}
Expand description

Which execution backend a numerical kernel should use.

§Variants and what they cost

  • Serial — one thread, scalar. Always available. The deterministic trusted reference; bit-for-bit reproducible run to run.
  • CpuMulti — rayon across CPU cores. Requires the parallel feature. Pays thread-pool overhead, so it loses on small problems; see CPU_MULTI_MIN_WORK_ITEMS. Reduction order is not generally reproducible unless a kernel says otherwise.
  • Gpu — wgpu compute. Requires the gpu feature, a non-Android target, and an actual adapter at run time. Pays a host-device transfer per dispatch, so it needs a much larger problem to win; see GPU_MIN_WORK_ITEMS. WGSL has no f64, so a GPU kernel that computes in f32 will NOT match the serial f64 path to full precision — each kernel must document its own measured deviation.

§Choosing one

Prefer select_backend over hand-picking. If you do name a backend, route it through resolve so an unavailable choice degrades instead of failing.

§Units

Dimensionless — this is a mode selector, not a quantity.

Variants§

§

Serial

Single-threaded scalar execution — always present, always the oracle.

§

CpuMulti

Multi-threaded CPU execution via rayon (parallel feature).

§

Gpu

GPU compute via wgpu (gpu feature, non-Android, adapter present).

Implementations§

Source§

impl ComputeBackend

Source

pub fn is_available(self) -> bool

Whether this backend can actually run in this build, on this target, right now.

  • Serial — always true.
  • CpuMulti — true when the parallel feature is on. Compile-time only; rayon needs no run-time probe.
  • Gpu — true only when the gpu feature is on, the target is not Android, and a GPU adapter was found by gpu_adapter_present. This one genuinely queries the machine.
Source

pub fn resolve(self) -> Self

Degrade this backend to the best one that is actually available, without erroring.

The order is Gpu -> CpuMulti -> Serial: a requested GPU with no adapter (or no gpu feature) tries multi-CPU, and failing that runs serially. Serial is always reachable, so this never fails and never panics.

This is the “graceful absence of a GPU” contract: a missing adapter is a normal outcome on a headless server, in CI, on Android, or on a laptop with no discrete GPU — not an error condition.

Source

pub fn label(self) -> &'static str

A short human-readable label, for benchmark tables and log lines.

Trait Implementations§

Source§

impl Clone for ComputeBackend

Source§

fn clone(&self) -> Self

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 Copy for ComputeBackend

Source§

impl Debug for ComputeBackend

Source§

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

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

impl Default for ComputeBackend

Source§

fn default() -> Self

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

impl Eq for ComputeBackend

Source§

impl Hash for ComputeBackend

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ComputeBackend

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ComputeBackend

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> Same for T

Source§

type Output = T

Should always be Self
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, 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.