pub struct BackendSelector { /* private fields */ }Expand description
Cost model for backend selection
Based on Gregg & Hazelwood (2011) 5× PCIe rule for GPU dispatch decisions.
Implementations§
Source§impl BackendSelector
impl BackendSelector
Sourcepub fn with_pcie_bandwidth(self, bandwidth: f64) -> Self
pub fn with_pcie_bandwidth(self, bandwidth: f64) -> Self
Configure custom PCIe bandwidth
Sourcepub fn with_gpu_gflops(self, gflops: f64) -> Self
pub fn with_gpu_gflops(self, gflops: f64) -> Self
Configure custom GPU throughput
Sourcepub fn with_min_dispatch_ratio(self, ratio: f64) -> Self
pub fn with_min_dispatch_ratio(self, ratio: f64) -> Self
Configure custom dispatch ratio threshold
Sourcepub fn select_backend(&self, data_bytes: usize, flops: u64) -> Backend
pub fn select_backend(&self, data_bytes: usize, flops: u64) -> Backend
Select optimal backend based on workload characteristics
§Arguments
data_bytes- Amount of data to transfer (host → device)flops- Floating point operations required
§Returns
Recommended backend based on cost model
§Cost Model
GPU dispatch is beneficial when:
compute_time > min_dispatch_ratio × transfer_timePer Gregg & Hazelwood (2011), the 5× rule accounts for:
- Host→Device transfer (PCIe overhead)
- Kernel launch latency
- Device→Host transfer
- CPU-GPU synchronization
Sourcepub fn select_for_vector_op(&self, n: usize, ops_per_element: u64) -> Backend
pub fn select_for_vector_op(&self, n: usize, ops_per_element: u64) -> Backend
Select backend for vector operations
§Arguments
n- Vector lengthops_per_element- Operations per element (e.g., 2 for dot product)
Sourcepub fn select_for_elementwise(&self, n: usize) -> Backend
pub fn select_for_elementwise(&self, n: usize) -> Backend
Select backend for element-wise operations
Element-wise ops are memory-bound, so GPU is rarely beneficial
Sourcepub fn select_with_moe(
&self,
complexity: OpComplexity,
data_size: usize,
) -> Backend
pub fn select_with_moe( &self, complexity: OpComplexity, data_size: usize, ) -> Backend
MoE (Mixture-of-Experts) routing: select backend based on operation complexity
§Arguments
complexity- Operation complexity (Low/Medium/High)data_size- Number of elements in the operation
§Returns
Recommended backend using adaptive thresholds per complexity level
§MoE Thresholds (per empirical performance analysis)
- Low complexity (element-wise): SIMD at 1M+ elements, never GPU
- Medium complexity (reductions): SIMD at 10K+, GPU at 100K+ elements
- High complexity (matmul): SIMD at 1K+, GPU at 10K+ elements
Sourcepub fn selection_stats(
&self,
complexity: OpComplexity,
data_size: usize,
) -> SelectionStats
pub fn selection_stats( &self, complexity: OpComplexity, data_size: usize, ) -> SelectionStats
Get selection statistics for profiling
Trait Implementations§
Source§impl Clone for BackendSelector
impl Clone for BackendSelector
Source§fn clone(&self) -> BackendSelector
fn clone(&self) -> BackendSelector
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BackendSelector
impl Debug for BackendSelector
Auto Trait Implementations§
impl Freeze for BackendSelector
impl RefUnwindSafe for BackendSelector
impl Send for BackendSelector
impl Sync for BackendSelector
impl Unpin for BackendSelector
impl UnsafeUnpin for BackendSelector
impl UnwindSafe for BackendSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more