1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 21:50:45 +01:00

Hadrons: meson fields saved in single precision

This commit is contained in:
Antonin Portelli 2018-08-14 17:19:38 +01:00
parent 2c67304716
commit 09001aedca
2 changed files with 30 additions and 27 deletions

View File

@ -38,6 +38,9 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp> #include <Grid/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp>
#define MF_PARALLEL_IO #define MF_PARALLEL_IO
#ifndef MF_IO_TYPE
#define MF_IO_TYPE ComplexF
#endif
BEGIN_HADRONS_NAMESPACE BEGIN_HADRONS_NAMESPACE
@ -65,6 +68,8 @@ class TA2AMesonField : public Module<A2AMesonFieldPar>
public: public:
FERM_TYPE_ALIASES(FImpl,); FERM_TYPE_ALIASES(FImpl,);
SOLVER_TYPE_ALIASES(FImpl,); SOLVER_TYPE_ALIASES(FImpl,);
typedef Eigen::TensorMap<Eigen::Tensor<Complex, 5, Eigen::RowMajor>> MesonField;
typedef Eigen::TensorMap<Eigen::Tensor<MF_IO_TYPE, 5, Eigen::RowMajor>> MesonFieldIo;
public: public:
// constructor // constructor
TA2AMesonField(const std::string name); TA2AMesonField(const std::string name);
@ -82,14 +87,14 @@ private:
std::string ioname(unsigned int m, unsigned int g) const; std::string ioname(unsigned int m, unsigned int g) const;
std::string filename(unsigned int m, unsigned int g) const; std::string filename(unsigned int m, unsigned int g) const;
void initFile(unsigned int m, unsigned int g); void initFile(unsigned int m, unsigned int g);
void saveBlock(const MesonField &mf, void saveBlock(const MesonFieldIo &mf,
unsigned int m, unsigned int g, unsigned int m, unsigned int g,
unsigned int i, unsigned int j); unsigned int i, unsigned int j);
private: private:
bool hasPhase_{false}; bool hasPhase_{false};
std::string momphName_; std::string momphName_;
std::vector<Gamma::Algebra> gamma_; std::vector<Gamma::Algebra> gamma_;
std::vector<std::vector<double>> mom_; std::vector<std::vector<double>> mom_;
std::vector<std::pair<unsigned int, unsigned int>> nodeFile_; std::vector<std::pair<unsigned int, unsigned int>> nodeFile_;
}; };
@ -174,7 +179,7 @@ void TA2AMesonField<FImpl>::setup(void)
// preallocate memory for meson field block // preallocate memory for meson field block
auto tgp = env().getDim().back()*gamma_.size()*mom_.size(); auto tgp = env().getDim().back()*gamma_.size()*mom_.size();
envTmp(Vector<Complex>, "mfBuf", 1, tgp*par().block*par().block); envTmp(Vector<MF_IO_TYPE>, "mfBuf", 1, tgp*par().block*par().block);
envTmp(Vector<Complex>, "mfCache", 1, tgp*par().cacheBlock*par().cacheBlock); envTmp(Vector<Complex>, "mfCache", 1, tgp*par().cacheBlock*par().cacheBlock);
} }
@ -195,18 +200,19 @@ void TA2AMesonField<FImpl>::execute(void)
LOG(Message) << "Computing all-to-all meson fields" << std::endl; LOG(Message) << "Computing all-to-all meson fields" << std::endl;
LOG(Message) << "W: '" << par().w << "' V: '" << par().v << "'" << std::endl; LOG(Message) << "W: '" << par().w << "' V: '" << par().v << "'" << std::endl;
LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j
<< " (" << sizeString(nt*N_i*N_j*sizeof(Complex)) << ")" << std::endl;
LOG(Message) << "Momenta:" << std::endl; LOG(Message) << "Momenta:" << std::endl;
for (auto &p: mom_) for (auto &p: mom_)
{ {
LOG(Message) << " " << p << std::endl; LOG(Message) << " " << p << std::endl;
} }
LOG(Message) << "Spin structures:" << std::endl; LOG(Message) << "Spin bilinears:" << std::endl;
for (auto &g: gamma_) for (auto &g: gamma_)
{ {
LOG(Message) << " " << g << std::endl; LOG(Message) << " " << g << std::endl;
} }
LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j
<< " (filesize " << sizeString(nt*N_i*N_j*sizeof(MF_IO_TYPE))
<< "/momentum/bilinear)" << std::endl;
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Momentum setup // Momentum setup
@ -246,8 +252,7 @@ void TA2AMesonField<FImpl>::execute(void)
double vol = env().getVolume(); double vol = env().getVolume();
double t_contr=0; double t_contr=0;
envGetTmp(Vector<MF_IO_TYPE>, mfBuf);
envGetTmp(Vector<Complex>, mfBuf);
envGetTmp(Vector<Complex>, mfCache); envGetTmp(Vector<Complex>, mfCache);
double t0 = usecond(); double t0 = usecond();
@ -267,7 +272,7 @@ void TA2AMesonField<FImpl>::execute(void)
<< i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]" << i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]"
<< std::endl; << std::endl;
MesonField mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj); MesonFieldIo mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj);
// Series of cache blocked chunks of the contractions within this block // Series of cache blocked chunks of the contractions within this block
for(int ii=0;ii<N_ii;ii+=cacheBlock) for(int ii=0;ii<N_ii;ii+=cacheBlock)
@ -361,7 +366,7 @@ void TA2AMesonField<FImpl>::execute(void)
} }
#endif #endif
stopTimer("IO: total"); stopTimer("IO: total");
blockSize = static_cast<double>(nmom*ngamma*nt*N_ii*N_jj*sizeof(Complex)); blockSize = static_cast<double>(nmom*ngamma*nt*N_ii*N_jj*sizeof(MF_IO_TYPE));
ioTime += getDTimer("IO: write block"); ioTime += getDTimer("IO: write block");
LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in " LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in "
<< ioTime << " us (" << ioTime << " us ("
@ -427,7 +432,7 @@ void TA2AMesonField<FImpl>::initFile(unsigned int m, unsigned int g)
write(writer, "gamma", gamma_[g]); write(writer, "gamma", gamma_[g]);
auto &group = writer.getGroup(); auto &group = writer.getGroup();
plist.setChunk(chunk.size(), chunk.data()); plist.setChunk(chunk.size(), chunk.data());
dataset = group.createDataSet("mesonField", Hdf5Type<Complex>::type(), dataset = group.createDataSet("mesonField", Hdf5Type<MF_IO_TYPE>::type(),
dataspace, plist); dataspace, plist);
#else #else
HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library"); HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library");
@ -435,7 +440,7 @@ void TA2AMesonField<FImpl>::initFile(unsigned int m, unsigned int g)
} }
template <typename FImpl> template <typename FImpl>
void TA2AMesonField<FImpl>::saveBlock(const MesonField &mf, void TA2AMesonField<FImpl>::saveBlock(const MesonFieldIo &mf,
unsigned int m, unsigned int g, unsigned int m, unsigned int g,
unsigned int i, unsigned int j) unsigned int i, unsigned int j)
{ {
@ -443,13 +448,13 @@ void TA2AMesonField<FImpl>::saveBlock(const MesonField &mf,
std::string f = filename(m, g); std::string f = filename(m, g);
Hdf5Reader reader(f); Hdf5Reader reader(f);
hsize_t nt = mf.dimension(2), hsize_t nt = mf.dimension(2),
Ni = mf.dimension(3), Ni = mf.dimension(3),
Nj = mf.dimension(4); Nj = mf.dimension(4);
std::vector<hsize_t> count = {nt, Ni, Nj}, std::vector<hsize_t> count = {nt, Ni, Nj},
offset = {0, static_cast<hsize_t>(i), offset = {0, static_cast<hsize_t>(i),
static_cast<hsize_t>(j)}, static_cast<hsize_t>(j)},
stride = {1, 1, 1}, stride = {1, 1, 1},
block = {1, 1, 1}; block = {1, 1, 1};
H5NS::DataSpace memspace(count.size(), count.data()), dataspace; H5NS::DataSpace memspace(count.size(), count.data()), dataspace;
H5NS::DataSet dataset; H5NS::DataSet dataset;
size_t shift; size_t shift;
@ -459,10 +464,10 @@ void TA2AMesonField<FImpl>::saveBlock(const MesonField &mf,
dataset = group.openDataSet("mesonField"); dataset = group.openDataSet("mesonField");
dataspace = dataset.getSpace(); dataspace = dataset.getSpace();
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(), dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
stride.data(), block.data()); stride.data(), block.data());
shift = (m*mf.dimension(1) + g)*nt*Ni*Nj; shift = (m*mf.dimension(1) + g)*nt*Ni*Nj;
dataset.write(mf.data() + shift, Hdf5Type<Complex>::type(), memspace, dataset.write(mf.data() + shift, Hdf5Type<MF_IO_TYPE>::type(), memspace,
dataspace); dataspace);
#else #else
HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library"); HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library");
#endif #endif

View File

@ -37,13 +37,11 @@ BEGIN_HADRONS_NAMESPACE
BEGIN_MODULE_NAMESPACE(MContraction) BEGIN_MODULE_NAMESPACE(MContraction)
typedef Eigen::TensorMap<Eigen::Tensor<Complex, 5, Eigen::RowMajor>> MesonField;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Cache blocked arithmetic routine // Cache blocked arithmetic routine
// Could move to Grid ??? // Could move to Grid ???
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename Field> template <typename Field, typename MesonField>
void makeMesonFieldBlock(MesonField &mat, void makeMesonFieldBlock(MesonField &mat,
const Field *lhs_wi, const Field *lhs_wi,
const Field *rhs_vj, const Field *rhs_vj,