Skip to content

Commit 146c1a4

Browse files
authored
Destroy left-over cuda events (#789)
* Destroy left-over cuda events * Remove unused variable
1 parent 0b0cbf8 commit 146c1a4

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

benchmarks/cpp/nvfuser/reduction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static void MagicScheduler_Reduction(benchmark::State& benchmark_state,
124124
// Sync everything up before we start
125125
cudaDeviceSynchronize();
126126
for (auto _ : benchmark_state) {
127-
CudaKernelTimer timer;
128127
auto cg_outputs = fe.runFusion({aten_input}, lparams);
129128
benchmark_state.SetIterationTime(fe.kernelTimeMs() / 1000.0);
130129
}

benchmarks/cpp/nvfuser/softmax.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,7 @@ static void MagicScheduler_Softmax_Dropout_Baseline(
217217

218218
for (auto _ : benchmark_state) {
219219
// Create
220-
float kernel_time_ms_ = 0;
221-
cudaEvent_t start_event = {};
222-
cudaEvent_t finish_event = {};
223-
224-
// Setup
225-
cudaEventCreate(&start_event);
226-
cudaEventCreate(&finish_event);
227-
cudaEventRecord(start_event);
220+
CudaKernelTimer timer;
228221

229222
// Run
230223
attention_scores = attention_scores / sqrt(kAttentionHeadSize);
@@ -234,12 +227,7 @@ static void MagicScheduler_Softmax_Dropout_Baseline(
234227
attention_probs = at::dropout(attention_probs, kDropoutProbability, true);
235228

236229
// Record
237-
cudaEventRecord(finish_event);
238-
cudaEventSynchronize(start_event);
239-
cudaEventSynchronize(finish_event);
240-
cudaEventElapsedTime(&kernel_time_ms_, start_event, finish_event);
241-
242-
benchmark_state.SetIterationTime(kernel_time_ms_ / 1000.0);
230+
benchmark_state.SetIterationTime(timer.elapsed() / 1000.0);
243231
cudaDeviceSynchronize();
244232
}
245233
}

benchmarks/cpp/nvfuser/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class CudaKernelTimer {
3737
cudaEventRecord(start_event);
3838
}
3939

40+
~CudaKernelTimer() {
41+
cudaEventDestroy(start_event);
42+
cudaEventDestroy(finish_event);
43+
}
44+
4045
float elapsed() {
4146
// Record
4247
cudaEventRecord(finish_event);

0 commit comments

Comments
 (0)