mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-21 17:22:03 +01:00
Compare commits
9 Commits
351795ac3a
...
4efa042f50
Author | SHA1 | Date | |
---|---|---|---|
4efa042f50 | |||
c7cb37e970 | |||
d34b207eab | |||
0e6fa6f6b8 | |||
38b87de53f | |||
aa5047a9e4 | |||
24b6ee0df9 | |||
1e79cc9cbe | |||
b3925df9c3 |
@ -436,8 +436,8 @@ public:
|
||||
}
|
||||
void ExchangeCoarseLinks(void){
|
||||
for(int p=0;p<geom.npoint;p++){
|
||||
_A[p] = Cell.Exchange(_A[p]);
|
||||
_Adag[p]= Cell.Exchange(_Adag[p]);
|
||||
_A[p] = Cell.ExchangePeriodic(_A[p]);
|
||||
_Adag[p]= Cell.ExchangePeriodic(_Adag[p]);
|
||||
}
|
||||
}
|
||||
virtual void Mdiag (const Field &in, Field &out){ assert(0);};
|
||||
|
@ -30,7 +30,7 @@ int getNumBlocksAndThreads(const Iterator n, const size_t sizeofsobj, Iterator &
|
||||
cudaGetDevice(&device);
|
||||
#endif
|
||||
#ifdef GRID_HIP
|
||||
hipGetDevice(&device);
|
||||
auto discard=hipGetDevice(&device);
|
||||
#endif
|
||||
|
||||
Iterator warpSize = gpu_props[device].warpSize;
|
||||
|
@ -276,18 +276,33 @@ inline void blockProject(Lattice<iVector<CComplex,nbasis > > &coarseData,
|
||||
|
||||
autoView( coarseData_ , coarseData, AcceleratorWrite);
|
||||
autoView( ip_ , ip, AcceleratorWrite);
|
||||
RealD t_IP=0;
|
||||
RealD t_co=0;
|
||||
RealD t_za=0;
|
||||
for(int v=0;v<nbasis;v++) {
|
||||
t_IP-=usecond();
|
||||
blockInnerProductD(ip,Basis[v],fineDataRed); // ip = <basis|fine>
|
||||
t_IP+=usecond();
|
||||
t_co-=usecond();
|
||||
accelerator_for( sc, coarse->oSites(), vobj::Nsimd(), {
|
||||
convertType(coarseData_[sc](v),ip_[sc]);
|
||||
});
|
||||
t_co+=usecond();
|
||||
|
||||
// improve numerical stability of projection
|
||||
// |fine> = |fine> - <basis|fine> |basis>
|
||||
ip=-ip;
|
||||
t_za-=usecond();
|
||||
blockZAXPY(fineDataRed,ip,Basis[v],fineDataRed);
|
||||
t_za+=usecond();
|
||||
}
|
||||
// std::cout << GridLogPerformance << " blockProject : blockInnerProduct : "<<t_IP<<" us"<<std::endl;
|
||||
// std::cout << GridLogPerformance << " blockProject : conv : "<<t_co<<" us"<<std::endl;
|
||||
// std::cout << GridLogPerformance << " blockProject : blockZaxpy : "<<t_za<<" us"<<std::endl;
|
||||
}
|
||||
// This only minimises data motion from CPU to GPU
|
||||
// there is chance of better implementation that does a vxk loop of inner products to data share
|
||||
// at the GPU thread level
|
||||
template<class vobj,class CComplex,int nbasis,class VLattice>
|
||||
inline void batchBlockProject(std::vector<Lattice<iVector<CComplex,nbasis>>> &coarseData,
|
||||
const std::vector<Lattice<vobj>> &fineData,
|
||||
@ -393,8 +408,15 @@ template<class vobj,class CComplex>
|
||||
Lattice<dotp> coarse_inner(coarse);
|
||||
|
||||
// Precision promotion
|
||||
RealD t;
|
||||
t=-usecond();
|
||||
fine_inner = localInnerProductD<vobj>(fineX,fineY);
|
||||
// t+=usecond(); std::cout << GridLogPerformance << " blockInnerProduct : localInnerProductD "<<t<<" us"<<std::endl;
|
||||
|
||||
t=-usecond();
|
||||
blockSum(coarse_inner,fine_inner);
|
||||
// t+=usecond(); std::cout << GridLogPerformance << " blockInnerProduct : blockSum "<<t<<" us"<<std::endl;
|
||||
t=-usecond();
|
||||
{
|
||||
autoView( CoarseInner_ , CoarseInner,AcceleratorWrite);
|
||||
autoView( coarse_inner_ , coarse_inner,AcceleratorRead);
|
||||
@ -402,6 +424,7 @@ template<class vobj,class CComplex>
|
||||
convertType(CoarseInner_[ss], TensorRemove(coarse_inner_[ss]));
|
||||
});
|
||||
}
|
||||
// t+=usecond(); std::cout << GridLogPerformance << " blockInnerProduct : convertType "<<t<<" us"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
@ -444,6 +467,9 @@ inline void blockNormalise(Lattice<CComplex> &ip,Lattice<vobj> &fineX)
|
||||
template<class vobj>
|
||||
inline void blockSum(Lattice<vobj> &coarseData,const Lattice<vobj> &fineData)
|
||||
{
|
||||
const int maxsubsec=256;
|
||||
typedef iVector<vobj,maxsubsec> vSubsec;
|
||||
|
||||
GridBase * fine = fineData.Grid();
|
||||
GridBase * coarse= coarseData.Grid();
|
||||
|
||||
@ -471,16 +497,32 @@ inline void blockSum(Lattice<vobj> &coarseData,const Lattice<vobj> &fineData)
|
||||
|
||||
vobj zz = Zero();
|
||||
|
||||
accelerator_for(sc,coarse->oSites(),vobj::Nsimd(),{
|
||||
// Somewhat lazy calculation
|
||||
// Find the biggest power of two subsection divisor less than or equal to maxsubsec
|
||||
int subsec=maxsubsec;
|
||||
int subvol;
|
||||
subvol=blockVol/subsec;
|
||||
while(subvol*subsec!=blockVol){
|
||||
subsec = subsec/2;
|
||||
subvol=blockVol/subsec;
|
||||
};
|
||||
|
||||
Lattice<vSubsec> coarseTmp(coarse);
|
||||
autoView( coarseTmp_, coarseTmp, AcceleratorWriteDiscard);
|
||||
auto coarseTmp_p= &coarseTmp_[0];
|
||||
|
||||
// Sum within subsecs in a first kernel
|
||||
accelerator_for(sce,subsec*coarse->oSites(),vobj::Nsimd(),{
|
||||
|
||||
int sc=sce/subsec;
|
||||
int e=sce%subsec;
|
||||
|
||||
// One thread per sub block
|
||||
Coordinate coor_c(_ndimension);
|
||||
Lexicographic::CoorFromIndex(coor_c,sc,coarse_rdimensions); // Block coordinate
|
||||
|
||||
auto cd = coalescedRead(zz);
|
||||
|
||||
for(int sb=0;sb<blockVol;sb++){
|
||||
|
||||
for(int sb=e*subvol;sb<MIN((e+1)*subvol,blockVol);sb++){
|
||||
int sf;
|
||||
Coordinate coor_b(_ndimension);
|
||||
Coordinate coor_f(_ndimension);
|
||||
@ -491,9 +533,18 @@ inline void blockSum(Lattice<vobj> &coarseData,const Lattice<vobj> &fineData)
|
||||
cd=cd+coalescedRead(fineData_p[sf]);
|
||||
}
|
||||
|
||||
coalescedWrite(coarseData_p[sc],cd);
|
||||
coalescedWrite(coarseTmp_[sc](e),cd);
|
||||
|
||||
});
|
||||
// Sum across subsecs in a second kernel
|
||||
accelerator_for(sc,coarse->oSites(),vobj::Nsimd(),{
|
||||
auto cd = coalescedRead(coarseTmp_p[sc](0));
|
||||
for(int e=1;e<subsec;e++){
|
||||
cd=cd+coalescedRead(coarseTmp_p[sc](e));
|
||||
}
|
||||
coalescedWrite(coarseData_p[sc],cd);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -550,7 +601,7 @@ inline void blockOrthogonalise(Lattice<CComplex> &ip,std::vector<Lattice<vobj> >
|
||||
blockOrthonormalize(ip,Basis);
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifdef GRID_ACCELERATED
|
||||
// TODO: CPU optimized version here
|
||||
template<class vobj,class CComplex,int nbasis>
|
||||
inline void blockPromote(const Lattice<iVector<CComplex,nbasis > > &coarseData,
|
||||
@ -576,26 +627,37 @@ inline void blockPromote(const Lattice<iVector<CComplex,nbasis > > &coarseData,
|
||||
autoView( fineData_ , fineData, AcceleratorWrite);
|
||||
autoView( coarseData_ , coarseData, AcceleratorRead);
|
||||
|
||||
typedef LatticeView<vobj> Vview;
|
||||
std::vector<Vview> AcceleratorVecViewContainer_h;
|
||||
for(int v=0;v<nbasis;v++) {
|
||||
AcceleratorVecViewContainer_h.push_back(Basis[v].View(AcceleratorRead));
|
||||
}
|
||||
static deviceVector<Vview> AcceleratorVecViewContainer; AcceleratorVecViewContainer.resize(nbasis);
|
||||
acceleratorCopyToDevice(&AcceleratorVecViewContainer_h[0],&AcceleratorVecViewContainer[0],nbasis *sizeof(Vview));
|
||||
auto Basis_p = &AcceleratorVecViewContainer[0];
|
||||
// Loop with a cache friendly loop ordering
|
||||
accelerator_for(sf,fine->oSites(),1,{
|
||||
Coordinate frdimensions=fine->_rdimensions;
|
||||
Coordinate crdimensions=coarse->_rdimensions;
|
||||
accelerator_for(sf,fine->oSites(),vobj::Nsimd(),{
|
||||
int sc;
|
||||
Coordinate coor_c(_ndimension);
|
||||
Coordinate coor_f(_ndimension);
|
||||
|
||||
Lexicographic::CoorFromIndex(coor_f,sf,fine->_rdimensions);
|
||||
Lexicographic::CoorFromIndex(coor_f,sf,frdimensions);
|
||||
for(int d=0;d<_ndimension;d++) coor_c[d]=coor_f[d]/block_r[d];
|
||||
Lexicographic::IndexFromCoor(coor_c,sc,coarse->_rdimensions);
|
||||
Lexicographic::IndexFromCoor(coor_c,sc,crdimensions);
|
||||
|
||||
for(int i=0;i<nbasis;i++) {
|
||||
/* auto basis_ = Basis[i], );*/
|
||||
if(i==0) fineData_[sf]=coarseData_[sc](i) *basis_[sf]);
|
||||
else fineData_[sf]=fineData_[sf]+coarseData_[sc](i)*basis_[sf]);
|
||||
}
|
||||
auto sum= coarseData_(sc)(0) *Basis_p[0](sf);
|
||||
for(int i=1;i<nbasis;i++) sum = sum + coarseData_(sc)(i)*Basis_p[i](sf);
|
||||
coalescedWrite(fineData_[sf],sum);
|
||||
});
|
||||
for(int v=0;v<nbasis;v++) {
|
||||
AcceleratorVecViewContainer_h[v].ViewClose();
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
#else
|
||||
// CPU version
|
||||
template<class vobj,class CComplex,int nbasis,class VLattice>
|
||||
inline void blockPromote(const Lattice<iVector<CComplex,nbasis > > &coarseData,
|
||||
Lattice<vobj> &fineData,
|
||||
|
@ -291,13 +291,13 @@ public:
|
||||
return tmp;
|
||||
}
|
||||
template<class vobj>
|
||||
inline Lattice<vobj> ExchangePeriodic(const Lattice<vobj> &in, const CshiftImplBase<vobj> &cshift = CshiftImplDefault<vobj>()) const
|
||||
inline Lattice<vobj> ExchangePeriodic(const Lattice<vobj> &in) const
|
||||
{
|
||||
GridBase *old_grid = in.Grid();
|
||||
int dims = old_grid->Nd();
|
||||
Lattice<vobj> tmp = in;
|
||||
for(int d=0;d<dims;d++){
|
||||
tmp = ExpandPeriodic(d,tmp,cshift); // rvalue && assignment
|
||||
tmp = ExpandPeriodic(d,tmp); // rvalue && assignment
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
@ -376,7 +376,7 @@ public:
|
||||
}
|
||||
|
||||
template<class vobj>
|
||||
inline Lattice<vobj> ExpandPeriodic(int dim, const Lattice<vobj> &in, const CshiftImplBase<vobj> &cshift = CshiftImplDefault<vobj>()) const
|
||||
inline Lattice<vobj> ExpandPeriodic(int dim, const Lattice<vobj> &in) const
|
||||
{
|
||||
Coordinate processors=unpadded_grid->_processors;
|
||||
GridBase *old_grid = in.Grid();
|
||||
|
@ -443,7 +443,7 @@ void LambdaApply(uint64_t numx, uint64_t numy, uint64_t numz, lambda Lambda)
|
||||
|
||||
#define accelerator_barrier(dummy) \
|
||||
{ \
|
||||
hipStreamSynchronize(computeStream); \
|
||||
auto tmp=hipStreamSynchronize(computeStream); \
|
||||
auto err = hipGetLastError(); \
|
||||
if ( err != hipSuccess ) { \
|
||||
printf("After hipDeviceSynchronize() : HIP error %s \n", hipGetErrorString( err )); \
|
||||
@ -476,19 +476,19 @@ inline void *acceleratorAllocDevice(size_t bytes)
|
||||
return ptr;
|
||||
};
|
||||
|
||||
inline void acceleratorFreeShared(void *ptr){ hipFree(ptr);};
|
||||
inline void acceleratorFreeDevice(void *ptr){ hipFree(ptr);};
|
||||
inline void acceleratorCopyToDevice(void *from,void *to,size_t bytes) { hipMemcpy(to,from,bytes, hipMemcpyHostToDevice);}
|
||||
inline void acceleratorCopyFromDevice(void *from,void *to,size_t bytes){ hipMemcpy(to,from,bytes, hipMemcpyDeviceToHost);}
|
||||
inline void acceleratorFreeShared(void *ptr){ auto discard=hipFree(ptr);};
|
||||
inline void acceleratorFreeDevice(void *ptr){ auto discard=hipFree(ptr);};
|
||||
inline void acceleratorCopyToDevice(void *from,void *to,size_t bytes) { auto discard=hipMemcpy(to,from,bytes, hipMemcpyHostToDevice);}
|
||||
inline void acceleratorCopyFromDevice(void *from,void *to,size_t bytes){ auto discard=hipMemcpy(to,from,bytes, hipMemcpyDeviceToHost);}
|
||||
//inline void acceleratorCopyDeviceToDeviceAsynch(void *from,void *to,size_t bytes) { hipMemcpy(to,from,bytes, hipMemcpyDeviceToDevice);}
|
||||
//inline void acceleratorCopySynchronise(void) { }
|
||||
inline void acceleratorMemSet(void *base,int value,size_t bytes) { hipMemset(base,value,bytes);}
|
||||
inline void acceleratorMemSet(void *base,int value,size_t bytes) { auto discard=hipMemset(base,value,bytes);}
|
||||
|
||||
inline void acceleratorCopyDeviceToDeviceAsynch(void *from,void *to,size_t bytes) // Asynch
|
||||
{
|
||||
hipMemcpyDtoDAsync(to,from,bytes, copyStream);
|
||||
auto discard=hipMemcpyDtoDAsync(to,from,bytes, copyStream);
|
||||
}
|
||||
inline void acceleratorCopySynchronise(void) { hipStreamSynchronize(copyStream); };
|
||||
inline void acceleratorCopySynchronise(void) { auto discard=hipStreamSynchronize(copyStream); };
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -414,7 +414,7 @@ void Grid_init(int *argc,char ***argv)
|
||||
// Logging
|
||||
////////////////////////////////////
|
||||
std::vector<std::string> logstreams;
|
||||
std::string defaultLog("Error,Warning,Message,Performance");
|
||||
std::string defaultLog("Error,Warning,Message,Memory");
|
||||
GridCmdOptionCSL(defaultLog,logstreams);
|
||||
GridLogConfigure(logstreams);
|
||||
|
||||
|
@ -41,7 +41,7 @@ AC_PROG_RANLIB
|
||||
|
||||
############### Get compiler informations
|
||||
AC_LANG([C++])
|
||||
AX_CXX_COMPILE_STDCXX(14,noext,mandatory)
|
||||
AX_CXX_COMPILE_STDCXX(17,noext,mandatory)
|
||||
AX_COMPILER_VENDOR
|
||||
AC_DEFINE_UNQUOTED([CXX_COMP_VENDOR],["$ax_cv_cxx_compiler_vendor"],
|
||||
[vendor of C++ compiler that will compile the code])
|
||||
|
1018
m4/ax_cxx_compile_stdcxx.m4
Normal file
1018
m4/ax_cxx_compile_stdcxx.m4
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ CLIME=`spack find --paths c-lime@2-3-9 | grep c-lime| cut -c 15-`
|
||||
--with-mpfr=/opt/cray/pe/gcc/mpfr/3.1.4/ \
|
||||
--disable-fermion-reps \
|
||||
CXX=hipcc MPICXX=mpicxx \
|
||||
CXXFLAGS="-fPIC -I{$ROCM_PATH}/include/ -std=c++14 -I${MPICH_DIR}/include -L/lib64 " \
|
||||
CXXFLAGS="-fPIC -I{$ROCM_PATH}/include/ -I${MPICH_DIR}/include -L/lib64 " \
|
||||
LDFLAGS="-L/lib64 -L${MPICH_DIR}/lib -lmpi -L${CRAY_MPICH_ROOTDIR}/gtl/lib -lmpi_gtl_hsa -lamdhip64 "
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user