10#ifndef NANOVDB_UTIL_CUDA_TIMER_H_HAS_BEEN_INCLUDED
11#define NANOVDB_UTIL_CUDA_TIMER_H_HAS_BEEN_INCLUDED
15#include <cuda_runtime_api.h>
23 cudaStream_t mStream{0};
24 cudaEvent_t mStart, mStop;
35 Timer(cudaStream_t stream = 0) : mStream(stream)
37 cudaEventCreate(&mStart);
38 cudaEventCreate(&mStop);
39 cudaEventRecord(mStart, mStream);
51 Timer(
const std::string &msg, cudaStream_t stream = 0, std::ostream& os = std::cerr)
54 os << msg <<
" ... " << std::flush;
55 cudaEventCreate(&mStart);
56 cudaEventCreate(&mStop);
57 cudaEventRecord(mStart, mStream);
63 cudaEventDestroy(mStart);
64 cudaEventDestroy(mStop);
72 void start() {cudaEventRecord(mStart, mStream);}
77 void start(
const std::string &msg, std::ostream& os = std::cerr)
79 os << msg <<
" ... " << std::flush;
86 void start(
const char* msg, std::ostream& os = std::cerr)
88 os << msg <<
" ... " << std::flush;
98 cudaEventRecord(mStop, mStream);
99 cudaEventSynchronize(mStop);
106 cudaEventElapsedTime(&msec, mStart, mStop);
120 inline void print(std::ostream& os = std::cerr)
123 os <<
"completed in " << msec <<
" milliseconds" << std::endl;
129 inline void print(
const char* msg, std::ostream& os = std::cerr)
136 inline void print(
const std::string &msg, std::ostream& os = std::cerr){this->
print(msg.c_str(), os);}
140 inline void stop(std::ostream& os = std::cerr)
150 inline void restart(
const std::string &msg, std::ostream& os = std::cerr)
153 this->
start(msg, os);
159using GpuTimer [[deprecated(
"Use nanovdb::util::cuda::Timer instead")]]=
util::cuda::Timer;
float elapsed()
elapsed time (since start) in miliseconds
Definition Timer.h:112
void print(const std::string &msg, std::ostream &os=std::cerr)
Like the above method but with a std::string arguments.
Definition Timer.h:136
void restart(const std::string &msg, std::ostream &os=std::cerr)
stop and start the timer
Definition Timer.h:150
void stop(std::ostream &os=std::cerr)
stop the timer
Definition Timer.h:140
Timer(cudaStream_t stream=0)
Default constructor.
Definition Timer.h:35
~Timer()
Destructor.
Definition Timer.h:61
void start()
Start the timer.
Definition Timer.h:72
Timer(const std::string &msg, cudaStream_t stream=0, std::ostream &os=std::cerr)
Construct and start the timer.
Definition Timer.h:51
void print(std::ostream &os=std::cerr)
Prints the elapsed time in milliseconds to a stream.
Definition Timer.h:120
void start(const std::string &msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:77
void record()
Definition Timer.h:96
void start(const char *msg, std::ostream &os=std::cerr)
Start the timer.
Definition Timer.h:86
float milliseconds() const
Return the time in milliseconds since record was called.
Definition Timer.h:103
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:129
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:31