Skip to content

Add funnystrompp mex - #1

Open
mmelnich wants to merge 29 commits into
mainfrom
add-funnystrompp-mex
Open

mmelnich wants to merge 29 commits into
mainfrom
add-funnystrompp-mex

Conversation

@mmelnich

Copy link
Copy Markdown
Contributor

WIP

mmelnich added 18 commits May 30, 2026 09:44
…ruct, Reorth flag; validateattributes in +randlapack wrapper
…nse-pending) not vendored; THIRD_PARTY_LICENSES; gated behind RANDLAPACK_BINDINGS_BENCHMARKS
…hContent benchmark baselines (Epperly MIT, Persson acknowledged); test_fun_nystrom_pp trace-vs-exact
…icit Omega1 removed, sketch_type deprecated); MEX rebuilt + tests pass both precisions
…ruct (adaptive depth for block_qfa, fixed d otherwise) for benchmark cost accounting
…crash (build blaspp as MKL ILP64 to match MATLAB's runtime BLAS)
…and OpenBLAS on macOS (avoid RandLAPACK's Accelerate BQRRP guard); guard GCC-only MEX link flags
…was scalar-only); document the times-struct lfa_us slots (block_qfa apply = compute_M incl. adaptive certificate)
… = library default) for the block_qfa certificate window
…es += auto_k/auto_s/probe_mv); AdaptiveDelay/AdaptiveMin knobs (inputs 15-16)
…const-marshal fix to avoid n^2 COW copy of A; budget-closure doc q*auto_k
…lly; widen lfa_us to six slots

adaptive_delay / adaptive_min were assigned only when the caller passed a
nonzero value, relying on the oracle being freshly constructed each call to
supply the library defaults. That assumption fails as soon as the oracle is
cached (the persistent-handle path), where the previous call's convergence
window leaks forward and changes d_used, the estimate and the matvec count.
Assign both unconditionally, restoring
BlockLanczosQFA<T>::default_adaptive_delay / _min by name when the caller
passes 0. The oracle is non-copyable and non-assignable, so "reset by
reconstruction" is not available.

lfa_us is now six wide (matvec, run_lanczos, apply, rest, total, reorth) to
carry the reorthogonalization timer the Lanczos classes now record, and the
size gate is >= 5 rather than == 5 so a wider vector is not silently rejected.

Requires RandLAPACK with default_adaptive_delay / _min and the six-slot times
vector.
…time)

Two fixes, both Windows-only and inert elsewhere:
1. Call randlapack_stage_runtime_dlls() on each MEX (guarded on the helper
   existing) so blaspp/lapackpp/backend DLLs land next to the .mexw64;
   MATLAB loads a MEX with its own directory on the DLL search path.
   Note: consumers must pass -DRANDLAPACK_RUNTIME_DLL_DIRS=<backend bin>
   at configure until the RandLAPACK package export bug is fixed (the
   installed config's default is masked by the helper's empty cache
   declaration).
2. Link MATLAB's own libiomp5md and suppress MSVC's libomp140 default-lib:
   MATLAB already hosts Intel's OpenMP runtime, and loading a second
   (LLVM) runtime aborts with OMP Error #15; the two share the kmpc ABI.

Validated on Windows: both MEX build (Ninja + MSVC), test_fun_nystrom_pp
and test_bqrrp pass in R2026a, harness validate('full') passes end to end.
Linux MEX rebuilt and re-tested unchanged.
Verified 2026-08-19 on a real Windows machine: without -G Ninja, CMake
selects the multi-config Visual Studio generator even inside the x64
developer shell, and the MEX lands in matlab/+randlapack/private/Debug/
where MATLAB's package loader never looks (also as an unoptimized Debug
binary). Without the DLL-dirs flag the MEX builds but fails to load in
MATLAB (missing BLAS runtime DLLs).
Executing the documented build verbatim on Windows produced a Debug MEX
(Ninja+MSVC initializes an unset build type to Debug: /Od /RTC1); on
Linux an unset build type compiles without optimization. Correct either
way, but timing-useless. Measured 2026-08-19.
…I, numeric-scalar inputs

Adaptive for block_qfa: 0 = fixed, 1 = Radau-certified (consistent with
scalar_qfa), 2 = legacy window; new RadauReturn (midpoint), AutoDepthCap and
AutoProbeFrac inputs; VecNnz = 0 selects the driver's auto density. Times
struct gains tr_U/tr_L/certified (block_qfa), probe_ms/probe_converged/
phase2_certified (auto), and a real oracle_mv for block_qfa; NaN marks
not-applicable fields. Marshalled buffers are unique_ptr-owned so no error
path leaks; read_int/read_double accept any real numeric scalar class; an
n-by-0 Omega2 raises instead of dividing by zero; infeasible auto budgets
surface as randlapack:fun_nystrom_pp:infeasibleBudget. Fixed the error-id
degradation: raise() threw through the engine and MATLAB's exception
re-entered the catch chain across the static-libstdc++/RTTI split, so every
identifier collapsed to StdError; raise() now throws a TU-local type and the
engine error is emitted last. Tests round-trip all six LFATypes in double
and single and assert the cost-accounting fields the campaign relies on.
RandLAPACK_DIR must name the directory holding RandLAPACKConfig.cmake,
which varies by distro (lib/ vs lib64/) and is the step collaborators
trip on. Search the known install layouts beneath the given directory
so the RandNLA-project root works directly, and replace find_package's
generic failure with an actionable message when nothing is found.
LFAType='adaptive' with AdaptiveMatvecCap; default-on symmetry check with
SkipSymCheck opt-out; ignored-knob warnings moved to the wrapper on
inputParser.UsingDefaults; Omega2 marshal skipped for auto/adaptive; certified
flag marshalled for scalar_qfa; unified error ids; vec_nnz per-row docs;
README example fixed. Tests green in double and single.
…, trace_estimate wrapper, degradation diagnostics

The Gauss / Radau-at-0 bracket needs the derivatives of f from order two up to alternate in
sign, not operator monotonicity; -x log x has the same pattern as log(1+x), so entropy is
admitted to scalar_auto/block_auto (poly and square stay blocked). The scalar tiers now
report tr_U and tr_L as sums of their per-column Gauss and Gauss-Radau values. Also:
scalar_auto/block_auto as LFAType values, CapRankFraction and QuadratureFraction,
FirstRowQL with its fallback reported, the symmetric-sketch build option, and
randlapack.trace_estimate with its tests.

The times struct grows from 22 to 27 fields to carry the kernel's degradation counters out:
ritz_clamped, rank_deficient_steps, min_diag_ratio, nystrom_clamped and bracket_evaluated,
summed over whichever Lanczos objects the call used. Without a field an event cannot reach a
result file however carefully the kernel records it. The help text documents them, and no
longer states tr_U >= tr_L as unconditional: the kernel itself notes tr_L can exceed tr_U
outside the operator-monotone regime, which is the entropy pages.
Input 28 spend_cap, output phase2_checked; under SpendCap the unevaluated lower bracket value and certificates are NaN; trace_estimate reports the pilot's certificate. Tests check the MEX allocation against a copy of spend_cap_split on a case that separates it from the rejected rule.
…acement helpers

- The MEX reads A, Omega2 and the sparse CSC arrays straight from MATLAB's buffers through
  const pointers, so a dense n x n problem holds one copy of A instead of two. The private
  copy stays available behind RANDLAPACK_FNPP_COPY_INPUT=1 (the paper's code path); builds
  without RANDLAPACK_SYMMETRIC_SKETCH always copy. times.input_copied reports which path ran.
- RANDLAPACK_PERF_PARCOPY=1 now warns once that it has no effect without the copy.
- fun_nystrom_pp.m: the symmetry check runs over column blocks of about 32 MB instead of
  forming A - A.' and abs(A(:)) (two n x n temporaries); the maxima are exact, so the
  result is bit-identical.
- New numa_place_mex (Linux): randlapack.numa_spread moves an array's pages round-robin
  over the NUMA nodes in place (move_pages), randlapack.numa_query reports the placement,
  and randlapack.load_dense reads a raw dense file with threads under an interleave policy.

Verified bit-identical to 2fa9639 in every load and placement mode (80/80 cases locally,
12 arms at n = 50,000 on ISAAC); peak memory at n = 50,000 drops from 41 to 22 GiB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant