From: Joe Jordan Date: Tue, 8 Jun 2021 17:36:18 +0000 (+0000) Subject: CoulombKernelType enum, lookup function, and tests X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=d41e6125cfd17dcf323f6777a065ff5ddb5677df;p=alexxy%2Fgromacs.git CoulombKernelType enum, lookup function, and tests --- diff --git a/src/gromacs/nbnxm/CMakeLists.txt b/src/gromacs/nbnxm/CMakeLists.txt index 70cce27c44..d95b2c5772 100644 --- a/src/gromacs/nbnxm/CMakeLists.txt +++ b/src/gromacs/nbnxm/CMakeLists.txt @@ -111,3 +111,7 @@ target_link_libraries(nbnxm INTERFACE target_link_libraries(nbnxm INTERFACE utility ) + +if (BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/src/gromacs/nbnxm/kernel_common.h b/src/gromacs/nbnxm/kernel_common.h index f93e03521d..f107ea5918 100644 --- a/src/gromacs/nbnxm/kernel_common.h +++ b/src/gromacs/nbnxm/kernel_common.h @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 2012,2013,2014,2015,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. @@ -54,6 +54,12 @@ #include "pairlist.h" struct interaction_const_t; +enum class CoulombInteractionType : int; + +namespace Nbnxm +{ +enum class EwaldExclusionType : int; +} // TODO: Consider using one nbk_func type now ener and noener are identical @@ -83,16 +89,21 @@ typedef nbk_func_noener* p_nbk_func_noener; /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels */ -enum +enum class CoulombKernelType : int { - coulktRF, - coulktTAB, - coulktTAB_TWIN, - coulktEWALD, - coulktEWALD_TWIN, - coulktNR + ReactionField, + Table, + TableTwin, + Ewald, + EwaldTwin, + Count }; +//! \brief Lookup function for Coulomb kernel type +CoulombKernelType getCoulombKernelType(Nbnxm::EwaldExclusionType ewaldExclusionType, + CoulombInteractionType coulombInteractionType, + bool haveEqualCoulombVwdRadii); + /*! \brief Kinds of Van der Waals treatments in SIMD Verlet kernels * * The \p LJCUT_COMB refers to the LJ combination rule for the short range. diff --git a/src/gromacs/nbnxm/kernel_file_generator/kernel_simd_template.h.pre b/src/gromacs/nbnxm/kernel_file_generator/kernel_simd_template.h.pre index a677e34610..00326672b1 100644 --- a/src/gromacs/nbnxm/kernel_file_generator/kernel_simd_template.h.pre +++ b/src/gromacs/nbnxm/kernel_file_generator/kernel_simd_template.h.pre @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 2012,2013,2014,2015,2017 by the GROMACS development team. - * 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. @@ -46,11 +46,11 @@ * The minor index of the array goes over both the LJ combination rules, * which is only supported by plain cut-off, and the LJ switch/PME functions. */ -static p_nbk_func_noener nbnxm_kernel_noener_simd_{1}[coulktNR][vdwktNR] = +static p_nbk_func_noener nbnxm_kernel_noener_simd_{1}[static_cast(CoulombKernelType::Count)][vdwktNR] = {2} -static p_nbk_func_ener nbnxm_kernel_ener_simd_{1}[coulktNR][vdwktNR] = +static p_nbk_func_ener nbnxm_kernel_ener_simd_{1}[static_cast(CoulombKernelType::Count)][vdwktNR] = {3} -static p_nbk_func_ener nbnxm_kernel_energrp_simd_{1}[coulktNR][vdwktNR] = +static p_nbk_func_ener nbnxm_kernel_energrp_simd_{1}[static_cast(CoulombKernelType::Count)][vdwktNR] = {4} #endif /* INCLUDE_KERNELFUNCTION_TABLES */ diff --git a/src/gromacs/nbnxm/kerneldispatch.cpp b/src/gromacs/nbnxm/kerneldispatch.cpp index 28769f6ff1..174dccf1fa 100644 --- a/src/gromacs/nbnxm/kerneldispatch.cpp +++ b/src/gromacs/nbnxm/kerneldispatch.cpp @@ -135,35 +135,37 @@ static void reduceGroupEnergySimdBuffers(int numGroups, int numGroups_2log, nbnx } } -static int getCoulombKernelType(const Nbnxm::KernelSetup& kernelSetup, const interaction_const_t& ic) +CoulombKernelType getCoulombKernelType(const Nbnxm::EwaldExclusionType ewaldExclusionType, + const CoulombInteractionType coulombInteractionType, + const bool haveEqualCoulombVwdRadii) { - if (EEL_RF(ic.eeltype) || ic.eeltype == CoulombInteractionType::Cut) + if (EEL_RF(coulombInteractionType) || coulombInteractionType == CoulombInteractionType::Cut) { - return coulktRF; + return CoulombKernelType::ReactionField; } else { - if (kernelSetup.ewaldExclusionType == Nbnxm::EwaldExclusionType::Table) + if (ewaldExclusionType == Nbnxm::EwaldExclusionType::Table) { - if (ic.rcoulomb == ic.rvdw) + if (haveEqualCoulombVwdRadii) { - return coulktTAB; + return CoulombKernelType::Table; } else { - return coulktTAB_TWIN; + return CoulombKernelType::TableTwin; } } else { - if (ic.rcoulomb == ic.rvdw) + if (haveEqualCoulombVwdRadii) { - return coulktEWALD; + return CoulombKernelType::Ewald; } else { - return coulktEWALD_TWIN; + return CoulombKernelType::EwaldTwin; } } } @@ -251,7 +253,8 @@ static void nbnxn_kernel_cpu(const PairlistSet& pairlistSet, const nbnxn_atomdata_t::Params& nbatParams = nbat->params(); - const int coulkt = getCoulombKernelType(kernelSetup, ic); + const int coulkt = static_cast(getCoulombKernelType( + kernelSetup.ewaldExclusionType, ic.eeltype, (ic.rcoulomb == ic.rvdw))); const int vdwkt = getVdwKernelType(kernelSetup, nbatParams, ic); gmx::ArrayRef pairlists = pairlistSet.cpuLists(); diff --git a/src/gromacs/nbnxm/kernels_reference/kernel_ref.h b/src/gromacs/nbnxm/kernels_reference/kernel_ref.h index 9d22aeddc2..2d9a1501f8 100644 --- a/src/gromacs/nbnxm/kernels_reference/kernel_ref.h +++ b/src/gromacs/nbnxm/kernels_reference/kernel_ref.h @@ -107,7 +107,7 @@ nbk_func_ener nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_VgrpF_ref; * advantage in using combination rules, so we (re-)use the same kernel. */ //! \{ -static const p_nbk_func_noener nbnxn_kernel_noener_ref[coulktNR][vdwktNR_ref] = { +static const p_nbk_func_noener nbnxn_kernel_noener_ref[static_cast(CoulombKernelType::Count)][vdwktNR_ref] = { { nbnxn_kernel_ElecRF_VdwLJ_F_ref, nbnxn_kernel_ElecRF_VdwLJ_F_ref, nbnxn_kernel_ElecRF_VdwLJ_F_ref, @@ -145,7 +145,7 @@ static const p_nbk_func_noener nbnxn_kernel_noener_ref[coulktNR][vdwktNR_ref] = nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_F_ref } }; -static const p_nbk_func_ener nbnxn_kernel_ener_ref[coulktNR][vdwktNR_ref] = { +static const p_nbk_func_ener nbnxn_kernel_ener_ref[static_cast(CoulombKernelType::Count)][vdwktNR_ref] = { { nbnxn_kernel_ElecRF_VdwLJ_VF_ref, nbnxn_kernel_ElecRF_VdwLJ_VF_ref, nbnxn_kernel_ElecRF_VdwLJ_VF_ref, @@ -183,7 +183,7 @@ static const p_nbk_func_ener nbnxn_kernel_ener_ref[coulktNR][vdwktNR_ref] = { nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_VF_ref } }; -static const p_nbk_func_ener nbnxn_kernel_energrp_ref[coulktNR][vdwktNR_ref] = { +static const p_nbk_func_ener nbnxn_kernel_energrp_ref[static_cast(CoulombKernelType::Count)][vdwktNR_ref] = { { nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref, diff --git a/src/gromacs/nbnxm/kernels_simd_2xmm/kernels.h b/src/gromacs/nbnxm/kernels_simd_2xmm/kernels.h index 30cff8abe7..4bb063d6be 100644 --- a/src/gromacs/nbnxm/kernels_simd_2xmm/kernels.h +++ b/src/gromacs/nbnxm/kernels_simd_2xmm/kernels.h @@ -143,7 +143,7 @@ nbk_func_ener nbnxm_kernel_ElecEwTwinCut_VdwLJEwCombGeom_VgrpF_2xmm; * The minor index of the array goes over both the LJ combination rules, * which is only supported by plain cut-off, and the LJ switch/PME functions. */ -static const p_nbk_func_noener nbnxm_kernel_noener_simd_2xmm[coulktNR][vdwktNR] = { +static const p_nbk_func_noener nbnxm_kernel_noener_simd_2xmm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_F_2xmm, nbnxm_kernel_ElecRF_VdwLJCombLB_F_2xmm, @@ -186,7 +186,7 @@ static const p_nbk_func_noener nbnxm_kernel_noener_simd_2xmm[coulktNR][vdwktNR] }, }; -static const p_nbk_func_ener nbnxm_kernel_ener_simd_2xmm[coulktNR][vdwktNR] = { +static const p_nbk_func_ener nbnxm_kernel_ener_simd_2xmm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_VF_2xmm, nbnxm_kernel_ElecRF_VdwLJCombLB_VF_2xmm, @@ -229,7 +229,7 @@ static const p_nbk_func_ener nbnxm_kernel_ener_simd_2xmm[coulktNR][vdwktNR] = { }, }; -static const p_nbk_func_ener nbnxm_kernel_energrp_simd_2xmm[coulktNR][vdwktNR] = { +static const p_nbk_func_ener nbnxm_kernel_energrp_simd_2xmm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_VgrpF_2xmm, nbnxm_kernel_ElecRF_VdwLJCombLB_VgrpF_2xmm, diff --git a/src/gromacs/nbnxm/kernels_simd_4xm/kernels.h b/src/gromacs/nbnxm/kernels_simd_4xm/kernels.h index 2168d180aa..2c8bc9636c 100644 --- a/src/gromacs/nbnxm/kernels_simd_4xm/kernels.h +++ b/src/gromacs/nbnxm/kernels_simd_4xm/kernels.h @@ -143,7 +143,7 @@ nbk_func_ener nbnxm_kernel_ElecEwTwinCut_VdwLJEwCombGeom_VgrpF_4xm; * The minor index of the array goes over both the LJ combination rules, * which is only supported by plain cut-off, and the LJ switch/PME functions. */ -static const p_nbk_func_noener nbnxm_kernel_noener_simd_4xm[coulktNR][vdwktNR] = { +static const p_nbk_func_noener nbnxm_kernel_noener_simd_4xm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_F_4xm, nbnxm_kernel_ElecRF_VdwLJCombLB_F_4xm, @@ -186,7 +186,7 @@ static const p_nbk_func_noener nbnxm_kernel_noener_simd_4xm[coulktNR][vdwktNR] = }, }; -static const p_nbk_func_ener nbnxm_kernel_ener_simd_4xm[coulktNR][vdwktNR] = { +static const p_nbk_func_ener nbnxm_kernel_ener_simd_4xm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_VF_4xm, nbnxm_kernel_ElecRF_VdwLJCombLB_VF_4xm, @@ -229,7 +229,7 @@ static const p_nbk_func_ener nbnxm_kernel_ener_simd_4xm[coulktNR][vdwktNR] = { }, }; -static const p_nbk_func_ener nbnxm_kernel_energrp_simd_4xm[coulktNR][vdwktNR] = { +static const p_nbk_func_ener nbnxm_kernel_energrp_simd_4xm[static_cast(CoulombKernelType::Count)][vdwktNR] = { { nbnxm_kernel_ElecRF_VdwLJCombGeom_VgrpF_4xm, nbnxm_kernel_ElecRF_VdwLJCombLB_VgrpF_4xm, diff --git a/src/gromacs/nbnxm/tests/CMakeLists.txt b/src/gromacs/nbnxm/tests/CMakeLists.txt new file mode 100644 index 0000000000..b679e903b5 --- /dev/null +++ b/src/gromacs/nbnxm/tests/CMakeLists.txt @@ -0,0 +1,38 @@ +# +# This file is part of the GROMACS molecular simulation package. +# +# Copyright (c) 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. +# +# GROMACS is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# GROMACS is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with GROMACS; if not, see +# http://www.gnu.org/licenses, or write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# If you want to redistribute modifications to GROMACS, please +# consider that scientific software is very special. Version +# control is crucial - bugs must be traceable. We will be happy to +# consider code for inclusion in the official distribution, but +# derived work must not be called official GROMACS. Details are found +# in the README & COPYING files - if they are missing, get the +# official version at http://www.gromacs.org. +# +# To help us fund GROMACS development, we humbly ask that you cite +# the research papers on the package. Check out http://www.gromacs.org. + +gmx_add_unit_test(NbnxmTests nbnxm-test + CPP_SOURCE_FILES + kernelsetup.cpp + ) diff --git a/src/gromacs/nbnxm/tests/kernelsetup.cpp b/src/gromacs/nbnxm/tests/kernelsetup.cpp new file mode 100644 index 0000000000..8873ed0f7d --- /dev/null +++ b/src/gromacs/nbnxm/tests/kernelsetup.cpp @@ -0,0 +1,89 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 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. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ +/*! \internal \file + * \brief + * Tests for Setup of kernels. + * + * \author Joe Jordan + * \ingroup module_nbnxm + */ +#include "gmxpre.h" + +#include "gromacs/mdtypes/md_enums.h" +#include "gromacs/nbnxm/kernel_common.h" +#include "gromacs/nbnxm/nbnxm.h" + +#include "testutils/testasserts.h" + +namespace gmx +{ + +TEST(KernelSetupTest, getCoulombKernelTypeRF) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::NotSet, CoulombInteractionType::RF, false), + CoulombKernelType::ReactionField); +} + +TEST(KernelSetupTest, getCoulombKernelTypeCut) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::NotSet, CoulombInteractionType::Cut, false), + CoulombKernelType::ReactionField); +} + +TEST(KernelSetupTest, getCoulombKernelTypeTable) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::Table, CoulombInteractionType::Count, true), + CoulombKernelType::Table); +} + +TEST(KernelSetupTest, getCoulombKernelTypeTableTwin) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::Table, CoulombInteractionType::Count, false), + CoulombKernelType::TableTwin); +} + +TEST(KernelSetupTest, getCoulombKernelTypeEwald) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::NotSet, CoulombInteractionType::Count, true), + CoulombKernelType::Ewald); +} + +TEST(KernelSetupTest, getCoulombKernelTypeEwaldTwin) +{ + EXPECT_EQ(getCoulombKernelType(Nbnxm::EwaldExclusionType::NotSet, CoulombInteractionType::Count, false), + CoulombKernelType::EwaldTwin); +} + +} // namespace gmx