Skip to main content

GpuBenchHarness

Struct GpuBenchHarness 

Source
pub struct GpuBenchHarness {
    pub warmup: u32,
    pub iterations: u32,
    pub reports: Vec<GpuBenchReport>,
}
Expand description

Timing harness for GPU/CPU backend comparison benchmarks.

Fields§

§warmup: u32

Warm-up iterations (not timed).

§iterations: u32

Timed iterations.

§reports: Vec<GpuBenchReport>

Collected reports.

Implementations§

Source§

impl GpuBenchHarness

Source

pub fn new() -> Self

Create a harness with 2 warm-up and 5 timed iterations.

Source

pub fn available_backends() -> Vec<BackendKind>

Return which backends are available in this build.

CPU is always available. wgpu and CUDA depend on feature flags and device availability (they appear in the list only when initialisation succeeds).

Source

pub fn bench_sph_density(&mut self, n: usize) -> Vec<GpuBenchReport>

Benchmark SPH density summation for n particles on all available backends.

Each particle’s density is recomputed from scratch each call to avoid caching effects. FLOPs estimated as 10 × N² (distance + kernel eval).

Source

pub fn bench_lbm_step( &mut self, nx: usize, ny: usize, nz: usize, ) -> Vec<GpuBenchReport>

Benchmark one LBM BGK step on an nx × ny × nz domain.

FLOPs estimated as 120 × nc (19 distribution reads + BGK + streaming).

Source

pub fn bench_parallel_scan(&mut self, n: usize) -> GpuBenchReport

Benchmark parallel prefix scan on n f64 elements (CPU Rayon scan).

FLOPs = 2n (N adds in up-sweep + N adds in down-sweep).

Source

pub fn run_full_suite(&mut self) -> String

Run the complete GPU benchmark suite and return a formatted summary.

use oxiphysics_gpu::gpu_bench::GpuBenchHarness;
let mut h = GpuBenchHarness::new();
let summary = h.run_full_suite();
assert!(!summary.is_empty());
Source

pub fn cpu_vs_wgpu_comparison(&mut self, n: usize) -> Vec<GpuBenchReport>

Benchmark CPU inclusive scan vs wgpu copy dispatch for n f64 elements.

Both sides operate on the same data (a ramp of 0.0..n). The wgpu side dispatches a copy shader (since f32 on-device means scan parity is a different test). Returns a Vec with one CPU report, and optionally one wgpu report if an adapter is available.

If no GPU adapter is present, only the CPU report is returned (no panic).

use oxiphysics_gpu::gpu_bench::GpuBenchHarness;
let mut h = GpuBenchHarness::new();
let reports = h.cpu_vs_wgpu_comparison(1000);
assert!(!reports.is_empty());
assert_eq!(reports[0].name, "cpu_copy_scan");
Source

pub fn cpu_vs_wgpu_sph(&mut self, n: usize) -> Vec<GpuBenchReport>

Benchmark the SPH density kernel on CPU and wgpu backends side-by-side.

Builds an SPH simulation with n particles arranged in a uniform grid inside the domain [-10, 10]³. Runs the full SphSimulation::step (density + pressure + accel + integrate) on both backends and returns timing reports.

If no wgpu adapter is available, only the CPU report is returned.

§Example
let mut h = oxiphysics_gpu::gpu_bench::GpuBenchHarness::new();
let reports = h.cpu_vs_wgpu_sph(64);
assert!(!reports.is_empty());
Source

pub fn cpu_vs_cuda_sph(&mut self, n: usize) -> Vec<GpuBenchReport>

Run SPH density on CPU and (optionally) CUDA; return timing reports.

The CPU path runs the same SphSimulation::step loop as Self::cpu_vs_wgpu_sph but is tagged with "cuda_sph_density_cpu".

Under the cuda-backend feature, a second report is added when a CUDA device is available at runtime. If no CUDA driver is present (e.g. on macOS) only the CPU report is returned — no panic.

§Example
let mut h = oxiphysics_gpu::gpu_bench::GpuBenchHarness::new();
let reports = h.cpu_vs_cuda_sph(64);
assert!(!reports.is_empty());
assert!(reports[0].name.contains("sph_density"));
assert!(reports[0].mean > std::time::Duration::ZERO);
Source

pub fn print_comparison(&self)

Print a comparison table for all collected reports.

Trait Implementations§

Source§

impl Default for GpuBenchHarness

Source§

fn default() -> Self

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

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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,