From b39a96292468d55a8fa11d1f77bd7cee9b81f726 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 30 Mar 2023 13:35:19 -0500 Subject: [PATCH 1/9] starting LCAO mw evaluate det ratios --- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 37 +++++++++++++++++++ .../LCAO/SoaLocalizedBasisSet.cpp | 9 +++++ 2 files changed, 46 insertions(+) diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 61380c4310..911a35836b 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -398,6 +398,8 @@ void LCAOrbitalSet::mw_evaluateVGLImplGEMM(const RefVectorWithLeader& sp assert(requested_orb_size <= OrbitalSetSize); ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); myBasisSet->mw_evaluateVGL(P_list, iat, basis_mw); + // TODO: make class for general blas interface in Platforms + // have instance of that class as member of LCAOrbitalSet, call gemm through that BLAS::gemm('T', 'N', requested_orb_size, // MOs spo_list.size() * DIM_VGL, // walkers * DIM_VGL @@ -407,6 +409,41 @@ void LCAOrbitalSet::mw_evaluateVGLImplGEMM(const RefVectorWithLeader& sp } } +void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + const RefVector& psi_v_list) const +{ + const size_t nw = spo_list.size(); + //RefVector> phi_v_list; + RefVector phi_v_list; + phi_v_list.reserve(nw); + + myBasisSet->mw_evaluateV(P_list, iat, phi_v_list); + + if (Identity) + { + for (int iw = 0; iw < nw; iw++) + std::copy_n(phi_v_list[iw].get().data(), OrbitalSetSize, psi_v_list[iw].get().data()); + } + else + { + const size_t requested_orb_size = phi_v_list.size(1); + assert(requested_orb_size <= OrbitalSetSize); + ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); + //TODO: psi <- C.phi (loop over walkers) + } +} + +void mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& vp_list, + const RefVector& psi_list, + const std::vector& invRow_ptr_list, + std::vector>& ratios_list) const +{ + //TODO: implement this +} + void LCAOrbitalSet::evaluateDetRatios(const VirtualParticleSet& VP, ValueVector& psi, const ValueVector& psiinv, diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp index c278faf7bf..35994154a9 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp @@ -216,6 +216,15 @@ void SoaLocalizedBasisSet::evaluateV(const ParticleSet& P, int iat, O } } +template +void SoaLocalizedBasisSet::mw_evaluateV(const RefVectorWithLeader& P_list, + int iat, + RefVector& vals_list) +{ + for (size_t iw = 0; iw < P_list.size(); iw++) + evaluateV(P_list[iw], iat, vals_list[iw]); +} + template void SoaLocalizedBasisSet::evaluateGradSourceV(const ParticleSet& P, int iat, From 8760d3170405f7f781cfc93bf72f748140d5ffab Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 30 Mar 2023 15:17:50 -0500 Subject: [PATCH 2/9] packed walker impl for evaluateV GEMM impl for LCAOrbitalSet::mw_evaluateValue loop over walkers impl for SPOSet::mw_evaluateValue and SoaLocalizedBasisSet::mw_evaluateV modified existing unit test to check output of LCAOrbitalSet::mw_evaluateValue (also calls SoaLocalizedBasisSet::mw_evaluateV) --- src/QMCWaveFunctions/BasisSetBase.h | 3 ++ src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 38 ++++++++++--------- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h | 5 +++ .../LCAO/SoaLocalizedBasisSet.cpp | 6 ++- .../LCAO/SoaLocalizedBasisSet.h | 13 +++++++ src/QMCWaveFunctions/SPOSet.cpp | 14 +++++++ src/QMCWaveFunctions/SPOSet.h | 12 ++++++ src/QMCWaveFunctions/tests/test_MO.cpp | 10 +++++ 8 files changed, 82 insertions(+), 19 deletions(-) diff --git a/src/QMCWaveFunctions/BasisSetBase.h b/src/QMCWaveFunctions/BasisSetBase.h index 3ed863ae03..ca58b48066 100644 --- a/src/QMCWaveFunctions/BasisSetBase.h +++ b/src/QMCWaveFunctions/BasisSetBase.h @@ -136,6 +136,7 @@ struct SoaBasisSetBase using vghgh_type = VectorSoaContainer; using ValueType = QMCTraits::ValueType; using OffloadMWVGLArray = Array>; // [VGL, walker, Orbs] + using OffloadMWVArray = Array>; // [walker, Orbs] ///size of the basis set int BasisSetSize; @@ -150,6 +151,8 @@ struct SoaBasisSetBase virtual void evaluateVGL(const ParticleSet& P, int iat, vgl_type& vgl) = 0; //Evaluates value, gradient, and laplacian for electron "iat". places them in a offload array for batched code. virtual void mw_evaluateVGL(const RefVectorWithLeader& P_list, int iat, OffloadMWVGLArray& vgl) = 0; + //Evaluates value for electron "iat". places it in a offload array for batched code. + virtual void mw_evaluateV(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) = 0; //Evaluates value, gradient, and Hessian for electron "iat". Parks them into a temporary data structure "vgh". virtual void evaluateVGH(const ParticleSet& P, int iat, vgh_type& vgh) = 0; //Evaluates value, gradient, and Hessian, and Gradient Hessian for electron "iat". Parks them into a temporary data structure "vghgh". diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 911a35836b..e80492f414 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -412,37 +412,41 @@ void LCAOrbitalSet::mw_evaluateVGLImplGEMM(const RefVectorWithLeader& sp void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, int iat, - const RefVector& psi_v_list) const + OffloadMWVArray& psi_v) const { const size_t nw = spo_list.size(); - //RefVector> phi_v_list; - RefVector phi_v_list; - phi_v_list.reserve(nw); + OffloadMWVArray phi_v; + phi_v.resize(nw, BasisSetSize); - myBasisSet->mw_evaluateV(P_list, iat, phi_v_list); + + myBasisSet->mw_evaluateV(P_list, iat, phi_v); if (Identity) { - for (int iw = 0; iw < nw; iw++) - std::copy_n(phi_v_list[iw].get().data(), OrbitalSetSize, psi_v_list[iw].get().data()); + std::copy_n(phi_v.data_at(0,0), OrbitalSetSize * nw, psi_v.data_at(0,0)); } else { - const size_t requested_orb_size = phi_v_list.size(1); + const size_t requested_orb_size = psi_v.size(1); assert(requested_orb_size <= OrbitalSetSize); ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); - //TODO: psi <- C.phi (loop over walkers) + BLAS::gemm('T', 'N', + requested_orb_size, // MOs + spo_list.size(), // walkers * DIM_VGL + BasisSetSize, // AOs + 1, C_partial_view.data(), BasisSetSize, phi_v.data(), BasisSetSize, 0, psi_v.data(), + requested_orb_size); } } -void mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, - const RefVectorWithLeader& vp_list, - const RefVector& psi_list, - const std::vector& invRow_ptr_list, - std::vector>& ratios_list) const -{ - //TODO: implement this -} +//void mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, +// const RefVectorWithLeader& vp_list, +// const RefVector& psi_list, +// const std::vector& invRow_ptr_list, +// std::vector>& ratios_list) const +//{ +// //TODO: implement this +//} void LCAOrbitalSet::evaluateDetRatios(const VirtualParticleSet& VP, ValueVector& psi, diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h index 18e141abd6..02fdccf4bb 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h @@ -289,6 +289,11 @@ struct LCAOrbitalSet : public SPOSet const RefVectorWithLeader& P_list, int iat, OffloadMWVGLArray& phi_vgl_v) const; + /// packed walker GEMM implementation + void mw_evaluateValue(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& phi_v) const override; }; } // namespace qmcplusplus #endif diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp index 35994154a9..e86c31cd63 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp @@ -219,10 +219,12 @@ void SoaLocalizedBasisSet::evaluateV(const ParticleSet& P, int iat, O template void SoaLocalizedBasisSet::mw_evaluateV(const RefVectorWithLeader& P_list, int iat, - RefVector& vals_list) + OffloadMWVArray& v) { for (size_t iw = 0; iw < P_list.size(); iw++) - evaluateV(P_list[iw], iat, vals_list[iw]); + { + evaluateV(P_list[iw], iat, v.data_at(iw,0)); + } } template diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h index 8ad5319dd9..69e793c566 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h @@ -46,6 +46,7 @@ class SoaLocalizedBasisSet : public SoaBasisSetBase using vghgh_type = typename BaseType::vghgh_type; using PosType = typename ParticleSet::PosType; using OffloadMWVGLArray = Array>; // [VGL, walker, Orbs] + using OffloadMWVArray = Array>; // [walker, Orbs] using BaseType::BasisSetSize; @@ -108,6 +109,18 @@ class SoaLocalizedBasisSet : public SoaBasisSetBase */ void evaluateVGL(const ParticleSet& P, int iat, vgl_type& vgl) override; + /** compute V using packed array with all walkers + * @param P_list list of quantum particleset (one for each walker) + * @param iat active particle + * @param v Array(n_walkers, BasisSetSize) + */ + void mw_evaluateV(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) override; + + /** compute VGL using packed array with all walkers + * @param P_list list of quantum particleset (one for each walker) + * @param iat active particle + * @param vgl Array(n_walkers, 5, BasisSetSize) + */ void mw_evaluateVGL(const RefVectorWithLeader& P_list, int iat, OffloadMWVGLArray& vgl) override; /** compute VGH diff --git a/src/QMCWaveFunctions/SPOSet.cpp b/src/QMCWaveFunctions/SPOSet.cpp index 60d233ff8d..946b79321a 100644 --- a/src/QMCWaveFunctions/SPOSet.cpp +++ b/src/QMCWaveFunctions/SPOSet.cpp @@ -103,6 +103,20 @@ void SPOSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, spo_list[iw].evaluateValue(P_list[iw], iat, psi_v_list[iw]); } +void SPOSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& psi_v) const +{ + ValueVector tmp_v; + assert(this == &spo_list.getLeader()); + for (int iw = 0; iw < spo_list.size(); iw++) + { + spo_list[iw].evaluateValue(P_list[iw], iat, tmp_v); + std::copy_n(tmp_v.data(), tmp_v.size(), psi_v.data_at(iw,0)); + } +} + void SPOSet::mw_evaluateVGLWithSpin(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, int iat, diff --git a/src/QMCWaveFunctions/SPOSet.h b/src/QMCWaveFunctions/SPOSet.h index 78b2c0afcc..1bf49d0f5a 100644 --- a/src/QMCWaveFunctions/SPOSet.h +++ b/src/QMCWaveFunctions/SPOSet.h @@ -50,6 +50,7 @@ class SPOSet : public QMCTraits using GGGMatrix = OrbitalSetTraits::GradHessMatrix; using SPOMap = std::map>; using OffloadMWVGLArray = Array>; // [VGL, walker, Orbs] + using OffloadMWVArray = Array>; // [walker, Orbs] template using OffloadMatrix = Matrix>; @@ -259,6 +260,17 @@ class SPOSet : public QMCTraits int iat, const RefVector& psi_v_list) const; + /** evaluate the values this single-particle orbital sets of multiple walkers + * @param spo_list the list of SPOSet pointers in a walker batch + * @param P_list the list of ParticleSet pointers in a walker batch + * @param iat active particle + * @param psi_v array of values over [walkers, SPOs] + */ + virtual void mw_evaluateValue(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& psi_v) const; + /** evaluate the values, gradients and laplacians of this single-particle orbital sets of multiple walkers * @param spo_list the list of SPOSet pointers in a walker batch * @param P_list the list of ParticleSet pointers in a walker batch diff --git a/src/QMCWaveFunctions/tests/test_MO.cpp b/src/QMCWaveFunctions/tests/test_MO.cpp index a6634c2200..9262221d52 100644 --- a/src/QMCWaveFunctions/tests/test_MO.cpp +++ b/src/QMCWaveFunctions/tests/test_MO.cpp @@ -430,6 +430,11 @@ void test_EtOH_mw(bool transform) RefVector dpsi_list = {dpsi_1, dpsi_2}; RefVector d2psi_list = {d2psi_1, d2psi_2}; + size_t nw = psi_list.size(); + SPOSet::OffloadMWVArray psi_v_array; + psi_v_array.resize(nw, n_mo); + sposet->mw_evaluateValue(spo_list, P_list, 0, psi_v_array); + //LCAOrbitalSet::OffloadMWVGLArray phi_vgl_v; //sposet->mw_evaluateVGL(spo_list, P_list, 0, phi_vgl_v); // FIXME: add resource management @@ -437,6 +442,11 @@ void test_EtOH_mw(bool transform) for (size_t iorb = 0; iorb < n_mo; iorb++) { + for (size_t iw = 0; iw < nw; iw++) + { + // test values from OffloadMWVArray impl. + CHECK(std::real(psi_v_array(iw, iorb)) == Approx(psi_list[iw].get()[iorb])); + } CHECK(std::real(psi_list[0].get()[iorb]) == Approx(psiref_0[iorb])); CHECK(std::real(psi_list[1].get()[iorb]) == Approx(psiref_1[iorb])); CHECK(std::real(d2psi_list[0].get()[iorb]) == Approx(d2psiref_0[iorb])); From 1205a4e297eae2622c7841a0e363e27250fd90ba Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 30 Mar 2023 15:38:00 -0500 Subject: [PATCH 3/9] fixed comment --- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index e80492f414..70c410a2ff 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -418,7 +418,6 @@ void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list OffloadMWVArray phi_v; phi_v.resize(nw, BasisSetSize); - myBasisSet->mw_evaluateV(P_list, iat, phi_v); if (Identity) @@ -432,7 +431,7 @@ void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); BLAS::gemm('T', 'N', requested_orb_size, // MOs - spo_list.size(), // walkers * DIM_VGL + spo_list.size(), // walkers BasisSetSize, // AOs 1, C_partial_view.data(), BasisSetSize, phi_v.data(), BasisSetSize, 0, psi_v.data(), requested_orb_size); From 8a7ac6fcf3d1fe1a90ff71cec97f3351dcf473d2 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 30 Mar 2023 16:35:48 -0500 Subject: [PATCH 4/9] moved packed impl to separate function --- src/QMCWaveFunctions/BasisSetBase.h | 2 +- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 20 +++++++++++++++++-- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h | 12 +++++++---- .../LCAO/SoaLocalizedBasisSet.cpp | 8 +++----- .../LCAO/SoaLocalizedBasisSet.h | 2 +- src/QMCWaveFunctions/SPOSet.cpp | 13 ------------ src/QMCWaveFunctions/SPOSet.h | 11 ---------- src/QMCWaveFunctions/tests/test_MO.cpp | 9 +++++---- 8 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/QMCWaveFunctions/BasisSetBase.h b/src/QMCWaveFunctions/BasisSetBase.h index ca58b48066..7be77b13cb 100644 --- a/src/QMCWaveFunctions/BasisSetBase.h +++ b/src/QMCWaveFunctions/BasisSetBase.h @@ -152,7 +152,7 @@ struct SoaBasisSetBase //Evaluates value, gradient, and laplacian for electron "iat". places them in a offload array for batched code. virtual void mw_evaluateVGL(const RefVectorWithLeader& P_list, int iat, OffloadMWVGLArray& vgl) = 0; //Evaluates value for electron "iat". places it in a offload array for batched code. - virtual void mw_evaluateV(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) = 0; + virtual void mw_evaluateValue(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) = 0; //Evaluates value, gradient, and Hessian for electron "iat". Parks them into a temporary data structure "vgh". virtual void evaluateVGH(const ParticleSet& P, int iat, vgh_type& vgh) = 0; //Evaluates value, gradient, and Hessian, and Gradient Hessian for electron "iat". Parks them into a temporary data structure "vghgh". diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 70c410a2ff..903b4e289a 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -412,13 +412,29 @@ void LCAOrbitalSet::mw_evaluateVGLImplGEMM(const RefVectorWithLeader& sp void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, int iat, - OffloadMWVArray& psi_v) const + const RefVector& psi_v_list) const +{ + OffloadMWVArray phi_v; + phi_v.resize(spo_list.size(), OrbitalSetSize); + mw_evaluateValueImplGEMM(spo_list, P_list, iat, phi_v); + + const size_t output_size = phi_v.size(1); + const size_t nw = phi_v.size(0); + + for (int iw = 0; iw < nw; iw++) + std::copy_n(phi_v.data_at(iw, 0), output_size, psi_v_list[iw].get().data()); +} + +void LCAOrbitalSet::mw_evaluateValueImplGEMM(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& psi_v) const { const size_t nw = spo_list.size(); OffloadMWVArray phi_v; phi_v.resize(nw, BasisSetSize); - myBasisSet->mw_evaluateV(P_list, iat, phi_v); + myBasisSet->mw_evaluateValue(P_list, iat, phi_v); if (Identity) { diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h index 02fdccf4bb..d98c9d3739 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h @@ -78,6 +78,10 @@ struct LCAOrbitalSet : public SPOSet void evaluateVGL(const ParticleSet& P, int iat, ValueVector& psi, GradVector& dpsi, ValueVector& d2psi) override; + void mw_evaluateValue(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + const RefVector& psi_v_list) const override; void mw_evaluateVGL(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, @@ -290,10 +294,10 @@ struct LCAOrbitalSet : public SPOSet int iat, OffloadMWVGLArray& phi_vgl_v) const; /// packed walker GEMM implementation - void mw_evaluateValue(const RefVectorWithLeader& spo_list, - const RefVectorWithLeader& P_list, - int iat, - OffloadMWVArray& phi_v) const override; + void mw_evaluateValueImplGEMM(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& phi_v) const; }; } // namespace qmcplusplus #endif diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp index e86c31cd63..ef6aac282f 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp @@ -217,14 +217,12 @@ void SoaLocalizedBasisSet::evaluateV(const ParticleSet& P, int iat, O } template -void SoaLocalizedBasisSet::mw_evaluateV(const RefVectorWithLeader& P_list, - int iat, - OffloadMWVArray& v) +void SoaLocalizedBasisSet::mw_evaluateValue(const RefVectorWithLeader& P_list, + int iat, + OffloadMWVArray& v) { for (size_t iw = 0; iw < P_list.size(); iw++) - { evaluateV(P_list[iw], iat, v.data_at(iw,0)); - } } template diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h index 69e793c566..191ccdc8f4 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.h @@ -114,7 +114,7 @@ class SoaLocalizedBasisSet : public SoaBasisSetBase * @param iat active particle * @param v Array(n_walkers, BasisSetSize) */ - void mw_evaluateV(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) override; + void mw_evaluateValue(const RefVectorWithLeader& P_list, int iat, OffloadMWVArray& v) override; /** compute VGL using packed array with all walkers * @param P_list list of quantum particleset (one for each walker) diff --git a/src/QMCWaveFunctions/SPOSet.cpp b/src/QMCWaveFunctions/SPOSet.cpp index 946b79321a..adca97ce42 100644 --- a/src/QMCWaveFunctions/SPOSet.cpp +++ b/src/QMCWaveFunctions/SPOSet.cpp @@ -103,19 +103,6 @@ void SPOSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, spo_list[iw].evaluateValue(P_list[iw], iat, psi_v_list[iw]); } -void SPOSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, - const RefVectorWithLeader& P_list, - int iat, - OffloadMWVArray& psi_v) const -{ - ValueVector tmp_v; - assert(this == &spo_list.getLeader()); - for (int iw = 0; iw < spo_list.size(); iw++) - { - spo_list[iw].evaluateValue(P_list[iw], iat, tmp_v); - std::copy_n(tmp_v.data(), tmp_v.size(), psi_v.data_at(iw,0)); - } -} void SPOSet::mw_evaluateVGLWithSpin(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, diff --git a/src/QMCWaveFunctions/SPOSet.h b/src/QMCWaveFunctions/SPOSet.h index 1bf49d0f5a..7ece1a569d 100644 --- a/src/QMCWaveFunctions/SPOSet.h +++ b/src/QMCWaveFunctions/SPOSet.h @@ -260,17 +260,6 @@ class SPOSet : public QMCTraits int iat, const RefVector& psi_v_list) const; - /** evaluate the values this single-particle orbital sets of multiple walkers - * @param spo_list the list of SPOSet pointers in a walker batch - * @param P_list the list of ParticleSet pointers in a walker batch - * @param iat active particle - * @param psi_v array of values over [walkers, SPOs] - */ - virtual void mw_evaluateValue(const RefVectorWithLeader& spo_list, - const RefVectorWithLeader& P_list, - int iat, - OffloadMWVArray& psi_v) const; - /** evaluate the values, gradients and laplacians of this single-particle orbital sets of multiple walkers * @param spo_list the list of SPOSet pointers in a walker batch * @param P_list the list of ParticleSet pointers in a walker batch diff --git a/src/QMCWaveFunctions/tests/test_MO.cpp b/src/QMCWaveFunctions/tests/test_MO.cpp index 9262221d52..4fd4f2b15a 100644 --- a/src/QMCWaveFunctions/tests/test_MO.cpp +++ b/src/QMCWaveFunctions/tests/test_MO.cpp @@ -431,9 +431,10 @@ void test_EtOH_mw(bool transform) RefVector d2psi_list = {d2psi_1, d2psi_2}; size_t nw = psi_list.size(); - SPOSet::OffloadMWVArray psi_v_array; - psi_v_array.resize(nw, n_mo); - sposet->mw_evaluateValue(spo_list, P_list, 0, psi_v_array); + SPOSet::ValueVector psi_v_1(n_mo); + SPOSet::ValueVector psi_v_2(n_mo); + RefVector psi_v_list = {psi_v_1, psi_v_2}; + sposet->mw_evaluateValue(spo_list, P_list, 0, psi_v_list); //LCAOrbitalSet::OffloadMWVGLArray phi_vgl_v; //sposet->mw_evaluateVGL(spo_list, P_list, 0, phi_vgl_v); @@ -445,7 +446,7 @@ void test_EtOH_mw(bool transform) for (size_t iw = 0; iw < nw; iw++) { // test values from OffloadMWVArray impl. - CHECK(std::real(psi_v_array(iw, iorb)) == Approx(psi_list[iw].get()[iorb])); + CHECK(std::real(psi_v_list[iw].get()[iorb]) == Approx(psi_list[iw].get()[iorb])); } CHECK(std::real(psi_list[0].get()[iorb]) == Approx(psiref_0[iorb])); CHECK(std::real(psi_list[1].get()[iorb]) == Approx(psiref_1[iorb])); From 68d6f781c846bd7de312838d3183b99349f0b8e0 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Fri, 31 Mar 2023 13:16:21 -0500 Subject: [PATCH 5/9] LCAO mw det ratios --- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 35 ++++++++++++--------- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h | 6 ++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 903b4e289a..230d26c14a 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -438,7 +438,7 @@ void LCAOrbitalSet::mw_evaluateValueImplGEMM(const RefVectorWithLeader& if (Identity) { - std::copy_n(phi_v.data_at(0,0), OrbitalSetSize * nw, psi_v.data_at(0,0)); + std::copy_n(phi_v.data_at(0, 0), OrbitalSetSize * nw, psi_v.data_at(0, 0)); } else { @@ -446,22 +446,29 @@ void LCAOrbitalSet::mw_evaluateValueImplGEMM(const RefVectorWithLeader& assert(requested_orb_size <= OrbitalSetSize); ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); BLAS::gemm('T', 'N', - requested_orb_size, // MOs - spo_list.size(), // walkers - BasisSetSize, // AOs - 1, C_partial_view.data(), BasisSetSize, phi_v.data(), BasisSetSize, 0, psi_v.data(), - requested_orb_size); + requested_orb_size, // MOs + spo_list.size(), // walkers + BasisSetSize, // AOs + 1, C_partial_view.data(), BasisSetSize, phi_v.data(), BasisSetSize, 0, psi_v.data(), requested_orb_size); } } -//void mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, -// const RefVectorWithLeader& vp_list, -// const RefVector& psi_list, -// const std::vector& invRow_ptr_list, -// std::vector>& ratios_list) const -//{ -// //TODO: implement this -//} +void LCAOrbitalSet::mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& vp_list, + const RefVector& psi_list, + const std::vector& invRow_ptr_list, + std::vector>& ratios_list) const +{ + size_t nw = spo_list.size(); + for (size_t iw = 0; iw < nw; iw++) + { + for (size_t iat = 0; iat < vp_list[iw].getTotalNum(); iat++) + { + spo_list[iw].evaluateValue(vp_list[iw], iat, psi_list[iw]); + ratios_list[iw][iat] = simd::dot(psi_list[iw].get().data(), invRow_ptr_list[iw], psi_list[iw].get().size()); + } + } +} void LCAOrbitalSet::evaluateDetRatios(const VirtualParticleSet& VP, ValueVector& psi, diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h index d98c9d3739..6f5341dad5 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.h @@ -90,6 +90,12 @@ struct LCAOrbitalSet : public SPOSet const RefVector& dpsi_v_list, const RefVector& d2psi_v_list) const override; + void mw_evaluateDetRatios(const RefVectorWithLeader& spo_list, + const RefVectorWithLeader& vp_list, + const RefVector& psi_list, + const std::vector& invRow_ptr_list, + std::vector>& ratios_list) const override; + void evaluateDetRatios(const VirtualParticleSet& VP, ValueVector& psi, const ValueVector& psiinv, From 95cc63c7f44b528e7b22d1d5bb9e7034872290b0 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 22 Jun 2023 16:35:59 -0500 Subject: [PATCH 6/9] add phi_v to shared resource --- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 17 +++++++++++------ .../LCAO/SoaLocalizedBasisSet.cpp | 2 +- src/QMCWaveFunctions/tests/test_MO.cpp | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 662d9db780..2ec78f6251 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -27,6 +27,7 @@ struct LCAOrbitalSet::LCAOMultiWalkerMem : public Resource OffloadMWVGLArray phi_vgl_v; // [5][NW][NumAO] + OffloadMWVArray phi_v; OffloadMWVGLArray basis_mw; }; @@ -453,8 +454,8 @@ void LCAOrbitalSet::mw_evaluateVGLImplGEMM(const RefVectorWithLeader& sp { ScopedTimer local(mo_timer_); ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); - // TODO: make class for general blas interface in Platforms - // have instance of that class as member of LCAOrbitalSet, call gemm through that + // TODO: make class for general blas interface in Platforms + // have instance of that class as member of LCAOrbitalSet, call gemm through that BLAS::gemm('T', 'N', requested_orb_size, // MOs spo_list.size() * DIM_VGL, // walkers * DIM_VGL @@ -470,7 +471,9 @@ void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list int iat, const RefVector& psi_v_list) const { - OffloadMWVArray phi_v; + assert(this == &spo_list.getLeader()); + auto& spo_leader = spo_list.getCastedLeader(); + auto& phi_v = spo_leader.mw_mem_handle_.getResource().phi_v; phi_v.resize(spo_list.size(), OrbitalSetSize); mw_evaluateValueImplGEMM(spo_list, P_list, iat, phi_v); @@ -486,8 +489,10 @@ void LCAOrbitalSet::mw_evaluateValueImplGEMM(const RefVectorWithLeader& int iat, OffloadMWVArray& psi_v) const { - const size_t nw = spo_list.size(); - OffloadMWVArray phi_v; + assert(this == &spo_list.getLeader()); + auto& spo_leader = spo_list.getCastedLeader(); + const size_t nw = spo_list.size(); + auto& phi_v = spo_leader.mw_mem_handle_.getResource().phi_v; phi_v.resize(nw, BasisSetSize); myBasisSet->mw_evaluateValue(P_list, iat, phi_v); @@ -515,7 +520,7 @@ void LCAOrbitalSet::mw_evaluateDetRatios(const RefVectorWithLeader& spo_ const std::vector& invRow_ptr_list, std::vector>& ratios_list) const { - size_t nw = spo_list.size(); + const size_t nw = spo_list.size(); for (size_t iw = 0; iw < nw; iw++) { for (size_t iat = 0; iat < vp_list[iw].getTotalNum(); iat++) diff --git a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp index ef6aac282f..6f4afa9d53 100644 --- a/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp +++ b/src/QMCWaveFunctions/LCAO/SoaLocalizedBasisSet.cpp @@ -222,7 +222,7 @@ void SoaLocalizedBasisSet::mw_evaluateValue(const RefVectorWithLeader OffloadMWVArray& v) { for (size_t iw = 0; iw < P_list.size(); iw++) - evaluateV(P_list[iw], iat, v.data_at(iw,0)); + evaluateV(P_list[iw], iat, v.data_at(iw, 0)); } template diff --git a/src/QMCWaveFunctions/tests/test_MO.cpp b/src/QMCWaveFunctions/tests/test_MO.cpp index afb36fa976..edf23e063e 100644 --- a/src/QMCWaveFunctions/tests/test_MO.cpp +++ b/src/QMCWaveFunctions/tests/test_MO.cpp @@ -426,7 +426,7 @@ void test_EtOH_mw(bool transform) size_t nw = psi_list.size(); SPOSet::ValueVector psi_v_1(n_mo); SPOSet::ValueVector psi_v_2(n_mo); - RefVector psi_v_list = {psi_v_1, psi_v_2}; + RefVector psi_v_list{psi_v_1, psi_v_2}; ResourceCollection pset_res("test_pset_res"); ResourceCollection spo_res("test_spo_res"); From 686413832f00c84a36eaff1774cc8edc8cff7a5d Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 22 Jun 2023 16:59:06 -0500 Subject: [PATCH 7/9] fixed AO/MO problem --- src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp index 2ec78f6251..61e254e00d 100644 --- a/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp +++ b/src/QMCWaveFunctions/LCAO/LCAOrbitalSet.cpp @@ -25,10 +25,10 @@ struct LCAOrbitalSet::LCAOMultiWalkerMem : public Resource std::unique_ptr makeClone() const override { return std::make_unique(*this); } - OffloadMWVGLArray phi_vgl_v; - // [5][NW][NumAO] - OffloadMWVArray phi_v; - OffloadMWVGLArray basis_mw; + OffloadMWVGLArray phi_vgl_v; // [5][NW][NumMO] + OffloadMWVGLArray basis_mw; // [5][NW][NumAO] + OffloadMWVArray phi_v; // [NW][NumMO] + OffloadMWVArray basis_v_mw; // [NW][NumMO] }; LCAOrbitalSet::LCAOrbitalSet(const std::string& my_name, std::unique_ptr&& bs) @@ -487,30 +487,31 @@ void LCAOrbitalSet::mw_evaluateValue(const RefVectorWithLeader& spo_list void LCAOrbitalSet::mw_evaluateValueImplGEMM(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, int iat, - OffloadMWVArray& psi_v) const + OffloadMWVArray& phi_v) const { assert(this == &spo_list.getLeader()); auto& spo_leader = spo_list.getCastedLeader(); const size_t nw = spo_list.size(); - auto& phi_v = spo_leader.mw_mem_handle_.getResource().phi_v; - phi_v.resize(nw, BasisSetSize); + auto& basis_v_mw = spo_leader.mw_mem_handle_.getResource().basis_v_mw; + basis_v_mw.resize(nw, BasisSetSize); - myBasisSet->mw_evaluateValue(P_list, iat, phi_v); + myBasisSet->mw_evaluateValue(P_list, iat, basis_v_mw); if (Identity) { - std::copy_n(phi_v.data_at(0, 0), OrbitalSetSize * nw, psi_v.data_at(0, 0)); + std::copy_n(basis_v_mw.data_at(0, 0), OrbitalSetSize * nw, phi_v.data_at(0, 0)); } else { - const size_t requested_orb_size = psi_v.size(1); + const size_t requested_orb_size = phi_v.size(1); assert(requested_orb_size <= OrbitalSetSize); ValueMatrix C_partial_view(C->data(), requested_orb_size, BasisSetSize); BLAS::gemm('T', 'N', requested_orb_size, // MOs spo_list.size(), // walkers BasisSetSize, // AOs - 1, C_partial_view.data(), BasisSetSize, phi_v.data(), BasisSetSize, 0, psi_v.data(), requested_orb_size); + 1, C_partial_view.data(), BasisSetSize, basis_v_mw.data(), BasisSetSize, 0, phi_v.data(), + requested_orb_size); } } From 47bb7cf0d23b4028561792fbda2f3cb8769664b8 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 22 Jun 2023 17:01:17 -0500 Subject: [PATCH 8/9] cleanup --- src/QMCWaveFunctions/tests/test_MO.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/QMCWaveFunctions/tests/test_MO.cpp b/src/QMCWaveFunctions/tests/test_MO.cpp index edf23e063e..8944909990 100644 --- a/src/QMCWaveFunctions/tests/test_MO.cpp +++ b/src/QMCWaveFunctions/tests/test_MO.cpp @@ -437,8 +437,6 @@ void test_EtOH_mw(bool transform) ResourceCollectionTeamLock mw_pset_lock(pset_res, P_list); ResourceCollectionTeamLock mw_sposet_lock(spo_res, spo_list); - //LCAOrbitalSet::OffloadMWVGLArray phi_vgl_v; - //sposet->mw_evaluateVGL(spo_list, P_list, 0, phi_vgl_v); sposet->mw_evaluateVGL(spo_list, P_list, 0, psi_list, dpsi_list, d2psi_list); sposet->mw_evaluateValue(spo_list, P_list, 0, psi_v_list); From bbc319bfec9b9d40a3a47b79a5adbba2feb7fbc2 Mon Sep 17 00:00:00 2001 From: Kevin Gasperich Date: Thu, 22 Jun 2023 17:04:01 -0500 Subject: [PATCH 9/9] minor cleanup --- src/QMCWaveFunctions/SPOSet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/QMCWaveFunctions/SPOSet.cpp b/src/QMCWaveFunctions/SPOSet.cpp index adca97ce42..60d233ff8d 100644 --- a/src/QMCWaveFunctions/SPOSet.cpp +++ b/src/QMCWaveFunctions/SPOSet.cpp @@ -103,7 +103,6 @@ void SPOSet::mw_evaluateValue(const RefVectorWithLeader& spo_list, spo_list[iw].evaluateValue(P_list[iw], iat, psi_v_list[iw]); } - void SPOSet::mw_evaluateVGLWithSpin(const RefVectorWithLeader& spo_list, const RefVectorWithLeader& P_list, int iat,