Reduce redundant CUDA Jacobian uploads during a linear solve#2806
Draft
LwhJesse wants to merge 1 commit intosu2code:developfrom
Draft
Reduce redundant CUDA Jacobian uploads during a linear solve#2806LwhJesse wants to merge 1 commit intosu2code:developfrom
LwhJesse wants to merge 1 commit intosu2code:developfrom
Conversation
pcarruscag
reviewed
May 1, 2026
Comment on lines
+1467
to
1470
| #ifdef HAVE_CUDA | ||
| if (config->GetCUDA()) Jacobian.HtDTransfer(); | ||
| #endif | ||
| auto mat_vec = CSysMatrixVectorProduct<ScalarType>(Jacobian, geometry, config); |
Member
There was a problem hiding this comment.
It seems we could make this part of CSysMatrixVectorProduct to handle all cases.
Author
There was a problem hiding this comment.
Good point, I agree.
I will revise this so the CUDA matrix upload is handled inside CSysMatrixVectorProduct, rather than requiring each caller to do it explicitly before constructing the matvec wrapper. Then GPUMatrixVectorProduct() can stay free of the per-matvec matrix upload, while the device-side matrix is reused across repeated operator() calls.
I will also remove the explicit HtDTransfer() calls from CSysSolve.cpp and CNewtonIntegration.hpp, check the other CSysMatrixVectorProduct construction paths, and re-run CUDA/non-CUDA tests before marking this ready for review.
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.
Proposed Changes
This draft PR reduces redundant CUDA Jacobian uploads in the CUDA matrix-vector product path.
Currently, the CUDA matvec path uploads the Jacobian from host to device inside each
GPUMatrixVectorProduct()call. This can repeatedly transfer the same matrix during a single linear solve.This patch moves the Jacobian upload to the beginning of the linear solve path, so the device-side matrix can be reused across repeated matvec calls within the same solve. The change assumes that the Jacobian remains unchanged during a single linear solve.
The implementation is intentionally small:
HtDTransfer()call fromCSysMatrixGPU.cu;CSysSolve.cpp;CNewtonIntegration.hpp.Preliminary local CUDA benchmarks on an RTX 4060 Laptop GPU show speedups across 6 cases:
Geometric mean speedup: approximately 1.275x.
Nsight Systems indicates that the speedup mainly comes from reduced Host-to-Device memcpy time. Nsight Compute shows that the
GPUMatrixVectorProductAddkernel itself is essentially unchanged, which is expected because this patch does not modify the kernel implementation.Draft Status
This PR is still a draft because I still need to:
develop;Related Work
None.
PR Checklist
--warnlevel=3when using meson).pre-commit run --allto format old commits.