mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 14:04:32 +00:00 
			
		
		
		
	Move compressors out of Cshift.
Slice iterators would help
This commit is contained in:
		@@ -30,33 +30,11 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Grid {
 | 
					namespace Grid {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<class vobj>
 | 
					 | 
				
			||||||
class SimpleCompressor {
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
  void Point(int) {};
 | 
					 | 
				
			||||||
  inline int  CommDatumSize(void) { return sizeof(vobj); }
 | 
					 | 
				
			||||||
  inline bool DecompressionStep(void) { return false; }
 | 
					 | 
				
			||||||
  inline void Compress(vobj *buf,int o,const vobj &in) { buf[o]=in; }
 | 
					 | 
				
			||||||
  inline void Exchange(vobj *mp,vobj *vp0,vobj *vp1,Integer type,Integer o){
 | 
					 | 
				
			||||||
    exchange(mp[2*o],mp[2*o+1],vp0[o],vp1[o],type);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  inline void Decompress(vobj *out,vobj *in, int o){ assert(0); }
 | 
					 | 
				
			||||||
  inline void CompressExchange(vobj *out0,vobj *out1,const vobj *in,
 | 
					 | 
				
			||||||
			       int j,int k, int m,int type){
 | 
					 | 
				
			||||||
    exchange(out0[j],out1[j],in[k],in[m],type);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  // For cshift. Cshift should drop compressor coupling altogether 
 | 
					 | 
				
			||||||
  // because I had to decouple the code from the Stencil anyway
 | 
					 | 
				
			||||||
  inline vobj operator() (const vobj &arg) {
 | 
					 | 
				
			||||||
    return arg;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
///////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////
 | 
				
			||||||
// Gather for when there is no need to SIMD split with compression
 | 
					// Gather for when there is no need to SIMD split 
 | 
				
			||||||
///////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////
 | 
				
			||||||
template<class vobj,class cobj,class compressor> void 
 | 
					template<class vobj> void 
 | 
				
			||||||
Gather_plane_simple (const Lattice<vobj> &rhs,commVector<cobj> &buffer,int dimension,int plane,int cbmask,compressor &compress, int off=0)
 | 
					Gather_plane_simple (const Lattice<vobj> &rhs,commVector<vobj> &buffer,int dimension,int plane,int cbmask, int off=0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int rd = rhs._grid->_rdimensions[dimension];
 | 
					  int rd = rhs._grid->_rdimensions[dimension];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,7 +52,7 @@ Gather_plane_simple (const Lattice<vobj> &rhs,commVector<cobj> &buffer,int dimen
 | 
				
			|||||||
      for(int b=0;b<e2;b++){
 | 
					      for(int b=0;b<e2;b++){
 | 
				
			||||||
	int o  = n*stride;
 | 
						int o  = n*stride;
 | 
				
			||||||
	int bo = n*e2;
 | 
						int bo = n*e2;
 | 
				
			||||||
	buffer[off+bo+b]=compress(rhs._odata[so+o+b]);
 | 
						buffer[off+bo+b]=rhs._odata[so+o+b];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else { 
 | 
					  } else { 
 | 
				
			||||||
@@ -90,17 +68,16 @@ Gather_plane_simple (const Lattice<vobj> &rhs,commVector<cobj> &buffer,int dimen
 | 
				
			|||||||
       }
 | 
					       }
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
     parallel_for(int i=0;i<table.size();i++){
 | 
					     parallel_for(int i=0;i<table.size();i++){
 | 
				
			||||||
       buffer[off+table[i].first]=compress(rhs._odata[so+table[i].second]);
 | 
					       buffer[off+table[i].first]=rhs._odata[so+table[i].second];
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
///////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////
 | 
				
			||||||
// Gather for when there *is* need to SIMD split with compression
 | 
					// Gather for when there *is* need to SIMD split 
 | 
				
			||||||
///////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////
 | 
				
			||||||
template<class cobj,class vobj,class compressor> void 
 | 
					template<class vobj> void 
 | 
				
			||||||
Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename cobj::scalar_object *> pointers,int dimension,int plane,int cbmask,compressor &compress)
 | 
					Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename vobj::scalar_object *> pointers,int dimension,int plane,int cbmask)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int rd = rhs._grid->_rdimensions[dimension];
 | 
					  int rd = rhs._grid->_rdimensions[dimension];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -121,8 +98,8 @@ Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename cobj::scalar_
 | 
				
			|||||||
	int o      =   n*n1;
 | 
						int o      =   n*n1;
 | 
				
			||||||
	int offset = b+n*e2;
 | 
						int offset = b+n*e2;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	cobj temp =compress(rhs._odata[so+o+b]);
 | 
						vobj temp =rhs._odata[so+o+b];
 | 
				
			||||||
	extract<cobj>(temp,pointers,offset);
 | 
						extract<vobj>(temp,pointers,offset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -139,32 +116,14 @@ Gather_plane_extract(const Lattice<vobj> &rhs,std::vector<typename cobj::scalar_
 | 
				
			|||||||
	int offset = b+n*e2;
 | 
						int offset = b+n*e2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ( ocb & cbmask ) {
 | 
						if ( ocb & cbmask ) {
 | 
				
			||||||
	  cobj temp =compress(rhs._odata[so+o+b]);
 | 
						  vobj temp =rhs._odata[so+o+b];
 | 
				
			||||||
	  extract<cobj>(temp,pointers,offset);
 | 
						  extract<vobj>(temp,pointers,offset);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//////////////////////////////////////////////////////
 | 
					 | 
				
			||||||
// Gather for when there is no need to SIMD split
 | 
					 | 
				
			||||||
//////////////////////////////////////////////////////
 | 
					 | 
				
			||||||
template<class vobj> void Gather_plane_simple (const Lattice<vobj> &rhs,commVector<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);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//////////////////////////////////////////////////////
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
// Scatter for when there is no need to SIMD split
 | 
					// Scatter for when there is no need to SIMD split
 | 
				
			||||||
//////////////////////////////////////////////////////
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
@@ -212,7 +171,7 @@ template<class vobj> void Scatter_plane_simple (Lattice<vobj> &rhs,commVector<vo
 | 
				
			|||||||
//////////////////////////////////////////////////////
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
// Scatter for when there *is* need to SIMD split
 | 
					// Scatter for when there *is* need to SIMD split
 | 
				
			||||||
//////////////////////////////////////////////////////
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
 template<class vobj,class cobj> void Scatter_plane_merge(Lattice<vobj> &rhs,std::vector<cobj *> pointers,int dimension,int plane,int cbmask)
 | 
					template<class vobj> void Scatter_plane_merge(Lattice<vobj> &rhs,std::vector<typename vobj::scalar_object *> pointers,int dimension,int plane,int cbmask)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int rd = rhs._grid->_rdimensions[dimension];
 | 
					  int rd = rhs._grid->_rdimensions[dimension];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -154,13 +154,7 @@ template<class vobj> void Cshift_comms(Lattice<vobj> &ret,const Lattice<vobj> &r
 | 
				
			|||||||
			   recv_from_rank,
 | 
								   recv_from_rank,
 | 
				
			||||||
			   bytes);
 | 
								   bytes);
 | 
				
			||||||
      grid->Barrier();
 | 
					      grid->Barrier();
 | 
				
			||||||
      /*
 | 
					
 | 
				
			||||||
      for(int i=0;i<send_buf.size();i++){
 | 
					 | 
				
			||||||
	assert(recv_buf.size()==buffer_size);
 | 
					 | 
				
			||||||
	assert(send_buf.size()==buffer_size);
 | 
					 | 
				
			||||||
	std::cout << "SendRecv_Cshift_comms ["<<i<<" "<< dimension<<"] snd "<<send_buf[i]<<" rcv " << recv_buf[i] << "  0x" << cbmask<<std::endl;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      */
 | 
					 | 
				
			||||||
      Scatter_plane_simple (ret,recv_buf,dimension,x,cbmask);
 | 
					      Scatter_plane_simple (ret,recv_buf,dimension,x,cbmask);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -246,13 +240,6 @@ template<class vobj> void  Cshift_comms_simd(Lattice<vobj> &ret,const Lattice<vo
 | 
				
			|||||||
			     (void *)&recv_buf_extract[i][0],
 | 
								     (void *)&recv_buf_extract[i][0],
 | 
				
			||||||
			     recv_from_rank,
 | 
								     recv_from_rank,
 | 
				
			||||||
			     bytes);
 | 
								     bytes);
 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	for(int w=0;w<recv_buf_extract[i].size();w++){
 | 
					 | 
				
			||||||
	  assert(recv_buf_extract[i].size()==buffer_size);
 | 
					 | 
				
			||||||
	  assert(send_buf_extract[i].size()==buffer_size);
 | 
					 | 
				
			||||||
	  std::cout << "SendRecv_Cshift_comms ["<<w<<" "<< dimension<<"] recv "<<recv_buf_extract[i][w]<<" send " << send_buf_extract[nbr_lane][w]  << cbmask<<std::endl;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	*/	
 | 
					 | 
				
			||||||
	grid->Barrier();
 | 
						grid->Barrier();
 | 
				
			||||||
	rpointers[i] = &recv_buf_extract[i][0];
 | 
						rpointers[i] = &recv_buf_extract[i][0];
 | 
				
			||||||
      } else { 
 | 
					      } else { 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user