-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLDeviceInformation.hpp
209 lines (170 loc) · 5.26 KB
/
CLDeviceInformation.hpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef TCL_DEVICE_HPP
#define TCL_DEVICE_HPP
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL\cl.h>
#endif
#include <vector>
#include "CLException.hpp"
namespace tcl
{
class CLDeviceInformation
{
private:
cl_device_id deviceId;
cl_device_type deviceType;
cl_uint maxComputeUnits;
cl_uint maxWorkItemDimensions;
size_t maxWorkGroupSize;
cl_uint maxClockFrequency;
cl_ulong maxMemoryAllocSize;
std::vector<size_t> maxWorkItemSizes;
cl_bool imageSupport;
cl_uint maxReadImageArgs;
cl_uint maxWriteImageArgs;
size_t image2dMaxWidth;
size_t image2dMaxHeight;
size_t image3dMaxWidth;
size_t image3dMaxHeight;
size_t image3dMaxDepth;
cl_uint maxSamplers;
size_t maxParameterSize;
cl_uint globalMemoryCachelineSize;
cl_ulong globalMemoryCacheSize;
cl_ulong globalMemorySize;
cl_ulong maxConstantBufferSize;
cl_ulong maxConstantArgs;
private:
template <typename T>
void GetDeviceInfo(T& var, const cl_device_info& type)
{
auto result = clGetDeviceInfo(deviceId, type, sizeof(T), &var, NULL);
if (result != CL_SUCCESS)
throw CLException("デバイスの情報が取得できない");
}
public:
/**
* デバイスIDを返す
*/
inline const cl_device_id& DeviceId() const {
return deviceId;
}
/**
* デバイスの種類を返す
*/
inline const cl_device_type& DeviceType() const {
return deviceType;
}
/**
* 使用可能なコア数を返す
*/
inline const cl_uint& MaxComputeUnits() const {
return maxComputeUnits;
}
/**
* 使用可能なワークアイテムの次元数を返す
*/
inline const cl_uint& MaxWorkItemDimensions() const {
return maxWorkItemDimensions;
}
/**
* ワークグループの最大数を返す
*/
inline const size_t& MaxWorkGroupSize() const {
return maxWorkGroupSize;
}
/**
* デバイスの最大設計クロック周波数をMHzで返す
*/
inline const cl_uint& MaxClockFrequency() const {
return maxClockFrequency;
}
/**
* 次元ごとの最大アイテム数を返す
*/
inline const std::vector<size_t>& MaxWorkItemSizes() const {
return maxWorkItemSizes;
}
/**
* メモリの確保可能な領域をバイト数で返す
*/
inline const cl_ulong& MaxMemoryAllocSize() const {
return maxMemoryAllocSize;
}
inline const cl_bool& ImageSupport() const {
return imageSupport;
}
inline const cl_uint& MaxReadImageArgs() const {
return maxReadImageArgs;
}
inline const cl_uint& MaxWriteImageArgs() const {
return maxWriteImageArgs;
}
inline const size_t& Image2dMaxWidth() const {
return image2dMaxWidth;
}
inline const size_t& Image2dMaxHeight() const {
return image2dMaxHeight;
}
inline const size_t& Image3dMaxWidth() const {
return image3dMaxWidth;
}
inline const size_t& Image3dMaxHeight() const {
return image3dMaxHeight;
}
inline const size_t& Image3dMaxDepth() const {
return image3dMaxDepth;
}
inline const cl_uint& MaxSamplers() const {
return maxSamplers;
}
inline const size_t& MaxParameterSize() const {
return maxParameterSize;
}
inline const cl_uint& GlobalMemoryCachelineSize() const {
return globalMemoryCachelineSize;
}
inline const cl_ulong& GlobalMemoryCacheSize() const {
return globalMemoryCacheSize;
}
inline const cl_ulong& GlobalMemorySize() const {
return globalMemorySize;
}
inline const cl_ulong& MaxConstantBufferSize() const {
return maxConstantBufferSize;
}
inline const cl_ulong& MaxConstantArgs() const {
return maxConstantArgs;
}
public:
CLDeviceInformation(const cl_device_id& deviceId)
: deviceId(deviceId)
{
GetDeviceInfo<cl_device_type>(deviceType, CL_DEVICE_TYPE);
GetDeviceInfo<cl_uint>(maxComputeUnits, CL_DEVICE_MAX_COMPUTE_UNITS);
GetDeviceInfo<cl_uint>(maxWorkItemDimensions, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
GetDeviceInfo<size_t>(maxWorkGroupSize, CL_DEVICE_MAX_WORK_GROUP_SIZE);
GetDeviceInfo<cl_uint>(maxClockFrequency, CL_DEVICE_MAX_CLOCK_FREQUENCY);
GetDeviceInfo<cl_ulong>(maxMemoryAllocSize, CL_DEVICE_MAX_MEM_ALLOC_SIZE);
GetDeviceInfo<cl_uint>(maxReadImageArgs, CL_DEVICE_MAX_READ_IMAGE_ARGS);
GetDeviceInfo<cl_uint>(maxWriteImageArgs, CL_DEVICE_MAX_WRITE_IMAGE_ARGS);
GetDeviceInfo<cl_bool>(imageSupport, CL_DEVICE_IMAGE_SUPPORT);
GetDeviceInfo<size_t>(image2dMaxWidth, CL_DEVICE_IMAGE2D_MAX_WIDTH);
GetDeviceInfo<size_t>(image2dMaxHeight, CL_DEVICE_IMAGE2D_MAX_HEIGHT);
GetDeviceInfo<size_t>(image3dMaxWidth, CL_DEVICE_IMAGE3D_MAX_WIDTH);
GetDeviceInfo<size_t>(image3dMaxHeight, CL_DEVICE_IMAGE3D_MAX_HEIGHT);
GetDeviceInfo<size_t>(image3dMaxDepth, CL_DEVICE_IMAGE3D_MAX_DEPTH);
GetDeviceInfo<cl_uint>(maxSamplers, CL_DEVICE_MAX_SAMPLERS);
GetDeviceInfo<size_t>(maxParameterSize, CL_DEVICE_MAX_PARAMETER_SIZE);
GetDeviceInfo<cl_uint>(globalMemoryCachelineSize, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE);
GetDeviceInfo<cl_ulong>(globalMemoryCacheSize, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE);
GetDeviceInfo<cl_ulong>(globalMemorySize, CL_DEVICE_GLOBAL_MEM_SIZE);
GetDeviceInfo<cl_ulong>(maxConstantBufferSize, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE);
GetDeviceInfo<cl_ulong>(maxConstantArgs, CL_DEVICE_MAX_CONSTANT_ARGS);
maxWorkItemSizes = std::vector<size_t>(maxWorkItemDimensions);
auto result = clGetDeviceInfo(deviceId, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t) * maxWorkItemDimensions, &maxWorkItemSizes[0], NULL);
}
};
}
#endif