forked from brichard19/BitCrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclUtil.cpp
69 lines (46 loc) · 1.68 KB
/
clUtil.cpp
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
#include "clutil.h"
void cl::clCall(cl_int err)
{
if(err != CL_SUCCESS) {
throw cl::CLException(err);
}
}
std::vector<cl::CLDeviceInfo> cl::getDevices()
{
std::vector<cl::CLDeviceInfo> deviceList;
cl_uint platformCount = 0;
clCall(clGetPlatformIDs(0, NULL, &platformCount));
if(platformCount == 0) {
return deviceList;
}
cl_platform_id* platforms = new cl_platform_id[platformCount];
clCall(clGetPlatformIDs(platformCount, platforms, NULL));
for(cl_uint i = 0; i < platformCount; i++) {
cl_uint deviceCount = 0;
clCall(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount));
if(deviceCount == 0) {
continue;
}
cl_device_id* devices = new cl_device_id[deviceCount];
clCall(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL));
for(cl_uint j = 0; j < deviceCount; j++) {
char buf[256] = {0};
cl::CLDeviceInfo info;
size_t size;
// Get device name
clCall(clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(buf), buf, &size));
info.name = std::string(buf, size);
int cores = 0;
clCall(clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cores), &cores, NULL));
info.cores = cores;
cl_ulong mem;
clCall(clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(mem), &mem, NULL));
info.mem = (uint64_t)mem;
info.id = devices[j];
deviceList.push_back(info);
}
delete devices;
}
delete platforms;
return deviceList;
}