2015-04-03 04:52:53 +01:00
|
|
|
#ifndef _GRID_CSHIFT_COMMON_H_
|
|
|
|
#define _GRID_CSHIFT_COMMON_H_
|
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
namespace Grid {
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
template<class vobj>
|
|
|
|
class SimpleCompressor {
|
|
|
|
public:
|
|
|
|
void Point(int) {};
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
vobj operator() (const vobj &arg) {
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
};
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Gather for when there is no need to SIMD split with compression
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
template<class vobj,class cobj,class compressor> void
|
|
|
|
Gather_plane_simple (const Lattice<vobj> &rhs,std::vector<cobj,alignedAllocator<cobj> > &buffer,int dimension,int plane,int cbmask,compressor &compress)
|
|
|
|
{
|
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
|
|
|
cbmask = 0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int so = plane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
|
|
|
for(int b=0;b<rhs._grid->_slice_block[dimension];b++){
|
2015-05-13 00:31:00 +01:00
|
|
|
int o = n*rhs._grid->_slice_stride[dimension];
|
|
|
|
int bo = n*rhs._grid->_slice_block[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int ocb=1<<rhs._grid->CheckerBoardFromOindex(o+b);// Could easily be a table lookup
|
|
|
|
if ( ocb &cbmask ) {
|
2015-05-13 00:31:00 +01:00
|
|
|
buffer[bo+b]=compress(rhs._odata[so+o+b]);
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Gather for when there *is* need to SIMD split with compression
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
template<class cobj,class vobj,class compressor> void
|
|
|
|
Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename cobj::scalar_object *> pointers,int dimension,int plane,int cbmask,compressor &compress)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
|
|
|
|
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
cbmask = 0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int so = plane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
|
|
|
for(int b=0;b<rhs._grid->_slice_block[dimension];b++){
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-05-10 23:29:21 +01:00
|
|
|
int o=n*rhs._grid->_slice_stride[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int offset = b+n*rhs._grid->_slice_block[dimension];
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int ocb=1<<rhs._grid->CheckerBoardFromOindex(o+b);
|
|
|
|
if ( ocb & cbmask ) {
|
|
|
|
cobj temp;
|
|
|
|
temp =compress(rhs._odata[so+o+b]);
|
|
|
|
extract<cobj>(temp,pointers,offset);
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Gather for when there is no need to SIMD split
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
template<class vobj> void Gather_plane_simple (const Lattice<vobj> &rhs,std::vector<vobj,alignedAllocator<vobj> > &buffer, int dimension,int plane,int cbmask)
|
|
|
|
{
|
|
|
|
SimpleCompressor<vobj> dontcompress;
|
|
|
|
Gather_plane_simple (rhs,buffer,dimension,plane,cbmask,dontcompress);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Gather for when there *is* need to SIMD split
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
template<class vobj> void Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename vobj::scalar_object *> pointers,int dimension,int plane,int cbmask)
|
|
|
|
{
|
|
|
|
SimpleCompressor<vobj> dontcompress;
|
|
|
|
Gather_plane_extract<vobj,vobj,decltype(dontcompress)>(rhs,pointers,dimension,plane,cbmask,dontcompress);
|
|
|
|
}
|
|
|
|
|
2015-04-03 04:52:53 +01:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Scatter for when there is no need to SIMD split
|
|
|
|
//////////////////////////////////////////////////////
|
2015-04-28 08:11:59 +01:00
|
|
|
template<class vobj> void Scatter_plane_simple (Lattice<vobj> &rhs,std::vector<vobj,alignedAllocator<vobj> > &buffer, int dimension,int plane,int cbmask)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
|
|
|
|
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
cbmask=0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int so = plane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
|
|
|
for(int b=0;b<rhs._grid->_slice_block[dimension];b++){
|
2015-05-13 00:31:00 +01:00
|
|
|
int o =n*rhs._grid->_slice_stride[dimension];
|
|
|
|
int bo =n*rhs._grid->_slice_block[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int ocb=1<<rhs._grid->CheckerBoardFromOindex(o+b);// Could easily be a table lookup
|
|
|
|
if ( ocb & cbmask ) {
|
2015-05-13 00:31:00 +01:00
|
|
|
rhs._odata[so+o+b]=buffer[bo+b];
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Scatter for when there *is* need to SIMD split
|
|
|
|
//////////////////////////////////////////////////////
|
2015-04-28 08:11:59 +01:00
|
|
|
template<class vobj,class cobj> void Scatter_plane_merge(Lattice<vobj> &rhs,std::vector<cobj *> pointers,int dimension,int plane,int cbmask)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
|
|
|
|
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
cbmask=0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int so = plane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
|
|
|
for(int b=0;b<rhs._grid->_slice_block[dimension];b++){
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-05-10 23:29:21 +01:00
|
|
|
int o = n*rhs._grid->_slice_stride[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int offset = b+n*rhs._grid->_slice_block[dimension];
|
|
|
|
int ocb=1<<rhs._grid->CheckerBoardFromOindex(o+b);
|
|
|
|
if ( ocb&cbmask ) {
|
|
|
|
merge(rhs._odata[so+o+b],pointers,offset);
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// local to node block strided copies
|
|
|
|
//////////////////////////////////////////////////////
|
2015-04-18 20:44:19 +01:00
|
|
|
template<class vobj> void Copy_plane(Lattice<vobj>& lhs,Lattice<vobj> &rhs, int dimension,int lplane,int rplane,int cbmask)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
|
|
|
|
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
cbmask=0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int ro = rplane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
|
|
|
int lo = lplane*lhs._grid->_ostride[dimension]; // base offset for start of plane
|
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
|
|
|
for(int b=0;b<rhs._grid->_slice_block[dimension];b++){
|
2015-05-26 04:02:54 +01:00
|
|
|
/*
|
2015-05-10 23:29:21 +01:00
|
|
|
int o =n*rhs._grid->_slice_stride[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int ocb=1<<lhs._grid->CheckerBoardFromOindex(o+b);
|
|
|
|
if ( ocb&cbmask ) {
|
2015-04-03 04:52:53 +01:00
|
|
|
lhs._odata[lo+o+b]=rhs._odata[ro+o+b];
|
|
|
|
}
|
2015-05-26 04:02:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int o =n*rhs._grid->_slice_stride[dimension]+b;
|
|
|
|
int ocb=1<<lhs._grid->CheckerBoardFromOindex(o);
|
|
|
|
if ( ocb&cbmask ) {
|
|
|
|
//lhs._odata[lo+o]=rhs._odata[ro+o];
|
|
|
|
vstream(lhs._odata[lo+o],rhs._odata[ro+o]);
|
|
|
|
}
|
|
|
|
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-22 09:33:15 +01:00
|
|
|
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
template<class vobj> void Copy_plane_permute(Lattice<vobj>& lhs,Lattice<vobj> &rhs, int dimension,int lplane,int rplane,int cbmask,int permute_type)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
2015-05-22 09:33:15 +01:00
|
|
|
|
2015-04-03 04:52:53 +01:00
|
|
|
int rd = rhs._grid->_rdimensions[dimension];
|
|
|
|
|
|
|
|
if ( !rhs._grid->CheckerBoarded(dimension) ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
cbmask=0x3;
|
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int ro = rplane*rhs._grid->_ostride[dimension]; // base offset for start of plane
|
|
|
|
int lo = lplane*lhs._grid->_ostride[dimension]; // base offset for start of plane
|
|
|
|
|
2015-05-13 00:31:00 +01:00
|
|
|
PARALLEL_NESTED_LOOP2
|
2015-04-28 08:11:59 +01:00
|
|
|
for(int n=0;n<rhs._grid->_slice_nblock[dimension];n++){
|
2015-05-15 11:36:22 +01:00
|
|
|
for(int b=0;b<rhs._grid->_slice_block [dimension];b++){
|
|
|
|
|
|
|
|
int o =n*rhs._grid->_slice_stride[dimension];
|
2015-04-28 08:11:59 +01:00
|
|
|
int ocb=1<<lhs._grid->CheckerBoardFromOindex(o+b);
|
|
|
|
if ( ocb&cbmask ) {
|
2015-04-03 04:52:53 +01:00
|
|
|
permute(lhs._odata[lo+o+b],rhs._odata[ro+o+b],permute_type);
|
|
|
|
}
|
2015-05-15 11:36:22 +01:00
|
|
|
|
|
|
|
}}
|
2015-04-03 04:52:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Local to node Cshift
|
|
|
|
//////////////////////////////////////////////////////
|
2015-04-18 20:44:19 +01:00
|
|
|
template<class vobj> void Cshift_local(Lattice<vobj>& ret,Lattice<vobj> &rhs,int dimension,int shift)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
|
|
|
int sshift[2];
|
|
|
|
|
|
|
|
sshift[0] = rhs._grid->CheckerBoardShift(rhs.checkerboard,dimension,shift,0);
|
|
|
|
sshift[1] = rhs._grid->CheckerBoardShift(rhs.checkerboard,dimension,shift,1);
|
|
|
|
|
|
|
|
if ( sshift[0] == sshift[1] ) {
|
|
|
|
Cshift_local(ret,rhs,dimension,shift,0x3);
|
|
|
|
} else {
|
|
|
|
Cshift_local(ret,rhs,dimension,shift,0x1);// if checkerboard is unfavourable take two passes
|
|
|
|
Cshift_local(ret,rhs,dimension,shift,0x2);// both with block stride loop iteration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
template<class vobj> Lattice<vobj> Cshift_local(Lattice<vobj> &ret,Lattice<vobj> &rhs,int dimension,int shift,int cbmask)
|
2015-04-03 04:52:53 +01:00
|
|
|
{
|
2015-04-06 11:26:24 +01:00
|
|
|
GridBase *grid = rhs._grid;
|
|
|
|
int fd = grid->_fdimensions[dimension];
|
|
|
|
int rd = grid->_rdimensions[dimension];
|
|
|
|
int ld = grid->_ldimensions[dimension];
|
|
|
|
int gd = grid->_gdimensions[dimension];
|
2015-04-03 04:52:53 +01:00
|
|
|
|
|
|
|
// Map to always positive shift modulo global full dimension.
|
|
|
|
shift = (shift+fd)%fd;
|
|
|
|
|
2015-04-06 11:26:24 +01:00
|
|
|
ret.checkerboard = grid->CheckerBoardDestination(rhs.checkerboard,shift);
|
2015-04-03 04:52:53 +01:00
|
|
|
|
|
|
|
// the permute type
|
2015-04-06 11:26:24 +01:00
|
|
|
int permute_dim =grid->PermuteDim(dimension);
|
|
|
|
int permute_type=grid->PermuteType(dimension);
|
2015-04-03 04:52:53 +01:00
|
|
|
|
|
|
|
for(int x=0;x<rd;x++){
|
|
|
|
|
|
|
|
int o = 0;
|
2015-04-06 11:26:24 +01:00
|
|
|
int bo = x * grid->_ostride[dimension];
|
2015-04-03 04:52:53 +01:00
|
|
|
|
|
|
|
int cb= (cbmask==0x2)? 1 : 0;
|
|
|
|
|
2015-04-06 11:26:24 +01:00
|
|
|
int sshift = grid->CheckerBoardShift(rhs.checkerboard,dimension,shift,cb);
|
2015-04-03 04:52:53 +01:00
|
|
|
int sx = (x+sshift)%rd;
|
|
|
|
|
|
|
|
int permute_slice=0;
|
|
|
|
if(permute_dim){
|
|
|
|
int wrap = sshift/rd;
|
|
|
|
int num = sshift%rd;
|
|
|
|
if ( x< rd-num ) permute_slice=wrap;
|
|
|
|
else permute_slice = 1-wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( permute_slice ) Copy_plane_permute(ret,rhs,dimension,x,sx,cbmask,permute_type);
|
|
|
|
else Copy_plane(ret,rhs,dimension,x,sx,cbmask);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
2015-04-03 04:52:53 +01:00
|
|
|
#endif
|