kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_HIP_TIMER_EVENT_HPP
2#define KOKKOS_UTILS_HIP_TIMER_EVENT_HPP
3
4#include "Kokkos_Core.hpp"
5
7{
8
14template <>
15struct Event<Kokkos::HIP>
16{
19 {
20 void operator()(ihipEvent_t* ptr) const {
21 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventDestroy(ptr));
22 }
23 };
24
25 using impl_event_t = hipEvent_t;
26 using event_storage_t = std::unique_ptr<ihipEvent_t, EventDeleter>;
27
28 static_assert(std::same_as<typename event_storage_t::pointer, impl_event_t>);
29
30 event_storage_t event = nullptr;
31
33 impl_event_t tmp = nullptr;
34 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventCreate(&tmp));
35 event.reset(tmp);
36 }
37
39 void record(const Kokkos::HIP& exec) { KOKKOS_IMPL_HIP_SAFE_CALL(hipEventRecord(event.get(), exec.hip_stream())); }
40
41 template <typename Duration = milliseconds>
42 Duration duration(Event& other) {
43 return std::chrono::duration_cast<Duration>(std::chrono::duration<float, std::milli>(elapsed(other)));
44 }
45
46private:
52 float elapsed(Event& other)
53 {
54 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventSynchronize(other.event.get()));
55 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventSynchronize(event.get()));
56
57 float elapsed_time;
58 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventElapsedTime(&elapsed_time, event.get(), other.event.get()));
59
60 return elapsed_time;
61 }
62
63};
64
65} // Kokkos::utils::timer
66
67#endif // KOKKOS_UTILS_HIP_TIMER_EVENT_HPP
To be used for the custom deleter of event.
Definition Event.hpp:19
std::unique_ptr< ihipEvent_t, EventDeleter > event_storage_t
Definition Event.hpp:26
void record(const Kokkos::HIP &exec)
Record this event in the execution space instance exec.
Definition Event.hpp:39
float elapsed(Event &other)
Measure the elapsed time in milliseconds.
Definition Event.hpp:52