Alsvinn  0.5.3
The fast FVM simulator with UQ support
CudaTimer.hpp
Go to the documentation of this file.
1 #pragma once
4 #include "alsutils/config.hpp"
5 #ifdef ALSVINN_HAVE_CUDA
6 #include <cuda_runtime.h>
7 #endif
8 #include <chrono>
9 namespace alsutils {
10 namespace timer {
11 #ifdef ALSVINN_HAVE_CUDA
12 class CudaTimer {
13 public:
14  template<class ...T> CudaTimer(cudaStream_t stream, T... names) :
15  data(TimerDatabase::getInstance().getTimerData(names...)),
16  stream(stream),
17  start(new
18  std::chrono::high_resolution_clock::time_point()) {
19 
20  addStartCallback();
21  }
22 
23  ~CudaTimer() noexcept(false);
24 
25 private:
26 
27  TimerData& data;
28  cudaStream_t stream;
29  void addStartCallback();
30 
31  // This is not the cleanest way of doing it, but at the moment I see no other
32  // way: We first allocate the space for storing the starting time on the heap
33  // this is then deleted in the second callback.
34  std::chrono::high_resolution_clock::time_point* start;
35 
36 };
37  #endif
38 } // namespace timer
39 } // namespace alsutils
40 #ifdef ALSVINN_HAVE_CUDA
41 #ifdef ALSVINN_USE_CUDA_TIMERS
42  #define ALSVINN_TIME_CUDA_BLOCK(STREAM, ...) ::alsutils::timer::CudaTimer ALSVINN_MAKE_TIMER_VARIABLE_NAME(__VA_ARGS__) (STREAM, ALSVINN_MAKE_TIMER_STRINGS(__VA_ARGS__))
43 #else
44  #define ALSVINN_TIME_CUDA_BLOCK(STREAM, ...)
45 #endif
46 #else
47  #define ALSVINN_TIME_CUDA_BLOCK(STREAM, ...)
48 #endif
Various utilities for mpi and cuda.
Definition: Factory.hpp:3
Definition: TimerData.hpp:10
static TimerDatabase & getInstance()
Definition: TimerDatabase.cpp:7