Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <sys/time.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include "Jikan.h"
#include "Jikan-config.h"
#ifdef INCLUDE_OPEN_MP
#include "omp.h"
#endif
using namespace std;
void Jikan::cuda_Jikan_start(const string& name)
{
#ifdef INCLUDE_OPEN_MP
#pragma omp master
{
#endif
bool ExistFlag;
ExistFlag = this->ifContains(name);
if(ExistFlag == false)
{
(this->Events)[name] = EventData(name);
this->EventType["CUDA events"].insert(name);
(this->Events)[name].ifCUDA = 1;
cudaEventCreate(&(((this->Events)[name]).gpu_start));
cudaEventCreate(&(((this->Events)[name]).gpu_end));
}
(this->Events)[name].ifStart = true;
cudaEventRecord ((this->Events)[name].gpu_start);
#ifdef INCLUDE_OPEN_MP
}
#endif
}
void Jikan::cuda_Jikan_end(const string& name)
{
#ifdef INCLUDE_OPEN_MP
#pragma omp master
{
#endif
bool ExistFlag, ifStart;
ExistFlag = this->ifContains(name);
ifStart = (this->Events)[name].ifStart;
if((!ExistFlag) || (!ifStart))
return;
float GPUtime = 0.0;
cudaEventRecord((this->Events)[name].gpu_end);
cudaEventSynchronize((this->Events)[name].gpu_end);
cudaEventElapsedTime(&GPUtime, (this->Events)[name].gpu_start, (this->Events)[name].gpu_end); //milliseconds
GPUtime *= 1e-3;
(this->Events)[name].elapsed_time += GPUtime;
(this->Events)[name].count ++;
#ifdef SAVE_TIME_SERIES
(this->Events)[name].time_series.push_back(GPUtime);
#endif
(this->Events)[name].ifStart = false;
#ifdef INCLUDE_OPEN_MP
}
#endif
}
void Jikan::FreeCudaEvents()
{
#ifdef INCLUDE_OPEN_MP
#pragma omp master
{
#endif
map<string, EventData>::iterator it;
for (it = this->Events.begin(); it!=this->Events.end(); ++it)
{
if((it->second).ifCUDA == 1)
{
cudaEventDestroy((it->second).gpu_start);
cudaEventDestroy((it->second).gpu_end);
}
}
#ifdef INCLUDE_OPEN_MP
}
#endif
}