ARTEMIS
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 
21 {
22 
27 {
28 public:
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 
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_
#define AMREX_GPU_DEVICE
#define ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: TextMsg.H:77
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition: KernelTimer.H:27
AMREX_GPU_DEVICE ~KernelTimer()
Destructor.
Definition: KernelTimer.H:61
AMREX_GPU_DEVICE KernelTimer(const bool do_timing, amrex::Real *cost)
Definition: KernelTimer.H:36
Definition: KernelTimer.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T Add(T *sum, T value) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)