forked from intel/pti-gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_ext_collector.h
151 lines (127 loc) · 4.06 KB
/
cl_ext_collector.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//==============================================================
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: MIT
// =============================================================
#ifndef PTI_TOOLS_CL_TRACER_CL_EXT_COLLECTOR_H_
#define PTI_TOOLS_CL_TRACER_CL_EXT_COLLECTOR_H_
#include <CL/cl.h>
#include "correlator.h"
#include "pti_assert.h"
class ClApiCollector;
class ClExtCollector {
public:
static ClExtCollector* Create(
ClApiCollector* cpu_collector, ClApiCollector* gpu_collector) {
PTI_ASSERT(cpu_collector != nullptr || gpu_collector != nullptr);
if (instance_ == nullptr) {
instance_ = new ClExtCollector(cpu_collector, gpu_collector);
}
return instance_;
}
static void Destroy() {
if (instance_ != nullptr) {
delete instance_;
}
}
static ClExtCollector* GetInstance() {
return instance_;
}
template <cl_device_type DEVICE_TYPE>
uint64_t GetTimestamp() const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
return GetTimestampGPU();
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
return GetTimestampCPU();
}
}
uint64_t GetTimestampCPU() const;
uint64_t GetTimestampGPU() const;
template <cl_device_type DEVICE_TYPE>
void AddFunctionTime(const char* function_name, uint64_t time) {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
AddFunctionTimeGPU(function_name, time);
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
AddFunctionTimeCPU(function_name, time);
}
}
void AddFunctionTimeCPU(const char* function_name, uint64_t time);
void AddFunctionTimeGPU(const char* function_name, uint64_t time);
template <cl_device_type DEVICE_TYPE>
bool IsCallTracing() const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
return IsCallTracingGPU();
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
return IsCallTracingCPU();
}
}
bool IsCallTracingCPU() const;
bool IsCallTracingGPU() const;
template <cl_device_type DEVICE_TYPE>
bool NeedPid() const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
return NeedPidGPU();
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
return NeedPidCPU();
}
}
bool NeedPidCPU() const;
bool NeedPidGPU() const;
template <cl_device_type DEVICE_TYPE>
bool NeedTid() const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
return NeedTidGPU();
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
return NeedTidCPU();
}
}
bool NeedTidCPU() const;
bool NeedTidGPU() const;
template <cl_device_type DEVICE_TYPE>
void Log(const std::string& message) const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
LogGPU(message);
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
LogCPU(message);
}
}
void LogCPU(const std::string& message) const;
void LogGPU(const std::string& message) const;
template <cl_device_type DEVICE_TYPE>
void Callback(
const char* function_name, uint64_t start, uint64_t end) const {
if (DEVICE_TYPE == CL_DEVICE_TYPE_GPU) {
PTI_ASSERT(gpu_collector_ != nullptr);
CallbackGPU(function_name, start, end);
} else {
PTI_ASSERT(cpu_collector_ != nullptr);
CallbackCPU(function_name, start, end);
}
}
void CallbackCPU(
const char* function_name, uint64_t start, uint64_t end) const;
void CallbackGPU(
const char* function_name, uint64_t start, uint64_t end) const;
private:
ClExtCollector(ClApiCollector* cpu_collector, ClApiCollector* gpu_collector)
: cpu_collector_(cpu_collector), gpu_collector_(gpu_collector) {
PTI_ASSERT(cpu_collector_ != nullptr || gpu_collector_ != nullptr);
}
private:
static ClExtCollector* instance_;
ClApiCollector* cpu_collector_ = nullptr;
ClApiCollector* gpu_collector_ = nullptr;
};
#endif // PTI_TOOLS_CL_TRACER_CL_EXT_COLLECTOR_H_