diff --git a/paddle/fluid/platform/event.h b/paddle/fluid/platform/event.h index 93fc56ab203b6013265490fb38d2de7012ef2c72..66bb77225a3a86894284e779774625c5e00956e6 100644 --- a/paddle/fluid/platform/event.h +++ b/paddle/fluid/platform/event.h @@ -120,6 +120,7 @@ class MemEvent { class CudaEvent { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) + public: CudaEvent() { #ifdef PADDLE_WITH_HIP @@ -129,7 +130,7 @@ class CudaEvent { #endif } - CudaEvent(unsigned int flags) : flags_(flags) { + explicit CudaEvent(unsigned int flags) : flags_(flags) { #ifdef PADDLE_WITH_HIP hipEventCreateWithFlags(&event_, flags_); #else @@ -137,7 +138,15 @@ class CudaEvent { #endif } - void Record(paddle::platform::stream::CUDAStream& stream) { + ~CudaEvent() { +#ifdef PADDLE_WITH_HIP + PADDLE_ENFORCE_CUDA_SUCCESS(hipEventDestroy(event_)); +#else + PADDLE_ENFORCE_CUDA_SUCCESS(cudaEventDestroy(event_)); +#endif + } + + void Record(const paddle::platform::stream::CUDAStream& stream) { #ifdef PADDLE_WITH_HIP PADDLE_ENFORCE_CUDA_SUCCESS(hipEventRecord(event_, stream.raw_stream())); #else