Move GPU traits into separate headers
[alexxy/gromacs.git] / src / gromacs / gpu_utils / gpuregiontimer_ocl.h
index fc64d04e96e18752607130dcad23cee6df3656ce..91e9e8de23bdf8faeebc28217caea500c4aa5e9f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -76,9 +69,22 @@ template <> class GpuRegionTimerImpl<GpuFramework::OpenCL>
 
     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;
@@ -102,6 +108,7 @@ template <> class GpuRegionTimerImpl<GpuFramework::OpenCL>
             return milliseconds;
         }
 
+        /*! \brief Resets internal state */
         inline void reset()
         {
             for (size_t i = 0; i < currentEvent_; i++)
@@ -116,6 +123,10 @@ template <> class GpuRegionTimerImpl<GpuFramework::OpenCL>
             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");
@@ -125,4 +136,7 @@ template <> class GpuRegionTimerImpl<GpuFramework::OpenCL>
         }
 };
 
+//! Short-hand for external use
+using GpuRegionTimer = GpuRegionTimerWrapper<GpuRegionTimerImpl>;
+
 #endif