CoulombKernelType enum, lookup function, and tests
authorJoe Jordan <ejjordan12@gmail.com>
Tue, 8 Jun 2021 17:36:18 +0000 (17:36 +0000)
committerPascal Merz <pascal.merz@me.com>
Tue, 8 Jun 2021 17:36:18 +0000 (17:36 +0000)
src/gromacs/nbnxm/CMakeLists.txt
src/gromacs/nbnxm/kernel_common.h
src/gromacs/nbnxm/kernel_file_generator/kernel_simd_template.h.pre
src/gromacs/nbnxm/kerneldispatch.cpp
src/gromacs/nbnxm/kernels_reference/kernel_ref.h
src/gromacs/nbnxm/kernels_simd_2xmm/kernels.h
src/gromacs/nbnxm/kernels_simd_4xm/kernels.h
src/gromacs/nbnxm/tests/CMakeLists.txt [new file with mode: 0644]
src/gromacs/nbnxm/tests/kernelsetup.cpp [new file with mode: 0644]

index 70cce27c4416c454d9bb94f0a6c42fe59534f2ba..d95b2c5772e26a6df39b6b5098e6c23b3127a5d4 100644 (file)
@@ -111,3 +111,7 @@ target_link_libraries(nbnxm INTERFACE
 target_link_libraries(nbnxm INTERFACE
         utility
         )
+
+if (BUILD_TESTING)
+    add_subdirectory(tests)
+endif()
index f93e03521d35b1f98080f028ec5b0b7ee9c08a50..f107ea591836a77d5789886622fa0af9280251a5 100644 (file)
@@ -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.
 #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.
index a677e346106dc3e13de313daf480ba72665d7cc5..00326672b1d25fed6b7e60c006ae024d8889afea 100644 (file)
@@ -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.
  * 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<int>(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<int>(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<int>(CoulombKernelType::Count)][vdwktNR] =
 {4}
 
 #endif /* INCLUDE_KERNELFUNCTION_TABLES */
index 28769f6ff131b7014f319bd508f5b75ea3bd2d9c..174dccf1fa3ba7a18998325339372e1308438513 100644 (file)
@@ -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<int>(getCoulombKernelType(
+            kernelSetup.ewaldExclusionType, ic.eeltype, (ic.rcoulomb == ic.rvdw)));
     const int vdwkt  = getVdwKernelType(kernelSetup, nbatParams, ic);
 
     gmx::ArrayRef<const NbnxnPairlistCpu> pairlists = pairlistSet.cpuLists();
index 9d22aeddc2e041f4ce8ee64f05d1c59f0624046a..2d9a1501f845cd9b80187388abdf43e8d7e26e67 100644 (file)
@@ -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<int>(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<int>(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<int>(CoulombKernelType::Count)][vdwktNR_ref] = {
     { nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref,
       nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref,
       nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref,
index 30cff8abe7a23d571b2f7feeb5d60f181b24bc01..4bb063d6beb795843f737035ee908daa679b9c94 100644 (file)
@@ -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<int>(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<int>(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<int>(CoulombKernelType::Count)][vdwktNR] = {
     {
             nbnxm_kernel_ElecRF_VdwLJCombGeom_VgrpF_2xmm,
             nbnxm_kernel_ElecRF_VdwLJCombLB_VgrpF_2xmm,
index 2168d180aaf3abe72d2c0ea1fb9942abb161d2d6..2c8bc9636c2187927e4e736af504359fbe7c4a0e 100644 (file)
@@ -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<int>(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<int>(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<int>(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 (file)
index 0000000..b679e90
--- /dev/null
@@ -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 (file)
index 0000000..8873ed0
--- /dev/null
@@ -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 <ejjordan@kth.se>
+ * \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