pub struct BackendDispatcher { /* private fields */ }Expand description
Cost-based backend selection
References:
- Gregg & Hazelwood (2011):
PCIebus bottleneck analysis - Breß et al. (2014): Operator variant selection on heterogeneous hardware
Implementations§
Source§impl BackendDispatcher
impl BackendDispatcher
Sourcepub fn select(total_bytes: usize, estimated_flops: f64) -> Backend
pub fn select(total_bytes: usize, estimated_flops: f64) -> Backend
Select backend based on arithmetic intensity (FLOPs/Byte)
§Arguments
total_bytes- Total data size in bytesestimated_flops- Estimated floating point operations
§Returns
Backend selection (GPU, SIMD, or Scalar)
§Algorithm
- Check minimum data size threshold (10 MB)
- Calculate
PCIetransfer time: bytes / 32 GB/s - Estimate GPU compute time: FLOPs / 100 GFLOP/s
- Apply 5x rule: GPU only if compute > 5x transfer
Sourcepub const fn arithmetic_intensity(total_flops: f64, total_bytes: usize) -> f64
pub const fn arithmetic_intensity(total_flops: f64, total_bytes: usize) -> f64
Calculate arithmetic intensity (FLOPs per byte)
Higher arithmetic intensity means more compute per data transfer, making GPU acceleration more beneficial.
§Arguments
total_flops- Total floating point operationstotal_bytes- Total data size in bytes
§Returns
Arithmetic intensity ratio (FLOPs/Byte)
§Example
use trueno_db::backend::BackendDispatcher;
// Matrix multiply: N^3 FLOPs for N^2 elements = N FLOPs/element
let intensity = BackendDispatcher::arithmetic_intensity(1_000_000_000.0, 100_000_000);
assert_eq!(intensity, 10.0); // 10 FLOPs per byteSourcepub const fn estimate_simple_aggregation_flops(num_elements: usize) -> f64
pub const fn estimate_simple_aggregation_flops(num_elements: usize) -> f64
Estimate FLOPs for simple aggregation (SUM, AVG, COUNT, MIN, MAX)
Simple aggregations perform ~1 FLOP per element (single pass)
§Arguments
num_elements- Number of elements to aggregate
§Returns
Estimated FLOPs
§Example
use trueno_db::backend::BackendDispatcher;
// SUM over 100M elements = 100M FLOPs
let flops = BackendDispatcher::estimate_simple_aggregation_flops(100_000_000);
assert_eq!(flops, 100_000_000.0);Sourcepub const fn estimate_group_by_flops(num_elements: usize) -> f64
pub const fn estimate_group_by_flops(num_elements: usize) -> f64
Estimate FLOPs for GROUP BY aggregation
GROUP BY requires hashing (5 FLOPs/element) + aggregation (1 FLOP/element)
§Arguments
num_elements- Number of elements to process
§Returns
Estimated FLOPs
§Example
use trueno_db::backend::BackendDispatcher;
// GROUP BY over 100M elements = 600M FLOPs
let flops = BackendDispatcher::estimate_group_by_flops(100_000_000);
assert_eq!(flops, 600_000_000.0);Sourcepub const fn estimate_filter_flops(num_elements: usize) -> f64
pub const fn estimate_filter_flops(num_elements: usize) -> f64
Sourcepub const fn estimate_join_flops(left_size: usize, right_size: usize) -> f64
pub const fn estimate_join_flops(left_size: usize, right_size: usize) -> f64
Auto Trait Implementations§
impl Freeze for BackendDispatcher
impl RefUnwindSafe for BackendDispatcher
impl Send for BackendDispatcher
impl Sync for BackendDispatcher
impl Unpin for BackendDispatcher
impl UnsafeUnpin for BackendDispatcher
impl UnwindSafe for BackendDispatcher
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