mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Drop std::vector container for the lattice data
This commit is contained in:
parent
c844cfcda8
commit
214f7a6f13
@ -55,11 +55,24 @@ extern int GridCshiftPermuteMap[4][16];
|
||||
// Basic expressions used in Expression Template
|
||||
////////////////////////////////////////////////
|
||||
|
||||
class LatticeBase
|
||||
// The data inside the lattice class
|
||||
class LatticeBase {};
|
||||
|
||||
template<class vobj> class LatticeAccelerator : public LatticeBase
|
||||
{
|
||||
public:
|
||||
virtual ~LatticeBase(void) = default;
|
||||
GridBase *_grid;
|
||||
int checkerboard;
|
||||
vobj *_odata; // A managed pointer
|
||||
uint64_t _odata_size;
|
||||
// virtual ~LatticeBase(void) = default;
|
||||
accelerator_inline LatticeAccelerator() : checkerboard(0), _odata(nullptr), _odata_size(0) {
|
||||
// std::cout << " Lattice accelerator object "<<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
};
|
||||
accelerator_inline int Checkerboard(void){ return checkerboard; };
|
||||
accelerator_inline uint64_t begin(void) const { return 0;};
|
||||
accelerator_inline uint64_t end(void) const { return _odata_size; };
|
||||
accelerator_inline vobj & operator[](size_t i) { return _odata[i]; };
|
||||
accelerator_inline const vobj & operator[](size_t i) const { return _odata[i]; };
|
||||
};
|
||||
|
||||
class LatticeExpressionBase {};
|
||||
@ -88,32 +101,61 @@ void inline conformable(GridBase *lhs,GridBase *rhs)
|
||||
}
|
||||
|
||||
template<class vobj>
|
||||
class Lattice : public LatticeBase
|
||||
class Lattice : public LatticeAccelerator<vobj>
|
||||
{
|
||||
private:
|
||||
// vobj * _odata_p;
|
||||
// uint64_t _odata_size;
|
||||
public:
|
||||
int checkerboard;
|
||||
Vector<vobj> _odata;
|
||||
|
||||
// to pthread need a computable loop where loop induction is not required
|
||||
accelerator int begin(void) const { return 0;};
|
||||
accelerator int end(void) const { return _odata.size(); }
|
||||
accelerator_inline vobj & operator[](int i) { return _odata[i]; };
|
||||
accelerator_inline const vobj & operator[](int i) const { return _odata[i]; };
|
||||
|
||||
public: // Move to private and fix
|
||||
GridBase *_grid;
|
||||
public:
|
||||
///////////////////////////////////////////////////
|
||||
// Member types
|
||||
///////////////////////////////////////////////////
|
||||
typedef typename vobj::scalar_type scalar_type;
|
||||
typedef typename vobj::vector_type vector_type;
|
||||
typedef vobj vector_object;
|
||||
|
||||
private:
|
||||
void dealloc(void)
|
||||
{
|
||||
alignedAllocator<vobj> alloc;
|
||||
// std::cout << " deallocating lattice "<<this << " odata " <<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
// // BACKTRACE();
|
||||
if( this->_odata_size ) {
|
||||
alloc.deallocate(this->_odata,this->_odata_size);
|
||||
this->_odata=nullptr;
|
||||
this->_odata_size=0;
|
||||
}
|
||||
}
|
||||
void resize(uint64_t size)
|
||||
{
|
||||
_odata.resize(size);
|
||||
// _odata_p = &_odata[0];
|
||||
// _odata_size = size;
|
||||
alignedAllocator<vobj> alloc;
|
||||
if ( this->_odata_size != size ) {
|
||||
dealloc();
|
||||
}
|
||||
this->_odata_size = size;
|
||||
if ( size )
|
||||
this->_odata = alloc.allocate(this->_odata_size);
|
||||
else
|
||||
this->_odata = nullptr;
|
||||
|
||||
// std::cout << " allocated lattice "<<this << " odata " <<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
// // BACKTRACE();
|
||||
}
|
||||
void copy_vec(vobj *ptr,uint64_t count)
|
||||
{
|
||||
dealloc();
|
||||
this->_odata = ptr;
|
||||
assert(this->_odata_size == count);
|
||||
// std::cout << " copied lattice "<<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
}
|
||||
public:
|
||||
~Lattice() {
|
||||
if ( this->_odata_size ) {
|
||||
// std::cout << " deleting lattice this"<<this << " odata " <<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
// // BACKTRACE();
|
||||
dealloc();
|
||||
// std::cout << " deleted lattice this"<<this<< " odata "<<this->_odata<<" size "<<this->_odata_size<<std::endl;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Expression Template closure support
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -127,16 +169,16 @@ public:
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
this->checkerboard=cb;
|
||||
|
||||
#ifdef STREAMING_STORES
|
||||
accelerator_loop(ss,(*this),{
|
||||
vobj tmp = eval(ss,expr);
|
||||
vstream(_odata[ss] ,tmp);
|
||||
vstream(this->_odata[ss] ,tmp);
|
||||
});
|
||||
#else
|
||||
accelerator_loop(ss,(*this),{
|
||||
_odata[ss]=eval(ss,expr);
|
||||
this->_odata[ss]=eval(ss,expr);
|
||||
});
|
||||
#endif
|
||||
return *this;
|
||||
@ -151,16 +193,16 @@ public:
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
this->checkerboard=cb;
|
||||
|
||||
#ifdef STREAMING_STORES
|
||||
accelerator_loop(ss,(*this),{
|
||||
vobj tmp = eval(ss,expr);
|
||||
vstream(_odata[ss] ,tmp);
|
||||
vstream(this->_odata[ss] ,tmp);
|
||||
});
|
||||
#else
|
||||
accelerator_loop(ss,(*this),{
|
||||
_odata[ss]=eval(ss,expr);
|
||||
this->_odata[ss]=eval(ss,expr);
|
||||
});
|
||||
#endif
|
||||
return *this;
|
||||
@ -175,16 +217,16 @@ public:
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
this->checkerboard=cb;
|
||||
|
||||
#ifdef STREAMING_STORES
|
||||
accelerator_loop(ss,(*this),{
|
||||
//vobj tmp = eval(ss,expr);
|
||||
vstream(_odata[ss] ,eval(ss,expr));
|
||||
vobj tmp = eval(ss,expr);
|
||||
vstream(this->_odata[ss] ,tmp);
|
||||
});
|
||||
#else
|
||||
accelerator_loop(ss,(*this),{
|
||||
_odata[ss] = eval(ss,expr);
|
||||
this->_odata[ss] = eval(ss,expr);
|
||||
});
|
||||
#endif
|
||||
return *this;
|
||||
@ -199,17 +241,16 @@ public:
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
this->checkerboard=cb;
|
||||
|
||||
resize(_grid->oSites());
|
||||
#ifdef STREAMING_STORES
|
||||
cpu_loop(ss,(*this),{
|
||||
vobj tmp = eval(ss,expr);
|
||||
vstream(_odata[ss] ,tmp);
|
||||
accelerator_loop(ss,(*this),{
|
||||
vstream(this->_odata[ss] ,eval(ss,expr));
|
||||
});
|
||||
#else
|
||||
cpu_loop(ss,(*this),{
|
||||
_odata[ss]=eval(ss,expr);
|
||||
accelerator_loop(ss,(*this),{
|
||||
this->_odata[ss]=eval(ss,expr);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
@ -218,22 +259,21 @@ public:
|
||||
_grid = nullptr;
|
||||
GridFromExpression(_grid,expr);
|
||||
assert(_grid!=nullptr);
|
||||
resize(_grid->oSites());
|
||||
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
|
||||
resize(_grid->oSites());
|
||||
this->checkerboard=cb;
|
||||
|
||||
#ifdef STREAMING_STORES
|
||||
cpu_loop(ss,(*this),{
|
||||
accelerator_loop(ss,(*this),{
|
||||
vobj tmp = eval(ss,expr);
|
||||
vstream(_odata[ss] ,tmp);
|
||||
vstream(this->_odata[ss] ,tmp);
|
||||
});
|
||||
#else
|
||||
cpu_loop(ss,(*this),{
|
||||
_odata[ss]=eval(ss,expr);
|
||||
accelerator_loop(ss,(*this),{
|
||||
this->_odata[ss]=eval(ss,expr);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
@ -246,46 +286,24 @@ public:
|
||||
int cb=-1;
|
||||
CBFromExpression(cb,expr);
|
||||
assert( (cb==Odd) || (cb==Even));
|
||||
checkerboard=cb;
|
||||
this->checkerboard=cb;
|
||||
|
||||
resize(_grid->oSites());
|
||||
cpu_loop(ss,(*this),{
|
||||
vstream(_odata[ss] ,eval(ss,expr));
|
||||
accelerator_loop(ss,(*this),{
|
||||
vstream(this->_odata[ss] ,eval(ss,expr));
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Constructor requires "grid" passed.
|
||||
// what about a default grid?
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Lattice(GridBase *grid) {
|
||||
_grid = grid;
|
||||
resize(grid->oSites());
|
||||
assert((((uint64_t)&_odata[0])&0xF) ==0);
|
||||
checkerboard=0;
|
||||
}
|
||||
|
||||
Lattice(const Lattice& r){ // copy constructor
|
||||
_grid = r._grid;
|
||||
checkerboard = r.checkerboard;
|
||||
resize(_grid->oSites());// essential
|
||||
cpu_loop(ss,(*this),{
|
||||
_odata[ss]=r._odata[ss];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual ~Lattice(void) = default;
|
||||
|
||||
// virtual ~Lattice(void) = default;
|
||||
/*
|
||||
void reset(GridBase* grid) {
|
||||
if (_grid != grid) {
|
||||
_grid = grid;
|
||||
resize(grid->oSites());
|
||||
checkerboard = 0;
|
||||
this->checkerboard = 0;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
template<class sobj> inline Lattice<vobj> & operator = (const sobj & r){
|
||||
accelerator_loop(ss,(*this),{
|
||||
@ -294,7 +312,39 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Follow rule of five, with Constructor requires "grid" passed
|
||||
// to user defined constructor
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Lattice(GridBase *grid) { // user defined constructor
|
||||
_grid = grid;
|
||||
// std::cout << "Lattice constructor(grid)"<<std::endl;
|
||||
resize(grid->oSites());
|
||||
assert((((uint64_t)&this->_odata[0])&0xF) ==0);
|
||||
this->checkerboard=0;
|
||||
}
|
||||
Lattice(const Lattice& r){ // copy constructor
|
||||
// std::cout << "Lattice constructor(const Lattice &) "<<this<<std::endl;
|
||||
_grid = r._grid;
|
||||
resize(r._odata_size);
|
||||
this->checkerboard = r.checkerboard;
|
||||
accelerator_loop(ss,(*this),{
|
||||
this->_odata[ss]=r._odata[ss];
|
||||
});
|
||||
}
|
||||
Lattice(Lattice && r){ // move constructor
|
||||
// std::cout << "Lattice move constructor(Lattice &) "<<this<<std::endl;
|
||||
_grid = r._grid;
|
||||
this->_odata = r._odata;
|
||||
this->_odata_size = r._odata_size;
|
||||
this->checkerboard= r.checkerboard;
|
||||
r._odata = nullptr;
|
||||
r._odata_size = 0;
|
||||
}
|
||||
// assignment template
|
||||
template<class robj> inline Lattice<vobj> & operator = (const Lattice<robj> & r){
|
||||
// std::cout << "Lattice = (Lattice &)"<<std::endl;
|
||||
typename std::enable_if<!std::is_same<robj,vobj>::value,int>::type i=0;
|
||||
this->checkerboard = r.checkerboard;
|
||||
conformable(*this,r);
|
||||
accelerator_loop(ss,(*this),{
|
||||
@ -302,6 +352,33 @@ public:
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
// Copy assignment
|
||||
inline Lattice<vobj> & operator = (const Lattice<vobj> & r){
|
||||
// std::cout << "Lattice = (Lattice &)"<<std::endl;
|
||||
this->checkerboard = r.checkerboard;
|
||||
conformable(*this,r);
|
||||
accelerator_loop(ss,(*this),{
|
||||
this->_odata[ss]=r._odata[ss];
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
// Move assignment if same type
|
||||
inline Lattice<vobj> & operator = (Lattice<vobj> && r){
|
||||
// std::cout << "Lattice = (Lattice &&)"<<std::endl;
|
||||
resize(0); // delete if appropriate
|
||||
|
||||
this->_grid = r._grid;
|
||||
this->checkerboard = r.checkerboard;
|
||||
|
||||
this->_odata = r._odata;
|
||||
this->_odata_size = r._odata_size;
|
||||
this->checkerboard= r.checkerboard;
|
||||
|
||||
r._odata = nullptr;
|
||||
r._odata_size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// *=,+=,-= operators inherit behvour from correspond */+/- operation
|
||||
template<class T> inline Lattice<vobj> &operator *=(const T &r) {
|
||||
|
Loading…
Reference in New Issue
Block a user