Skip to content

Single-pass LSMR iterations and sorted observation layout - #86

Merged
eloualiche merged 4 commits into
FixedEffects:mainfrom
matthieugomez:single-pass-lsmr
Aug 28, 2026
Merged

Single-pass LSMR iterations and sorted observation layout#86
eloualiche merged 4 commits into
FixedEffects:mainfrom
matthieugomez:single-pass-lsmr

Conversation

@matthieugomez

@matthieugomez matthieugomez commented Aug 28, 2026

Copy link
Copy Markdown
Member
  • Restructure lsmr! so each iteration runs one fused pass over the observations (bidiag_forward!).
  • Sort observations by the block with the largest coefficient tile when that tile outgrows the cache (only on CPU).
  • Metal: kernels launch asynchronously with one host wait per iteration, threadgroup widths come from each compiled pipeline (fixes crashes on kernels whose register use caps below the device width), and a fused device kernel does all scatters plus the norm in one launch.
  • Consolidate benchmarks

- Keep the Golub-Kahan u unnormalized, folding 1/beta into the scalar
  recurrences, so the gather A'u can be accumulated in the same loop
  that builds u (linearity: A'(u/beta) = (A'u)/beta)
- bidiag_forward!: scatter of every block, the norm, and (when all
  blocks have per-thread buffers) the gathers in one pass over u;
  generic mul!-based fallback keeps the GPU extensions working
- lsmr! now requires x = 0 on entry (both solvers already pass it)
- Sort observations by the block with the largest coefficient tile when
  it outgrows the cache: its coefficient accesses stream instead of
  scatter, and its gather runs race-free without per-thread buffers at
  any cardinality (SortedGather), inside the fused single-pass iteration
- Metal: launch kernels asynchronously with one host wait per LSMR
  iteration, and pick threadgroup widths from each compiled pipeline
- CUDA/Metal: fused bidiagonalization kernel (all scatters plus the norm
  in one launch), with the cross-block norm reduced without Float32 drift
- Store the A'u workspace on the solvers instead of allocating per solve
benchmark.jl defines each problem once (simple, hard worker-firm,
interacted, three-way, large-cardinality sorted) and runs 6 columns
through one solver on cpu, Metal, and CUDA, with measured timings as
comments; replaces the previous per-topic benchmark scripts.
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.41722% with 189 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@3290c4f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
ext/MetalExt.jl 0.00% 70 Missing ⚠️
src/CPU.jl 57.57% 56 Missing ⚠️
ext/CUDAExt.jl 0.00% 53 Missing ⚠️
src/utils/lsmr.jl 68.18% 7 Missing ⚠️
src/AbsorptionPlan.jl 86.95% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #86   +/-   ##
=======================================
  Coverage        ?   59.62%           
=======================================
  Files           ?       12           
  Lines           ?     1241           
  Branches        ?        0           
=======================================
  Hits            ?      740           
  Misses          ?      501           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eloualiche
eloualiche merged commit 1eab719 into FixedEffects:main Aug 28, 2026
6 checks passed
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.

2 participants