Skip to content

refactor(csp-batch): the slab descriptor and the mass, L_bol and weights block behind the SSP source (step 2, second slice) - #132

Merged
elijahmathews merged 1 commit into
feat/hotpath-02-ssp-sourcefrom
feat/hotpath-02b-ssp-source-blocks
Nov 19, 2026
Merged

elijahmathews merged 1 commit into
feat/hotpath-02-ssp-sourcefrom
feat/hotpath-02b-ssp-source-blocks

Conversation

@elijahmathews

Copy link
Copy Markdown
Owner

Stack: the unification plan (doc/HOT_PATHS_PLAN.md), step 2 of 5, second slice, after #131. Merge order: ..., #130, #131, this.

What changes

Two more pieces of the driver that were steered by the SSP-source flags move behind the source of #131:

  • ssp_source_describe: the per-model slab descriptor of the resident basis or the operators (zlo, zhi, dz from the model's logzsol with a basis per metallicity, and with the [alpha/Fe] planes of the context's stack the plane stride nzs, da and the slabs of the lower plane), and the refusal (status 2) of a model whose horizontal-branch modification is not in the operators of its metallicity.
  • ssp_source_scalars: the mass, L_bol and weights loops of the three kinds of source (weights over metallicities, the operators' own surviving mass and L_bol, the resident basis blended or its first plane), host and device, with the weights cast to kernel precision (the body of the loops is model_sums / model_sums_zw of refactor(csp-batch): one body for the mass, L_bol and weight loops (hot paths 7) #125).

The driver calls them in place of the blocks (about 90 lines out of compute_csp_batch); the routines hold what they replace, so the file is about 95 lines longer with the type and the routines of both slices (7060 lines against 6965), not shorter: this slice is about the structure (the driver no longer forms the descriptor or runs the loops of a source), and the line count falls only when the remaining flag-steered code goes behind the source as well (the nebular calls, the backward pass: step 4). doc/HOT_PATHS_PLAN.md gets the status.

Verification

  • 45 forward dumps of the free-parameter matrix, host FP64 (N = 1000) before and after: tools/compare_forward_dump.py, 0 differ bit for bit.
  • 45 forward dumps on the R9700 (FP32 kernels, ROCm container, both trees rebuilt from scratch, the compile logs have csp_batch.f90): 0 differ bit for bit. This slice moved device launch code (the mass and L_bol kernels) into a routine, so the device dumps are the check of it.
  • Host FP64 and FP32: unit suite (45), test_csp_batch, test_batch_equivalence, test_csp_batch_grad green. R9700 device tests (ssp_operator, csp_batch, csp_batch_grad, batch_equivalence, c_batch_grad, physics_oracles) pass. nvfortran 26.1 (NVHPC container): compiles for the A100; not run (no NVIDIA GPU): this PR moves device launches, so it joins the list for the ICDS session.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5

…hts block behind the SSP source (unification plan, step 2, second slice)

ssp_source_describe forms the per-model slabs of the resident basis or operators (zlo, zhi, dz, da, nzs, and the refusal of a horizontal-branch modification not in the operators); ssp_source_scalars holds the mass, L_bol and weights loops of the three kinds of source, host and device. The driver calls them. Bit-identical (45 forward dumps, host).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5
@elijahmathews
elijahmathews added this pull request to stack #114 November 19, 2026 00:14
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.43478% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.01%. Comparing base (8976899) to head (73b549f).

Files with missing lines Patch % Lines
src/physics/opensps_csp_batch.f90 80.43% 4 Missing and 5 partials ⚠️

❌ Your patch check has failed because the patch coverage (80.43%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@                      Coverage Diff                       @@
##           feat/hotpath-02-ssp-source     #132      +/-   ##
==============================================================
- Coverage                       75.02%   75.01%   -0.02%     
==============================================================
  Files                              51       51              
  Lines                           14429    14446      +17     
  Branches                         6066     6072       +6     
==============================================================
+ Hits                            10826    10836      +10     
- Misses                           1475     1479       +4     
- Partials                         2128     2131       +3     

☔ 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.

@elijahmathews
elijahmathews marked this pull request as ready for review November 19, 2026 16:55
@elijahmathews
elijahmathews merged commit cb6ad71 into main Nov 19, 2026
28 of 30 checks passed
@elijahmathews
elijahmathews deleted the feat/hotpath-02b-ssp-source-blocks branch November 19, 2026 17:49
elijahmathews added a commit that referenced this pull request Nov 19, 2026
…e step 5 analysis (#133)

Stack: the unification plan (`doc/HOT_PATHS_PLAN.md`), step 3 of 5,
after #132. Merge order: ..., #131, #132, this.

## What changes

- `slab_blend_wp` / `slab_blend_kp`: one definition of the blend that
was written out at every site: `(1 - da) ((1 - dz) a + dz b) + da ((1 -
dz) a' + dz b')` with the [alpha/Fe] planes, `(1 - dz) a + dz b` with a
basis per metallicity, `a` with a single basis. Used for the nebular
ionizing-photon sums (the table `q0`, the continuum rows of the basis,
forward and in the backward pass) and in `model_sums` for the
interpolated mass and L_bol. They are `declare target` (in the module's
list) and `pure`.
- Only the sites where the cascade was an exact match (five, and the two
blends of `model_sums`): the derivative forms and the sites with another
structure stay as they are, so the saving is a few lines; what changes
is that there is one definition of the blend.
- `doc/HOT_PATHS_PLAN.md`: the status of step 3, and the analysis of
step 5 (the remaining conditionals are mostly the OpenMP device/host
directive switch, which no template removes). Also trims three comment
lines of #132 to 132 columns.

## Verification

- 45 forward dumps of the free-parameter matrix, host FP64 (N = 1000): 0
differ bit for bit against the tip of #132. 45 on the R9700 (FP32
kernels, ROCm container, both trees rebuilt from scratch,
`csp_batch.f90` in both compile logs): 0 differ bit for bit (the helpers
run in device kernels).
- Host FP64 and FP32: unit suite (45), `test_csp_batch`,
`test_batch_equivalence`, `test_csp_batch_grad` green. R9700 device
tests pass. nvfortran 26.1: compiles for the A100; not run (no NVIDIA
GPU); this PR puts the helpers in device kernels, so it joins the list
for the ICDS session.

## Where the plan stands

Steps 0 - 3 are done; step 5 is analysed and stops at the age sums; step
4 (splitting the driver into stages) is the open one and is not started.

🤖 Generated with [Claude Code](https://claude.ai/code)

https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
elijahmathews added a commit that referenced this pull request Nov 19, 2026
…step 4, first part) (#134)

Stack: the unification plan (`doc/HOT_PATHS_PLAN.md`), step 4 of 5,
first part, after #133. Merge order: ..., #132, #133, this.

## What changes

`compute_csp_batch` was 1037 lines. Four blocks of it were host-only
code with a clear input and output; they are routines now (the driver is
867 lines):

- `batch_check_shapes`: the sizes of the optional arguments against the
batch (status 3, or 2 for redshifted colours without `zred_mags`), and
the modes the optional arguments make (`parts`, `grad`, `given_w`).
- `batch_check_models`: the values of the models this path does not
support (status 2): a non-positive age without given weights, an invalid
`uvb`/`wgp`, an SFH whose gradient is not covered, isochrone
modifications or IMF limits that differ from the SSPs', several
metallicities without per-metallicity operators; and `zvar`.
- `batch_imf_vectors`: the IMF parameter vector of every model and the
operators' work arrays (with the per-model limits of #126).
- `batch_chain_derivatives`: the chain-rule factors of the reverse pass.

No device code moves. The device-steered stages (SFH weights, the
nebular and attenuation calls, smoothing, photometry) are still inline:
splitting them needs a workspace type for the packed arrays and the
device mapping rules checked on the R9700; that is not in this PR.
`doc/HOT_PATHS_PLAN.md` gets the status and the finding below.

## A finding that changed the check

At the default flags, forward dumps of this change differ from the
parent's for about 7% of the models of a batch, by 1e-16 relative (up to
7e-16 in a pixel; gradient dumps 1e-14 of their scale), though the diff
of the driver is the call and the removed checks. Bisecting: the
shape-check extraction alone causes it; an empty call in its place does
not; `-O1` or `-fno-tree-vectorize` removes it; the library calls
`_ZGVbN2v_exp`, `_log`, `_log10` and `_pow` (glibc's libmvec: `nm -D
libopensps.so | grep _ZGV`). GCC vectorizes loops that call `exp`, `log`
and `pow` with the vector routines, which differ from the scalar libm by
about an ulp, and which loops vectorize depends on the code around them.
It is not uninitialized memory (heap poisoning with `MALLOC_PERTURB_`,
locals set to NaN: no change), not inlining (`-fno-inline`), not the
thread count, not FMA (the build has no `-march`). So CPU numbers of the
library depend on the layout of the code at the 1e-16 level, which
matters for how refactors are checked: the plan now says to compare CPU
builds with `-fno-tree-vectorize`. The device kernels have no libmvec;
their dumps stayed bit-identical through every step.

## Verification

- With `-fno-tree-vectorize` (the parent and this tree built alike,
FP64, OpenMP host threads; N = 300, the resident basis, metallicity,
[alpha/Fe], the IMF per model with the modification factors, a
closed-form field): forward dumps 6 of 6 and gradient dumps 6 of 6 bit
for bit.
- At the default flags: 45 forward dumps agree to 1e-14 (observed
7e-16); 45 gradient dumps to 1e-14 of their scale.
- Host FP64 and FP32: unit suite (45, including the refusal cases that
these checks implement), `test_csp_batch`, `test_batch_equivalence`,
`test_csp_batch_grad` green. R9700 device tests pass. nvfortran 26.1:
compiles for the A100.

🤖 Generated with [Claude Code](https://claude.ai/code)

https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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