kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_CUDA_TIMER_EVENT_HPP
2#define KOKKOS_UTILS_CUDA_TIMER_EVENT_HPP
3
4#include "Kokkos_Core.hpp"
5
7{
8
9template <>
10struct Event<Kokkos::Cuda>
11{
12 using impl_event_t = cudaEvent_t;
13
14 impl_event_t event = nullptr;
15
16 Event() { KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventCreate(&event)); }
17
18 ~Event() { KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventDestroy(event)); }
19
20 void record(const Kokkos::Cuda& space) { KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventRecord(event, space.cuda_stream())); }
21
22 template <typename Duration = milliseconds>
23 Duration duration(Event& other) {
24 return std::chrono::duration_cast<Duration>(std::chrono::duration<float, std::milli>(elapsed(other)));
25 }
26
27private:
33 float elapsed(Event& other)
34 {
35 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(other.event));
36 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(event));
37
38 float elapsed_time;
39 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventElapsedTime(&elapsed_time, event, other.event));
40
41 return elapsed_time;
42 }
43
44};
45
46} // Kokkos::utils::timer
47
48#endif // KOKKOS_UTILS_CUDA_TIMER_EVENT_HPP
void record(const Kokkos::Cuda &space)
Definition Event.hpp:20