Skip to content

Commit 7fa5517

Browse files
authored
Reduce redundant CUDA Jacobian uploads during a linear solve (#2806)
* Reduce redundant CUDA Jacobian uploads * Move CUDA Jacobian upload into CSysMatrixVectorProduct * Defer CUDA matrix upload to first matvec use
1 parent ee4de5c commit 7fa5517

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Common/include/linear_algebra/CMatrixVectorProduct.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct<ScalarType> {
7272
const CSysMatrix<ScalarType>& matrix; /*!< \brief pointer to matrix that defines the product. */
7373
CGeometry* geometry; /*!< \brief geometry associated with the matrix. */
7474
const CConfig* config; /*!< \brief config of the problem. */
75+
mutable bool matrix_uploaded = false; /*!< \brief Upload the matrix lazily on the first actual GPU matvec. */
7576

7677
public:
7778
/*!
@@ -97,6 +98,10 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct<ScalarType> {
9798
inline void operator()(const CSysVector<ScalarType>& u, CSysVector<ScalarType>& v) const override {
9899
if (config->GetCUDA()) {
99100
#ifdef HAVE_CUDA
101+
if (!matrix_uploaded) {
102+
matrix.HtDTransfer();
103+
matrix_uploaded = true;
104+
}
100105
matrix.GPUMatrixVectorProduct(u, v, geometry, config);
101106
#else
102107
SU2_MPI::Error(

Common/src/linear_algebra/CSysMatrixGPU.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ void CSysMatrix<ScalarType>::GPUMatrixVectorProduct(const CSysVector<ScalarType>
7070
ScalarType* d_vec = vec.GetDevicePointer();
7171
ScalarType* d_prod = prod.GetDevicePointer();
7272

73-
HtDTransfer();
7473
vec.HtDTransfer();
7574
prod.GPUSetVal(0.0);
7675

0 commit comments

Comments
 (0)