Ginkgo: gko::Timer Class Reference

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
gko::Timer Class Referenceabstract

Represents a generic timer that can be used to record time points and measure time differences on host or device streams. More...

`#include <ginkgo/core/base/timer.hpp>`

Inheritance diagram for gko::Timer:
[legend]

## Public Member Functions
time_point | create_time_point ()
| Returns a newly created time point.
virtual void | record (time_point &time)=0
| Records a time point at the current time.
virtual void | wait (time_point &time)=0
| Waits until all kernels in-process when recording the time point are finished.
std::chrono::nanoseconds | difference (time_point &start, time_point &stop)
| Computes the difference between the two time points in nanoseconds.
virtual std::chrono::nanoseconds | difference_async (const time_point &start, const time_point &stop)=0
| Computes the difference between the two time points in nanoseconds.

## Static Public Member Functions
static std::unique_ptr< Timer > | create_for_executor (std::shared_ptr< const Executor > exec)
| Creates the timer type most suitable for recording accurate timings of kernels on the given executor.

## Detailed Description

Represents a generic timer that can be used to record time points and measure time differences on host or device streams.

To keep the runtime overhead of timing minimal, time points need to be allocated beforehand using Timer::create_time_point:

auto begin = timer->create_time_point();
auto end = timer->create_time_point();
// ...
timer->record(begin);
run_expensive_operation();
timer->record(end);
auto elapsed = timer->difference(begin, end);

## Member Function Documentation

## ◆ create_for_executor()

std::unique_ptr< Timer > gko::Timer::create_for_executor | ( | std::shared_ptr< const Executor > | exec | ) |
| static

Creates the timer type most suitable for recording accurate timings of kernels on the given executor.

Parameters

  exec | the executor to create a Timer for

Returns
  CpuTimer for ReferenceExecutor and OmpExecutor, CudaTimer for CudaExecutor, HipTimer for HipExecutor or DpcppTimer for DpcppExecutor.

## ◆ create_time_point()

time_point gko::Timer::create_time_point | ( |  | ) |

Returns a newly created time point.

Time points may only be used with the timer they were created with.

## ◆ difference()

std::chrono::nanoseconds gko::Timer::difference | ( | time_point & | start,
|  | time_point & | stop )

Computes the difference between the two time points in nanoseconds.

The function synchronizes with stop before computing the difference.

Parameters

  start | the first time point (earlier)
  end | the second time point (later)

Returns
  the difference between the time points in nanoseconds.

## ◆ difference_async()

virtual std::chrono::nanoseconds gko::Timer::difference_async | ( | const time_point & | start,
|  | const time_point & | stop )
| pure virtual

Computes the difference between the two time points in nanoseconds.

This asynchronous version does not synchronize itself, so the time points need to have been synchronized with, i.e. timer->wait(stop) needs to have been called. The version is intended for more advanced users who want to measure the overhead of timing functionality separately.

Parameters

  start | the first time point (earlier)
  end | the second time point (later)

Returns
  the difference between the time points in nanoseconds.

Implemented in gko::CpuTimer, gko::CudaTimer, gko::DpcppTimer, and gko::HipTimer.

## ◆ record()

virtual void gko::Timer::record | ( | time_point & | time | ) |
| pure virtual

Records a time point at the current time.

Implemented in gko::CpuTimer, gko::CudaTimer, gko::DpcppTimer, and gko::HipTimer.

## ◆ wait()

virtual void gko::Timer::wait | ( | time_point & | time | ) |
| pure virtual

Waits until all kernels in-process when recording the time point are finished.

Implemented in gko::CpuTimer, gko::CudaTimer, gko::DpcppTimer, and gko::HipTimer.

The documentation for this class was generated from the following file:

- ginkgo/core/base/timer.hpp