rvec_inc(a, tmp);
}
-/*! \brief Calls cudaStreamSynchronize() in the stream \p s.
+/*! \brief Wait for all taks in stream \p s to complete.
*
* \param[in] s stream to synchronize with
*/
CU_RET_ERR(stat, "cudaStreamSynchronize failed");
}
+/*! \brief Returns true if all tasks in \p s have completed.
+ *
+ * \param[in] s stream to check
+ *
+ * \returns True if all tasks enqueued in the stream \p s (at the time of this call) have completed.
+ */
+static inline bool haveStreamTasksCompleted(cudaStream_t s)
+{
+ cudaError_t stat = cudaStreamQuery(s);
+
+ if (stat == cudaErrorNotReady)
+ {
+ // work is still in progress in the stream
+ return false;
+ }
+
+ GMX_ASSERT(stat != cudaErrorInvalidResourceHandle, "Stream idnetifier not valid");
+
+ // cudaSuccess and cudaErrorNotReady are the expected return values
+ CU_RET_ERR(stat, "Unexpected cudaStreamQuery failure");
+
+ GMX_ASSERT(stat == cudaSuccess, "Values other than cudaSuccess should have been explicitly handled");
+
+ return true;
+}
+
#endif