COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
carma_timer.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // This file is part of COMPASS <https://anr-compass.github.io/compass/>
3 //
4 // Copyright (C) 2011-2019 COMPASS Team <https://github.com/ANR-COMPASS>
5 // All rights reserved.
6 // Distributed under GNU - LGPL
7 //
8 // COMPASS is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
9 // General Public License as published by the Free Software Foundation, either version 3 of the License,
10 // or any later version.
11 //
12 // COMPASS: End-to-end AO simulation tool using GPU acceleration
13 // The COMPASS platform was designed to meet the need of high-performance for the simulation of AO systems.
14 //
15 // The final product includes a software package for simulating all the critical subcomponents of AO,
16 // particularly in the context of the ELT and a real-time core based on several control approaches,
17 // with performances consistent with its integration into an instrument. Taking advantage of the specific
18 // hardware architecture of the GPU, the COMPASS tool allows to achieve adequate execution speeds to
19 // conduct large simulation campaigns called to the ELT.
20 //
21 // The COMPASS platform can be used to carry a wide variety of simulations to both testspecific components
22 // of AO of the E-ELT (such as wavefront analysis device with a pyramid or elongated Laser star), and
23 // various systems configurations such as multi-conjugate AO.
24 //
25 // COMPASS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
26 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 // See the GNU Lesser General Public License for more details.
28 //
29 // You should have received a copy of the GNU Lesser General Public License along with COMPASS.
30 // If not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>.
31 // -----------------------------------------------------------------------------
32 
41 
42 
43 #ifndef CARMA_TIMER_H_
44 #define CARMA_TIMER_H_
45 
46 #include <carma_context.h>
47 #include <carma_obj.h>
48 
52 class CarmaTimer {
53  protected:
54  cudaEvent_t start_event, stop_event;
55  cudaStream_t stream = 0;
56  double total_time;
57 
58  public:
60  carma_safe_call(cudaEventCreate(&start_event));
61  carma_safe_call(cudaEventCreate(&stop_event));
62  total_time = 0.0;
63  }
64 
66  cudaEventDestroy(start_event);
67  cudaEventDestroy(stop_event);
68  }
69 
70  void start() { carma_safe_call(cudaEventRecord(start_event, stream)); }
71 
72  void reset() { total_time = 0.0; }
73 
75  void stop() {
76  float gpuTime;
77  carma_safe_call(cudaEventRecord(stop_event, stream));
78  carma_safe_call(cudaEventSynchronize(stop_event));
79  carma_safe_call(cudaEventElapsedTime(&gpuTime, start_event, stop_event));
80  total_time += (double)1e-3 * gpuTime;
81  }
82 
83  void set_stream(cudaStream_t newStream) { stream = newStream; }
85  double elapsed() { return total_time; }
86 };
87 
88 void get_clock_count(long long int *clock_counter);
89 void get_clock_count(double *, long long int *clock_counter, double gpu_freq);
90 class CarmaClock {
91  public:
93  double gpu_freq;
94  long cc;
95  long long int *clock_counter;
96 
97  CarmaClock(CarmaContext *context, int i) {
98  cudaDeviceProp cdp;
99  cudaGetDeviceProperties(&cdp, context->get_active_device());
100  gpu_freq = cdp.clockRate * 1000;
101  long dims[2] = {1, i};
102  time_buffer = new CarmaObj<double>(context, dims);
103  cc = 0;
104  cudaMalloc(&clock_counter, sizeof(long long int));
105  }
106 
108  delete time_buffer;
109  cudaFree(clock_counter);
110  }
111 
113 
114  void toc() {
116  cc++;
117  if (cc >= time_buffer->get_nb_elements()) cc = 0;
118  }
119 };
120 #endif // CARMA_TIMER_H_
CarmaClock
Definition: carma_timer.h:90
CarmaClock::clock_counter
long long int * clock_counter
Definition: carma_timer.h:95
CarmaTimer
a simple timer for CUDA kernel.
Definition: carma_timer.h:52
CarmaClock::time_buffer
CarmaObj< double > * time_buffer
Definition: carma_timer.h:92
carma_context.h
carma_safe_call
#define carma_safe_call(err)
Definition: carma_utils.h:145
get_clock_count
void get_clock_count(long long int *clock_counter)
CarmaTimer::stop_event
cudaEvent_t stop_event
Definition: carma_timer.h:54
CarmaTimer::reset
void reset()
Definition: carma_timer.h:72
CarmaTimer::~CarmaTimer
~CarmaTimer()
Definition: carma_timer.h:65
CarmaTimer::CarmaTimer
CarmaTimer()
Definition: carma_timer.h:59
CarmaTimer::set_stream
void set_stream(cudaStream_t newStream)
Definition: carma_timer.h:83
CarmaTimer::start_event
cudaEvent_t start_event
Definition: carma_timer.h:54
CarmaClock::CarmaClock
CarmaClock(CarmaContext *context, int i)
Definition: carma_timer.h:97
CarmaObj< double >
carma_obj.h
CarmaTimer::total_time
double total_time
Definition: carma_timer.h:56
CarmaContext
this class provides the context in which CarmaObj are created
Definition: carma_context.h:104
CarmaObj::get_nb_elements
int get_nb_elements()
Definition: carma_obj.h:241
CarmaTimer::elapsed
double elapsed()
Definition: carma_timer.h:85
CarmaClock::~CarmaClock
~CarmaClock()
Definition: carma_timer.h:107
CarmaClock::tic
void tic()
Definition: carma_timer.h:112
CarmaObj::get_data_at
T_data * get_data_at(int index)
Definition: carma_obj.h:231
CarmaClock::toc
void toc()
Definition: carma_timer.h:114
CarmaClock::gpu_freq
double gpu_freq
Definition: carma_timer.h:93
CarmaClock::cc
long cc
Definition: carma_timer.h:94
CarmaTimer::stream
cudaStream_t stream
Definition: carma_timer.h:55
CarmaTimer::start
void start()
Definition: carma_timer.h:70
CarmaTimer::stop
void stop()
Definition: carma_timer.h:75