diff --git a/Common/include/linear_algebra/CMatrixVectorProduct.hpp b/Common/include/linear_algebra/CMatrixVectorProduct.hpp index 878bb132b98..a0cecaa63d7 100644 --- a/Common/include/linear_algebra/CMatrixVectorProduct.hpp +++ b/Common/include/linear_algebra/CMatrixVectorProduct.hpp @@ -72,6 +72,7 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct { const CSysMatrix& matrix; /*!< \brief pointer to matrix that defines the product. */ CGeometry* geometry; /*!< \brief geometry associated with the matrix. */ const CConfig* config; /*!< \brief config of the problem. */ + mutable bool matrix_uploaded = false; /*!< \brief Upload the matrix lazily on the first actual GPU matvec. */ public: /*! @@ -97,6 +98,10 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct { inline void operator()(const CSysVector& u, CSysVector& v) const override { if (config->GetCUDA()) { #ifdef HAVE_CUDA + if (!matrix_uploaded) { + matrix.HtDTransfer(); + matrix_uploaded = true; + } matrix.GPUMatrixVectorProduct(u, v, geometry, config); #else SU2_MPI::Error( diff --git a/Common/src/linear_algebra/CSysMatrixGPU.cu b/Common/src/linear_algebra/CSysMatrixGPU.cu index 90389264ed3..7e0c81ca54f 100644 --- a/Common/src/linear_algebra/CSysMatrixGPU.cu +++ b/Common/src/linear_algebra/CSysMatrixGPU.cu @@ -70,7 +70,6 @@ void CSysMatrix::GPUMatrixVectorProduct(const CSysVector ScalarType* d_vec = vec.GetDevicePointer(); ScalarType* d_prod = prod.GetDevicePointer(); - HtDTransfer(); vec.HtDTransfer(); prod.GPUSetVal(0.0);