mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-04 19:25:56 +01:00
Hadrons: object creation that get properly captured by the memory profiler
This commit is contained in:
parent
e78794688a
commit
0fbf445edd
@ -100,11 +100,16 @@ public:
|
||||
// general memory management
|
||||
void addObject(const std::string name,
|
||||
const int moduleAddress = -1);
|
||||
template <typename T, typename P>
|
||||
template <typename B, typename T, typename ... Ts>
|
||||
void createDerivedObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args);
|
||||
template <typename T, typename ... Ts>
|
||||
void createObject(const std::string name,
|
||||
const Storage storage,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
P &&pt);
|
||||
Ts && ... args);
|
||||
void setObjectModule(const unsigned int objAddress,
|
||||
const int modAddress);
|
||||
template <typename T>
|
||||
@ -195,11 +200,11 @@ void Holder<T>::reset(T *pt)
|
||||
* Environment template implementation *
|
||||
******************************************************************************/
|
||||
// general memory management ///////////////////////////////////////////////////
|
||||
template <typename T, typename P>
|
||||
void Environment::createObject(const std::string name,
|
||||
template <typename B, typename T, typename ... Ts>
|
||||
void Environment::createDerivedObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
P &&pt)
|
||||
Ts && ... args)
|
||||
{
|
||||
if (!hasObject(name))
|
||||
{
|
||||
@ -210,13 +215,13 @@ void Environment::createObject(const std::string name,
|
||||
|
||||
if (!object_[address].data)
|
||||
{
|
||||
MemoryStats memStats;
|
||||
MemoryStats memStats;
|
||||
|
||||
MemoryProfiler::stats = &memStats;
|
||||
object_[address].storage = storage;
|
||||
object_[address].Ls = Ls;
|
||||
object_[address].data.reset(new Holder<T>(pt));
|
||||
object_[address].size = memStats.totalAllocated;
|
||||
object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
|
||||
object_[address].size = memStats.maxAllocated;
|
||||
object_[address].type = &typeid(T);
|
||||
MemoryProfiler::stats = nullptr;
|
||||
}
|
||||
@ -226,6 +231,15 @@ void Environment::createObject(const std::string name,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename ... Ts>
|
||||
void Environment::createObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args)
|
||||
{
|
||||
createDerivedObject<T, T>(name, storage, Ls, std::forward<Ts>(args)...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T * Environment::getObject(const unsigned int address) const
|
||||
{
|
||||
|
@ -98,39 +98,42 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance;
|
||||
#define envHasType(type, name)\
|
||||
env().template isObjectOfType<type>(name)
|
||||
|
||||
#define envCreate(type, name, Ls, pt)\
|
||||
env().template createObject<type>(name, Environment::Storage::object, Ls, pt)
|
||||
#define envCreate(type, name, Ls, ...)\
|
||||
env().template createObject<type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCreateDerived(base, type, name, Ls, ...)\
|
||||
env().template createDerivedObject<base, type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCreateLat4(type, name)\
|
||||
envCreate(type, name, 1, new type(env().getGrid()))
|
||||
envCreate(type, name, 1, env().getGrid())
|
||||
|
||||
#define envCreateLat5(type, name, Ls)\
|
||||
envCreate(type, name, Ls, new type(env().getGrid(Ls)))
|
||||
envCreate(type, name, Ls, env().getGrid(Ls))
|
||||
|
||||
#define envCreateLat(...)\
|
||||
MACRO_REDIRECT(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__)
|
||||
|
||||
#define envCache(type, name, Ls, pt)\
|
||||
env().template createObject<type>(name, Environment::Storage::cache, Ls, pt)
|
||||
#define envCache(type, name, Ls, ...)\
|
||||
env().template createObject<type>(name, Environment::Storage::cache, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCacheLat4(type, name)\
|
||||
envCache(type, name, 1, new type(env().getGrid()))
|
||||
envCache(type, name, 1, env().getGrid())
|
||||
|
||||
#define envCacheLat5(type, name, Ls)\
|
||||
envCache(type, name, Ls, new type(env().getGrid(Ls)))
|
||||
envCache(type, name, Ls, env().getGrid(Ls))
|
||||
|
||||
#define envCacheLat(...)\
|
||||
MACRO_REDIRECT(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__)
|
||||
|
||||
#define envTmp(type, name, Ls, pt)\
|
||||
#define envTmp(type, name, Ls, ...)\
|
||||
env().template createObject<type>(getName() + "_tmp_" + name, \
|
||||
Environment::Storage::temporary, Ls, pt)
|
||||
Environment::Storage::temporary, Ls, __VA_ARGS__)
|
||||
|
||||
#define envTmpLat4(type, name)\
|
||||
envTmp(type, name, 1, new type(env().getGrid()))
|
||||
envTmp(type, name, 1, env().getGrid())
|
||||
|
||||
#define envTmpLat5(type, name, Ls)\
|
||||
envTmp(type, name, Ls, new type(env().getGrid(Ls)))
|
||||
envTmp(type, name, Ls, env().getGrid(Ls))
|
||||
|
||||
#define envTmpLat(...)\
|
||||
MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__)
|
||||
|
@ -118,9 +118,8 @@ void TDWF<FImpl>::setup(void)
|
||||
auto &grb5 = *env().getRbGrid(par().Ls);
|
||||
std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
|
||||
typename DomainWallFermion<FImpl>::ImplParams implParams(boundary);
|
||||
envCreate(FMat, getName(), par().Ls,
|
||||
new DomainWallFermion<FImpl>(U, g5, grb5, g4, grb4, par().mass,
|
||||
par().M5, implParams));
|
||||
envCreateDerived(FMat, DomainWallFermion<FImpl>, getName(), par().Ls, U, g5,
|
||||
grb5, g4, grb4, par().mass, par().M5, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
|
@ -111,9 +111,8 @@ void TWilson<FImpl>::setup(void)
|
||||
auto &gridRb = *env().getRbGrid();
|
||||
std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
|
||||
typename WilsonFermion<FImpl>::ImplParams implParams(boundary);
|
||||
envCreate(FMat, getName(), 1, new WilsonFermion<FImpl>(U, grid, gridRb,
|
||||
par().mass,
|
||||
implParams));
|
||||
envCreateDerived(FMat, WilsonFermion<FImpl>, getName(), 1, U, grid, gridRb,
|
||||
par().mass, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
|
@ -114,7 +114,7 @@ void TRBPrecCG<FImpl>::setup(void)
|
||||
|
||||
schurSolver(mat, source, sol);
|
||||
};
|
||||
envCreate(SolverFn, getName(), Ls, new SolverFn(solver));
|
||||
envCreate(SolverFn, getName(), Ls, solver);
|
||||
env().addOwnership(getName(), par().action);
|
||||
}
|
||||
|
||||
|
@ -251,8 +251,7 @@ Graph<unsigned int> VirtualMachine::makeModuleGraph(void) const
|
||||
// general execution ///////////////////////////////////////////////////////////
|
||||
#define BIG_SEP "==============="
|
||||
#define SEP "---------------"
|
||||
#define MEM_MSG(size)\
|
||||
sizeString((size)*env().getLocalVolume()) << " (" << sizeString(size) << "/site)"
|
||||
#define MEM_MSG(size) sizeString(size)
|
||||
|
||||
VirtualMachine::Size
|
||||
VirtualMachine::executeProgram(const std::vector<unsigned int> &p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user