Merge common nbnxn CUDA/OpenCL GPU wait code-paths
[alexxy/gromacs.git] / src / gromacs / gpu_utils / oclutils.h
index 72af59a2018982e30cad3ba13a77a7d03f80982b..7723fe424cf9db9739b2e59d6d25c1194ba98764 100644 (file)
@@ -53,6 +53,8 @@
 
 #include <string>
 
+#include "gromacs/utility/gmxassert.h"
+
 /*! \brief OpenCL vendor IDs */
 typedef enum {
     OCL_VENDOR_NVIDIA = 0,
@@ -135,4 +137,15 @@ void ocl_pfree(void *h_ptr);
 /*! \brief Convert error code to diagnostic string */
 std::string ocl_get_error_string(cl_int error);
 
+/*! \brief Calls clFinish() in the stream \p s.
+ *
+ * \param[in] s stream to synchronize with
+ */
+static inline void gpuStreamSynchronize(cl_command_queue s)
+{
+    cl_int cl_error = clFinish(s);
+    GMX_RELEASE_ASSERT(CL_SUCCESS == cl_error,
+                       ("Error caught during clFinish:" + ocl_get_error_string(cl_error)).c_str());
+}
+
 #endif