PERF-2 P3: the batched device V-cycle microbenchmark — mg_vcycle.cu (masked variable-coefficient five-point red-black half-sweeps, residual, CSR restriction in a fixed order, prolongation, coarsest sweeps; [K][n] layout, blockIdx.y = march), LevelExport/export_hierarchy and vcycle_f32_reference on the CPU side, and the ignored cuda-feature test that checks the K = 1 device V-cycle against the CPU f32 reference and times K = 1 / 8 / 16 per march
CI / Build (macos-latest) (push) Waiting to run
CI / Test (macos-latest) (push) Blocked by required conditions
CI / Test (ubuntu-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (macos-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (ubuntu-latest) (push) Blocked by required conditions
CI / WASM Build + Size Check (push) Blocked by required conditions
CI / Distributed Training Tests (push) Blocked by required conditions
CI / CI Success (push) Blocked by required conditions
Performance Benchmarks / Run Benchmarks (push) Failing after 6s
CI / Build (ubuntu-latest) (push) Failing after 5s
Documentation / Build API Documentation (push) Failing after 6s
Documentation / Build User Guide (push) Successful in 7s
CI / Format Check (push) Failing after 12s
CI / Clippy Check (push) Failing after 36s
CI / Build CPU-Only (Explicit) (push) Failing after 1m37s
CI / Build (macos-latest) (push) Waiting to run
CI / Test (macos-latest) (push) Blocked by required conditions
CI / Test (ubuntu-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (macos-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (ubuntu-latest) (push) Blocked by required conditions
CI / WASM Build + Size Check (push) Blocked by required conditions
CI / Distributed Training Tests (push) Blocked by required conditions
CI / CI Success (push) Blocked by required conditions
Performance Benchmarks / Run Benchmarks (push) Failing after 6s
CI / Build (ubuntu-latest) (push) Failing after 5s
Documentation / Build API Documentation (push) Failing after 6s
Documentation / Build User Guide (push) Successful in 7s
CI / Format Check (push) Failing after 12s
CI / Clippy Check (push) Failing after 36s
CI / Build CPU-Only (Explicit) (push) Failing after 1m37s
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YJPeT6WA2e7YvAnS875AHL
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
53078c2aa7
commit
0dc95a8de5
@@ -65,7 +65,8 @@ pub use piso::{PisoParameters, PisoResult, PisoSolver};
|
||||
#[cfg(feature = "cuda")]
|
||||
pub use piso_gpu::PisoGpuSolver;
|
||||
pub use poisson::{
|
||||
MgPrecision, MgSmoother, MultigridParameters, PcgCache, PoissonProblem, PoissonSolution,
|
||||
LevelExport, MgPrecision, MgSmoother, MultigridParameters, PcgCache, PoissonProblem,
|
||||
PoissonSolution, export_hierarchy, vcycle_f32_reference,
|
||||
PoissonSolverKind, configure_threads, solve_multigrid_pcg, solve_multigrid_pcg_cached,
|
||||
};
|
||||
pub use polygon_sdf::PolygonSdf;
|
||||
|
||||
@@ -1001,6 +1001,99 @@ pub fn configure_threads(threads: usize) -> usize {
|
||||
n
|
||||
}
|
||||
|
||||
/// PERF-2 P3 (`docs/perf2_campaign.md`): one hierarchy level exported for a
|
||||
/// device V-cycle — the sanitised f32 coefficients, the active-cell and
|
||||
/// colour index lists, the parent map, and the coarse cells' children in
|
||||
/// CSR form (so a restriction can sum in a fixed order on the device).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LevelExport {
|
||||
pub nx: usize,
|
||||
pub ny: usize,
|
||||
pub cells: Vec<u32>,
|
||||
pub red: Vec<u32>,
|
||||
pub black: Vec<u32>,
|
||||
/// Fine cell → coarse cell (`u32::MAX` without an equation; empty on
|
||||
/// the coarsest level).
|
||||
pub coarse_of: Vec<u32>,
|
||||
/// For the NEXT level's cells, in its `cells` order: the fine cells
|
||||
/// restricting into each (CSR: `children_ptr[c]..children_ptr[c + 1]`).
|
||||
pub children_ptr: Vec<u32>,
|
||||
pub children_idx: Vec<u32>,
|
||||
pub ae: Vec<f32>,
|
||||
pub aw: Vec<f32>,
|
||||
pub an: Vec<f32>,
|
||||
pub as_: Vec<f32>,
|
||||
pub ap: Vec<f32>,
|
||||
}
|
||||
|
||||
/// The f32 hierarchy of `problem` (red-black colour lists included), level
|
||||
/// 0 fine, for a device implementation of [`Hierarchy::apply_preconditioner`].
|
||||
pub fn export_hierarchy(problem: &PoissonProblem, params: &MultigridParameters) -> Vec<LevelExport> {
|
||||
let hier = Hierarchy::<f32>::build(problem, params);
|
||||
let depth = hier.levels.len();
|
||||
(0..depth)
|
||||
.map(|l| {
|
||||
let lv = &hier.levels[l];
|
||||
let to_u32 = |v: &[usize]| v.iter().map(|&i| i as u32).collect::<Vec<u32>>();
|
||||
let (children_ptr, children_idx) = if l + 1 < depth {
|
||||
let coarse = &hier.levels[l + 1];
|
||||
let mut pos = vec![usize::MAX; coarse.problem.nx * coarse.problem.ny];
|
||||
for (k, &c) in coarse.cells.iter().enumerate() {
|
||||
pos[c] = k;
|
||||
}
|
||||
let mut lists: Vec<Vec<u32>> = vec![Vec::new(); coarse.cells.len()];
|
||||
for &idx in &lv.cells {
|
||||
let c = lv.coarse_of[idx];
|
||||
if coarse.active[c] {
|
||||
lists[pos[c]].push(idx as u32);
|
||||
}
|
||||
}
|
||||
let mut ptr = Vec::with_capacity(lists.len() + 1);
|
||||
let mut flat = Vec::new();
|
||||
ptr.push(0u32);
|
||||
for list in &lists {
|
||||
flat.extend_from_slice(list);
|
||||
ptr.push(flat.len() as u32);
|
||||
}
|
||||
(ptr, flat)
|
||||
} else {
|
||||
(Vec::new(), Vec::new())
|
||||
};
|
||||
LevelExport {
|
||||
nx: lv.problem.nx,
|
||||
ny: lv.problem.ny,
|
||||
cells: to_u32(&lv.cells),
|
||||
red: to_u32(&lv.red),
|
||||
black: to_u32(&lv.black),
|
||||
coarse_of: lv
|
||||
.coarse_of
|
||||
.iter()
|
||||
.map(|&c| if c == usize::MAX { u32::MAX } else { c as u32 })
|
||||
.collect(),
|
||||
children_ptr,
|
||||
children_idx,
|
||||
ae: lv.ae.clone(),
|
||||
aw: lv.aw.clone(),
|
||||
an: lv.an.clone(),
|
||||
as_: lv.as_.clone(),
|
||||
ap: lv.ap.clone(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// One f32 V-cycle of `problem`'s hierarchy on `r` (the CPU reference for a
|
||||
/// device V-cycle): `z = M⁻¹ r` exactly as the preconditioner computes it.
|
||||
pub fn vcycle_f32_reference(
|
||||
problem: &PoissonProblem,
|
||||
params: &MultigridParameters,
|
||||
r: &[f64],
|
||||
z: &mut [f64],
|
||||
) {
|
||||
let mut hier = Hierarchy::<f32>::build(problem, params);
|
||||
hier.apply_preconditioner(r, z);
|
||||
}
|
||||
|
||||
/// A reusable prepared solver per V-cycle precision (PERF-2 P1.1): the
|
||||
/// operator's hierarchy is rebuilt only when the operator changes.
|
||||
#[derive(Default)]
|
||||
|
||||
Reference in New Issue
Block a user