COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
CarmaTimer Class Reference

a simple timer for CUDA kernel. More...

#include <carma_timer.h>

Collaboration diagram for CarmaTimer:

Public Member Functions

 CarmaTimer ()
 
 ~CarmaTimer ()
 
void start ()
 
void reset ()
 
void stop ()
 
void set_stream (cudaStream_t newStream)
 
double elapsed ()
 

Protected Attributes

cudaEvent_t start_event
 
cudaEvent_t stop_event
 
cudaStream_t stream = 0
 
double total_time
 

Detailed Description

a simple timer for CUDA kernel.

this class provides the timer features to CarmaObj

Author
COMPASS Team https://github.com/ANR-COMPASS
Version
5.0.0
Date
2011/01/28

Definition at line 52 of file carma_timer.h.

Constructor & Destructor Documentation

◆ CarmaTimer()

CarmaTimer::CarmaTimer ( )

Definition at line 59 of file carma_timer.h.

59  {
60  carma_safe_call(cudaEventCreate(&start_event));
61  carma_safe_call(cudaEventCreate(&stop_event));
62  total_time = 0.0;
63  }

◆ ~CarmaTimer()

CarmaTimer::~CarmaTimer ( )

Definition at line 65 of file carma_timer.h.

65  {
66  cudaEventDestroy(start_event);
67  cudaEventDestroy(stop_event);
68  }

Member Function Documentation

◆ elapsed()

double CarmaTimer::elapsed ( )

return elapsed time in seconds (as record in total_time)

Definition at line 85 of file carma_timer.h.

85 { return total_time; }

◆ reset()

void CarmaTimer::reset ( )

Definition at line 72 of file carma_timer.h.

72 { total_time = 0.0; }

◆ set_stream()

void CarmaTimer::set_stream ( cudaStream_t  newStream)

Definition at line 83 of file carma_timer.h.

83 { stream = newStream; }

◆ start()

void CarmaTimer::start ( )

Definition at line 70 of file carma_timer.h.

70 { carma_safe_call(cudaEventRecord(start_event, stream)); }

◆ stop()

void CarmaTimer::stop ( )

stop timer and accumulate time in seconds

Definition at line 75 of file carma_timer.h.

75  {
76  float gpuTime;
77  carma_safe_call(cudaEventRecord(stop_event, stream));
78  carma_safe_call(cudaEventSynchronize(stop_event));
79  carma_safe_call(cudaEventElapsedTime(&gpuTime, start_event, stop_event));
80  total_time += (double)1e-3 * gpuTime;
81  }
Here is the caller graph for this function:

Member Data Documentation

◆ start_event

cudaEvent_t CarmaTimer::start_event
protected

Definition at line 54 of file carma_timer.h.

◆ stop_event

cudaEvent_t CarmaTimer::stop_event
protected

Definition at line 54 of file carma_timer.h.

◆ stream

cudaStream_t CarmaTimer::stream = 0
protected

Definition at line 55 of file carma_timer.h.

◆ total_time

double CarmaTimer::total_time
protected

Definition at line 56 of file carma_timer.h.


The documentation for this class was generated from the following file:
carma_safe_call
#define carma_safe_call(err)
Definition: carma_utils.h:145
CarmaTimer::stop_event
cudaEvent_t stop_event
Definition: carma_timer.h:54
CarmaTimer::start_event
cudaEvent_t start_event
Definition: carma_timer.h:54
CarmaTimer::total_time
double total_time
Definition: carma_timer.h:56
CarmaTimer::stream
cudaStream_t stream
Definition: carma_timer.h:55