Skip to content

Commit 090c863

Browse files
add CuddEvent destructor function (#34610)
1 parent 0989211 commit 090c863

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

paddle/fluid/platform/event.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class MemEvent {
120120

121121
class CudaEvent {
122122
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
123+
123124
public:
124125
CudaEvent() {
125126
#ifdef PADDLE_WITH_HIP
@@ -129,15 +130,23 @@ class CudaEvent {
129130
#endif
130131
}
131132

132-
CudaEvent(unsigned int flags) : flags_(flags) {
133+
explicit CudaEvent(unsigned int flags) : flags_(flags) {
133134
#ifdef PADDLE_WITH_HIP
134135
hipEventCreateWithFlags(&event_, flags_);
135136
#else
136137
cudaEventCreateWithFlags(&event_, flags_);
137138
#endif
138139
}
139140

140-
void Record(paddle::platform::stream::CUDAStream& stream) {
141+
~CudaEvent() {
142+
#ifdef PADDLE_WITH_HIP
143+
PADDLE_ENFORCE_CUDA_SUCCESS(hipEventDestroy(event_));
144+
#else
145+
PADDLE_ENFORCE_CUDA_SUCCESS(cudaEventDestroy(event_));
146+
#endif
147+
}
148+
149+
void Record(const paddle::platform::stream::CUDAStream& stream) {
141150
#ifdef PADDLE_WITH_HIP
142151
PADDLE_ENFORCE_CUDA_SUCCESS(hipEventRecord(event_, stream.raw_stream()));
143152
#else

0 commit comments

Comments
 (0)