From e1327e7ea0b7e1c08cbcb9e6c1ca58a78d9610eb Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Thu, 16 Jul 2020 16:57:46 -0400 Subject: [PATCH] Optional bounds check debug code --- Grid/lattice/Lattice_view.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Grid/lattice/Lattice_view.h b/Grid/lattice/Lattice_view.h index 3b76b921..bfbd5f52 100644 --- a/Grid/lattice/Lattice_view.h +++ b/Grid/lattice/Lattice_view.h @@ -52,6 +52,7 @@ public: // This will be safe to call from accelerator_for and is trivially copy constructible // The copy constructor for this will need to be used by device lambda functions ///////////////////////////////////////////////////////////////////////////////////////// +#undef LATTICE_BOUNDS_CHECK template class LatticeView : public LatticeAccelerator { @@ -61,14 +62,36 @@ public: void * cpu_ptr; #ifdef GRID_SIMT accelerator_inline const typename vobj::scalar_object operator()(size_t i) const { +#ifdef LATTICE_BOUNDS_CHECK + assert(i_odata_size); + assert(i>=0); +#endif return coalescedRead(this->_odata[i]); } #else - accelerator_inline const vobj & operator()(size_t i) const { return this->_odata[i]; } + accelerator_inline const vobj & operator()(size_t i) const { +#ifdef LATTICE_BOUNDS_CHECK + assert(i_odata_size); + assert(i>=0); +#endif + return this->_odata[i]; + } #endif - accelerator_inline const vobj & operator[](size_t i) const { return this->_odata[i]; }; - accelerator_inline vobj & operator[](size_t i) { return this->_odata[i]; }; + accelerator_inline const vobj & operator[](size_t i) const { +#ifdef LATTICE_BOUNDS_CHECK + assert(i_odata_size); + assert(i>=0); +#endif + return this->_odata[i]; + }; + accelerator_inline vobj & operator[](size_t i) { +#ifdef LATTICE_BOUNDS_CHECK + assert(i_odata_size); + assert(i>=0); +#endif + return this->_odata[i]; + }; accelerator_inline uint64_t begin(void) const { return 0;}; accelerator_inline uint64_t end(void) const { return this->_odata_size; };