BioDynaMo  v1.05.120-25dc9790
cuda_timer.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_GPU_CUDA_TIMER_H_
16 #define CORE_GPU_CUDA_TIMER_H_
17 
18 #if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
19 #ifdef USE_CUDA
20 
21 #include <iostream>
22 #include <string>
23 
24 namespace bdm {
25 
26 class CudaTimer {
27  public:
28  CudaTimer(std::string name) : name_(name) {
29  cudaEventCreate(&start_);
30  cudaEventCreate(&stop_);
31  cudaEventRecord(start_, 0);
32  }
33 
34  ~CudaTimer() {
35  cudaEventRecord(stop_, 0);
36  float duration;
37  cudaEventSynchronize(stop_);
38  cudaEventElapsedTime(&duration, start_, stop_);
39  std::cout << name_ << " " << duration << std::endl;
40  cudaEventDestroy(start_);
41  cudaEventDestroy(stop_);
42  }
43 
44  private:
45  cudaEvent_t start_;
46  cudaEvent_t stop_;
47  std::string name_;
48 };
49 
50 } // namespace bdm
51 
52 #endif // USE_CUDA
53 #endif // !__ROOTCLING__ && !G__DICTIONARY
54 #endif // CORE_GPU_CUDA_TIMER_H_
bdm
Definition: agent.cc:39