kokkos-utils 0.0.7
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_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6import kokkos.core;
7#else
8#include "Kokkos_Core.hpp"
9#endif
10
12{
13
19template <>
20struct Event<Kokkos::HIP>
21{
24 {
25 void operator()(ihipEvent_t* ptr) const {
26 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventDestroy(ptr));
27 }
28 };
29
30 using impl_event_t = hipEvent_t;
31 using event_storage_t = std::unique_ptr<ihipEvent_t, EventDeleter>;
32
33 static_assert(std::same_as<typename event_storage_t::pointer, impl_event_t>);
34
35 event_storage_t event = nullptr;
36
38 impl_event_t tmp = nullptr;
39 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventCreate(&tmp));
40 event.reset(tmp);
41 }
42
44 void record(const Kokkos::HIP& exec) { KOKKOS_IMPL_HIP_SAFE_CALL(hipEventRecord(event.get(), exec.hip_stream())); }
45
46 template <typename Duration = milliseconds>
47 Duration duration(Event& other) {
48 return std::chrono::duration_cast<Duration>(std::chrono::duration<float, std::milli>(elapsed(other)));
49 }
50
51private:
57 float elapsed(Event& other)
58 {
59 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventSynchronize(other.event.get()));
60 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventSynchronize(event.get()));
61
62 float elapsed_time;
63 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventElapsedTime(&elapsed_time, event.get(), other.event.get()));
64
65 return elapsed_time;
66 }
67
68};
69
70} // Kokkos::utils::timer
71
72#endif // KOKKOS_UTILS_HIP_TIMER_EVENT_HPP
To be used for the custom deleter of event.
Definition Event.hpp:24
std::unique_ptr< ihipEvent_t, EventDeleter > event_storage_t
Definition Event.hpp:31
void record(const Kokkos::HIP &exec)
Record this event in the execution space instance exec.
Definition Event.hpp:44
float elapsed(Event &other)
Measure the elapsed time in milliseconds.
Definition Event.hpp:57