/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#define GMX_GPU_UTILS_GPUREGIONTIMER_CUH
#include "gromacs/gpu_utils/cudautils.cuh"
+#include "gromacs/gpu_utils/gputraits.cuh"
#include "gpuregiontimer.h"
-template <> struct GpuTraits<GpuFramework::CUDA>
-{
- using CommandStream = cudaStream_t;
- using CommandEvent = void;
-};
-
-//! Short-hand for external use
-using GpuRegionTimer = GpuRegionTimerWrapper<GpuFramework::CUDA>;
-
-template <> class GpuRegionTimerImpl<GpuFramework::CUDA>
+/*! \libinternal \brief
+ * This is a GPU region timing implementation for CUDA.
+ * It provides methods for measuring the last timespan.
+ * Copying/assignment is disabled since the underlying timing events are owned by this.
+ */
+class GpuRegionTimerImpl
{
- //! Short-hand
- using CommandStream = typename GpuTraits<GpuFramework::CUDA>::CommandStream;
//! The underlying timing event pair - the beginning and the end of the timespan
cudaEvent_t eventStart_, eventStop_;
CU_RET_ERR(cudaEventCreate(&eventStart_, eventFlags), "GPU timing creation failure");
CU_RET_ERR(cudaEventCreate(&eventStop_, eventFlags), "GPU timing creation failure");
}
-
~GpuRegionTimerImpl()
{
CU_RET_ERR(cudaEventDestroy(eventStart_), "GPU timing destruction failure");
CU_RET_ERR(cudaEventDestroy(eventStop_), "GPU timing destruction failure");
}
+ //! No copying
+ GpuRegionTimerImpl(const GpuRegionTimerImpl &) = delete;
+ //! No assignment
+ GpuRegionTimerImpl &operator = (GpuRegionTimerImpl &&) = delete;
+ //! Moving is disabled but can be considered in the future if needed
+ GpuRegionTimerImpl(GpuRegionTimerImpl &&) = delete;
+ /*! \brief Will be called before the region start. */
inline void openTimingRegion(CommandStream s)
{
CU_RET_ERR(cudaEventRecord(eventStart_, s), "GPU timing recording failure");
}
+ /*! \brief Will be called after the region end. */
inline void closeTimingRegion(CommandStream s)
{
CU_RET_ERR(cudaEventRecord(eventStop_, s), "GPU timing recording failure");
}
+ /*! \brief Returns the last measured region timespan (in milliseconds) and calls reset() */
inline double getLastRangeTime()
{
float milliseconds = 0.0;
return milliseconds;
}
+ /*! \brief Resets internal state */
inline void reset(){}
};
+//! Short-hand for external use
+using GpuRegionTimer = GpuRegionTimerWrapper<GpuRegionTimerImpl>;
+
#endif
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
static const bool c_debugTimerState = true;
#endif
-/*! \libinternal \brief
- * Enumeration of possible GPU build-paths.
- * \todo Move somewhere general?
- */
-enum class GpuFramework
-{
- CUDA,
- OpenCL
-};
-
-/*! \libinternal \brief
- * GPU build-path traits such as types.
- * \todo Move somewhere general?
- */
-template <GpuFramework> struct GpuTraits
-{
- using CommandStream = void; //!< GPU command stream
- using CommandEvent = void; //!< Single command call timing event - used in OpenCL
-};
-
-/*! \libinternal \brief
- * This is a GPU region timing implementation interface.
- * It should provide methods for measuring the last timespan.
- * Copying/assignment is disabled since the underlying timing events are owned by this.
- */
-template <GpuFramework framework> class GpuRegionTimerImpl
-{
- //! Short-hands
- using CommandStream = typename GpuTraits<framework>::CommandStream;
- using CommandEvent = typename GpuTraits<framework>::CommandEvent;
-
- public:
-
- GpuRegionTimerImpl() = default;
- ~GpuRegionTimerImpl() = default;
- //! No copying
- GpuRegionTimerImpl(const GpuRegionTimerImpl &) = delete;
- //! No assignment
- GpuRegionTimerImpl &operator=(GpuRegionTimerImpl &&) = delete;
- //! Moving is disabled but can be considered in the future if needed
- GpuRegionTimerImpl(GpuRegionTimerImpl &&) = delete;
-
- /*! \brief Will be called before the region start. */
- inline void openTimingRegion(CommandStream) = 0;
- /*! \brief Will be called after the region end. */
- inline void closeTimingRegion(CommandStream) = 0;
- /*! \brief Resets any internal state if needed */
- inline void reset() = 0;
- /*! \brief Returns the last measured region timespan (in milliseconds) and calls reset() */
- inline double getLastRangeTime() = 0;
- /*! \brief Returns a new raw timing event
- * for passing into individual GPU API calls
- * within the region if the API requires it (e.g. on OpenCL). */
- inline CommandEvent *fetchNextEvent() = 0;
-};
-
/*! \libinternal \brief
* This is a GPU region timing wrapper class.
* It allows for host-side tracking of the accumulated execution timespans in GPU code
* as far as current implementation allows (see TODO in getLastRangeTime() for a disabled check).
* Internally it uses GpuRegionTimerImpl for measuring regions.
*/
-template <GpuFramework framework> class GpuRegionTimerWrapper
+template <typename GpuRegionTimerImpl> class GpuRegionTimerWrapper
{
- //! Short-hands
- using CommandStream = typename GpuTraits<framework>::CommandStream;
- using CommandEvent = typename GpuTraits<framework>::CommandEvent;
//! The timer state used for debug-only assertions
enum class TimerState
{
} debugState_ = TimerState::Idle;
//! The number of times the timespan has been measured
- unsigned int callCount_ = 0;
+ unsigned int callCount_ = 0;
//! The accumulated duration of the timespans measured (milliseconds)
- double totalMilliseconds_ = 0.0;
+ double totalMilliseconds_ = 0.0;
//! The underlying region timer implementation
- GpuRegionTimerImpl<framework> impl_;
+ GpuRegionTimerImpl impl_;
public:
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <array>
+#include "gromacs/gpu_utils/gputraits_ocl.h"
#include "gromacs/gpu_utils/oclutils.h"
#include "gpuregiontimer.h"
-template <> struct GpuTraits<GpuFramework::OpenCL>
-{
- using CommandStream = cl_command_queue;
- using CommandEvent = cl_event;
-};
-
-//! Short-hand for external use
-using GpuRegionTimer = GpuRegionTimerWrapper<GpuFramework::OpenCL>;
-
+/*! \libinternal \brief
+ * This is a GPU region timing implementation for OpenCL.
+ * It provides methods for measuring the last timespan.
+ * Copying/assignment is disabled since the underlying timing events are owned by this.
+ */
// cppcheck-suppress noConstructor
-template <> class GpuRegionTimerImpl<GpuFramework::OpenCL>
+class GpuRegionTimerImpl
{
- //! Short-hands
- using CommandStream = typename GpuTraits<GpuFramework::OpenCL>::CommandStream;
- using CommandEvent = typename GpuTraits<GpuFramework::OpenCL>::CommandEvent;
-
/*! \brief The underlying individual timing events array.
* The maximum size is chosen arbitrarily to work with current code, and can be changed.
* There is simply no need for run-time resizing, and it's unlikely we'll ever need more than 10.
public:
+ GpuRegionTimerImpl() = default;
+ ~GpuRegionTimerImpl() = default;
+ //! No copying
+ GpuRegionTimerImpl(const GpuRegionTimerImpl &) = delete;
+ //! No assignment
+ GpuRegionTimerImpl &operator=(GpuRegionTimerImpl &&) = delete;
+ //! Moving is disabled but can be considered in the future if needed
+ GpuRegionTimerImpl(GpuRegionTimerImpl &&) = delete;
+
+ /*! \brief Will be called before the region start. */
inline void openTimingRegion(CommandStream){}
+
+ /*! \brief Will be called after the region end. */
inline void closeTimingRegion(CommandStream){}
+ /*! \brief Returns the last measured region timespan (in milliseconds) and calls reset() */
inline double getLastRangeTime()
{
double milliseconds = 0.0;
return milliseconds;
}
+ /*! \brief Resets internal state */
inline void reset()
{
for (size_t i = 0; i < currentEvent_; i++)
events_.fill(nullptr);
}
+ /*! \brief Returns a new raw timing event
+ * for passing into individual GPU API calls
+ * within the region if the API requires it (e.g. on OpenCL).
+ */
inline CommandEvent *fetchNextEvent()
{
GMX_ASSERT(currentEvent_ < events_.size(), "Increase c_maxEventNumber_ if needed");
}
};
+//! Short-hand for external use
+using GpuRegionTimer = GpuRegionTimerWrapper<GpuRegionTimerImpl>;
+
#endif
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2018, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_GPU_UTILS_GPUTRAITS_CUH
+#define GMX_GPU_UTILS_GPUTRAITS_CUH
+
+/*! \libinternal \file
+ * \brief Declares the CUDA type traits.
+ * \author Aleksei Iupinov <a.yupinov@gmail.com>
+ *
+ * \inlibraryapi
+ */
+
+//! \brief GPU command stream
+using CommandStream = cudaStream_t;
+//! \brief Single GPU call timing event - meaningless in CUDA
+using CommandEvent = void;
+
+#endif
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2018, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_GPU_UTILS_GPUTRAITS_OCL_H
+#define GMX_GPU_UTILS_GPUTRAITS_OCL_H
+
+/*! \libinternal \file
+ * \brief Declares the OpenCL type traits.
+ * \author Aleksei Iupinov <a.yupinov@gmail.com>
+ *
+ * \inlibraryapi
+ */
+
+#include "gromacs/gpu_utils/gmxopencl.h"
+
+//! \brief GPU command stream
+using CommandStream = cl_command_queue;
+//! \brief Single GPU call timing event
+using CommandEvent = cl_event;
+
+#endif
#include "thread_mpi/atomic.h"
+#include "gromacs/gpu_utils/gputraits_ocl.h"
#include "gromacs/gpu_utils/oclutils.h"
#include "gromacs/hardware/hw_info.h"
#include "gromacs/mdlib/force_flags.h"
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#define NBNXN_OPENCL_TYPES_H
#include "gromacs/gpu_utils/gmxopencl.h"
+#include "gromacs/gpu_utils/gputraits_ocl.h"
#include "gromacs/gpu_utils/oclutils.h"
#include "gromacs/mdlib/nbnxn_gpu_types_common.h"
#include "gromacs/mdlib/nbnxn_pairlist.h"