COMPASS
5.4.4
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-2023 COMPASS Team <https://github.com/ANR-COMPASS>
5
// All rights reserved.
6
7
// -----------------------------------------------------------------------------
8
16
17
18
#ifndef CARMA_TIMER_H_
19
#define CARMA_TIMER_H_
20
21
#include <
carma_context.h
>
22
#include <
carma_obj.h
>
23
27
class
CarmaTimer
{
28
protected
:
29
cudaEvent_t
start_event
,
stop_event
;
30
cudaStream_t
stream
= 0;
31
double
total_time
;
32
33
public
:
34
CarmaTimer
() {
35
carma_safe_call
(cudaEventCreate(&
start_event
));
36
carma_safe_call
(cudaEventCreate(&
stop_event
));
37
total_time
= 0.0;
38
}
39
40
~CarmaTimer
() {
41
cudaEventDestroy(
start_event
);
42
cudaEventDestroy(
stop_event
);
43
}
44
45
void
start
() {
carma_safe_call
(cudaEventRecord(
start_event
,
stream
)); }
46
47
void
reset
() {
total_time
= 0.0; }
48
50
void
stop
() {
51
float
gpuTime;
52
carma_safe_call
(cudaEventRecord(
stop_event
,
stream
));
53
carma_safe_call
(cudaEventSynchronize(
stop_event
));
54
carma_safe_call
(cudaEventElapsedTime(&gpuTime,
start_event
,
stop_event
));
55
total_time
+= (double)1e-3 * gpuTime;
56
}
57
58
void
set_stream
(cudaStream_t newStream) {
stream
= newStream; }
60
double
elapsed
() {
return
total_time
; }
61
};
62
63
void
get_clock_count
(
long
long
int
*clock_counter);
64
void
get_clock_count
(
double
*,
long
long
int
*clock_counter,
double
gpu_freq);
65
class
CarmaClock
{
66
public
:
67
CarmaObj<double>
*
time_buffer
;
68
double
gpu_freq
;
69
long
cc
;
70
long
long
int
*
clock_counter
;
71
72
CarmaClock
(
CarmaContext
*context,
int
i) {
73
cudaDeviceProp cdp;
74
cudaGetDeviceProperties(&cdp, context->
get_active_device
());
75
gpu_freq
= cdp.clockRate * 1000;
76
long
dims[2] = {1, i};
77
time_buffer
=
new
CarmaObj<double>
(context, dims);
78
cc
= 0;
79
cudaMalloc(&
clock_counter
,
sizeof
(
long
long
int
));
80
}
81
82
~CarmaClock
() {
83
delete
time_buffer
;
84
cudaFree(
clock_counter
);
85
}
86
87
void
tic
() {
get_clock_count
(
clock_counter
); }
88
89
void
toc
() {
90
get_clock_count
(
time_buffer
->
get_data_at
(
cc
),
clock_counter
,
gpu_freq
);
91
cc
++;
92
if
(
cc
>=
time_buffer
->
get_nb_elements
())
cc
= 0;
93
}
94
};
95
#endif
// CARMA_TIMER_H_
carma_context.h
carma_obj.h
get_clock_count
void get_clock_count(long long int *clock_counter)
carma_safe_call
#define carma_safe_call(err)
Definition:
carma_utils.h:108
CarmaClock
Definition:
carma_timer.h:65
CarmaClock::gpu_freq
double gpu_freq
Definition:
carma_timer.h:68
CarmaClock::toc
void toc()
Definition:
carma_timer.h:89
CarmaClock::cc
long cc
Definition:
carma_timer.h:69
CarmaClock::time_buffer
CarmaObj< double > * time_buffer
Definition:
carma_timer.h:67
CarmaClock::CarmaClock
CarmaClock(CarmaContext *context, int i)
Definition:
carma_timer.h:72
CarmaClock::clock_counter
long long int * clock_counter
Definition:
carma_timer.h:70
CarmaClock::tic
void tic()
Definition:
carma_timer.h:87
CarmaClock::~CarmaClock
~CarmaClock()
Definition:
carma_timer.h:82
CarmaContext
this class provides the context in which CarmaObj are created
Definition:
carma_context.h:79
CarmaContext::get_active_device
int get_active_device()
Definition:
carma_context.h:108
CarmaObj< double >
CarmaObj::get_data_at
T_data * get_data_at(int index)
Definition:
carma_obj.h:209
CarmaObj::get_nb_elements
int get_nb_elements()
Definition:
carma_obj.h:219
CarmaTimer
a simple timer for CUDA kernel.
Definition:
carma_timer.h:27
CarmaTimer::start_event
cudaEvent_t start_event
Definition:
carma_timer.h:29
CarmaTimer::start
void start()
Definition:
carma_timer.h:45
CarmaTimer::~CarmaTimer
~CarmaTimer()
Definition:
carma_timer.h:40
CarmaTimer::set_stream
void set_stream(cudaStream_t newStream)
Definition:
carma_timer.h:58
CarmaTimer::stream
cudaStream_t stream
Definition:
carma_timer.h:30
CarmaTimer::CarmaTimer
CarmaTimer()
Definition:
carma_timer.h:34
CarmaTimer::stop_event
cudaEvent_t stop_event
Definition:
carma_timer.h:29
CarmaTimer::elapsed
double elapsed()
Definition:
carma_timer.h:60
CarmaTimer::reset
void reset()
Definition:
carma_timer.h:47
CarmaTimer::total_time
double total_time
Definition:
carma_timer.h:31
CarmaTimer::stop
void stop()
Definition:
carma_timer.h:50
libcarma
include.h
carma_timer.h
Generated by
1.9.1