Skip to main content

Executor

Struct Executor 

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

Runs ComputeOps through the GPU->CPU cascade.

Build ONE and reuse it: it probes the GPU exactly once at construction and caches the handle. A program that makes an Executor per call pays the adapter-enumeration cost every time and defeats the caching.

Implementations§

Source§

impl Executor

Source

pub fn new() -> Self

Build an executor, probing for a GPU once.

Never fails: a missing GPU is not an error here, it just means every op will take the CPU path. Use Executor::has_gpu if you need to know which way the cascade will go.

Source

pub fn cpu_only() -> Self

Build an executor that is FORCED onto the CPU path, ignoring any GPU.

This is what makes the CPU fallback testable on a machine that does have a GPU: with no adapter to borrow, run can only cascade to CPU.

Source

pub fn has_gpu(&self) -> bool

Does this executor have a GPU to use? false means every run lands on CPU. Handy for tests (skip the GPU==CPU assertion when there is no GPU) and for logging which path a workload will take.

Source

pub fn gpu_context(&self) -> Option<&GpuContext>

The cached GPU context, if any. Lets a caller run the GPU path directly (e.g. a test asserting GPU==CPU) without going through the cascade.

Source

pub fn run<O>(&self, op: &O, input: &O::Input<'_>) -> O::Output
where O: ComputeOp,

Run an op through the cascade: GPU first, CPU on any failure.

This is the one method callers normally use. It always returns a result:

  • GPU present and its path succeeds -> the GPU result.
  • GPU present but its path returns Err -> the CPU result (logged as a fall-back at warn… once tracing is wired; today the Err is simply swallowed into the CPU path).
  • no GPU at all -> straight to the CPU result.

The cascade itself is the small ?/unwrap_or_else dance below: build a Result for the GPU attempt (short-circuiting to Err if there is no context), then unwrap_or_else onto the infallible CPU path.

Trait Implementations§

Source§

impl Debug for Executor

Source§

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

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

impl Default for Executor

Source§

fn default() -> Executor

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,