Clean up nbnxm bounding boxes
authorBerk Hess <hess@kth.se>
Tue, 5 Mar 2019 15:11:07 +0000 (16:11 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 6 Mar 2019 13:37:08 +0000 (14:37 +0100)
Changed a flat array to array of 1D BB structs.
Changed a macro to a constexpr.

Change-Id: I75bb6792a3e99dc152450398a90f5414ae79fd8c

src/gromacs/nbnxm/grid.cpp
src/gromacs/nbnxm/grid.h
src/gromacs/nbnxm/pairlist.cpp

index 473b9e1ebafc11d67ba4aa428d28839623bcccd8..ec7101a30c57c49549944aecc78cbc65c7141b21 100644 (file)
@@ -208,7 +208,7 @@ void Grid::setDimensions(const nbnxn_search *nbs,
     {
         numClusters_.resize(maxNumCells);
     }
-    bbcz_.resize(maxNumCells*NNBSBB_D);
+    bbcz_.resize(maxNumCells);
 
     /* This resize also zeros the contents, this avoid possible
      * floating exceptions in SIMD with the unused bb elements.
@@ -1039,8 +1039,8 @@ void Grid::sortColumnsCpuGeometry(nbnxn_search *nbs,
             {
                 cellFilled = cell;
             }
-            bbcz_[cell*NNBSBB_D    ] = bb_[cellFilled].lower.z;
-            bbcz_[cell*NNBSBB_D + 1] = bb_[cellFilled].upper.z;
+            bbcz_[cell].lower = bb_[cellFilled].lower.z;
+            bbcz_[cell].upper = bb_[cellFilled].upper.z;
         }
 
         /* Set the unused atom indices to -1 */
@@ -1118,8 +1118,8 @@ void Grid::sortColumnsGpuGeometry(nbnxn_search *nbs,
                                               (numAtoms + geometry_.numAtomsICluster - 1)/ geometry_.numAtomsICluster);
 
                 /* Store the z-boundaries of the bounding box of the cell */
-                bbcz_[cell*NNBSBB_D  ] = x[nbs->a[atomOffsetZ]][ZZ];
-                bbcz_[cell*NNBSBB_D+1] = x[nbs->a[atomOffsetZ + numAtoms - 1]][ZZ];
+                bbcz_[cell].lower = x[nbs->a[atomOffsetZ]][ZZ];
+                bbcz_[cell].upper = x[nbs->a[atomOffsetZ + numAtoms - 1]][ZZ];
             }
 
             if (c_gpuNumClusterPerCellY > 1)
index 35a5266cc46068400dda3ae437dbf16be1c89622..23e0571ed42c2d29830d670f5d6094cf4aba2c94 100644 (file)
@@ -140,14 +140,22 @@ struct BoundingBox
     Corner upper; //!< upper, along x and y and z, corner
 };
 
+/*! \internal
+ * \brief Bounding box for one dimension of a grid cell
+ */
+struct BoundingBox1D
+{
+    float lower; //!< lower bound
+    float upper; //!< upper bound
+};
+
+/*! \brief The number of bounds along one dimension of a bounding box */
+static constexpr int c_numBoundingBoxBounds1D = 2;
 
 #ifndef DOXYGEN
 
 // TODO: Convert macros to constexpr int
 
-/* Pair search box lower and upper bound in z only. */
-#define NNBSBB_D         2
-
 /* Bounding box calculations are (currently) always in single precision, so
  * we only need to check for single precision support here.
  * This uses less (cache-)memory and SIMD is faster, at least on x86.
@@ -182,7 +190,7 @@ struct BoundingBox
 /* Store bounding boxes corners as quadruplets: xxxxyyyyzzzz */
 #    define NBNXN_BBXXXX  1
 /* Size of a quadruplet of bounding boxes, each 2 corners, stored packed */
-#    define NNBSBB_XXXX  (2*DIM*STRIDE_PBB)
+#    define NNBSBB_XXXX  (STRIDE_PBB*DIM*Nbnxm::c_numBoundingBoxBounds1D)
 
 #else  /* NBNXN_SEARCH_BB_SIMD4 */
 
@@ -362,7 +370,7 @@ class Grid
         }
 
         //! Returns the bounding boxes along z for all cells on the grid
-        gmx::ArrayRef<const float> zBoundingBoxes() const
+        gmx::ArrayRef<const BoundingBox1D> zBoundingBoxes() const
         {
             return bbcz_;
         }
@@ -475,7 +483,7 @@ class Grid
 
         /* Bounding boxes */
         //! Bounding boxes in z for the cells
-        std::vector<float>                                  bbcz_;
+        std::vector<BoundingBox1D>                          bbcz_;
         //! 3D bounding boxes for the sub cells
         std::vector < BoundingBox, gmx::AlignedAllocator < BoundingBox>> bb_;
         //! 3D j-bounding boxes for the case where the i- and j-cluster sizes are different
index 8fc0dbf55f01b7fbae6158b4e02a299b57d17f54..82e0177bbf31617375bbffbeae62982f0ad83a05 100644 (file)
 #include "internal.h"
 #include "pairlistwork.h"
 
-using namespace gmx;                   // TODO: Remove when this file is moved into gmx namespace
+using namespace gmx;                        // TODO: Remove when this file is moved into gmx namespace
 
-using nbnxn_bb_t = Nbnxm::BoundingBox; // TODO: Remove when refactoring this file
+using nbnxn_bb_t    = Nbnxm::BoundingBox;   // TODO: Remove when refactoring this file
+using BoundingBox1D = Nbnxm::BoundingBox1D; // TODO: Remove when refactoring this file
 
-using Grid       = Nbnxm::Grid;        // TODO: Remove when refactoring this file
+using Grid          = Nbnxm::Grid;          // TODO: Remove when refactoring this file
 
 // Convience alias for partial Nbnxn namespace usage
 using InteractionLocality = Nbnxm::InteractionLocality;
@@ -521,7 +522,7 @@ static float subc_bb_dist2_simd4(int                              si,
         Simd4Float        d2x, d2y, d2z;                       \
         Simd4Float        d2s, d2t;                            \
                                                  \
-        shi = (si)*NNBSBB_D*DIM;                       \
+        shi = (si)*Nbnxm::c_numBoundingBoxBounds1D*DIM; \
                                                  \
         xi_l = load4((bb_i)+shi+0*STRIDE_PBB);   \
         yi_l = load4((bb_i)+shi+1*STRIDE_PBB);   \
@@ -3371,10 +3372,10 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs,
     /* We use the normal bounding box format for both grid types */
     bb_i  = iGrid.iBoundingBoxes();
 #endif
-    gmx::ArrayRef<const float> bbcz_i  = iGrid.zBoundingBoxes();
-    gmx::ArrayRef<const int>   flags_i = iGrid.clusterFlags();
-    gmx::ArrayRef<const float> bbcz_j  = jGrid.zBoundingBoxes();
-    int                        cell0_i = iGrid.cellOffset();
+    gmx::ArrayRef<const BoundingBox1D> bbcz_i  = iGrid.zBoundingBoxes();
+    gmx::ArrayRef<const int>           flags_i = iGrid.clusterFlags();
+    gmx::ArrayRef<const BoundingBox1D> bbcz_j  = jGrid.zBoundingBoxes();
+    int                                cell0_i = iGrid.cellOffset();
 
     if (debug)
     {
@@ -3431,8 +3432,8 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs,
         {
             const real shz = tz*box[ZZ][ZZ];
 
-            bz0 = bbcz_i[ci*NNBSBB_D  ] + shz;
-            bz1 = bbcz_i[ci*NNBSBB_D+1] + shz;
+            bz0 = bbcz_i[ci].lower + shz;
+            bz1 = bbcz_i[ci].upper + shz;
 
             if (tz == 0)
             {
@@ -3621,8 +3622,8 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs,
                                  */
                                 int downTestCell = midCell;
                                 while (downTestCell >= columnStart &&
-                                       (bbcz_j[downTestCell*NNBSBB_D + 1] >= bz0 ||
-                                        d2xy + gmx::square(bbcz_j[downTestCell*NNBSBB_D + 1] - bz0) < rlist2))
+                                       (bbcz_j[downTestCell].upper >= bz0 ||
+                                        d2xy + gmx::square(bbcz_j[downTestCell].upper - bz0) < rlist2))
                                 {
                                     downTestCell--;
                                 }
@@ -3636,8 +3637,8 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs,
                                  */
                                 int upTestCell = midCell + 1;
                                 while (upTestCell < columnEnd &&
-                                       (bbcz_j[upTestCell*NNBSBB_D] <= bz1 ||
-                                        d2xy + gmx::square(bbcz_j[upTestCell*NNBSBB_D] - bz1) < rlist2))
+                                       (bbcz_j[upTestCell].lower <= bz1 ||
+                                        d2xy + gmx::square(bbcz_j[upTestCell].lower - bz1) < rlist2))
                                 {
                                     upTestCell++;
                                 }