10#ifndef NANOVDB_UTIL_CUDA_TIMER_H_HAS_BEEN_INCLUDED
11#define NANOVDB_UTIL_CUDA_TIMER_H_HAS_BEEN_INCLUDED
16#include <cuda_runtime_api.h>
24 cudaStream_t mStream{0};
25 cudaEvent_t mStart, mStop;
36 Timer(cudaStream_t stream = 0) : mStream(stream)
38 cudaEventCreate(&mStart);
39 cudaEventCreate(&mStop);
40 cudaEventRecord(mStart, mStream);
52 Timer(
const std::string &msg, cudaStream_t stream = 0, std::ostream& os = std::cerr)
55 os << msg <<
" ... " << std::flush;
56 cudaEventCreate(&mStart);
57 cudaEventCreate(&mStop);
58 cudaEventRecord(mStart, mStream);
64 cudaEventDestroy(mStart);
65 cudaEventDestroy(mStop);
73 void start() {cudaEventRecord(mStart, mStream);}
78 void start(
const std::string &msg, std::ostream& os = std::cerr)
80 os << msg <<
" ... " << std::flush;
87 void start(
const char* msg, std::ostream& os = std::cerr)
89 os << msg <<
" ... " << std::flush;
99 cudaEventRecord(mStop, mStream);
100 cudaEventSynchronize(mStop);
107 cudaEventElapsedTime(&msec, mStart, mStop);
121 inline void print(std::ostream& os = std::cerr)
124 os <<
"completed in " << msec <<
" milliseconds" << std::endl;
130 inline void print(
const char* msg, std::ostream& os = std::cerr)
137 inline void print(
const std::string &msg, std::ostream& os = std::cerr){this->
print(msg.c_str(), os);}
141 inline void stop(std::ostream& os = std::cerr)
151 inline void restart(
const std::string &msg, std::ostream& os = std::cerr)
154 this->
start(msg, os);
float elapsed()
elapsed time (since start) in miliseconds
Definition Timer.h:113
void print(const std::string &msg, std::ostream &os=std::cerr)
Like the above method but with a std::string arguments.
Definition Timer.h:137
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer
Definition Timer.h:151
void stop(std::ostream &os=std::cerr)
stop the timer
Definition Timer.h:141
Timer(cudaStream_t stream=0)
Default constructor.
Definition Timer.h:36
~Timer()
Destructor.
Definition Timer.h:62
void start()
Start the timer.
Definition Timer.h:73
Timer(const std::string &msg, cudaStream_t stream=0, std::ostream &os=std::cerr)
Construct and start the timer.
Definition Timer.h:52
void print(std::ostream &os=std::cerr)
Prints the elapsed time in milliseconds to a stream.
Definition Timer.h:121
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:78
void record()
Definition Timer.h:97
void start(const char *msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:87
float milliseconds() const
Return the time in milliseconds since record was called.
Definition Timer.h:104
void print(const char *msg, std::ostream &os=std::cerr)
Prints a message followed by the elapsed time in milliseconds to a stream.
Definition Timer.h:130
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:34