Skip to content

YAKL Timers

Matt Norman edited this page May 9, 2022 · 9 revisions

By default YAKL's timers use YAKL's own internal timer library, but these can be overriden (see below). To use YAKL's timers, please use yakl::timer_init(), yakl::timer_start("label"), yakl::timer_stop("label"), and yakl::timer_finalize().

yakl::timer_start("mylabel")
...
yakl::timer_stop("mylabel")

If using YAKL's internal timers:

If you're using YAKL's internal timers, please be sure to set the CPP macro -DYAKL_PROFILE to turn them on and get output. YAKL automatically calls yakl::timer_init() and yakl::timer_finalize() for you during yakl::init() and yakl::finalize() when using the default internal YAKL timers. To make profiling easier when using YAKL's internal timers, you can also pass -DYAKL_AUTO_PROFILE, and YAKL will wrap timer calls around every parallel_for call in the code using its name as a label. All parallel_for calls without a string name will be timed as "unlabeled".

Important: All timer calls involve an fence() operation to ensure GPU kernels are accurately timed. This can add significant overhead to latency-sensitive (small-workload) applications. Also, if you do not specify either -DYAKL_PROFILE or -DYAKL_AUTO_PROFILE, then all timer calls will become no-ops.

If overriding YAKL's timers with your own

To override YAKL's timers to use another library, such as GPTL for instance, please use the following functions to override YAKL's timer calls with your own perferred code:

yakl::set_timer_init    ( std::function<void ()>             func );
yakl::set_timer_finalize( std::function<void ()>             func );
yakl::set_timer_start   ( std::function<void (char const *)> func );
yakl::set_timer_stop    ( std::function<void (char const *)> func );

If you've overriden YAKL's internal timers with your own, please to not set YAKL_PROFILE or YAKL_AUTO_PROFILE at this time, as these are not needed to enable overridden timer calls, and they may interfere and cause problems. These will be enabled for external timers in the future, but for now, for external timers, please manually place timer_start() and timer_stop(). You will also need to call timer_init() and timer_finalize() manually after setting the functions to use custom code. YAKL only calls these automatically if YAKL_PROFILE or YAKL_AUTO_PROFILE are set.

Clone this wiki locally