Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:44

0001 #ifndef HeterogeneousCore_CUDAUtilities_eventWorkHasCompleted_h
0002 #define HeterogeneousCore_CUDAUtilities_eventWorkHasCompleted_h
0003 
0004 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0005 
0006 #include <cuda_runtime.h>
0007 
0008 namespace cms {
0009   namespace cuda {
0010     /**
0011    * Returns true if the work captured by the event (=queued to the
0012    * CUDA stream at the point of cudaEventRecord()) has completed.
0013    *
0014    * Returns false if any captured work is incomplete.
0015    *
0016    * In case of errors, throws an exception.
0017    */
0018     inline bool eventWorkHasCompleted(cudaEvent_t event) {
0019       const auto ret = cudaEventQuery(event);
0020       if (ret == cudaSuccess) {
0021         return true;
0022       } else if (ret == cudaErrorNotReady) {
0023         return false;
0024       }
0025       // leave error case handling to cudaCheck
0026       cudaCheck(ret);
0027       return false;  // to keep compiler happy
0028     }
0029   }  // namespace cuda
0030 }  // namespace cms
0031 
0032 #endif