Repository navigation
PERF: Run the trust region on device arrays - #40
Merged
Merged
Conversation
With NuMPI 0.19, tr_newton_bounded iterates in the array module and on the device of x0. optimize_trust_region now passes it the design as an array of the fields' module (cupy on a GPU), so the design, gradient and Hessian products stay on the device and only reduced scalars reach the host; the result is returned on the host as before. StressTargetProblem computes in the fields' module throughout and returns gradient and Hessian product of the caller's kind: device arrays for the trust region, host arrays (one copy) for L-BFGS and the tests. The Hessian cache's design, ensure_state's comparison and the tolerance controller's KKT norm move to the device, NodalElementMap takes device input and can scatter to the device, and simulate.py's callback sums the iterate independently of its kind. GPU tests check that device input gives device output and that the trust region iterates on device arrays and follows the CPU run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NuMPI's CuPy support (reductions and the trust region on device arrays) ships as the bug-fix release 0.18.1, not 0.19.0. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Step 3 of the plan: the optimization loop stays on the GPU. Stacked on #39, which it needs for the regularization's device path. Requires NuMPI 0.19.0 (muSpectre/NuMPI#106), so it can only be merged after that release.
What changes
optimize_trust_regionpasses the design totr_newton_boundedas an array of the fields' module (CuPy on a GPU). With NuMPI #106 the trust region iterates on that device, so the design, gradient and Hessian products never leave it. Only scalars reach the host (dot products and maxima, plus the objective). The result is still returned on the host. The callback receives device arrays, which the docstring now says.StressTargetProblemcomputes in the fields' module throughout and returns its gradient and Hessian product as the same kind of array it was given: device arrays for the trust region, host arrays (one copy each way) for L-BFGS and the tests. The cached design,ensure_state's comparison and the tolerance controller's gradient norm move to the device.NodalElementMaptakes device input, andscatter/scatter_mean(..., on_device=True)return the gradient on the device.simulate.py's callback sums the iterate withrho.sum(), which works for host and device arrays.What this removes
Per objective evaluation, two full-field copies (design in, gradient out). Per Hessian product, two more (direction in, product out). The trust region's own vector arithmetic (the optimization's "(other)", about 22 s of 842 in the last 4-rank run) also moves from host NumPy to the GPU. The gain is modest, but nothing that grows with the grid stays on the host.
Tests
New GPU tests in
test/test_gpu.py:They're skipped here (no CuPy) and need a run on MI300A.
The CPU suite passes (249) against NuMPI #106.
🤖 Generated with Claude Code