From da919949f99d13157bb3109169c3882d4621b8e2 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Fri, 23 Aug 2024 12:34:41 -0400 Subject: [PATCH] Clean up the accelerator pick/set checkerboard --- Grid/cartesian/Cartesian_base.h | 1 + Grid/cartesian/Cartesian_red_black.h | 1 + Grid/lattice/Lattice_transfer.h | 41 +++++----------------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/Grid/cartesian/Cartesian_base.h b/Grid/cartesian/Cartesian_base.h index bb3c3b3f..96f2bfd5 100644 --- a/Grid/cartesian/Cartesian_base.h +++ b/Grid/cartesian/Cartesian_base.h @@ -91,6 +91,7 @@ public: //////////////////////////////////////////////////////////////// virtual int CheckerBoarded(int dim)=0; virtual int CheckerBoard(const Coordinate &site)=0; + virtual int CheckerDim(void){ return 0; }; virtual int CheckerBoardDestination(int source_cb,int shift,int dim)=0; virtual int CheckerBoardShift(int source_cb,int dim,int shift,int osite)=0; virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift,int cb)=0; diff --git a/Grid/cartesian/Cartesian_red_black.h b/Grid/cartesian/Cartesian_red_black.h index 092d4910..5de1af7b 100644 --- a/Grid/cartesian/Cartesian_red_black.h +++ b/Grid/cartesian/Cartesian_red_black.h @@ -60,6 +60,7 @@ public: int _checker_dim; std::vector _checker_board; + virtual int CheckerDim(void){ return _checker_dim; }; virtual int CheckerBoarded(int dim){ if( dim==_checker_dim) return 1; else return 0; diff --git a/Grid/lattice/Lattice_transfer.h b/Grid/lattice/Lattice_transfer.h index c475829d..6a53436a 100644 --- a/Grid/lattice/Lattice_transfer.h +++ b/Grid/lattice/Lattice_transfer.h @@ -42,50 +42,21 @@ inline void subdivides(GridBase *coarse,GridBase *fine) assert((fine->_rdimensions[d] / coarse->_rdimensions[d])* coarse->_rdimensions[d]==fine->_rdimensions[d]); } } - //////////////////////////////////////////////////////////////////////////////////////////// // remove and insert a half checkerboard //////////////////////////////////////////////////////////////////////////////////////////// + template inline void pickCheckerboard(int cb,Lattice &half,const Lattice &full) { - half.Checkerboard() = cb; - - autoView( half_v, half, CpuWrite); - autoView( full_v, full, CpuRead); - thread_for(ss, full.Grid()->oSites(),{ - int cbos; - Coordinate coor; - full.Grid()->oCoorFromOindex(coor,ss); - cbos=half.Grid()->CheckerBoard(coor); - - if (cbos==cb) { - int ssh=half.Grid()->oIndex(coor); - half_v[ssh] = full_v[ss]; - } - }); + acceleratorPickCheckerboard(cb,half,full); } template inline void setCheckerboard(Lattice &full,const Lattice &half) { - int cb = half.Checkerboard(); - autoView( half_v , half, CpuRead); - autoView( full_v , full, CpuWrite); - thread_for(ss,full.Grid()->oSites(),{ - - Coordinate coor; - int cbos; - - full.Grid()->oCoorFromOindex(coor,ss); - cbos=half.Grid()->CheckerBoard(coor); - - if (cbos==cb) { - int ssh=half.Grid()->oIndex(coor); - full_v[ss]=half_v[ssh]; - } - }); + acceleratorSetCheckerboard(full,half); } -template inline void acceleratorPickCheckerboard(int cb,Lattice &half,const Lattice &full, int checker_dim_half=0) +template inline void acceleratorPickCheckerboard(int cb,Lattice &half,const Lattice &full, int dummy=0) { half.Checkerboard() = cb; autoView(half_v, half, AcceleratorWrite); @@ -95,6 +66,7 @@ template inline void acceleratorPickCheckerboard(int cb,Lattice_ndimension; Coordinate checker_dim_mask_half = half.Grid()->_checker_dim_mask; Coordinate ostride_half = half.Grid()->_ostride; + int checker_dim_half = half.Grid()->CheckerDim(); accelerator_for(ss, full.Grid()->oSites(),full.Grid()->Nsimd(),{ Coordinate coor; @@ -119,7 +91,7 @@ template inline void acceleratorPickCheckerboard(int cb,Lattice inline void acceleratorSetCheckerboard(Lattice &full,const Lattice &half, int checker_dim_half=0) +template inline void acceleratorSetCheckerboard(Lattice &full,const Lattice &half, int dummy=0) { int cb = half.Checkerboard(); autoView(half_v , half, AcceleratorRead); @@ -129,6 +101,7 @@ template inline void acceleratorSetCheckerboard(Lattice &full, unsigned long ndim_half = half.Grid()->_ndimension; Coordinate checker_dim_mask_half = half.Grid()->_checker_dim_mask; Coordinate ostride_half = half.Grid()->_ostride; + int checker_dim_half = half.Grid()->CheckerDim(); accelerator_for(ss,full.Grid()->oSites(),full.Grid()->Nsimd(),{ Coordinate coor;