Skip to main content

BackendDispatcher

Struct BackendDispatcher 

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

Cost-based backend selection

References:

  • Gregg & Hazelwood (2011): PCIe bus bottleneck analysis
  • Breß et al. (2014): Operator variant selection on heterogeneous hardware

Implementations§

Source§

impl BackendDispatcher

Source

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 bytes
  • estimated_flops - Estimated floating point operations
§Returns

Backend selection (GPU, SIMD, or Scalar)

§Algorithm
  1. Check minimum data size threshold (10 MB)
  2. Calculate PCIe transfer time: bytes / 32 GB/s
  3. Estimate GPU compute time: FLOPs / 100 GFLOP/s
  4. Apply 5x rule: GPU only if compute > 5x transfer
Source

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 operations
  • total_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 byte
Source

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);
Source

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);
Source

pub const fn estimate_filter_flops(num_elements: usize) -> f64

Estimate FLOPs for WHERE filter

Filters require predicate evaluation (~2 FLOPs per element)

§Arguments
  • num_elements - Number of elements to filter
§Returns

Estimated FLOPs

Source

pub const fn estimate_join_flops(left_size: usize, right_size: usize) -> f64

Estimate FLOPs for JOIN operation

Hash join: Build hash table (5 FLOPs/elem) + Probe (5 FLOPs/elem)

§Arguments
  • left_size - Number of elements in left table
  • right_size - Number of elements in right table
§Returns

Estimated FLOPs

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> 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, 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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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