imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cuda_timer.cu
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11
12// =======
13// Headers
14// =======
15
16#include "./cuda_timer.h"
17
18
19// ===========
20// Constructor
21// ===========
22
25
31
32
33// ==========
34// Destructor
35// ==========
36
39
45
46
47// =====
48// start
49// =====
50
53
55{
57}
58
59
60// ====
61// stop
62// ====
63
66
68{
69 cudaEventRecord(this->stop_time, 0);
70}
71
72
73// =======
74// elapsed
75// =======
76
79
80float CudaTimer::elapsed() const
81{
82 float elapsed_time;
84 cudaEventElapsedTime(&elapsed_time, this->start_time, this->stop_time);
85
86 // Convert from milli-second to second
87 return elapsed_time / 1.0e+3;
88}
~CudaTimer()
Destructor for CudaTimer.
Definition cuda_timer.cu:40
void stop()
Stops the timer.
Definition cuda_timer.cu:67
void start()
Starts the timer.
Definition cuda_timer.cu:54
cudaEvent_t stop_time
Definition cuda_timer.h:73
float elapsed() const
Returns the elapsed time in seconds.
Definition cuda_timer.cu:80
CudaTimer()
constructor for CudaTimer
Definition cuda_timer.cu:26
cudaEvent_t start_time
Definition cuda_timer.h:72
cudaError_t cudaEventSynchronize(cudaEvent_t event)
Definition of CUDA's cudaEventSynchronize function using dynamically loaded cudart library.
cudaError_t cudaEventElapsedTime(float *ms, cudaEvent_t start, cudaEvent_t end)
Definition of CUDA's cudaEventElapsedTime function using dynamically loaded cudart library.
cudaError_t cudaEventCreate(cudaEvent_t *event)
Definition of CUDA's cudaEventCreate function using dynamically loaded cudart library.
cudaError_t cudaEventDestroy(cudaEvent_t event)
Definition of CUDA's cudaEventDestroy function using dynamically loaded cudart library.
cudaError_t cudaEventRecord(cudaEvent_t event, cudaStream_t stream)
Definition of CUDA's cudaEventRecord function using dynamically loaded cudart library.