WarpX
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 KERNELTIMER_H_
8 #define KERNELTIMER_H_
9 
10 #include "Utils/TextMsg.H"
11 #include "WarpX.H"
12 
13 #include <AMReX.H>
14 #include <AMReX_REAL.H>
15 
16 // #ifdef WARPX_USE_GPUCLOCK
17 
18 #include <climits>
19 
24 {
25 public:
33 #if (defined AMREX_USE_GPU)
34  (const bool do_timing, amrex::Real* cost)
35  : m_do_timing(do_timing)
36 #else
37  (const bool do_timing, amrex::Real* cost)
38 #endif
39  {
40 #if (defined AMREX_USE_GPU)
41 # if (defined WARPX_USE_GPUCLOCK)
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  AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_do_timing == false,
51  "KernelTimer not yet supported for this hardware." );
52 # endif
53  }
54 # else // WARPX_USE_GPUCLOCK
55  AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_do_timing == false,
56  "`algo.load_balance_costs_update = gpuclock` requires to compile with `-DWarpX_GPUCLOCK=ON`.");
57 # endif // WARPX_USE_GPUCLOCK
58 #else // AMREX_USE_GPU
59  amrex::ignore_unused(do_timing, cost);
60 #endif // AMREX_USE_GPU
61  }
62 
66 #if (defined AMREX_USE_GPU)
67  if (m_do_timing && m_cost) {
68 # if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
69  m_wt = clock64() - m_wt;
70  amrex::Gpu::Atomic::Add( m_cost, amrex::Real(m_wt));
71 # elif defined(AMREX_USE_DPCPP)
72  // To be updated
73 # endif
74  }
75 #endif
76  }
77 
78 #if (defined AMREX_USE_GPU)
79 private:
81  bool m_do_timing;
82 
84  amrex::Real* m_cost = nullptr;
85 
87  long long int m_wt;
88 #endif
89 };
90 #endif
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
#define AMREX_GPU_DEVICE
AMREX_GPU_DEVICE ~KernelTimer()
Destructor.
Definition: KernelTimer.H:65
Defines a timer object to be used on GPU; measures summed thread cycles.
Definition: KernelTimer.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T Add(T *sum, T value) noexcept