Skip to content

Commit

Permalink
Fix autotuner chaining in MPCD
Browse files Browse the repository at this point in the history
  • Loading branch information
mphoward committed Nov 26, 2024
1 parent 559a2f4 commit d7d5114
Show file tree
Hide file tree
Showing 26 changed files with 185 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Change Log
(`#1934 <https://github.com/glotzerlab/hoomd-blue/pull/1934>`__).
* Correctly apply ``HPMCIntegrator.external_potentials`` in ``hoomd.hpmc.update.MuVT``
(`#1941 <https://github.com/glotzerlab/hoomd-blue/pull/1941>`__).
* Ensure GPU autotuners for MPCD methods are included in ``hoomd.Operations.is_tuning_complete`` and
``hoomd.Operations.tune_kernel_parameters`` through ``hoomd.mpcd.Integrator``
(`#1951 <https://github.com/glotzerlab/hoomd-blue/pull/1951>`__).

*Added*

Expand Down
19 changes: 19 additions & 0 deletions hoomd/mpcd/ATCollisionMethod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ mpcd::ATCollisionMethod::~ATCollisionMethod()
detachCallbacks();
}

void mpcd::ATCollisionMethod::startAutotuning()
{
mpcd::CollisionMethod::startAutotuning();
if (m_thermo)
m_thermo->startAutotuning();
if (m_rand_thermo)
m_rand_thermo->startAutotuning();
}

bool mpcd::ATCollisionMethod::isAutotuningComplete()
{
bool result = mpcd::CollisionMethod::isAutotuningComplete();
if (m_thermo)
result = result && m_thermo->isAutotuningComplete();
if (m_rand_thermo)
result = result && m_rand_thermo->isAutotuningComplete();
return result;
}

/*!
* \param timestep Current timestep.
*/
Expand Down
10 changes: 8 additions & 2 deletions hoomd/mpcd/ATCollisionMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class PYBIND11_EXPORT ATCollisionMethod : public mpcd::CollisionMethod
//! Destructor
virtual ~ATCollisionMethod();

void setCellList(std::shared_ptr<mpcd::CellList> cl);
//! Start autotuning kernel launch parameters
void startAutotuning() override;

//! Check if kernel autotuning is complete
bool isAutotuningComplete() override;

void setCellList(std::shared_ptr<mpcd::CellList> cl) override;

//! Get the temperature
std::shared_ptr<Variant> getTemperature() const
Expand All @@ -55,7 +61,7 @@ class PYBIND11_EXPORT ATCollisionMethod : public mpcd::CollisionMethod
std::shared_ptr<Variant> m_T; //!< Temperature for thermostat

//! Implementation of the collision rule
virtual void rule(uint64_t timestep);
virtual void rule(uint64_t timestep) override;

//! Draw velocities for particles in each cell
virtual void drawVelocities(uint64_t timestep);
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/ATCollisionMethodGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class PYBIND11_EXPORT ATCollisionMethodGPU : public mpcd::ATCollisionMethod

protected:
//! Draw velocities for particles in each cell on the GPU
virtual void drawVelocities(uint64_t timestep);
virtual void drawVelocities(uint64_t timestep) override;

//! Apply the random velocities to particles in each cell on the GPU
virtual void applyVelocities();
virtual void applyVelocities() override;

private:
std::shared_ptr<Autotuner<1>> m_tuner_draw; //!< Tuner for drawing random velocities
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/BounceBackNVE.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class PYBIND11_EXPORT BounceBackNVE : public hoomd::md::IntegrationMethodTwoStep
virtual ~BounceBackNVE();

//! Performs the first step of the integration
virtual void integrateStepOne(uint64_t timestep);
virtual void integrateStepOne(uint64_t timestep) override;

//! Performs the second step of the integration
virtual void integrateStepTwo(uint64_t timestep);
virtual void integrateStepTwo(uint64_t timestep) override;

//! Get the streaming geometry
std::shared_ptr<Geometry> getGeometry()
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/BounceBackNVEGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ template<class Geometry> class PYBIND11_EXPORT BounceBackNVEGPU : public BounceB
}

//! Performs the first step of the integration
virtual void integrateStepOne(uint64_t timestep);
virtual void integrateStepOne(uint64_t timestep) override;

//! Performs the second step of the integration
virtual void integrateStepTwo(uint64_t timestep);
virtual void integrateStepTwo(uint64_t timestep) override;

private:
std::shared_ptr<Autotuner<1>> m_tuner_1;
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/BounceBackStreamingMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PYBIND11_EXPORT BounceBackStreamingMethod : public mpcd::StreamingMethod
}

//! Implementation of the streaming rule
virtual void stream(uint64_t timestep);
virtual void stream(uint64_t timestep) override;

//! Get the streaming geometry
std::shared_ptr<Geometry> getGeometry() const
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/BounceBackStreamingMethodGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PYBIND11_EXPORT BounceBackStreamingMethodGPU
}

//! Implementation of the streaming rule
virtual void stream(uint64_t timestep);
virtual void stream(uint64_t timestep) override;

protected:
std::shared_ptr<Autotuner<1>> m_tuner;
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/CellListGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PYBIND11_EXPORT CellListGPU : public mpcd::CellList

protected:
//! Compute the cell list of particles on the GPU
virtual void buildCellList();
virtual void buildCellList() override;

//! Callback to sort cell list on the GPU when particle data is sorted
virtual void sort(uint64_t timestep,
Expand Down
23 changes: 23 additions & 0 deletions hoomd/mpcd/CellThermoCompute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ void mpcd::CellThermoCompute::compute(uint64_t timestep)
m_needs_net_reduce = true;
}

void mpcd::CellThermoCompute::startAutotuning()
{
Compute::startAutotuning();
#ifdef ENABLE_MPI
if (m_vel_comm)
m_vel_comm->startAutotuning();
if (m_energy_comm)
m_energy_comm->startAutotuning();
#endif // ENABLE_MPI
}

bool mpcd::CellThermoCompute::isAutotuningComplete()
{
bool result = Compute::isAutotuningComplete();
#ifdef ENABLE_MPI
if (m_vel_comm)
result = result && m_vel_comm->isAutotuningComplete();
if (m_energy_comm)
result = result && m_energy_comm->isAutotuningComplete();
#endif // ENABLE_MPI
return result;
}

void mpcd::CellThermoCompute::computeCellProperties(uint64_t timestep)
{
/*
Expand Down
8 changes: 7 additions & 1 deletion hoomd/mpcd/CellThermoCompute.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class PYBIND11_EXPORT CellThermoCompute : public Compute
virtual ~CellThermoCompute();

//! Compute the cell thermodynamic properties
void compute(uint64_t timestep);
void compute(uint64_t timestep) override;

//! Start autotuning kernel launch parameters
void startAutotuning() override;

//! Check if kernel autotuning is complete
bool isAutotuningComplete() override;

//! Get the cell indexer for the attached cell list
const Index3D& getCellIndexer() const
Expand Down
8 changes: 4 additions & 4 deletions hoomd/mpcd/CellThermoComputeGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class PYBIND11_EXPORT CellThermoComputeGPU : public mpcd::CellThermoCompute
protected:
#ifdef ENABLE_MPI
//! Begin the calculation of outer cell properties on the GPU
virtual void beginOuterCellProperties();
virtual void beginOuterCellProperties() override;

//! Finish the calculation of outer cell properties on the GPU
virtual void finishOuterCellProperties();
virtual void finishOuterCellProperties() override;
#endif // ENABLE_MPI

//! Calculate the inner cell properties on the GPU
virtual void calcInnerCellProperties();
virtual void calcInnerCellProperties() override;

//! Compute the net properties from the cell properties
virtual void computeNetProperties();
virtual void computeNetProperties() override;

private:
std::shared_ptr<Autotuner<2>> m_begin_tuner; //!< Tuner for cell begin kernel
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/CommunicatorGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PYBIND11_EXPORT CommunicatorGPU : public mpcd::Communicator
//@{

//! Migrate particle data to local domain
virtual void migrateParticles(uint64_t timestep);
virtual void migrateParticles(uint64_t timestep) override;
//@}

//! Set maximum number of communication stages
Expand All @@ -71,7 +71,7 @@ class PYBIND11_EXPORT CommunicatorGPU : public mpcd::Communicator

protected:
//! Set the communication flags for the particle data on the GPU
virtual void setCommFlags(const BoxDim& box);
virtual void setCommFlags(const BoxDim& box) override;

private:
/* General communication */
Expand Down
69 changes: 65 additions & 4 deletions hoomd/mpcd/Integrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace hoomd
* \param deltaT Fundamental integration timestep
*/
mpcd::Integrator::Integrator(std::shared_ptr<SystemDefinition> sysdef, Scalar deltaT)
: IntegratorTwoStep(sysdef, deltaT)
: md::IntegratorTwoStep(sysdef, deltaT)
{
m_exec_conf->msg->notice(5) << "Constructing MPCD Integrator" << std::endl;

Expand Down Expand Up @@ -98,7 +98,7 @@ void mpcd::Integrator::update(uint64_t timestep)
m_stream->stream(timestep);

// execute MD steps
IntegratorTwoStep::update(timestep);
md::IntegratorTwoStep::update(timestep);
}

/*!
Expand All @@ -107,7 +107,7 @@ void mpcd::Integrator::update(uint64_t timestep)
*/
void mpcd::Integrator::setDeltaT(Scalar deltaT)
{
IntegratorTwoStep::setDeltaT(deltaT);
md::IntegratorTwoStep::setDeltaT(deltaT);
if (m_stream)
m_stream->setDeltaT(deltaT);
}
Expand All @@ -119,7 +119,7 @@ void mpcd::Integrator::setDeltaT(Scalar deltaT)
*/
void mpcd::Integrator::prepRun(uint64_t timestep)
{
IntegratorTwoStep::prepRun(timestep);
md::IntegratorTwoStep::prepRun(timestep);

// synchronize cell list in mpcd methods
syncCellList();
Expand All @@ -137,6 +137,67 @@ void mpcd::Integrator::prepRun(uint64_t timestep)
#endif // ENABLE_MPI
}

void mpcd::Integrator::startAutotuning()
{
md::IntegratorTwoStep::startAutotuning();

m_sysdef->getMPCDParticleData()->startAutotuning();

if (m_collide)
{
m_collide->startAutotuning();
}
if (m_stream)
{
m_stream->startAutotuning();
}
if (m_sorter)
{
m_sorter->startAutotuning();
}
#ifdef ENABLE_MPI
if (m_mpcd_comm)
{
m_mpcd_comm->startAutotuning();
}
#endif
for (auto& filler : m_fillers)
{
filler->startAutotuning();
}
}

bool mpcd::Integrator::isAutotuningComplete()
{
bool result = md::IntegratorTwoStep::isAutotuningComplete();

result = result && m_sysdef->getMPCDParticleData()->isAutotuningComplete();

if (m_collide)
{
result = result && m_collide->isAutotuningComplete();
}
if (m_stream)
{
result = result && m_stream->isAutotuningComplete();
}
if (m_sorter)
{
result = result && m_sorter->isAutotuningComplete();
}
#ifdef ENABLE_MPI
if (m_mpcd_comm)
{
result = result && m_mpcd_comm->isAutotuningComplete();
}
#endif
for (auto& filler : m_fillers)
{
result = result && filler->isAutotuningComplete();
}
return result;
}

void mpcd::Integrator::syncCellList()
{
if (m_collide)
Expand Down
12 changes: 9 additions & 3 deletions hoomd/mpcd/Integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ class PYBIND11_EXPORT Integrator : public hoomd::md::IntegratorTwoStep
virtual ~Integrator();

//! Take one timestep forward
virtual void update(uint64_t timestep);
virtual void update(uint64_t timestep) override;

//! Change the timestep
virtual void setDeltaT(Scalar deltaT);
virtual void setDeltaT(Scalar deltaT) override;

//! Prepare for the run
virtual void prepRun(uint64_t timestep);
virtual void prepRun(uint64_t timestep) override;

//! Start autotuning kernel launch parameters
void startAutotuning() override;

//! Check if kernel autotuning is complete
bool isAutotuningComplete() override;

//! Get the MPCD cell list shared by all methods
std::shared_ptr<mpcd::CellList> getCellList() const
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/ParallelPlateGeometryFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class PYBIND11_EXPORT ParallelPlateGeometryFiller : public mpcd::ManualVirtualPa
unsigned int m_N_hi; //!< number of particles to fill above channel

//! Compute the total number of particles to fill
virtual void computeNumFill();
virtual void computeNumFill() override;

//! Draw particles within the fill volume
virtual void drawParticles(uint64_t timestep);
virtual void drawParticles(uint64_t timestep) override;
};
} // end namespace mpcd
} // end namespace hoomd
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/ParallelPlateGeometryFillerGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PYBIND11_EXPORT ParallelPlateGeometryFillerGPU : public mpcd::ParallelPlat

protected:
//! Draw particles within the fill volume on the GPU
virtual void drawParticles(uint64_t timestep);
virtual void drawParticles(uint64_t timestep) override;

private:
std::shared_ptr<hoomd::Autotuner<1>> m_tuner; //!< Autotuner for drawing particles
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/PlanarPoreGeometryFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class PYBIND11_EXPORT PlanarPoreGeometryFiller : public mpcd::ManualVirtualParti
GPUArray<uint2> m_ranges; //!< Particle tag ranges for filling

//! Compute the total number of particles to fill
virtual void computeNumFill();
virtual void computeNumFill() override;

//! Draw particles within the fill volume
virtual void drawParticles(uint64_t timestep);
virtual void drawParticles(uint64_t timestep) override;

private:
bool m_needs_recompute;
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/PlanarPoreGeometryFillerGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PYBIND11_EXPORT PlanarPoreGeometryFillerGPU : public mpcd::PlanarPoreGeome

protected:
//! Draw particles within the fill volume on the GPU
virtual void drawParticles(uint64_t timestep);
virtual void drawParticles(uint64_t timestep) override;

private:
std::shared_ptr<hoomd::Autotuner<1>> m_tuner; //!< Autotuner for drawing particles
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/RejectionVirtualParticleFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PYBIND11_EXPORT RejectionVirtualParticleFiller : public mpcd::VirtualParti
}

//! Fill the particles outside the confinement
virtual void fill(uint64_t timestep);
virtual void fill(uint64_t timestep) override;

protected:
std::shared_ptr<const Geometry> m_geom;
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/RejectionVirtualParticleFillerGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PYBIND11_EXPORT RejectionVirtualParticleFillerGPU

protected:
//! Fill the volume outside the confinement
virtual void fill(uint64_t timestep);
virtual void fill(uint64_t timestep) override;

private:
GPUArray<bool> m_keep_particles; // Track whether particles are in/out of bounds for geometry
Expand Down
Loading

0 comments on commit d7d5114

Please sign in to comment.