From 090c863aca0fc5088ea6ce4bdff2f42da4fe80da Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Thu, 5 Aug 2021 10:36:20 +0800 Subject: [PATCH] add CuddEvent destructor function (#34610) --- paddle/fluid/platform/event.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/platform/event.h b/paddle/fluid/platform/event.h index 93fc56ab203..66bb77225a3 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 -- GitLab