trnsolver 0.18.0__tar.gz → 0.20.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trnsolver-0.18.0 → trnsolver-0.20.0}/CHANGELOG.md +104 -1
- {trnsolver-0.18.0/trnsolver.egg-info → trnsolver-0.20.0}/PKG-INFO +11 -1
- {trnsolver-0.18.0 → trnsolver-0.20.0}/README.md +8 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/api/eigen.md +1 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/benchmarks.md +62 -0
- trnsolver-0.20.0/examples/scf_df_rhf.py +987 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/examples/scf_eigen.py +12 -12
- {trnsolver-0.18.0 → trnsolver-0.20.0}/pyproject.toml +4 -1
- trnsolver-0.20.0/scripts/bench_jacobi_multicore.py +232 -0
- trnsolver-0.20.0/scripts/bench_scf.py +310 -0
- trnsolver-0.20.0/scripts/probe_large_n_split.py +114 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_eigh_cutover.py +49 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_jacobi.py +253 -0
- trnsolver-0.20.0/tests/test_scf_df_rhf.py +207 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/__init__.py +1 -1
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/eigen.py +134 -6
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/nki/dispatch.py +14 -1
- trnsolver-0.20.0/trnsolver/nki/eigh_pool.py +407 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/nki/jacobi.py +120 -19
- {trnsolver-0.18.0 → trnsolver-0.20.0/trnsolver.egg-info}/PKG-INFO +11 -1
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver.egg-info/SOURCES.txt +6 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver.egg-info/requires.txt +2 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/pull_request_template.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/workflows/ci.yml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/workflows/neuron.yml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/workflows/notify-umbrella.yml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.github/workflows/publish.yml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.gitignore +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/.pre-commit-config.yaml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/CLAUDE.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/CODE_OF_CONDUCT.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/CONTRIBUTING.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/LICENSE +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/benchmarks/bench_cuda.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/benchmarks/bench_solver.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/benchmarks/conftest.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/api/factor.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/api/iterative.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/api/nki.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/architecture.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/aws_setup.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/developing_kernels.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/index.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/installation.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/docs/quickstart.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/infra/terraform/README.md +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/infra/terraform/gpu.tf +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/infra/terraform/main.tf +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/mkdocs.yml +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/scripts/bench_jacobi.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/scripts/run_cuda_tests.sh +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/scripts/run_neuron_tests.sh +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/scripts/run_simulator_tests.sh +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/scripts/stop_neuron_ci.sh +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/setup.cfg +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/conftest.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_compile.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_dtype.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_eigen.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_eigh_neuron.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_factor.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_iterative.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_native_dispatch.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_nki_compile.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_nki_native.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/tests/test_nki_sim.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/_jacobi.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/factor.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/iterative.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/nki/__init__.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver/nki/_native.py +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver.egg-info/dependency_links.txt +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/trnsolver.egg-info/top_level.txt +0 -0
- {trnsolver-0.18.0 → trnsolver-0.20.0}/uv.lock +0 -0
|
@@ -7,11 +7,114 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.20.0] — 2026-10-31
|
|
11
|
+
|
|
12
|
+
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
13
|
+
|
|
14
|
+
Headline: opt-in per-core worker-process pool for batched Jacobi `eigh` (`TRNSOLVER_EIGH_POOL=proc`): 3.65× scaling on 4 cores, 1.75–2.0× faster than 8-thread CPU at n=64–128, B≥1024 (#57); host tensors now take the host-LAPACK cutover on TorchNeuron hosts (an n=64 call was 265 s, now 0.15 ms), and a DF-RHF SCF example built from the suite (#58).
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **DF-RHF SCF end to end on the trnsci libraries (#15).**
|
|
19
|
+
`examples/scf_df_rhf.py` runs closed-shell density-fitted Hartree-Fock with
|
|
20
|
+
the J/K build on packed three-centre integrals (`trnblas.gemv`/`syrk`,
|
|
21
|
+
`trntensor.einsum`/`unpack_tril`), DIIS, and `trnsolver.eigh` (or
|
|
22
|
+
`eigh_generalized`) per iteration, on the host or a NeuronCore. Systems: a
|
|
23
|
+
synthetic s-Gaussian H2 lattice with closed-form integrals (no
|
|
24
|
+
dependencies), or PySCF integrals for real molecules (water, benzene,
|
|
25
|
+
C_kH_2k+2). `scripts/bench_scf.py` times each stage per iteration, CPU
|
|
26
|
+
against device against float64, and one `eigh` at SCF sizes
|
|
27
|
+
(`--eigh-only`). The float64 loop matches PySCF's DF-RHF energy to
|
|
28
|
+
1e-11 Eh. On Trn2 (one logical core, host pinned to 2 CPUs), time to
|
|
29
|
+
convergence is 9.5x (n_ao = 250), 38x (490) and 51x / 78x (970, packed /
|
|
30
|
+
resident unpacked integrals) faster than the same loop on those 2 CPUs;
|
|
31
|
+
below n_ao ~ 128 the device is slower. `eigh` (host LAPACK through aten)
|
|
32
|
+
is the largest device stage up to n_ao = 250 (32-39%), J/K from 490 up
|
|
33
|
+
(54%, then 72-83% at 970). Options: J/K split over NeuronCores
|
|
34
|
+
(`neuron-jk<k>` modes; 1.5x on the J/K stage with 4 cores), resident
|
|
35
|
+
unpacked integrals (`--jk-square`), and a GEMM-only purification solver
|
|
36
|
+
(`--solver purify`; slower than the host `eigh` at every measured size,
|
|
37
|
+
kept as the measured experiment).
|
|
38
|
+
Tests: `tests/test_scf_df_rhf.py` (CPU).
|
|
39
|
+
- **Process-pool multi-core Jacobi `eigh`, opt-in (#29).**
|
|
40
|
+
`TRNSOLVER_EIGH_POOL=proc` (with `TRNSOLVER_EIGH_CORES=<k>|auto`) solves a
|
|
41
|
+
host batch on persistent worker processes, one per logical NeuronCore
|
|
42
|
+
(`TRNSOLVER_EIGH_POOL_CORES`, else `NEURON_RT_VISIBLE_CORES`), instead of
|
|
43
|
+
one host thread per core. Inputs go through per-worker shared-memory
|
|
44
|
+
segments; workers write results straight into a shared output buffer
|
|
45
|
+
that the returned tensors are views of, reused once the caller drops
|
|
46
|
+
them. Workers start on the first call and stay up
|
|
47
|
+
(`trnsolver.nki.eigh_pool.shutdown()` frees the cores); a failed pool
|
|
48
|
+
shuts down and `eigh` falls back to one core. The calling process must
|
|
49
|
+
not use the pool's cores itself, so device-resident input keeps the
|
|
50
|
+
thread split. Trn2, n = 128, B = 4096, 8 host CPUs: 1 / 2 / 4 cores
|
|
51
|
+
1182 / 607 / 324 ms (thread split 1227 / 763 / 531 ms; 8-thread
|
|
52
|
+
batch-parallel LAPACK 655 ms). Default (unset) unchanged.
|
|
53
|
+
- `TRNSOLVER_JACOBI_SWEEPS_PER_LAUNCH=<k>`: the scalar kernel (padded
|
|
54
|
+
n <= 32) runs its first sweeps k per launch (5-14% faster on Trn2 at
|
|
55
|
+
n = 32). Default 1, unchanged.
|
|
56
|
+
- `scripts/bench_jacobi_multicore.py --modes pool`, and
|
|
57
|
+
`scripts/probe_large_n_split.py`, the step-cost probe behind the
|
|
58
|
+
single-matrix multi-core verdict in #29.
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- **`eigh` of a host tensor on a TorchNeuron host no longer runs the NKI
|
|
63
|
+
path (#15).** With the default backend, a CPU tensor skipped the #42
|
|
64
|
+
cutover and drove the launch-bound NKI tridiagonalization through the
|
|
65
|
+
device: 265 s for one n = 64 call on Trn2 (first call, with compiles),
|
|
66
|
+
against 0.15 ms for LAPACK. Host inputs on the native path now take the
|
|
67
|
+
cutover, i.e. host LAPACK. `TRNSOLVER_EIGH_NKI_MIN_N=0`,
|
|
68
|
+
`TRNSOLVER_REQUIRE_NKI=1` and the simulator keep the kernel path.
|
|
69
|
+
- `examples/scf_eigen.py`: the closed-shell density is `P = 2 C_occ C_occ^T`
|
|
70
|
+
(was `C_occ C_occ^T`, inconsistent with `F = H + J - K/2`), the energy is
|
|
71
|
+
evaluated at the density the Fock matrix was built from, and the default
|
|
72
|
+
tolerance is 1e-5 (1e-8 is below what fp32 resolves; the demo never
|
|
73
|
+
converged).
|
|
74
|
+
|
|
75
|
+
## [0.19.0] — 2026-10-31
|
|
76
|
+
|
|
77
|
+
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
78
|
+
|
|
79
|
+
Headline: opt-in batched Jacobi `eigh` across logical NeuronCores (`TRNSOLVER_EIGH_CORES`): n=128, B=1024 drops from 310 to 152 ms on four cores (#54); corrects the v0.18.0 CPU-baseline headline.
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- **Batched Jacobi `eigh` across NeuronCores, opt-in (#48).**
|
|
84
|
+
`TRNSOLVER_EIGH_CORES=<k>|auto` splits a `method="jacobi"` batch (and the
|
|
85
|
+
`method="auto"` Jacobi region) into whole-tile chunks, one per logical
|
|
86
|
+
NeuronCore, each solved by its own host thread. `auto` uses every visible
|
|
87
|
+
core while each keeps at least 512 / 256 / 128 matrices (padded n = 32 /
|
|
88
|
+
64 / 128). The default (unset or 1) is the single-core path, unchanged.
|
|
89
|
+
Chunks for other cores go through the host: direct core-to-core copies
|
|
90
|
+
gave no speed-up. The first call for a split shape runs the chunks in
|
|
91
|
+
turn, because NKI tracing (also inside aten ops) is not thread-safe; if
|
|
92
|
+
the split fails, `eigh` falls back to one core. Trn2, n = 128, B = 1024,
|
|
93
|
+
device input: 1 / 2 / 4 cores 309 / 202 / 127 ms (8 host CPUs);
|
|
94
|
+
batch-parallel CPU LAPACK on 8 threads 159 ms.
|
|
95
|
+
- `scripts/bench_jacobi_multicore.py`: the 1 / 2 / 4-core, process-per-core
|
|
96
|
+
and CPU (batched, and batch-parallel threads) measurements.
|
|
97
|
+
|
|
98
|
+
### Corrected
|
|
99
|
+
|
|
100
|
+
- **The v0.18.0 headline overstated the CPU comparison.** Its "1.5–2.2×
|
|
101
|
+
faster than CPU LAPACK" compared against batched `torch.linalg.eigh`,
|
|
102
|
+
which barely uses extra threads at these sizes. Splitting the batch
|
|
103
|
+
across the same 2 threads is 1.6–5.8× faster. Against that baseline the
|
|
104
|
+
single-core kernel at n = 128, B = 1024 is 310 vs 352 ms (1.13×), not
|
|
105
|
+
321 vs 668 ms (#54).
|
|
106
|
+
|
|
107
|
+
### Fixed
|
|
108
|
+
|
|
109
|
+
- Native launches run on the input's NeuronCore (`neuron:k`) instead of
|
|
110
|
+
always on the current device, and the Jacobi driver keeps its work on a
|
|
111
|
+
NeuronCore-resident input's core.
|
|
112
|
+
|
|
10
113
|
## [0.18.0] — 2026-10-30
|
|
11
114
|
|
|
12
115
|
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron; LNC=1 and LNC=2) — see trnsci/trnsci#35.
|
|
13
116
|
|
|
14
|
-
Headline performance: block Jacobi kernel for 33 ≤ n ≤ 128 and a measured `eigh(method="auto")` region; inside it batched `eigh` on Trn2 is 1.5–2.2× faster than CPU LAPACK, e.g. 321 vs 668 ms at n=128, B=1024 (#52).
|
|
117
|
+
Headline performance: block Jacobi kernel for 33 ≤ n ≤ 128 and a measured `eigh(method="auto")` region; inside it batched `eigh` on Trn2 is 1.5–2.2× faster than CPU LAPACK, e.g. 321 vs 668 ms at n=128, B=1024 (#52). *Corrected in the next release: that baseline is batched `torch.linalg.eigh`; against the batch split over the same threads the gain is about 1.13× (#54).*
|
|
15
118
|
|
|
16
119
|
### Added
|
|
17
120
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trnsolver
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.20.0
|
|
4
4
|
Summary: Linear solvers and eigendecomposition for AWS Trainium via NKI
|
|
5
5
|
Author-email: Scott Friedman <scttfrdmn@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -32,6 +32,8 @@ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
|
|
|
32
32
|
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
33
33
|
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
34
34
|
Requires-Dist: scipy>=1.11; extra == "dev"
|
|
35
|
+
Requires-Dist: trnblas>=0.9; extra == "dev"
|
|
36
|
+
Requires-Dist: trntensor>=0.20; extra == "dev"
|
|
35
37
|
Dynamic: license-file
|
|
36
38
|
|
|
37
39
|
# trnsolver
|
|
@@ -130,6 +132,14 @@ python examples/scf_eigen.py --nbasis 50 --nocc 10
|
|
|
130
132
|
|
|
131
133
|
Demonstrates the self-consistent-field iteration: build Fock matrix → solve generalized eigenproblem `FC = SCε` → build density → check convergence. This is the headline use case for quantum-chemistry workflows, feeding into DF-MP2 via `trnblas`.
|
|
132
134
|
|
|
135
|
+
`examples/scf_df_rhf.py` is the end-to-end version: density-fitted restricted Hartree–Fock with the J/K build on packed three-centre integrals (`trnblas`, `trntensor`), DIIS, and `trnsolver.eigh` every iteration, on the host or a NeuronCore. `scripts/bench_scf.py` times each stage against the CPU and float64 (PySCF integrals for real molecules if PySCF is installed; a synthetic s-Gaussian H2 lattice otherwise):
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
python examples/scf_df_rhf.py --system h2-lattice:16
|
|
139
|
+
python scripts/bench_scf.py --systems h2-lattice:16 --modes cpu,cpu64
|
|
140
|
+
python scripts/bench_scf.py --systems pyscf:alkane20 --modes cpu,neuron,neuron-nosync # on Trn2
|
|
141
|
+
```
|
|
142
|
+
|
|
133
143
|
## Status
|
|
134
144
|
|
|
135
145
|
**v0.18.0** — Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron; LNC=1 and LNC=2; trnsci/trnsci#35). `eigh(A, method="jacobi")` gains a block Jacobi NKI kernel for 33 ≤ n ≤ 128 (padded sizes 64 and 128), and `eigh(method="auto")` now uses the Jacobi kernel for FP32 batches on the `neuron` device inside a measured (n, B) region, where it beats the aten cutover (#52). Inside that region batched `eigh` is 1.5–2.2× faster than CPU LAPACK; at n=128, B=1024 it takes 321 ms against 668 ms. Outside the region the default cutover is unchanged.
|
|
@@ -94,6 +94,14 @@ python examples/scf_eigen.py --nbasis 50 --nocc 10
|
|
|
94
94
|
|
|
95
95
|
Demonstrates the self-consistent-field iteration: build Fock matrix → solve generalized eigenproblem `FC = SCε` → build density → check convergence. This is the headline use case for quantum-chemistry workflows, feeding into DF-MP2 via `trnblas`.
|
|
96
96
|
|
|
97
|
+
`examples/scf_df_rhf.py` is the end-to-end version: density-fitted restricted Hartree–Fock with the J/K build on packed three-centre integrals (`trnblas`, `trntensor`), DIIS, and `trnsolver.eigh` every iteration, on the host or a NeuronCore. `scripts/bench_scf.py` times each stage against the CPU and float64 (PySCF integrals for real molecules if PySCF is installed; a synthetic s-Gaussian H2 lattice otherwise):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python examples/scf_df_rhf.py --system h2-lattice:16
|
|
101
|
+
python scripts/bench_scf.py --systems h2-lattice:16 --modes cpu,cpu64
|
|
102
|
+
python scripts/bench_scf.py --systems pyscf:alkane20 --modes cpu,neuron,neuron-nosync # on Trn2
|
|
103
|
+
```
|
|
104
|
+
|
|
97
105
|
## Status
|
|
98
106
|
|
|
99
107
|
**v0.18.0** — Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron; LNC=1 and LNC=2; trnsci/trnsci#35). `eigh(A, method="jacobi")` gains a block Jacobi NKI kernel for 33 ≤ n ≤ 128 (padded sizes 64 and 128), and `eigh(method="auto")` now uses the Jacobi kernel for FP32 batches on the `neuron` device inside a measured (n, B) region, where it beats the aten cutover (#52). Inside that region batched `eigh` is 1.5–2.2× faster than CPU LAPACK; at n=128, B=1024 it takes 321 ms against 668 ms. Outside the region the default cutover is unchanged.
|
|
@@ -8,6 +8,7 @@ Symmetric eigendecomposition `A = V Λ Vᵀ` for real symmetric `A`. Returns `(e
|
|
|
8
8
|
|
|
9
9
|
- `auto`: on the native `neuron` device, n < `TRNSOLVER_EIGH_NKI_MIN_N` (default 512) uses `torch.linalg.eigh`; otherwise the NKI path (Householder tridiagonalization, host QR iteration). Off-device, `torch.linalg.eigh`.
|
|
10
10
|
- `jacobi` (#48): batched Jacobi for `(n, n)` or `(..., n, n)` input. On the native `neuron` device (FP32, n ≤ 128) it runs the SBUF-resident one-sided Jacobi kernel: one launch per sweep, each holding up to 128 tiles of 128 / n matrices (512 at n = 32) in SBUF. Elsewhere it runs a torch implementation (two-sided Jacobi as batched matmuls). Uses the lower triangle, like `torch.linalg.eigh`. For 33 ≤ n ≤ 128 the kernel is block Jacobi: per step the Tensor Engine forms each matrix's Gram matrix and applies one orthogonal matmul per block pair, and the Vector Engine only rotates the 16 × 16 pair Gram blocks.
|
|
11
|
+
- Multi-core (opt-in): `TRNSOLVER_EIGH_CORES=<k>|auto` splits a Jacobi batch over logical NeuronCores, one host thread per core (#48). With `TRNSOLVER_EIGH_POOL=proc` as well, a **host** batch goes to persistent worker processes instead, one per core (`TRNSOLVER_EIGH_POOL_CORES`, else `NEURON_RT_VISIBLE_CORES`), through shared memory (#29). The pool is the faster split (Trn2, n = 128, B = 4096, 8 host CPUs: 324 ms on 4 cores against 531 ms with threads and 655 ms for 8-thread batch-parallel LAPACK), but a NeuronCore belongs to one process: the calling process must not use those cores itself, so device-resident input keeps the thread split. Workers start on the first call (about 10 s, plus any kernel compile) and stay up; call `trnsolver.nki.eigh_pool.shutdown()` to free the cores. Scripts that use the pool need an `if __name__ == "__main__":` guard (the workers are spawned). `TRNSOLVER_JACOBI_SWEEPS_PER_LAUNCH=<k>` runs the scalar kernel's (n ≤ 32) first sweeps k per launch: 5–14% faster on one core (Trn2).
|
|
11
12
|
- `auto` also runs the Jacobi kernel for FP32 batches on the native `neuron` device inside a measured region (n ≤ 32 with B ≥ 512, 33 ≤ n ≤ 64 with B ≥ 256, 65 ≤ n ≤ 128 with B ≥ 1024, plus B ≥ 256 for n ≥ 96 and B ≥ 64 at n = 128), where it beats the aten cutover. `TRNSOLVER_EIGH_JACOBI_AUTO` overrides the region.
|
|
12
13
|
|
|
13
14
|
```python
|
|
@@ -78,6 +78,68 @@ Reproduce: `AWS_PROFILE=aws ./scripts/run_cuda_tests.sh g5`.
|
|
|
78
78
|
|
|
79
79
|
_Pending — classical Jacobi was architecturally mismatched to NKI (see [#9](https://github.com/trnsci/trnsolver/issues/9) post-mortem). Phase 1 redesign is iterating against the new NKI 0.3.0 CPU simulator (Neuron SDK 2.29, April 2026) with full-sweep Jacobi / Householder-QR / block-Jacobi candidates; hardware numbers will land once the redesigned kernel validates in simulation._
|
|
80
80
|
|
|
81
|
+
## DF-RHF SCF end to end (Trn2, #15)
|
|
82
|
+
|
|
83
|
+
`scripts/bench_scf.py` on trn2.3xlarge, SDK 2.33 native TorchNeuron, LNC=2,
|
|
84
|
+
one logical NeuronCore, host threads pinned to one physical core
|
|
85
|
+
(`OMP_NUM_THREADS=2 taskset -c 2,8`). PySCF cc-pVDZ / cc-pvdz-jkfit
|
|
86
|
+
integrals (`h2-lattice:16` is the synthetic s-Gaussian system). fp32 on
|
|
87
|
+
CPU and device; the reference is PySCF's float64 DF-RHF energy on the same
|
|
88
|
+
integrals, which the float64 loop (`cpu64`) reproduces to 1e-11 Eh. Warm
|
|
89
|
+
times; the first run of each shape pays a one-off compile (6-10 s at water,
|
|
90
|
+
up to 455 s at n_ao = 970). The CPU runs keep the unpacked integrals
|
|
91
|
+
resident (at n_ao = 970, `--k-cache-gb 24`); one logical core's 24 GB holds
|
|
92
|
+
them only without the packed copy (`--jk-square`).
|
|
93
|
+
|
|
94
|
+
| system | n_ao / naux / nocc | CPU fp32: iters, total | device: iters, total | speedup |
|
|
95
|
+
|---|---|---|---|---|
|
|
96
|
+
| water | 24 / 116 / 5 | 10, 5.3 ms | 10, 60.2 ms | 0.09x |
|
|
97
|
+
| benzene | 114 / 558 / 21 | 11, 113 ms | 10, 130 ms | 0.87x |
|
|
98
|
+
| h2-lattice:16 | 128 / 256 / 16 | 10, 93.0 ms | 8, 61.9 ms | 1.5x |
|
|
99
|
+
| C10H22 | 250 / 1206 / 41 | 16, 2.82 s | 16, 0.30 s | 9.5x |
|
|
100
|
+
| C20H42 | 490 / 2366 / 81 | 15, 28.0 s | 15, 0.74 s | 38x |
|
|
101
|
+
| C40H82 | 970 / 4686 / 161 | 22, 493 s | 22, 9.62 s (packed); 22, 6.36 s (`--jk-square`); 19, 4.06 s (`--jk-square`, J/K on 4 cores) | 51x; 78x; 121x |
|
|
102
|
+
|
|
103
|
+
Energy against the float64 reference: the fp32 total energy is off by
|
|
104
|
+
8e-6 to 6e-4 Eh on the device and up to 2e-2 Eh on the CPU (fp32
|
|
105
|
+
accumulation in the host BLAS J and K; at C10H22 with a laptop BLAS,
|
|
106
|
+
1.6e-3 Eh from J and 7e-4 Eh from K). Re-evaluating it in float64 at the
|
|
107
|
+
fp32 orbitals (`E(C)`) gives 2e-10 to 5e-7 Eh up to n_ao = 490 and 5e-8
|
|
108
|
+
to 1e-7 Eh at 970, so the fp32 loops converge to the right orbitals; a
|
|
109
|
+
final float64 energy evaluation recovers the energy.
|
|
110
|
+
|
|
111
|
+
Median per-iteration stage times on the device (ms):
|
|
112
|
+
|
|
113
|
+
| system | J/K | DIIS | eigh | other | largest |
|
|
114
|
+
|---|---|---|---|---|---|
|
|
115
|
+
| water | 1.49 | 2.01 | 2.18 | 1.17 | eigh (32%) |
|
|
116
|
+
| benzene | 3.84 | 3.22 | 5.48 | 3.05 | eigh (35%) |
|
|
117
|
+
| C10H22 | 7.93 | 3.11 | 8.94 | 3.18 | eigh (39%) |
|
|
118
|
+
| C20H42 | 27.7 | 5.02 | 16.3 | 1.86 | J/K (54%) |
|
|
119
|
+
| C40H82 (packed) | 361 | 6.82 | 65.6 | 3.95 | J/K (83%) |
|
|
120
|
+
| C40H82 (`--jk-square`) | 213 | 6.99 | 71.3 | 4.25 | J/K (72%) |
|
|
121
|
+
| C40H82 (`--jk-square`, J/K on 4 cores) | 139 | 6.81 | 63.4 | 4.25 | J/K (65%) |
|
|
122
|
+
|
|
123
|
+
On the CPU, J/K is 74-99% of every iteration from n_ao = 114 up.
|
|
124
|
+
|
|
125
|
+
J/K split over logical NeuronCores at C40H82 (whole chip, `neuron-jk<k>`
|
|
126
|
+
modes, one Python thread issuing to every core, inputs and partial
|
|
127
|
+
results staged through the host): per iteration 437 / 325 / 306 ms on
|
|
128
|
+
1 / 2 / 4 cores with packed integrals, 289 / 221 / 214 ms with
|
|
129
|
+
`--jk-square`; the J/K stage itself goes 213 -> 139 ms on 4 cores (1.5x).
|
|
130
|
+
Within one aux block of 532 at n_ao = 970, the gather that unpacks the
|
|
131
|
+
packed triangle takes 28 ms, the half-transform GEMM 5.7 ms, the permute
|
|
132
|
+
4.4 ms and the SYRK 5.8 ms; the two GEMMs run at about 28 TFLOP/s.
|
|
133
|
+
|
|
134
|
+
`eigh` here is one n x n solve per iteration. On a `neuron` tensor it is
|
|
135
|
+
`torch.linalg.eigh`, which TorchNeuron computes on the host: 1.5 / 2.2 /
|
|
136
|
+
4.4 / 17 / 105 ms at n = 64 / 128 / 256 / 512 / 1024, against 0.15 / 0.58 /
|
|
137
|
+
2.5 / 12 / 91 ms for host LAPACK on the same two threads. The batched
|
|
138
|
+
Jacobi kernel and the process pool are for batches; for one n = 64 / 128
|
|
139
|
+
matrix the Jacobi kernel takes 8.6 / 12 ms. A GEMM-only replacement
|
|
140
|
+
(canonical purification, `--solver purify`) took 36 / 48 / 111 ms
|
|
141
|
+
compiled at n = 250 / 490 / 970.
|
|
142
|
+
|
|
81
143
|
## Notes
|
|
82
144
|
|
|
83
145
|
- `inv_sqrt_spd_ns` is Newton-Schulz — all GEMM. On CPU it loses to the eigendecomposition path because eigh is heavily optimized in LAPACK/MKL. On GPU it wins at n ≥ 256 because the workload shape fits the Tensor Core pipeline. Trainium's Tensor Engine should show a similar win once `trnblas` GEMM validates on hardware.
|