/*! \brief Create Update-Constrain object.
*
* The constructor is given a non-nullptr \p deviceStream, in which all the update and constrain
- * routines are executed. \p xUpdatedOnDevice should mark the completion of all kernels that
- * modify coordinates. The event is maintained outside this class and also passed to all (if
- * any) consumers of the updated coordinates. The \p xUpdatedOnDevice also can not be a nullptr
- * because the markEvent(...) method is called unconditionally.
+ * routines are executed.
*
* \param[in] ir Input record data: LINCS takes number of iterations and order of
* projection from it.
* \param[in] numTempScaleValues Number of temperature scaling groups. Zero for no temperature scaling.
* \param[in] deviceContext GPU device context.
* \param[in] deviceStream GPU stream to use.
- * \param[in] xUpdatedOnDevice The event synchronizer to use to mark that update is done
- * on the GPU.
* \param[in] wcycle The wallclock counter
*/
- UpdateConstrainGpu(const t_inputrec& ir,
- const gmx_mtop_t& mtop,
- int numTempScaleValues,
- const DeviceContext& deviceContext,
- const DeviceStream& deviceStream,
- GpuEventSynchronizer* xUpdatedOnDevice,
- gmx_wallcycle* wcycle);
+ UpdateConstrainGpu(const t_inputrec& ir,
+ const gmx_mtop_t& mtop,
+ int numTempScaleValues,
+ const DeviceContext& deviceContext,
+ const DeviceStream& deviceStream,
+ gmx_wallcycle* wcycle);
~UpdateConstrainGpu();
*/
void setPbc(PbcType pbcType, const matrix box);
- /*! \brief Return the synchronizer associated with the event indicated that the coordinates are ready on the device.
+ /*! \brief Return the synchronizer associated with the event that indicates
+ * that the coordinates are ready on the device.
*/
- GpuEventSynchronizer* getCoordinatesReadySync();
+ GpuEventSynchronizer* xUpdatedOnDeviceEvent();
/*! \brief
* Returns whether the maximum number of coupled constraints is supported
}
}
- coordinatesReady_->markEvent(deviceStream_);
+ xUpdatedOnDeviceEvent_.markEvent(deviceStream_);
wallcycle_sub_stop(wcycle_, WallCycleSubCounter::LaunchGpuUpdateConstrain);
wallcycle_stop(wcycle_, WallCycleCounter::LaunchGpu);
wallcycle_stop(wcycle_, WallCycleCounter::LaunchGpu);
}
-UpdateConstrainGpu::Impl::Impl(const t_inputrec& ir,
- const gmx_mtop_t& mtop,
- const int numTempScaleValues,
- const DeviceContext& deviceContext,
- const DeviceStream& deviceStream,
- GpuEventSynchronizer* xUpdatedOnDevice,
- gmx_wallcycle* wcycle) :
- deviceContext_(deviceContext),
- deviceStream_(deviceStream),
- coordinatesReady_(xUpdatedOnDevice),
- wcycle_(wcycle)
+UpdateConstrainGpu::Impl::Impl(const t_inputrec& ir,
+ const gmx_mtop_t& mtop,
+ const int numTempScaleValues,
+ const DeviceContext& deviceContext,
+ const DeviceStream& deviceStream,
+ gmx_wallcycle* wcycle) :
+ deviceContext_(deviceContext), deviceStream_(deviceStream), wcycle_(wcycle)
{
- GMX_ASSERT(xUpdatedOnDevice != nullptr, "The event synchronizer can not be nullptr.");
-
integrator_ = std::make_unique<LeapFrogGpu>(deviceContext_, deviceStream_, numTempScaleValues);
if (sc_haveGpuConstraintSupport)
{
setPbcAiuc(numPbcDimensions(pbcType), box, &pbcAiuc_);
}
-GpuEventSynchronizer* UpdateConstrainGpu::Impl::getCoordinatesReadySync()
+GpuEventSynchronizer* UpdateConstrainGpu::Impl::xUpdatedOnDeviceEvent()
{
- return coordinatesReady_;
+ return &xUpdatedOnDeviceEvent_;
}
-UpdateConstrainGpu::UpdateConstrainGpu(const t_inputrec& ir,
- const gmx_mtop_t& mtop,
- const int numTempScaleValues,
- const DeviceContext& deviceContext,
- const DeviceStream& deviceStream,
- GpuEventSynchronizer* xUpdatedOnDevice,
- gmx_wallcycle* wcycle) :
- impl_(new Impl(ir, mtop, numTempScaleValues, deviceContext, deviceStream, xUpdatedOnDevice, wcycle))
+UpdateConstrainGpu::UpdateConstrainGpu(const t_inputrec& ir,
+ const gmx_mtop_t& mtop,
+ const int numTempScaleValues,
+ const DeviceContext& deviceContext,
+ const DeviceStream& deviceStream,
+ gmx_wallcycle* wcycle) :
+ impl_(new Impl(ir, mtop, numTempScaleValues, deviceContext, deviceStream, wcycle))
{
}
impl_->setPbc(pbcType, box);
}
-GpuEventSynchronizer* UpdateConstrainGpu::getCoordinatesReadySync()
+GpuEventSynchronizer* UpdateConstrainGpu::xUpdatedOnDeviceEvent()
{
- return impl_->getCoordinatesReadySync();
+ return impl_->xUpdatedOnDeviceEvent();
}
bool UpdateConstrainGpu::isNumCoupledConstraintsSupported(const gmx_mtop_t& mtop)
#include "gmxpre.h"
+#include "config.h"
+
+#include "gromacs/gpu_utils/gpueventsynchronizer.h"
#include "gromacs/mdlib/leapfrog_gpu.h"
#include "gromacs/mdlib/lincs_gpu.h"
#include "gromacs/mdlib/settle_gpu.h"
/*! \brief Create Update-Constrain object.
*
* The constructor is given a non-nullptr \p deviceStream, in which all the update and constrain
- * routines are executed. \p xUpdatedOnDevice should mark the completion of all kernels that
- * modify coordinates. The event is maintained outside this class and also passed to all (if
- * any) consumers of the updated coordinates. The \p xUpdatedOnDevice also can not be a nullptr
- * because the markEvent(...) method is called unconditionally.
+ * routines are executed.
*
* \param[in] ir Input record data: LINCS takes number of iterations and order of
* projection from it.
* \param[in] numTempScaleValues Number of temperature scaling groups. Set zero for no temperature coupling.
* \param[in] deviceContext GPU device context.
* \param[in] deviceStream GPU stream to use.
- * \param[in] xUpdatedOnDevice The event synchronizer to use to mark that
- * update is done on the GPU.
* \param[in] wcycle The wallclock counter
*/
- Impl(const t_inputrec& ir,
- const gmx_mtop_t& mtop,
- int numTempScaleValues,
- const DeviceContext& deviceContext,
- const DeviceStream& deviceStream,
- GpuEventSynchronizer* xUpdatedOnDevice,
- gmx_wallcycle* wcycle);
+ Impl(const t_inputrec& ir,
+ const gmx_mtop_t& mtop,
+ int numTempScaleValues,
+ const DeviceContext& deviceContext,
+ const DeviceStream& deviceStream,
+ gmx_wallcycle* wcycle);
~Impl();
/*! \brief Return the synchronizer associated with the event indicated that the coordinates are ready on the device.
*/
- GpuEventSynchronizer* getCoordinatesReadySync();
+ GpuEventSynchronizer* xUpdatedOnDeviceEvent();
/*! \brief
* Returns whether the maximum number of coupled constraints is supported
//! SETTLE GPU object for water constrains
std::unique_ptr<SettleGpu> settleGpu_;
- //! An pointer to the event to indicate when the update of coordinates is complete
- GpuEventSynchronizer* coordinatesReady_;
+ //! The event to indicate when the update of coordinates is complete
+ GpuEventSynchronizer xUpdatedOnDeviceEvent_;
//! The wallclock counter
gmx_wallcycle* wcycle_ = nullptr;
};
const int /* numTempScaleValues */,
const DeviceContext& /* deviceContext */,
const DeviceStream& /* deviceStream */,
- GpuEventSynchronizer* /* xUpdatedOnDevice */,
gmx_wallcycle* /*wcycle*/) :
impl_(nullptr)
{
"A CPU stub for UpdateConstrain was called instead of the correct implementation.");
}
-GpuEventSynchronizer* UpdateConstrainGpu::getCoordinatesReadySync()
+GpuEventSynchronizer* UpdateConstrainGpu::xUpdatedOnDeviceEvent()
{
GMX_ASSERT(!impl_,
"A CPU stub for UpdateConstrain was called instead of the correct implementation.");
ekind->ngtc,
fr->deviceStreamManager->context(),
fr->deviceStreamManager->stream(gmx::DeviceStreamType::UpdateAndConstraints),
- stateGpu->xUpdatedOnDevice(),
wcycle);
+ stateGpu->setXUpdatedOnDeviceEvent(integrator->xUpdatedOnDeviceEvent());
+
integrator->setPbc(PbcType::Xyz, state->box);
}
*/
void waitCoordinatesCopiedToDevice(AtomLocality atomLocality);
- /*! \brief Getter for the event synchronizer for the update is done on th GPU
+ /*! \brief Setter for the event synchronizer for the update is done on th GPU
*
- * \returns The event to synchronize the stream coordinates wre updated on device.
+ * \param[in] xUpdatedOnDeviceEvent The event to synchronize the stream coordinates wre updated on device.
*/
- GpuEventSynchronizer* xUpdatedOnDevice();
+ void setXUpdatedOnDeviceEvent(GpuEventSynchronizer* xUpdatedOnDeviceEvent);
/*! \brief Copy positions from the GPU memory.
*
"GPU implementation.");
}
-GpuEventSynchronizer* StatePropagatorDataGpu::xUpdatedOnDevice()
+void StatePropagatorDataGpu::setXUpdatedOnDeviceEvent(GpuEventSynchronizer* /* xUpdatedOnDeviceEvent */)
{
GMX_ASSERT(!impl_,
"A CPU stub method from GPU state propagator data was called instead of one from "
"GPU implementation.");
- return nullptr;
}
void StatePropagatorDataGpu::copyCoordinatesToGpu(const gmx::ArrayRef<const gmx::RVec> /* h_x */,
*/
void waitCoordinatesCopiedToDevice(AtomLocality atomLocality);
- /*! \brief Getter for the event synchronizer for the update is done on th GPU
+ /*! \brief Setter for the event synchronizer for the update is done on th GPU
*
- * \returns The event to synchronize the stream coordinates wre updated on device.
+ * \param[in] xUpdatedOnDeviceEvent The event to synchronize the stream coordinates wre updated on device.
*/
- GpuEventSynchronizer* xUpdatedOnDevice();
+ void setXUpdatedOnDeviceEvent(GpuEventSynchronizer* xUpdatedOnDeviceEvent);
/*! \brief Copy positions from the GPU memory.
*
* \todo Reconsider naming. It should be xCopiedToDevice or xH2DCopyComplete, etc.
*/
EnumerationArray<AtomLocality, GpuEventSynchronizer> xReadyOnDevice_;
- //! An event that the coordinates are ready after update-constraints execution
- GpuEventSynchronizer xUpdatedOnDevice_;
+ //! A pointer to an event that the coordinates are ready after update-constraints execution
+ GpuEventSynchronizer* xUpdatedOnDeviceEvent_ = nullptr;
//! An array of events that indicate D2H copy of coordinates is complete (one event for each atom locality)
EnumerationArray<AtomLocality, GpuEventSynchronizer> xReadyOnHost_;
# include "gromacs/gpu_utils/device_stream_manager.h"
# include "gromacs/gpu_utils/devicebuffer.h"
+# include "gromacs/gpu_utils/gpueventsynchronizer.h"
# include "gromacs/math/vectypes.h"
# include "gromacs/mdtypes/state_propagator_data_gpu.h"
# include "gromacs/timing/wallcycle.h"
}
if (atomLocality == AtomLocality::Local && simulationWork.useGpuUpdate && !stepWork.doNeighborSearch)
{
- return &xUpdatedOnDevice_;
+ GMX_ASSERT(xUpdatedOnDeviceEvent_ != nullptr, "The event synchronizer can not be nullptr.");
+ return xUpdatedOnDeviceEvent_;
}
else
{
wallcycle_stop(wcycle_, WallCycleCounter::WaitGpuStatePropagatorData);
}
-GpuEventSynchronizer* StatePropagatorDataGpu::Impl::xUpdatedOnDevice()
+void StatePropagatorDataGpu::Impl::setXUpdatedOnDeviceEvent(GpuEventSynchronizer* xUpdatedOnDeviceEvent)
{
- return &xUpdatedOnDevice_;
+ GMX_ASSERT(xUpdatedOnDeviceEvent != nullptr, "The event synchronizer can not be nullptr.");
+ xUpdatedOnDeviceEvent_ = xUpdatedOnDeviceEvent;
}
void StatePropagatorDataGpu::Impl::copyCoordinatesFromGpu(gmx::ArrayRef<gmx::RVec> h_x, AtomLocality atomLocality)
return impl_->waitCoordinatesCopiedToDevice(atomLocality);
}
-GpuEventSynchronizer* StatePropagatorDataGpu::xUpdatedOnDevice()
+void StatePropagatorDataGpu::setXUpdatedOnDeviceEvent(GpuEventSynchronizer* xUpdatedOnDeviceEvent)
{
- return impl_->xUpdatedOnDevice();
+ impl_->setXUpdatedOnDeviceEvent(xUpdatedOnDeviceEvent);
}
void StatePropagatorDataGpu::copyCoordinatesFromGpu(gmx::ArrayRef<RVec> h_x, AtomLocality atomLocality)