ARTEMIS
Source
ablastr
parallelization
KernelTimer.H
Go to the documentation of this file.
1
/* Copyright 2019-2020 Michael Rowan, Axel Huebl, Kevin Gott
2
*
3
* This file is part of WarpX.
4
*
5
* License: BSD-3-Clause-LBNL
6
*/
7
#ifndef ABLASTR_KERNELTIMER_H_
8
#define ABLASTR_KERNELTIMER_H_
9
10
#include "
ablastr/utils/TextMsg.H
"
11
12
#include <
AMReX.H
>
13
#include <
AMReX_BLassert.H
>
14
#include <
AMReX_GpuAtomic.H
>
15
#include <
AMReX_GpuQualifiers.H
>
16
#include <
AMReX_REAL.H
>
17
18
#include <climits>
19
20
namespace
ablastr::parallelization
21
{
22
26
class
KernelTimer
27
{
28
public
:
34
AMREX_GPU_DEVICE
35
KernelTimer
36
(
const
bool
do_timing, amrex::Real* cost)
37
#if (defined AMREX_USE_GPU)
38
: m_do_timing(do_timing)
39
#endif
40
{
41
#if (defined AMREX_USE_GPU)
42
if
(m_do_timing && cost) {
43
m_cost = cost;
44
# if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
45
// Start the timer
46
m_wt = clock64();
47
48
# elif defined(AMREX_USE_DPCPP)
49
// To be updated
50
ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE
(m_do_timing ==
false
,
51
"KernelTimer not yet supported for this hardware."
);
52
# endif
53
}
54
#else
// AMREX_USE_GPU
55
amrex::ignore_unused
(do_timing, cost);
56
#endif
// AMREX_USE_GPU
57
}
58
60
AMREX_GPU_DEVICE
61
~KernelTimer
() {
62
#if (defined AMREX_USE_GPU)
63
if
(m_do_timing && m_cost) {
64
# if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
65
m_wt = clock64() - m_wt;
66
amrex::Gpu::Atomic::Add
( m_cost, amrex::Real(m_wt));
67
# elif defined(AMREX_USE_DPCPP)
68
// To be updated
69
# endif
70
}
71
#endif
//AMREX_USE_GPU
72
}
73
74
#if (defined AMREX_USE_GPU)
75
private
:
77
bool
m_do_timing;
78
80
amrex::Real* m_cost =
nullptr
;
81
83
long
long
int
m_wt;
84
#endif
//AMREX_USE_GPU
85
};
86
87
}
// namespace ablastr::parallelization
88
89
#endif
// ABLASTR_KERNELTIMER_H_
AMReX.H
AMReX_BLassert.H
AMReX_GpuAtomic.H
AMReX_GpuQualifiers.H
AMREX_GPU_DEVICE
#define AMREX_GPU_DEVICE
AMReX_REAL.H
TextMsg.H
ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE
#define ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition:
TextMsg.H:77
ablastr::parallelization::KernelTimer
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition:
KernelTimer.H:27
ablastr::parallelization::KernelTimer::~KernelTimer
AMREX_GPU_DEVICE ~KernelTimer()
Destructor.
Definition:
KernelTimer.H:61
ablastr::parallelization::KernelTimer::KernelTimer
AMREX_GPU_DEVICE KernelTimer(const bool do_timing, amrex::Real *cost)
Definition:
KernelTimer.H:36
ablastr::parallelization
Definition:
KernelTimer.H:21
amrex::Gpu::Atomic::Add
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T Add(T *sum, T value) noexcept
amrex::ignore_unused
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
Generated by
1.9.1