Repository navigation
refactor(csp-batch): the per-model host indices and the SFH-weights stage as routines (step 4, second part) - #135
Merged
elijahmathews merged 2 commits intoNov 19, 2026
Conversation
…tage as routines (unification plan, step 4, second part) batch_model_indices (birth-cloud age, star formation rate, dust emission and AGN indices of every model) and batch_sfh_weights (the weights of every model, host and device) leave compute_csp_batch (867 to 809 lines). Bit-identical: CPU with -fno-tree-vectorize (forward and gradient dumps), and 45 forward dumps on the R9700. Conditionals 961 to 962 (the pbuf declaration of the moved stage). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) 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-04-driver-stages #135 +/- ##
=================================================================
- Coverage 74.98% 74.95% -0.04%
=================================================================
Files 51 51
Lines 14461 14472 +11
Branches 6077 6084 +7
=================================================================
+ Hits 10844 10847 +3
- Misses 1478 1482 +4
- Partials 2139 2143 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ed by it batch_sfh_weights declared pbuf(n_mod) before n_mod was typed: a GNU extension in gfortran's default mode, an error with -std=f2008 and in LLVM flang (the two CI jobs that failed on this branch). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5
elijahmathews
marked this pull request as ready for review
November 19, 2026 16:55
elijahmathews
added a commit
that referenced
this pull request
Nov 19, 2026
…n programmers (#136) Stack: after #135. Merge order: ..., #134, #135, this. Documentation only. `doc/HOT_PATH_TOUR.md`: a map of the hot path for someone who knows stellar populations and not necessarily Fortran. The route of a call from the C API to `compute_csp_batch`; the steps of the routine in order (checks, per-model setup, SFH weights, age sums, nebular emission, dust attenuation, dust emission, IGM and AGN, smoothing, magnitudes, the reverse pass) with the routine and the file of each; the three sources of the SSPs and the K slabs; the age-sum kernel as a first thing to read; a glossary of the Fortran and OpenMP constructs the code uses (`real(WP)`/`real(KP)`, `intent`, assumed and explicit shape, pointers, `!$omp` directives, the `#if` switch, `.inc` templates); and where to look when a batch is refused, slow, or differs between builds. Names are used instead of line numbers, so the tour does not go stale as the code moves; every routine named in it was checked to exist. 🤖 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
…nes, and a stage index in the driver (step 4, third part) (#137) Stack: the unification plan (`doc/HOT_PATHS_PLAN.md`), step 4 of 5, third part, after #136 (the tour). Merge order: ..., #135, #136, this. ## What changes - `batch_mass_cotangent`: the mass output's cotangent in the reverse pass (the resident basis): `wbl(k, m)` gains `mass_bar(m)` times the model's blend of the basis' surviving masses, and with per-model metallicity and gradients the `logzsol` and `afe` rows gain the mass's derivative with respect to `dz` and `da`. - `batch_sfh_gradients`: the SFH parameters' gradients through the weights' tangents (`sfh_weights_tangent`, FP64 on the host, one model per thread). - A stage index at the top of `compute_csp_batch`: a comment that lists the stages (0 checks and plan, 1 setup, 2 SFH weights, 3 age sums, 4 nebular, 5 attenuation, 6 dust emission / IGM / AGN, 7 smoothing, 8 magnitudes, 9 the reverse pass) with the routine of each, so that reading the driver gives the map that `doc/HOT_PATH_TOUR.md` explains in plain terms. The code of the driver is 759 lines (1037 at the start of step 4), 775 with the index. The plan (`doc/HOT_PATHS_PLAN.md`) gets the status. ## Verification - CPU, both trees built with `-fno-tree-vectorize` (see #134): forward dumps 6 of 6 and gradient dumps 6 of 6 bit for bit (the resident basis, metallicity, [alpha/Fe], the IMF per model with the modification factors, a closed-form field). The gradient dumps exercise both new routines (the benchmark gives `mass_bar` and the SFH parameters' rows). - R9700 (both trees rebuilt from scratch, `csp_batch.f90` in both compile logs): 45 forward dumps, 0 differ bit for bit. - Host FP64 and FP32 suites, the six R9700 device tests and the nvfortran 26.1 compile pass. - The stage index is a comment (checked: it builds). 🤖 Generated with [Claude Code](https://claude.ai/code) https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5 --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: the unification plan (
doc/HOT_PATHS_PLAN.md), step 4 of 5, second part, after #134. Merge order: ..., #133, #134, this.What changes
Two more stages leave
compute_csp_batch(867 to 809 lines):batch_model_indices: the host loop that forms every model's setup: the age index of its birth-cloud time (it_tesc), its star formation rate at its age (sfr, if asked), whether it has dust emission and the interpolation indices and weights of the dust emission grid, and of the AGN template.batch_sfh_weights: the SFH-weights stage, which is device code: the weights of every model over the ages, copied from the given matrix on the host for few models, copied on the device, or computed on the device withsfh_weights_core(one thread per model). The comments about why the host form is a plain loop (LLVM's libomp crash at one thread, GPU build: compute_csp_batch segfaults on the host with OMP_NUM_THREADS=1 for batches below HOST_SFH_MAX #87) travel with it.The stage routines take what they read as explicit-shape dummies (the same arrangement as
ssp_source_scalars), and the packed parameter array as the other stage routines do (pbuf, the raw words with flang). Conditionals 961 to 962: the#ifthat selects the declaration ofpbufin the new routine; the baseline is raised by one in this change.Verification
-fno-tree-vectorize(see the finding of refactor(csp-batch): the host-only blocks of the driver as routines (step 4, first part) #134 on libmvec): forward dumps 6 of 6 and gradient dumps 6 of 6 bit for bit (the resident basis, metallicity, [alpha/Fe], the IMF per model with the modification factors, a closed-form field).csp_batch.f90in both compile logs): 45 forward dumps of the free-parameter matrix, 0 differ bit for bit. This part moves a device stage, so these are the check of it.Where step 4 stands
The nebular and attenuation calls, smoothing, photometry and the reverse pass (about 180 lines, the 30 arguments of
batch_backward) are still inline. They share many arrays (the packedipk,rpk,lpk,routand the work arrays), so cutting them needs a workspace type and the device mapping rules checked on the R9700 after each cut; I would do that as its own PRs.🤖 Generated with Claude Code
https://claude.ai/code/session_01MXDRCs7ATQiqhT6RLPLXR5