From f7ecbe68c1df2c15fd3f70c3c721ae7e18981141 Mon Sep 17 00:00:00 2001 From: Andrey Alekseenko Date: Thu, 11 Mar 2021 11:43:07 +0000 Subject: [PATCH] Disable GPU update in the presence of frozen atoms There is a known bug (Issue #3920) affecting GPU update when frozen atoms are present. The bug is expected to be resolved in GROMACS 2022. In GROMACS 2021, we disable the invalid configuration to prevent users from getting invalid results. This is a backport of !1241 and !1255. Refs #3920 --- src/gromacs/mdlib/mdatoms.cpp | 5 ++--- src/gromacs/mdrun/runner.cpp | 3 ++- src/gromacs/mdtypes/inputrec.cpp | 9 ++++++++- src/gromacs/mdtypes/inputrec.h | 5 ++++- src/gromacs/modularsimulator/modularsimulator.cpp | 6 ++---- src/gromacs/taskassignment/decidegpuusage.cpp | 8 +++++++- src/gromacs/taskassignment/decidegpuusage.h | 4 +++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/gromacs/mdlib/mdatoms.cpp b/src/gromacs/mdlib/mdatoms.cpp index 0d1abd8565..fb538837b1 100644 --- a/src/gromacs/mdlib/mdatoms.cpp +++ b/src/gromacs/mdlib/mdatoms.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team. - * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -291,8 +291,7 @@ void atoms2md(const gmx_mtop_t* mtop, { srenew(md->cACC, md->nalloc); } - if (opts->nFreeze - && (opts->ngfrz > 1 || opts->nFreeze[0][XX] || opts->nFreeze[0][YY] || opts->nFreeze[0][ZZ])) + if (inputrecFrozenAtoms(ir)) { srenew(md->cFREEZE, md->nalloc); } diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index f5ebb604bb..2a5a7c2fe8 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1240,12 +1240,13 @@ int Mdrunner::mdrunner() try { const bool useUpdateGroups = cr->dd ? ddUsesUpdateGroups(*cr->dd) : false; + const bool haveFrozenAtoms = inputrecFrozenAtoms(inputrec.get()); useGpuForUpdate = decideWhetherToUseGpuForUpdate( useDomainDecomposition, useUpdateGroups, pmeRunMode, domdecOptions.numPmeRanks > 0, useGpuForNonbonded, updateTarget, gpusWereDetected, *inputrec, mtop, doEssentialDynamics, gmx_mtop_ftype_count(mtop, F_ORIRES) > 0, - replExParams.exchangeInterval > 0, doRerun, devFlags, mdlog); + replExParams.exchangeInterval > 0, haveFrozenAtoms, doRerun, devFlags, mdlog); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR diff --git a/src/gromacs/mdtypes/inputrec.cpp b/src/gromacs/mdtypes/inputrec.cpp index b872095f52..05a09523fb 100644 --- a/src/gromacs/mdtypes/inputrec.cpp +++ b/src/gromacs/mdtypes/inputrec.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2010, The GROMACS development team. * Copyright (c) 2012,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -1506,6 +1506,13 @@ bool inputrecPbcXY2Walls(const t_inputrec* ir) return (ir->pbcType == PbcType::XY && ir->nwall == 2); } +bool inputrecFrozenAtoms(const t_inputrec* ir) +{ + return ((ir->opts.nFreeze != nullptr) + && (ir->opts.ngfrz > 1 || ir->opts.nFreeze[0][XX] != 0 || ir->opts.nFreeze[0][YY] != 0 + || ir->opts.nFreeze[0][ZZ] != 0)); +} + bool integratorHasConservedEnergyQuantity(const t_inputrec* ir) { if (!EI_MD(ir->eI)) diff --git a/src/gromacs/mdtypes/inputrec.h b/src/gromacs/mdtypes/inputrec.h index 46cb924592..6e4ee727ab 100644 --- a/src/gromacs/mdtypes/inputrec.h +++ b/src/gromacs/mdtypes/inputrec.h @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -644,6 +644,9 @@ gmx_bool inputrecNphTrotter(const t_inputrec* ir); /*! \brief Return true if the simulation is 2D periodic with two walls. */ bool inputrecPbcXY2Walls(const t_inputrec* ir); +//! \brief Return true if the simulation has frozen atoms (non-trivial freeze groups). +bool inputrecFrozenAtoms(const t_inputrec* ir); + /*! \brief Returns true for MD integator with T and/or P-coupling that supports * calculating a conserved energy quantity. * diff --git a/src/gromacs/modularsimulator/modularsimulator.cpp b/src/gromacs/modularsimulator/modularsimulator.cpp index 2450711c10..102fe2a2ff 100644 --- a/src/gromacs/modularsimulator/modularsimulator.cpp +++ b/src/gromacs/modularsimulator/modularsimulator.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019,2020, by the GROMACS development team, led by + * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -257,9 +257,7 @@ bool ModularSimulator::isInputCompatible(bool exitOn "Acceleration is not supported by the modular simulator."); isInputCompatible = isInputCompatible - && conditionalAssert(inputrec->opts.ngfrz == 1 && inputrec->opts.nFreeze[0][XX] == 0 - && inputrec->opts.nFreeze[0][YY] == 0 - && inputrec->opts.nFreeze[0][ZZ] == 0, + && conditionalAssert(!inputrecFrozenAtoms(inputrec), "Freeze groups are not supported by the modular simulator."); isInputCompatible = isInputCompatible diff --git a/src/gromacs/taskassignment/decidegpuusage.cpp b/src/gromacs/taskassignment/decidegpuusage.cpp index 7d96638fde..53ff94c346 100644 --- a/src/gromacs/taskassignment/decidegpuusage.cpp +++ b/src/gromacs/taskassignment/decidegpuusage.cpp @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 2015,2016,2017,2018,2019 by the GROMACS development team. - * Copyright (c) 2020, by the GROMACS development team, led by + * Copyright (c) 2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -544,6 +544,7 @@ bool decideWhetherToUseGpuForUpdate(const bool isDomainDecom const bool useEssentialDynamics, const bool doOrientationRestraints, const bool useReplicaExchange, + const bool haveFrozenAtoms, const bool doRerun, const DevelopmentFeatureFlags& devFlags, const gmx::MDLogger& mdlog) @@ -684,6 +685,11 @@ bool decideWhetherToUseGpuForUpdate(const bool isDomainDecom "The number of coupled constraints is higher than supported in the GPU LINCS " "code.\n"; } + if (haveFrozenAtoms) + { + // There is a known bug with frozen atoms and GPU update, see Issue #3920. + errorMessage += "Frozen atoms not supported.\n"; + } if (!errorMessage.empty()) { diff --git a/src/gromacs/taskassignment/decidegpuusage.h b/src/gromacs/taskassignment/decidegpuusage.h index b5fd83907f..765636c448 100644 --- a/src/gromacs/taskassignment/decidegpuusage.h +++ b/src/gromacs/taskassignment/decidegpuusage.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -278,6 +278,7 @@ bool decideWhetherToUseGpusForBonded(bool useGpuForNonbonded, * \param[in] useEssentialDynamics If essential dynamics is active. * \param[in] doOrientationRestraints If orientation restraints are enabled. * \param[in] useReplicaExchange If this is a REMD simulation. + * \param[in] haveFrozenAtoms If this simulation has frozen atoms (see Issue #3920). * \param[in] doRerun It this is a rerun. * \param[in] devFlags GPU development / experimental feature flags. * \param[in] mdlog MD logger. @@ -298,6 +299,7 @@ bool decideWhetherToUseGpuForUpdate(bool isDomainDecom bool useEssentialDynamics, bool doOrientationRestraints, bool useReplicaExchange, + bool haveFrozenAtoms, bool doRerun, const DevelopmentFeatureFlags& devFlags, const gmx::MDLogger& mdlog); -- 2.22.0