kokkos-utils
0.0.5
Toggle main menu visibility
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
6
namespace
Kokkos::utils::timer
7
{
8
14
template
<>
15
struct
Event
<
Kokkos
::Cuda>
16
{
18
struct
EventDeleter
19
{
20
void
operator()
(CUevent_st* ptr)
const
{
21
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventDestroy(ptr));
22
}
23
};
24
25
using
impl_event_t
= cudaEvent_t;
26
using
event_storage_t
= std::unique_ptr<CUevent_st, EventDeleter>;
27
28
static_assert
(std::same_as<typename event_storage_t::pointer, impl_event_t>);
29
30
event_storage_t
event
=
nullptr
;
31
32
Event
() {
33
impl_event_t
tmp =
nullptr
;
34
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventCreate(&tmp));
35
event
.reset(tmp);
36
}
37
39
void
record
(
const
Kokkos::Cuda& exec) { KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventRecord(
event
.get(), exec.cuda_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
46
private
:
52
float
elapsed
(
Event
& other)
53
{
54
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(other.
event
.get()));
55
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(
event
.get()));
56
57
float
elapsed_time;
58
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventElapsedTime(&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_CUDA_TIMER_EVENT_HPP
Kokkos::utils::timer
Definition
Duration.hpp:7
Kokkos
Definition
InsertOp.hpp:9
Kokkos::utils::timer::Event< Kokkos::Cuda >::EventDeleter
To be used for the custom deleter of event.
Definition
Event.hpp:19
Kokkos::utils::timer::Event< Kokkos::Cuda >::EventDeleter::operator()
void operator()(CUevent_st *ptr) const
Definition
Event.hpp:20
Kokkos::utils::timer::Event< Kokkos::Cuda >::elapsed
float elapsed(Event &other)
Measure the elapsed time in milliseconds.
Definition
Event.hpp:52
Kokkos::utils::timer::Event< Kokkos::Cuda >::impl_event_t
cudaEvent_t impl_event_t
Definition
Event.hpp:25
Kokkos::utils::timer::Event< Kokkos::Cuda >::record
void record(const Kokkos::Cuda &exec)
Record this event in the execution space instance exec.
Definition
Event.hpp:39
Kokkos::utils::timer::Event< Kokkos::Cuda >::event
event_storage_t event
Definition
Event.hpp:30
Kokkos::utils::timer::Event< Kokkos::Cuda >::duration
Duration duration(Event &other)
Definition
Event.hpp:42
Kokkos::utils::timer::Event< Kokkos::Cuda >::event_storage_t
std::unique_ptr< CUevent_st, EventDeleter > event_storage_t
Definition
Event.hpp:26
Kokkos::utils::timer::Event< Kokkos::Cuda >::Event
Event()
Definition
Event.hpp:32
Kokkos::utils::timer::Event::event
impl_event_t event
Definition
Event.hpp:41
include
kokkos-utils
timer
Cuda
Event.hpp
Generated on
for kokkos-utils by
1.18.0