From f46f0ca40123410d0f2437eb85bfffa9ed6d95c4 Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Wed, 16 Jun 2021 09:42:22 +0000 Subject: [PATCH] Use unique_ptr in forcerec --- src/gromacs/mdlib/sim_util.cpp | 7 ++++--- src/gromacs/mdrun/runner.cpp | 7 ++----- src/gromacs/mdtypes/forcerec.h | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 8795ec6188..5b3f72dd87 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -1470,7 +1470,7 @@ void do_force(FILE* fplog, /* Note that with a GPU the launch overhead of the list transfer is not timed separately */ nbv->constructPairlist(InteractionLocality::Local, top->excls, step, nrnb); - nbv->setupGpuShortRangeWork(fr->listedForcesGpu, InteractionLocality::Local); + nbv->setupGpuShortRangeWork(fr->listedForcesGpu.get(), InteractionLocality::Local); wallcycle_sub_stop(wcycle, WallCycleSubCounter::NBSSearchLocal); wallcycle_stop(wcycle, WallCycleCounter::NS); @@ -1559,7 +1559,7 @@ void do_force(FILE* fplog, /* Note that with a GPU the launch overhead of the list transfer is not timed separately */ nbv->constructPairlist(InteractionLocality::NonLocal, top->excls, step, nrnb); - nbv->setupGpuShortRangeWork(fr->listedForcesGpu, InteractionLocality::NonLocal); + nbv->setupGpuShortRangeWork(fr->listedForcesGpu.get(), InteractionLocality::NonLocal); wallcycle_sub_stop(wcycle, WallCycleSubCounter::NBSSearchNonLocal); wallcycle_stop(wcycle, WallCycleCounter::NS); // TODO refactor this GPU halo exchange re-initialisation @@ -2285,7 +2285,8 @@ void do_force(FILE* fplog, } } - launchGpuEndOfStepTasks(nbv, fr->listedForcesGpu, fr->pmedata, enerd, *runScheduleWork, step, wcycle); + launchGpuEndOfStepTasks( + nbv, fr->listedForcesGpu.get(), fr->pmedata, enerd, *runScheduleWork, step, wcycle); if (DOMAINDECOMP(cr)) { diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index a1cc472958..45c569630c 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1611,7 +1611,6 @@ int Mdrunner::mdrunner() const bool thisRankHasPmeGpuTask = gpuTaskAssignments.thisRankHasPmeGpuTask(); std::unique_ptr mdAtoms; std::unique_ptr vsite; - std::unique_ptr listedForcesGpu; t_nrnb nrnb; if (thisRankHasDuty(cr, DUTY_PP)) @@ -1677,13 +1676,12 @@ int Mdrunner::mdrunner() GMX_RELEASE_ASSERT(deviceStreamManager != nullptr, "GPU device stream manager should be valid in order to use GPU " "version of bonded forces."); - listedForcesGpu = std::make_unique( + fr->listedForcesGpu = std::make_unique( mtop.ffparams, fr->ic->epsfac * fr->fudgeQQ, deviceStreamManager->context(), deviceStreamManager->bondedStream(havePPDomainDecomposition(cr)), wcycle.get()); - fr->listedForcesGpu = listedForcesGpu.get(); } /* Initialize the mdAtoms structure. @@ -2073,8 +2071,7 @@ int Mdrunner::mdrunner() mdAtoms.reset(nullptr); globalState.reset(nullptr); mdModules_.reset(nullptr); // destruct force providers here as they might also use the GPU - listedForcesGpu.reset(nullptr); - fr.reset(nullptr); // destruct forcerec before gpu + fr.reset(nullptr); // destruct forcerec before gpu // TODO convert to C++ so we can get rid of these frees sfree(disresdata); diff --git a/src/gromacs/mdtypes/forcerec.h b/src/gromacs/mdtypes/forcerec.h index 8abdadfa9f..d4bcb4c350 100644 --- a/src/gromacs/mdtypes/forcerec.h +++ b/src/gromacs/mdtypes/forcerec.h @@ -257,8 +257,8 @@ struct t_forcerec // The listed forces calculation data, 1 entry or multiple entries with multiple time stepping std::vector listedForces; - /* TODO: Replace the pointer by an object once we got rid of C */ - gmx::ListedForcesGpu* listedForcesGpu = nullptr; + // The listed forces calculation data for GPU + std::unique_ptr listedForcesGpu; /* Ewald correction thread local virial and energy data */ int nthread_ewc = 0; -- 2.22.0