Skip to content
This repository was archived by the owner on Aug 20, 2026. It is now read-only.

refactor(reg_flow): port kernel_*/matvec_all/diag_all/relax_* onto teeny - #33

Merged
balbasty merged 4 commits into
claude/fastfields-teeny-refactor-js42idfrom
claude/reg-flow-lame-all-relax
Aug 1, 2026
Merged

refactor(reg_flow): port kernel_*/matvec_all/diag_all/relax_* onto teeny#33
balbasty merged 4 commits into
claude/fastfields-teeny-refactor-js42idfrom
claude/reg-flow-lame-all-relax

Conversation

@balbasty

Copy link
Copy Markdown
Collaborator

Summary

  • Batch-only+center (kernel_absolute, kernel_membrane, kernel_bending, kernel_all, kernel_lame): these five were still on the legacy index2offset batch loop despite matvec/diag for the same energies already being teenified. Peeled each (*batch,*spatial) cell to its batch origin (rank-nbatch+ndim carrier, peel_front_at<-ndim>) and wrote the stencil at the existing center_offset.
  • Stencil (matvec_all, diag_all): mirrors matvec_bending/diag_bending's established peel + batch-cell-caching pattern, with the combined Lamé+bending kernel and its extra shears/div params.
  • Relax (Gauss-Seidel/patch-coloring) (relax_membrane_, relax_bending_, relax_lame_, relax_all_): the first relax port in the project. Kept the algorithm byte-for-byte (same patch1/2/3, matvec_X<isub>/diag_X<set>, PosDef::relax_, sweep counts). Wrapped sol/hes/grd once as rank-(nbatch+ndim)anyrank carriers and replaced the index2offset_v2/index2offset per-voxel decode with the same peel-and-cache-per-batch-cell idiom used by the stencil matvec/diag. Iteration order differs from the original decode, but this is immaterial: patch coloring makes same-color voxels in one sweep mutually independent.
  • Left out of scope, correctly: matvec_lame/diag_lame (not in cpu-lib's public reg_flow.cpp dispatch prior to this — see fastfields-cpu-lib#39, which wires them in), and the *_jrls variants (not wired anywhere).

Test plan

  • make -C ../fastfields-cpu-lib test CXX=clang++ — 854 checks, 0 failures
  • make -C ../fastfields-cpu-lib test CXX=g++ — 854 checks, 0 failures
  • g++ -fsanitize=address,undefined -O1 build — 854 checks, 0 failures
  • Confirmed the pre-branch reg_flow.h reproduces the same 854/0 baseline against the current kernels checkout (the diag cross-term fix in fastfields-kernels#32 landed mid-task and bumped the baseline from 830→854; this branch's changes reproduce it exactly, no regression or self-adjointness drift)

Generated by Claude Code

claude added 4 commits July 27, 2026 19:58
These were still on the legacy index2offset batch loop even though
matvec/diag for the same three energies were already teenified. Peel
each (*batch,*spatial) cell down to its batch origin (rank-nbatch+ndim
carrier, peel_front_at<-ndim>) and write the kernel at the existing
center_offset — no per-voxel spatial decode needed since these write
one stencil per batch cell, not per voxel.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xcQBMEdA5eQtTsx2wB3AC
…nto teeny
matvec_all/diag_all are stencil-shaped like matvec_bending/diag_bending
(same peel + batch-cell caching + manual spatial decode), just with the
lame+bending combined kernel and its extra shears/div parameters.
kernel_all/kernel_lame are batch-only+center, mirroring the
kernel_absolute/membrane/bending pattern from the previous commit
(peel_front_at<-ndim> over batch cells, write at center_offset).
matvec_lame/diag_lame are intentionally left untouched: they aren't in
cpu-lib's reg_flow.cpp dispatch table (only relax_lame_/kernel_lame
are wired), so they're out of scope for this port.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xcQBMEdA5eQtTsx2wB3AC
First relax port in the project (reg_field's relax sweeps are still
broken dead code, per CLAUDE.md). Keeps the Gauss-Seidel / patch-
coloring algorithm byte-for-byte (same patch1/matvec_membrane<isub>/
diag_membrane<set>/PosDef::relax_ calls, same n < 2*niter sweep count),
but replaces the index2offset_v2/index2offset per-voxel decode with a
peel: sol/hes/grd are wrapped once as rank-(nbatch+ndim) anyrank
carriers (no trailing channel needed -- only the batch-cell base
pointer matters), peeled per batch cell with the same re-peel-on-
batch-change caching used by the matvec/diag stencils, then the
spatial offset is folded by hand from the cached cell pointer.
Iteration order over the flat index range differs from the original
Fortran-layout index2offset_v2 decode (batch cells now vary slowly,
matching the stencil convention, instead of batch dim 0 varying
fastest), but this doesn't affect the result: patch coloring makes
same-color voxels within one sweep mutually independent, so every
voxel's Gauss-Seidel update is a pure function of data written in
prior sweeps, not of loop order. checks: 830, failures: 0 unchanged
across clang++, g++, and g++ -fsanitize=address,undefined.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xcQBMEdA5eQtTsx2wB3AC
…eeny
Same peel-based port as relax_membrane_ (previous commit), applied to
the other three Gauss-Seidel / patch-coloring relax sweeps now wired
in cpu-lib's dispatch table: relax_bending_ (patch3, kernelsize_bending,
matvec_bending<isub>/diag_bending<set>), relax_lame_ (patch2,
kernelsize_lame, matvec_lame<isub>/diag_lame<set>), and relax_all_
(patch3, kernelsize_all, matvec_all<isub>/diag_all<set>, the combined
bending+lame kernel with its extra shears/div parameters). The
Gauss-Seidel math, sweep counts (pow<ndim>(2|3)*niter), and
PosDef::relax_ call are untouched -- only the index2offset_v2 per-voxel
decode is replaced by the same batch-cell peel + cache used by
relax_membrane_.
Verified against the CPU library's reg_flow test suite (residual and
self-adjointness checks, not just compile-and-run) on clang++, g++,
and g++ -fsanitize=address,undefined -O1: checks: 854, failures: 0,
matching the current fastfields-kernels-pinned baseline exactly (the
shared kernels checkout picked up an unrelated upstream diag_bending
sign fix mid-session, which is why the true current baseline reads 854
rather than the 830 quoted before that fix landed -- confirmed by
building the untouched, pre-this-branch reg_flow.h against the same
kernels checkout and getting the identical 854/0).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xcQBMEdA5eQtTsx2wB3AC
@balbastyClaude

Copy link
Copy Markdown
CollaboratorAuthor

Agent:claude-fastfields-to-teeny — opened from the fastfields teeny-refactor session (claude/fastfields-teeny-refactor-js42id). Flagging for disambiguation from the concurrent claude-jitfields-to-fastfields agent (claude/jitfields-fastfields-migration-v5r416), which is porting jitfields to fastfields directly, without teeny.


Generated by Claude Code

@balbasty
balbasty merged commit ac21632 into claude/fastfields-teeny-refactor-js42idAug 1, 2026
1 check failed
@balbasty
balbasty deleted the claude/reg-flow-lame-all-relax branch August 1, 2026 08:17
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@balbasty@claude