Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
timer.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_TIMER_HPP_
6#define GKO_PUBLIC_CORE_BASE_TIMER_HPP_
7
8
9#include <chrono>
10
11
12#include <ginkgo/core/base/executor.hpp>
13
14
15namespace gko {
16
17
22public:
24
26
27 time_point& operator=(time_point&&);
28
29 time_point(const time_point&) = delete;
30
31 time_point& operator=(const time_point&) = delete;
32
33private:
34 time_point();
35
36 friend class Timer;
37 friend class CpuTimer;
38 friend class CudaTimer;
39 friend class HipTimer;
40 friend class DpcppTimer;
41
43 enum class type {
45 cpu,
47 cuda,
49 hip,
51 dpcpp,
52 };
53
54 type type_;
55 union data_union {
56 CUevent_st* cuda_event;
57 GKO_HIP_EVENT_STRUCT* hip_event;
58 sycl::event* dpcpp_event;
59 std::chrono::steady_clock::time_point chrono;
60
61 data_union();
62 } data_;
63};
64
65
81class Timer {
82public:
83 virtual ~Timer() = default;
84
90
94 virtual void record(time_point& time) = 0;
95
100 virtual void wait(time_point& time) = 0;
101
110 std::chrono::nanoseconds difference(time_point& start, time_point& stop);
111
124 virtual std::chrono::nanoseconds difference_async(
125 const time_point& start, const time_point& stop) = 0;
126
137 static std::unique_ptr<Timer> create_for_executor(
138 std::shared_ptr<const Executor> exec);
139
140protected:
142 virtual void init_time_point(time_point& time) = 0;
143};
144
145
147class CpuTimer : public Timer {
148public:
149 void record(time_point& time) override;
150
151 void wait(time_point& time) override;
152
153 std::chrono::nanoseconds difference_async(const time_point& start,
154 const time_point& stop) override;
155
156protected:
157 void init_time_point(time_point& time) override;
158};
159
160
167class CudaTimer : public Timer {
168public:
169 void record(time_point& time) override;
170
171 void wait(time_point& time) override;
172
173 std::chrono::nanoseconds difference_async(const time_point& start,
174 const time_point& stop) override;
175
176 CudaTimer(std::shared_ptr<const CudaExecutor> exec);
177
178protected:
179 void init_time_point(time_point& time) override;
180
181private:
182 int device_id_;
183 CUstream_st* stream_;
184};
185
186
193class HipTimer : public Timer {
194public:
195 void record(time_point& time) override;
196
197 void wait(time_point& time) override;
198
199 std::chrono::nanoseconds difference_async(const time_point& start,
200 const time_point& stop) override;
201
202 HipTimer(std::shared_ptr<const HipExecutor> exec);
203
204protected:
205 void init_time_point(time_point& time) override;
206
207private:
208 int device_id_;
209 GKO_HIP_STREAM_STRUCT* stream_;
210};
211
212
214class DpcppTimer : public Timer {
215public:
216 void record(time_point& time) override;
217
218 void wait(time_point& time) override;
219
220 std::chrono::nanoseconds difference_async(const time_point& start,
221 const time_point& stop) override;
222
223 DpcppTimer(std::shared_ptr<const DpcppExecutor> exec);
224
225protected:
226 void init_time_point(time_point& time) override;
227
228private:
229 sycl::queue* queue_;
230};
231
232
233} // namespace gko
234
235
236#endif // GKO_PUBLIC_CORE_BASE_TIMER_HPP_
A timer using std::chrono::steady_clock for timing.
Definition timer.hpp:147
std::chrono::nanoseconds difference_async(const time_point &start, const time_point &stop) override
Computes the difference between the two time points in nanoseconds.
void wait(time_point &time) override
Waits until all kernels in-process when recording the time point are finished.
void record(time_point &time) override
Records a time point at the current time.
A timer using events for timing on a CudaExecutor.
Definition timer.hpp:167
void wait(time_point &time) override
Waits until all kernels in-process when recording the time point are finished.
std::chrono::nanoseconds difference_async(const time_point &start, const time_point &stop) override
Computes the difference between the two time points in nanoseconds.
void record(time_point &time) override
Records a time point at the current time.
A timer using kernels for timing on a DpcppExecutor in profiling mode.
Definition timer.hpp:214
void record(time_point &time) override
Records a time point at the current time.
std::chrono::nanoseconds difference_async(const time_point &start, const time_point &stop) override
Computes the difference between the two time points in nanoseconds.
void wait(time_point &time) override
Waits until all kernels in-process when recording the time point are finished.
A timer using events for timing on a HipExecutor.
Definition timer.hpp:193
void wait(time_point &time) override
Waits until all kernels in-process when recording the time point are finished.
std::chrono::nanoseconds difference_async(const time_point &start, const time_point &stop) override
Computes the difference between the two time points in nanoseconds.
void record(time_point &time) override
Records a time point at the current time.
Represents a generic timer that can be used to record time points and measure time differences on hos...
Definition timer.hpp:81
std::chrono::nanoseconds difference(time_point &start, time_point &stop)
Computes the difference between the two time points in nanoseconds.
time_point create_time_point()
Returns a newly created time point.
virtual void wait(time_point &time)=0
Waits until all kernels in-process when recording the time point are finished.
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.
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.
virtual void record(time_point &time)=0
Records a time point at the current time.
An opaque wrapper for a time point generated by a timer.
Definition timer.hpp:21
The Ginkgo namespace.
Definition abstract_factory.hpp:20