OpenVDB 13.1.0
Loading...
Searching...
No Matches
Timer Class Reference

#include <nanovdb/util/cuda/Timer.h>

Public Member Functions

 Timer (cudaStream_t stream=0)
 Default constructor.
 Timer (const std::string &msg, cudaStream_t stream=0, std::ostream &os=std::cerr)
 Construct and start the timer.
 ~Timer ()
 Destructor.
void start ()
 Start the timer.
void start (const std::string &msg, std::ostream &os=std::cerr)
 Start the timer.
void start (const char *msg, std::ostream &os=std::cerr)
 Start the timer.
void record ()
float milliseconds () const
 Return the time in milliseconds since record was called.
float elapsed ()
 elapsed time (since start) in miliseconds
void print (std::ostream &os=std::cerr)
 Prints the elapsed time in milliseconds to a stream.
void print (const char *msg, std::ostream &os=std::cerr)
 Prints a message followed by the elapsed time in milliseconds to a stream.
void print (const std::string &msg, std::ostream &os=std::cerr)
 Like the above method but with a std::string arguments.
void stop (std::ostream &os=std::cerr)
 stop the timer
void restart (const std::string &msg, std::ostream &os=std::cerr)
 stop and start the timer

Constructor & Destructor Documentation

◆ Timer() [1/2]

Timer ( cudaStream_t stream = 0)
inline

Default constructor.

Parameters
streamCUDA stream to be timed (defaults to stream 0)
Note
Starts the timer
Warning
cudaEventCreate creates the event for the current device and cudaEventRecord requires that the event and stream are associated with the same device. So it's important to call cudaSetDevice(device) so device matches the one used when stream was created.

◆ Timer() [2/2]

Timer ( const std::string & msg,
cudaStream_t stream = 0,
std::ostream & os = std::cerr )
inline

Construct and start the timer.

Parameters
msgstring message to be printed when timer is started
streamCUDA stream to be timed (defaults to stream 0)
osoutput stream for the message above
Warning
cudaEventCreate creates the event for the current device and cudaEventRecord requires that the event and stream are associated with the same device. So it's important to call cudaSetDevice(device) so device matches the one used when stream was created.

◆ ~Timer()

~Timer ( )
inline

Destructor.

Member Function Documentation

◆ elapsed()

float elapsed ( )
inline

elapsed time (since start) in miliseconds

Returns
elapsed time (since start) in miliseconds

◆ milliseconds()

float milliseconds ( ) const
inline

Return the time in milliseconds since record was called.

◆ print() [1/3]

void print ( const char * msg,
std::ostream & os = std::cerr )
inline

Prints a message followed by the elapsed time in milliseconds to a stream.

Parameters
msgmessage to print before the time
osstream to print to

◆ print() [2/3]

void print ( const std::string & msg,
std::ostream & os = std::cerr )
inline

Like the above method but with a std::string arguments.

◆ print() [3/3]

void print ( std::ostream & os = std::cerr)
inline

Prints the elapsed time in milliseconds to a stream.

Parameters
osoutput stream to print to

◆ record()

void record ( )
inline
Warning
cudaEventRecord requires that the event and stream are associated with the same device. So it's important to call cudaSetDevice(device) so it matches the device used when mStream was created.

◆ restart()

void restart ( const std::string & msg,
std::ostream & os = std::cerr )
inline

stop and start the timer

Parameters
msgstring message to be printed when timer is started
osoutput stream for the message above
Warning
Remember to call start before restart

◆ start() [1/3]

void start ( )
inline

Start the timer.

Warning
cudaEventRecord requires that the event and stream are associated with the same device. So it's important to call cudaSetDevice(device) so device matches the one used when mStream was created.

◆ start() [2/3]

void start ( const char * msg,
std::ostream & os = std::cerr )
inline

Start the timer.

Parameters
msgstring message to be printed when timer is started
osoutput stream for the message above

◆ start() [3/3]

void start ( const std::string & msg,
std::ostream & os = std::cerr )
inline

Start the timer.

Parameters
msgstring message to be printed when timer is started
osoutput stream for the message above

◆ stop()

void stop ( std::ostream & os = std::cerr)
inline

stop the timer

Parameters
osoutput stream for the message above