mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Hadrons: code cleaning
This commit is contained in:
parent
f6593dc881
commit
9f4f8a14a3
@ -41,7 +41,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
|||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
// general A2A matrix set class based on Eigen tensors and Grid-allocated memory
|
// general A2A matrix set based on Eigen tensors and Grid-allocated memory
|
||||||
// Dimensions:
|
// Dimensions:
|
||||||
// 0 - ext - external field (momentum, EM field, ...)
|
// 0 - ext - external field (momentum, EM field, ...)
|
||||||
// 1 - str - spin-color structure
|
// 1 - str - spin-color structure
|
||||||
@ -51,26 +51,9 @@ BEGIN_HADRONS_NAMESPACE
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using A2AMatrixSet = Eigen::TensorMap<Eigen::Tensor<T, 5, Eigen::RowMajor>>;
|
using A2AMatrixSet = Eigen::TensorMap<Eigen::Tensor<T, 5, Eigen::RowMajor>>;
|
||||||
|
|
||||||
template <typename T>
|
/******************************************************************************
|
||||||
class A2AMatrixIo
|
* Abstract class for A2A kernels *
|
||||||
{
|
******************************************************************************/
|
||||||
public:
|
|
||||||
A2AMatrixIo(void) = default;
|
|
||||||
A2AMatrixIo(std::string filename, std::string dataname,
|
|
||||||
const unsigned int nt, const unsigned int ni,
|
|
||||||
const unsigned int nj);
|
|
||||||
~A2AMatrixIo(void) = default;
|
|
||||||
template <typename MetadataType>
|
|
||||||
void initFile(const MetadataType &d, const unsigned int chunkSize);
|
|
||||||
void saveBlock(const T *data, const unsigned int i, const unsigned int j,
|
|
||||||
const unsigned int blockSizei, const unsigned int blockSizej);
|
|
||||||
void saveBlock(const A2AMatrixSet<T> &m, const unsigned int ext, const unsigned int str,
|
|
||||||
const unsigned int i, const unsigned int j);
|
|
||||||
private:
|
|
||||||
std::string filename_, dataname_;
|
|
||||||
unsigned int nt_, ni_, nj_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, typename Field>
|
template <typename T, typename Field>
|
||||||
class A2AKernel
|
class A2AKernel
|
||||||
{
|
{
|
||||||
@ -83,6 +66,36 @@ public:
|
|||||||
virtual double bytes(const unsigned int blockSizei, const unsigned int blockSizej) = 0;
|
virtual double bytes(const unsigned int blockSizei, const unsigned int blockSizej) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Class to handle A2A matrix block HDF5 I/O *
|
||||||
|
******************************************************************************/
|
||||||
|
template <typename T>
|
||||||
|
class A2AMatrixIo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
A2AMatrixIo(void) = default;
|
||||||
|
A2AMatrixIo(std::string filename, std::string dataname,
|
||||||
|
const unsigned int nt, const unsigned int ni,
|
||||||
|
const unsigned int nj);
|
||||||
|
// destructor
|
||||||
|
~A2AMatrixIo(void) = default;
|
||||||
|
// file allocation
|
||||||
|
template <typename MetadataType>
|
||||||
|
void initFile(const MetadataType &d, const unsigned int chunkSize);
|
||||||
|
// block I/O
|
||||||
|
void saveBlock(const T *data, const unsigned int i, const unsigned int j,
|
||||||
|
const unsigned int blockSizei, const unsigned int blockSizej);
|
||||||
|
void saveBlock(const A2AMatrixSet<T> &m, const unsigned int ext, const unsigned int str,
|
||||||
|
const unsigned int i, const unsigned int j);
|
||||||
|
private:
|
||||||
|
std::string filename_, dataname_;
|
||||||
|
unsigned int nt_, ni_, nj_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Wrapper for A2A matrix block computation *
|
||||||
|
******************************************************************************/
|
||||||
template <typename T, typename Field, typename MetadataType, typename TIo = T>
|
template <typename T, typename Field, typename MetadataType, typename TIo = T>
|
||||||
class A2AMatrixBlockComputation
|
class A2AMatrixBlockComputation
|
||||||
{
|
{
|
||||||
@ -96,6 +109,7 @@ private:
|
|||||||
typedef std::function<std::string(const unsigned int, const unsigned int)> FilenameFn;
|
typedef std::function<std::string(const unsigned int, const unsigned int)> FilenameFn;
|
||||||
typedef std::function<MetadataType(const unsigned int, const unsigned int)> MetadataFn;
|
typedef std::function<MetadataType(const unsigned int, const unsigned int)> MetadataFn;
|
||||||
public:
|
public:
|
||||||
|
// constructor
|
||||||
A2AMatrixBlockComputation(GridBase *grid,
|
A2AMatrixBlockComputation(GridBase *grid,
|
||||||
const unsigned int orthogDim,
|
const unsigned int orthogDim,
|
||||||
const unsigned int next,
|
const unsigned int next,
|
||||||
@ -103,6 +117,7 @@ public:
|
|||||||
const unsigned int blockSize,
|
const unsigned int blockSize,
|
||||||
const unsigned int cacheBlockSize,
|
const unsigned int cacheBlockSize,
|
||||||
TimerArray *tArray = nullptr);
|
TimerArray *tArray = nullptr);
|
||||||
|
// execution
|
||||||
void execute(const std::vector<Field> &left,
|
void execute(const std::vector<Field> &left,
|
||||||
const std::vector<Field> &right,
|
const std::vector<Field> &right,
|
||||||
A2AKernel<T, Field> &kernel,
|
A2AKernel<T, Field> &kernel,
|
||||||
@ -110,6 +125,7 @@ public:
|
|||||||
const FilenameFn &filenameFn,
|
const FilenameFn &filenameFn,
|
||||||
const MetadataFn &metadataFn);
|
const MetadataFn &metadataFn);
|
||||||
private:
|
private:
|
||||||
|
// I/O handler
|
||||||
void saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h);
|
void saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h);
|
||||||
private:
|
private:
|
||||||
TimerArray *tArray_;
|
TimerArray *tArray_;
|
||||||
@ -120,6 +136,100 @@ private:
|
|||||||
std::vector<IoHelper> nodeIo_;
|
std::vector<IoHelper> nodeIo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* A2AMatrixIo template implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
A2AMatrixIo<T>::A2AMatrixIo(std::string filename, std::string dataname,
|
||||||
|
const unsigned int nt, const unsigned int ni,
|
||||||
|
const unsigned int nj)
|
||||||
|
: filename_(filename), dataname_(dataname)
|
||||||
|
, nt_(nt), ni_(ni), nj_(nj)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// file allocation /////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
template <typename MetadataType>
|
||||||
|
void A2AMatrixIo<T>::initFile(const MetadataType &d, const unsigned int chunkSize)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_HDF5
|
||||||
|
std::vector<hsize_t> dim = {static_cast<hsize_t>(nt_),
|
||||||
|
static_cast<hsize_t>(ni_),
|
||||||
|
static_cast<hsize_t>(nj_)},
|
||||||
|
chunk = {static_cast<hsize_t>(nt_),
|
||||||
|
static_cast<hsize_t>(chunkSize),
|
||||||
|
static_cast<hsize_t>(chunkSize)};
|
||||||
|
H5NS::DataSpace dataspace(dim.size(), dim.data());
|
||||||
|
H5NS::DataSet dataset;
|
||||||
|
H5NS::DSetCreatPropList plist;
|
||||||
|
|
||||||
|
// create empty file just with metadata
|
||||||
|
{
|
||||||
|
Hdf5Writer writer(filename_);
|
||||||
|
write(writer, dataname_, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the dataset
|
||||||
|
Hdf5Reader reader(filename_);
|
||||||
|
|
||||||
|
push(reader, dataname_);
|
||||||
|
auto &group = reader.getGroup();
|
||||||
|
plist.setChunk(chunk.size(), chunk.data());
|
||||||
|
dataset = group.createDataSet(HADRONS_A2AM_NAME, Hdf5Type<T>::type(), dataspace, plist);
|
||||||
|
#else
|
||||||
|
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// block I/O ///////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
void A2AMatrixIo<T>::saveBlock(const T *data,
|
||||||
|
const unsigned int i,
|
||||||
|
const unsigned int j,
|
||||||
|
const unsigned int blockSizei,
|
||||||
|
const unsigned int blockSizej)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_HDF5
|
||||||
|
Hdf5Reader reader(filename_);
|
||||||
|
std::vector<hsize_t> count = {nt_, blockSizei, blockSizej},
|
||||||
|
offset = {0, static_cast<hsize_t>(i),
|
||||||
|
static_cast<hsize_t>(j)},
|
||||||
|
stride = {1, 1, 1},
|
||||||
|
block = {1, 1, 1};
|
||||||
|
H5NS::DataSpace memspace(count.size(), count.data()), dataspace;
|
||||||
|
H5NS::DataSet dataset;
|
||||||
|
size_t shift;
|
||||||
|
|
||||||
|
push(reader, dataname_);
|
||||||
|
auto &group = reader.getGroup();
|
||||||
|
dataset = group.openDataSet(HADRONS_A2AM_NAME);
|
||||||
|
dataspace = dataset.getSpace();
|
||||||
|
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
|
||||||
|
stride.data(), block.data());
|
||||||
|
dataset.write(data, Hdf5Type<T>::type(), memspace, dataspace);
|
||||||
|
#else
|
||||||
|
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
|
||||||
|
const unsigned int ext, const unsigned int str,
|
||||||
|
const unsigned int i, const unsigned int j)
|
||||||
|
{
|
||||||
|
unsigned int blockSizei = m.dimension(3);
|
||||||
|
unsigned int blockSizej = m.dimension(4);
|
||||||
|
unsigned int nstr = m.dimension(1);
|
||||||
|
size_t offset = (ext*nstr + str)*nt_*blockSizei*blockSizej;
|
||||||
|
|
||||||
|
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* A2AMatrixBlockComputation template implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||||
A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||||
::A2AMatrixBlockComputation(GridBase *grid,
|
::A2AMatrixBlockComputation(GridBase *grid,
|
||||||
@ -133,23 +243,15 @@ A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
, next_(next), nstr_(nstr), blockSize_(blockSize), cacheBlockSize_(cacheBlockSize)
|
, next_(next), nstr_(nstr), blockSize_(blockSize), cacheBlockSize_(cacheBlockSize)
|
||||||
, tArray_(tArray)
|
, tArray_(tArray)
|
||||||
{
|
{
|
||||||
std::cout << nt_ << std::endl;
|
|
||||||
std::cout << next_ << std::endl;
|
|
||||||
std::cout << nstr_ << std::endl;
|
|
||||||
std::cout << cacheBlockSize_ << std::endl;
|
|
||||||
std::cout << blockSize_ << std::endl;
|
|
||||||
mCache_.resize(nt_*next_*nstr_*cacheBlockSize_*cacheBlockSize_);
|
mCache_.resize(nt_*next_*nstr_*cacheBlockSize_*cacheBlockSize_);
|
||||||
mBuf_.resize(nt_*next_*nstr_*blockSize_*blockSize_);
|
mBuf_.resize(nt_*next_*nstr_*blockSize_*blockSize_);
|
||||||
std::cout << mCache_.size() << std::endl;
|
|
||||||
std::cout << mBuf_.size() << std::endl;
|
|
||||||
std::cout << blockSize << std::endl;
|
|
||||||
std::cout << cacheBlockSize << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define START_TIMER(name) if (tArray_) tArray_->startTimer(name)
|
#define START_TIMER(name) if (tArray_) tArray_->startTimer(name)
|
||||||
#define STOP_TIMER(name) if (tArray_) tArray_->stopTimer(name)
|
#define STOP_TIMER(name) if (tArray_) tArray_->stopTimer(name)
|
||||||
#define GET_TIMER(name) ((tArray_ != nullptr) ? tArray_->getDTimer(name) : 0.)
|
#define GET_TIMER(name) ((tArray_ != nullptr) ? tArray_->getDTimer(name) : 0.)
|
||||||
|
|
||||||
|
// execution ///////////////////////////////////////////////////////////////////
|
||||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||||
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||||
::execute(const std::vector<Field> &left, const std::vector<Field> &right,
|
::execute(const std::vector<Field> &left, const std::vector<Field> &right,
|
||||||
@ -157,20 +259,16 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
const FilenameFn &filenameFn, const MetadataFn &metadataFn)
|
const FilenameFn &filenameFn, const MetadataFn &metadataFn)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// i,j is first loop over SchurBlock factors reusing 5D matrices
|
// i,j is first loop over blockSize_ factors
|
||||||
// ii,jj is second loop over cacheBlock factors for high perf contractoin
|
// ii,jj is second loop over cacheBlockSize_ factors for high perf contractions
|
||||||
// iii,jjj are loops within cacheBlock
|
// iii,jjj are loops within cacheBlock
|
||||||
// Total index is sum of these i+ii+iii etc...
|
// Total index is sum of these i+ii+iii etc...
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int N_i = left.size();
|
int N_i = left.size();
|
||||||
int N_j = right.size();
|
int N_j = right.size();
|
||||||
double flops;
|
double flops, bytes, t_kernel;
|
||||||
double bytes;
|
double nodes = grid_->NodeCount();
|
||||||
double t_kernel = 0.;
|
|
||||||
double nodes = grid_->NodeCount();
|
|
||||||
double tot_kernel;
|
|
||||||
|
|
||||||
double t0 = usecond();
|
|
||||||
int NBlock_i = N_i/blockSize_ + (((N_i % blockSize_) != 0) ? 1 : 0);
|
int NBlock_i = N_i/blockSize_ + (((N_i % blockSize_) != 0) ? 1 : 0);
|
||||||
int NBlock_j = N_j/blockSize_ + (((N_j % blockSize_) != 0) ? 1 : 0);
|
int NBlock_j = N_j/blockSize_ + (((N_j % blockSize_) != 0) ? 1 : 0);
|
||||||
|
|
||||||
@ -180,15 +278,13 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
// Get the W and V vectors for this block^2 set of terms
|
// Get the W and V vectors for this block^2 set of terms
|
||||||
int N_ii = MIN(N_i-i,blockSize_);
|
int N_ii = MIN(N_i-i,blockSize_);
|
||||||
int N_jj = MIN(N_j-j,blockSize_);
|
int N_jj = MIN(N_j-j,blockSize_);
|
||||||
|
A2AMatrixSet<TIo> mBlock(mBuf_.data(), next_, nstr_, nt_, N_ii, N_jj);
|
||||||
|
|
||||||
LOG(Message) << "All-to-all matrix block "
|
LOG(Message) << "All-to-all matrix block "
|
||||||
<< j/blockSize_ + NBlock_j*i/blockSize_ + 1
|
<< j/blockSize_ + NBlock_j*i/blockSize_ + 1
|
||||||
<< "/" << NBlock_i*NBlock_j << " [" << i <<" .. "
|
<< "/" << NBlock_i*NBlock_j << " [" << i <<" .. "
|
||||||
<< i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]"
|
<< i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
A2AMatrixSet<TIo> mBlock(mBuf_.data(), next_, nstr_, 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
|
||||||
flops = 0.0;
|
flops = 0.0;
|
||||||
bytes = 0.0;
|
bytes = 0.0;
|
||||||
@ -201,18 +297,12 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
int N_jjj = MIN(N_jj-jj,cacheBlockSize_);
|
int N_jjj = MIN(N_jj-jj,cacheBlockSize_);
|
||||||
A2AMatrixSet<T> mCacheBlock(mCache_.data(), next_, nstr_, nt_, N_iii, N_jjj);
|
A2AMatrixSet<T> mCacheBlock(mCache_.data(), next_, nstr_, nt_, N_iii, N_jjj);
|
||||||
|
|
||||||
// makeMesonFieldBlock(mfCacheBlock, &w[i+ii], &v[j+jj], gamma_, ph,
|
|
||||||
// env().getNd() - 1, this);
|
|
||||||
START_TIMER("kernel");
|
START_TIMER("kernel");
|
||||||
kernel(mCacheBlock, &left[i+ii], &right[j+jj], orthogDim_, t);
|
kernel(mCacheBlock, &left[i+ii], &right[j+jj], orthogDim_, t);
|
||||||
STOP_TIMER("kernel");
|
STOP_TIMER("kernel");
|
||||||
t_kernel += t;
|
t_kernel += t;
|
||||||
// flops for general N_c & N_s
|
flops += kernel.flops(N_iii, N_jjj);
|
||||||
// flops += vol * ( 2 * 8.0 + 6.0 + 8.0*nmom) * N_iii*N_jjj*ngamma;
|
bytes += kernel.bytes(N_iii, N_jjj);
|
||||||
// bytes += vol * (12.0 * sizeof(Complex) ) * N_iii*N_jjj
|
|
||||||
// + vol * ( 2.0 * sizeof(Complex) *nmom ) * N_iii*N_jjj* ngamma;
|
|
||||||
flops += kernel.flops(N_iii, N_jjj);
|
|
||||||
bytes += kernel.bytes(N_iii, N_jjj);
|
|
||||||
|
|
||||||
START_TIMER("cache copy");
|
START_TIMER("cache copy");
|
||||||
parallel_for_nest5(int e =0;e<next_;e++)
|
parallel_for_nest5(int e =0;e<next_;e++)
|
||||||
@ -227,8 +317,6 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perf
|
// perf
|
||||||
// tot_kernel = getDTimer("contraction: colour trace & mom.")
|
|
||||||
// + getDTimer("contraction: local space sum");
|
|
||||||
LOG(Message) << "Kernel perf " << flops/t_kernel/1.0e3/nodes
|
LOG(Message) << "Kernel perf " << flops/t_kernel/1.0e3/nodes
|
||||||
<< " Gflop/s/node " << std::endl;
|
<< " Gflop/s/node " << std::endl;
|
||||||
LOG(Message) << "Kernel perf " << bytes/t_kernel*1.0e6/1024/1024/1024/nodes
|
LOG(Message) << "Kernel perf " << bytes/t_kernel*1.0e6/1024/1024/1024/nodes
|
||||||
@ -236,8 +324,7 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
|
|
||||||
// IO
|
// IO
|
||||||
double blockSize, ioTime;
|
double blockSize, ioTime;
|
||||||
unsigned int myRank = grid_->ThisRank(),
|
unsigned int myRank = grid_->ThisRank(), nRank = grid_->RankCount();
|
||||||
nRank = grid_->RankCount();
|
|
||||||
|
|
||||||
LOG(Message) << "Writing block to disk" << std::endl;
|
LOG(Message) << "Writing block to disk" << std::endl;
|
||||||
ioTime = -GET_TIMER("IO: write block");
|
ioTime = -GET_TIMER("IO: write block");
|
||||||
@ -293,6 +380,7 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I/O handler /////////////////////////////////////////////////////////////////
|
||||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||||
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||||
::saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h)
|
::saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h)
|
||||||
@ -308,91 +396,9 @@ void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
|||||||
STOP_TIMER("IO: write block");
|
STOP_TIMER("IO: write block");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
#undef START_TIMER
|
||||||
A2AMatrixIo<T>::A2AMatrixIo(std::string filename, std::string dataname,
|
#undef STOP_TIMER
|
||||||
const unsigned int nt, const unsigned int ni,
|
#undef GET_TIMER
|
||||||
const unsigned int nj)
|
|
||||||
: filename_(filename), dataname_(dataname)
|
|
||||||
, nt_(nt), ni_(ni), nj_(nj)
|
|
||||||
{}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
template <typename MetadataType>
|
|
||||||
void A2AMatrixIo<T>::initFile(const MetadataType &d, const unsigned int chunkSize)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_HDF5
|
|
||||||
std::vector<hsize_t> dim = {static_cast<hsize_t>(nt_),
|
|
||||||
static_cast<hsize_t>(ni_),
|
|
||||||
static_cast<hsize_t>(nj_)},
|
|
||||||
chunk = {static_cast<hsize_t>(nt_),
|
|
||||||
static_cast<hsize_t>(chunkSize),
|
|
||||||
static_cast<hsize_t>(chunkSize)};
|
|
||||||
H5NS::DataSpace dataspace(dim.size(), dim.data());
|
|
||||||
H5NS::DataSet dataset;
|
|
||||||
H5NS::DSetCreatPropList plist;
|
|
||||||
|
|
||||||
// create empty file just with metadata
|
|
||||||
{
|
|
||||||
Hdf5Writer writer(filename_);
|
|
||||||
write(writer, dataname_, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the dataset
|
|
||||||
Hdf5Reader reader(filename_);
|
|
||||||
|
|
||||||
push(reader, dataname_);
|
|
||||||
auto &group = reader.getGroup();
|
|
||||||
plist.setChunk(chunk.size(), chunk.data());
|
|
||||||
dataset = group.createDataSet(HADRONS_A2AM_NAME, Hdf5Type<T>::type(), dataspace, plist);
|
|
||||||
#else
|
|
||||||
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void A2AMatrixIo<T>::saveBlock(const T *data,
|
|
||||||
const unsigned int i,
|
|
||||||
const unsigned int j,
|
|
||||||
const unsigned int blockSizei,
|
|
||||||
const unsigned int blockSizej)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_HDF5
|
|
||||||
Hdf5Reader reader(filename_);
|
|
||||||
std::vector<hsize_t> count = {nt_, blockSizei, blockSizej},
|
|
||||||
offset = {0, static_cast<hsize_t>(i),
|
|
||||||
static_cast<hsize_t>(j)},
|
|
||||||
stride = {1, 1, 1},
|
|
||||||
block = {1, 1, 1};
|
|
||||||
H5NS::DataSpace memspace(count.size(), count.data()), dataspace;
|
|
||||||
H5NS::DataSet dataset;
|
|
||||||
size_t shift;
|
|
||||||
|
|
||||||
push(reader, dataname_);
|
|
||||||
auto &group = reader.getGroup();
|
|
||||||
dataset = group.openDataSet(HADRONS_A2AM_NAME);
|
|
||||||
dataspace = dataset.getSpace();
|
|
||||||
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
|
|
||||||
stride.data(), block.data());
|
|
||||||
dataset.write(data, Hdf5Type<T>::type(), memspace, dataspace);
|
|
||||||
#else
|
|
||||||
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
|
|
||||||
const unsigned int ext, const unsigned int str,
|
|
||||||
const unsigned int i, const unsigned int j)
|
|
||||||
{
|
|
||||||
unsigned int blockSizei = m.dimension(3);
|
|
||||||
unsigned int blockSizej = m.dimension(4);
|
|
||||||
unsigned int nstr = m.dimension(1);
|
|
||||||
size_t offset = (ext*nstr + str)*nt_*blockSizei*blockSizej;
|
|
||||||
|
|
||||||
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ public:
|
|||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMesonFieldPar,
|
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMesonFieldPar,
|
||||||
int, cacheBlock,
|
int, cacheBlock,
|
||||||
int, block,
|
int, block,
|
||||||
std::string, v,
|
std::string, left,
|
||||||
std::string, w,
|
std::string, right,
|
||||||
std::string, output,
|
std::string, output,
|
||||||
std::string, gammas,
|
std::string, gammas,
|
||||||
std::vector<std::string>, mom);
|
std::vector<std::string>, mom);
|
||||||
@ -140,11 +140,6 @@ public:
|
|||||||
virtual void setup(void);
|
virtual void setup(void);
|
||||||
// execution
|
// execution
|
||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
private:
|
|
||||||
// IO
|
|
||||||
std::string ioname(const unsigned int m, const unsigned int g) const;
|
|
||||||
std::string filename(const unsigned int m, const unsigned int g) const;
|
|
||||||
void saveBlock(const A2AMatrixSet<MF_IO_TYPE> &mf, IoHelper &h);
|
|
||||||
private:
|
private:
|
||||||
bool hasPhase_{false};
|
bool hasPhase_{false};
|
||||||
std::string momphName_;
|
std::string momphName_;
|
||||||
@ -154,7 +149,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
MODULE_REGISTER(A2AMesonField, ARG(TA2AMesonField<FIMPL>), MContraction);
|
MODULE_REGISTER(A2AMesonField, ARG(TA2AMesonField<FIMPL>), MContraction);
|
||||||
MODULE_REGISTER(ZA2AMesonField, ARG(TA2AMesonField<ZFIMPL>), MContraction);
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* TA2AMesonField implementation *
|
* TA2AMesonField implementation *
|
||||||
@ -171,7 +165,7 @@ TA2AMesonField<FImpl>::TA2AMesonField(const std::string name)
|
|||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
std::vector<std::string> TA2AMesonField<FImpl>::getInput(void)
|
std::vector<std::string> TA2AMesonField<FImpl>::getInput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> in = {par().v, par().w};
|
std::vector<std::string> in = {par().left, par().right};
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@ -227,7 +221,6 @@ void TA2AMesonField<FImpl>::setup(void)
|
|||||||
}
|
}
|
||||||
mom_.push_back(p);
|
mom_.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
envCache(std::vector<ComplexField>, momphName_, 1,
|
envCache(std::vector<ComplexField>, momphName_, 1,
|
||||||
par().mom.size(), envGetGrid(ComplexField));
|
par().mom.size(), envGetGrid(ComplexField));
|
||||||
envTmpLat(ComplexField, "coor");
|
envTmpLat(ComplexField, "coor");
|
||||||
@ -240,19 +233,19 @@ void TA2AMesonField<FImpl>::setup(void)
|
|||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
void TA2AMesonField<FImpl>::execute(void)
|
void TA2AMesonField<FImpl>::execute(void)
|
||||||
{
|
{
|
||||||
auto &v = envGet(std::vector<FermionField>, par().v);
|
auto &left = envGet(std::vector<FermionField>, par().left);
|
||||||
auto &w = envGet(std::vector<FermionField>, par().w);
|
auto &right = envGet(std::vector<FermionField>, par().right);
|
||||||
|
|
||||||
int nt = env().getDim().back();
|
int nt = env().getDim().back();
|
||||||
int N_i = w.size();
|
int N_i = left.size();
|
||||||
int N_j = v.size();
|
int N_j = right.size();
|
||||||
int ngamma = gamma_.size();
|
int ngamma = gamma_.size();
|
||||||
int nmom = mom_.size();
|
int nmom = mom_.size();
|
||||||
int block = par().block;
|
int block = par().block;
|
||||||
int cacheBlock = par().cacheBlock;
|
int cacheBlock = par().cacheBlock;
|
||||||
|
|
||||||
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) << "Left: '" << par().left << "' Right: '" << par().right << "'" << std::endl;
|
||||||
LOG(Message) << "Momenta:" << std::endl;
|
LOG(Message) << "Momenta:" << std::endl;
|
||||||
for (auto &p: mom_)
|
for (auto &p: mom_)
|
||||||
{
|
{
|
||||||
@ -309,7 +302,7 @@ void TA2AMesonField<FImpl>::execute(void)
|
|||||||
auto filenameFn = [this, &ionameFn](const unsigned int m, const unsigned int g)
|
auto filenameFn = [this, &ionameFn](const unsigned int m, const unsigned int g)
|
||||||
{
|
{
|
||||||
return par().output + "." + std::to_string(vm().getTrajectory())
|
return par().output + "." + std::to_string(vm().getTrajectory())
|
||||||
+ "/" + ioname(m, g) + ".h5";
|
+ "/" + ionameFn(m, g) + ".h5";
|
||||||
};
|
};
|
||||||
|
|
||||||
auto metadataFn = [this](const unsigned int m, const unsigned int g)
|
auto metadataFn = [this](const unsigned int m, const unsigned int g)
|
||||||
@ -328,189 +321,7 @@ void TA2AMesonField<FImpl>::execute(void)
|
|||||||
Kernel kernel(gamma_, ph, envGetGrid(FermionField));
|
Kernel kernel(gamma_, ph, envGetGrid(FermionField));
|
||||||
|
|
||||||
envGetTmp(Computation, computation);
|
envGetTmp(Computation, computation);
|
||||||
computation.execute(w, v, kernel, ionameFn, filenameFn, metadataFn);
|
computation.execute(left, right, kernel, ionameFn, filenameFn, metadataFn);
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// i,j is first loop over SchurBlock factors reusing 5D matrices
|
|
||||||
// ii,jj is second loop over cacheBlock factors for high perf contractoin
|
|
||||||
// iii,jjj are loops within cacheBlock
|
|
||||||
// Total index is sum of these i+ii+iii etc...
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// double flops;
|
|
||||||
// double bytes;
|
|
||||||
// double vol = env().getVolume();
|
|
||||||
// double t_kernel = 0.0;
|
|
||||||
// double nodes = env().getGrid()->NodeCount();
|
|
||||||
// double tot_kernel;
|
|
||||||
|
|
||||||
// envGetTmp(Vector<MF_IO_TYPE>, mfBuf);
|
|
||||||
// envGetTmp(Vector<Complex>, mfCache);
|
|
||||||
|
|
||||||
// double t0 = usecond();
|
|
||||||
// int NBlock_i = N_i/block + (((N_i % block) != 0) ? 1 : 0);
|
|
||||||
// int NBlock_j = N_j/block + (((N_j % block) != 0) ? 1 : 0);
|
|
||||||
|
|
||||||
// for(int i=0;i<N_i;i+=block)
|
|
||||||
// for(int j=0;j<N_j;j+=block)
|
|
||||||
// {
|
|
||||||
// // Get the W and V vectors for this block^2 set of terms
|
|
||||||
// int N_ii = MIN(N_i-i,block);
|
|
||||||
// int N_jj = MIN(N_j-j,block);
|
|
||||||
|
|
||||||
// LOG(Message) << "Meson field block "
|
|
||||||
// << j/block + NBlock_j*i/block + 1
|
|
||||||
// << "/" << NBlock_i*NBlock_j << " [" << i <<" .. "
|
|
||||||
// << i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]"
|
|
||||||
// << std::endl;
|
|
||||||
|
|
||||||
// A2AMatrixSet<MF_IO_TYPE> mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj);
|
|
||||||
|
|
||||||
// // Series of cache blocked chunks of the contractions within this block
|
|
||||||
// flops = 0.0;
|
|
||||||
// bytes = 0.0;
|
|
||||||
// for(int ii=0;ii<N_ii;ii+=cacheBlock)
|
|
||||||
// for(int jj=0;jj<N_jj;jj+=cacheBlock)
|
|
||||||
// {
|
|
||||||
// int N_iii = MIN(N_ii-ii,cacheBlock);
|
|
||||||
// int N_jjj = MIN(N_jj-jj,cacheBlock);
|
|
||||||
// A2AMatrixSet<Complex> mfCacheBlock(mfCache.data(),nmom,ngamma,nt,N_iii,N_jjj);
|
|
||||||
|
|
||||||
// startTimer("contraction: total");
|
|
||||||
// makeMesonFieldBlock(mfCacheBlock, &w[i+ii], &v[j+jj], gamma_, ph,
|
|
||||||
// env().getNd() - 1, this);
|
|
||||||
// stopTimer("contraction: total");
|
|
||||||
|
|
||||||
// // flops for general N_c & N_s
|
|
||||||
// flops += vol * ( 2 * 8.0 + 6.0 + 8.0*nmom) * N_iii*N_jjj*ngamma;
|
|
||||||
// bytes += vol * (12.0 * sizeof(Complex) ) * N_iii*N_jjj
|
|
||||||
// + vol * ( 2.0 * sizeof(Complex) *nmom ) * N_iii*N_jjj* ngamma;
|
|
||||||
|
|
||||||
// startTimer("cache copy");
|
|
||||||
// parallel_for_nest5(int m =0;m< nmom;m++)
|
|
||||||
// for(int g =0;g< ngamma;g++)
|
|
||||||
// for(int t =0;t< nt;t++)
|
|
||||||
// for(int iii=0;iii< N_iii;iii++)
|
|
||||||
// for(int jjj=0;jjj< N_jjj;jjj++)
|
|
||||||
// {
|
|
||||||
// mfBlock(m,g,t,ii+iii,jj+jjj) = mfCacheBlock(m,g,t,iii,jjj);
|
|
||||||
// }
|
|
||||||
// stopTimer("cache copy");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // perf
|
|
||||||
// tot_kernel = getDTimer("contraction: colour trace & mom.")
|
|
||||||
// + getDTimer("contraction: local space sum");
|
|
||||||
// t_kernel = tot_kernel - t_kernel;
|
|
||||||
// LOG(Message) << "Kernel perf " << flops/t_kernel/1.0e3/nodes
|
|
||||||
// << " Gflop/s/node " << std::endl;
|
|
||||||
// LOG(Message) << "Kernel perf " << bytes/t_kernel*1.0e6/1024/1024/1024/nodes
|
|
||||||
// << " GB/s/node " << std::endl;
|
|
||||||
// t_kernel = tot_kernel;
|
|
||||||
|
|
||||||
// // IO
|
|
||||||
// if (!par().output.empty())
|
|
||||||
// {
|
|
||||||
// double blockSize, ioTime;
|
|
||||||
// unsigned int myRank = env().getGrid()->ThisRank(),
|
|
||||||
// nRank = env().getGrid()->RankCount();
|
|
||||||
|
|
||||||
// LOG(Message) << "Writing block to disk" << std::endl;
|
|
||||||
// ioTime = -getDTimer("IO: write block");
|
|
||||||
// startTimer("IO: total");
|
|
||||||
// makeFileDir(filename(0, 0), env().getGrid());
|
|
||||||
// #ifdef MF_PARALLEL_IO
|
|
||||||
// env().getGrid()->Barrier();
|
|
||||||
// // make task list for current node
|
|
||||||
// nodeIo_.clear();
|
|
||||||
// for(int f = myRank; f < nmom*ngamma; f += nRank)
|
|
||||||
// {
|
|
||||||
// IoHelper h;
|
|
||||||
|
|
||||||
// h.i = i;
|
|
||||||
// h.j = j;
|
|
||||||
// h.m = f/ngamma;
|
|
||||||
// h.g = f % ngamma;
|
|
||||||
// h.io = A2AMatrixIo<MF_IO_TYPE>(filename(h.m, h.g),
|
|
||||||
// ioname(h.m, h.g), nt, N_i, N_j);
|
|
||||||
// for (auto pmu: mom_[h.m])
|
|
||||||
// {
|
|
||||||
// h.md.momentum.push_back(pmu);
|
|
||||||
// }
|
|
||||||
// h.md.gamma = gamma_[h.g];
|
|
||||||
// nodeIo_.push_back(h);
|
|
||||||
// }
|
|
||||||
// // parallel IO
|
|
||||||
// for (auto &h: nodeIo_)
|
|
||||||
// {
|
|
||||||
// saveBlock(mfBlock, h);
|
|
||||||
// }
|
|
||||||
// env().getGrid()->Barrier();
|
|
||||||
// #else
|
|
||||||
// // serial IO, for testing purposes only
|
|
||||||
// for(int m = 0; m < nmom; m++)
|
|
||||||
// for(int g = 0; g < ngamma; g++)
|
|
||||||
// {
|
|
||||||
// IoHelper h;
|
|
||||||
|
|
||||||
// h.i = i;
|
|
||||||
// h.j = j;
|
|
||||||
// h.m = m;
|
|
||||||
// h.g = g;
|
|
||||||
// h.io = A2AMatrixIo<MF_IO_TYPE>(filename(h.m, h.g),
|
|
||||||
// ioname(h.m, h.g), nt, N_i, N_j);
|
|
||||||
// for (auto pmu: mom_[h.m])
|
|
||||||
// {
|
|
||||||
// h.md.momentum.push_back(pmu);
|
|
||||||
// }
|
|
||||||
// h.md.gamma = gamma_[h.g];
|
|
||||||
// saveBlock(mfBlock, h);
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
// stopTimer("IO: total");
|
|
||||||
// blockSize = static_cast<double>(nmom*ngamma*nt*N_ii*N_jj*sizeof(MF_IO_TYPE));
|
|
||||||
// ioTime += getDTimer("IO: write block");
|
|
||||||
// LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in "
|
|
||||||
// << ioTime << " us ("
|
|
||||||
// << blockSize/ioTime*1.0e6/1024/1024
|
|
||||||
// << " MB/s)" << std::endl;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// IO
|
|
||||||
template <typename FImpl>
|
|
||||||
std::string TA2AMesonField<FImpl>::ioname(unsigned int m, unsigned int g) const
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << gamma_[g] << "_";
|
|
||||||
for (unsigned int mu = 0; mu < mom_[m].size(); ++mu)
|
|
||||||
{
|
|
||||||
ss << mom_[m][mu] << ((mu == mom_[m].size() - 1) ? "" : "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FImpl>
|
|
||||||
std::string TA2AMesonField<FImpl>::filename(unsigned int m, unsigned int g) const
|
|
||||||
{
|
|
||||||
return par().output + "." + std::to_string(vm().getTrajectory())
|
|
||||||
+ "/" + ioname(m, g) + ".h5";
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FImpl>
|
|
||||||
void TA2AMesonField<FImpl>::saveBlock(const A2AMatrixSet<MF_IO_TYPE> &mf, IoHelper &h)
|
|
||||||
{
|
|
||||||
if ((h.i == 0) and (h.j == 0))
|
|
||||||
{
|
|
||||||
startTimer("IO: file creation");
|
|
||||||
h.io.initFile(h.md, par().block);
|
|
||||||
stopTimer("IO: file creation");
|
|
||||||
}
|
|
||||||
startTimer("IO: write block");
|
|
||||||
h.io.saveBlock(mf, h.m, h.g, h.i, h.j);
|
|
||||||
stopTimer("IO: write block");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END_MODULE_NAMESPACE
|
END_MODULE_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user