forked from brichard19/BitCrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceManager.cpp
61 lines (51 loc) · 1.64 KB
/
DeviceManager.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
#include "DeviceManager.h"
#ifdef BUILD_CUDA
#include "cudaUtil.h"
#endif
#ifdef BUILD_OPENCL
#include "clutil.h"
#endif
std::vector<DeviceManager::DeviceInfo> DeviceManager::getDevices()
{
int deviceId = 0;
std::vector<DeviceManager::DeviceInfo> devices;
#ifdef BUILD_CUDA
// Get CUDA devices
try {
std::vector<cuda::CudaDeviceInfo> cudaDevices = cuda::getDevices();
for(int i = 0; i < cudaDevices.size(); i++) {
DeviceManager::DeviceInfo device;
device.name = cudaDevices[i].name;
device.type = DeviceType::CUDA;
device.id = deviceId;
device.physicalId = cudaDevices[i].id;
device.memory = cudaDevices[i].mem;
device.computeUnits = cudaDevices[i].mpCount;
devices.push_back(device);
deviceId++;
}
} catch(cuda::CudaException ex) {
throw DeviceManager::DeviceManagerException(ex.msg);
}
#endif
#ifdef BUILD_OPENCL
// Get OpenCL devices
try {
std::vector<cl::CLDeviceInfo> clDevices = cl::getDevices();
for(int i = 0; i < clDevices.size(); i++) {
DeviceManager::DeviceInfo device;
device.name = clDevices[i].name;
device.type = DeviceType::OpenCL;
device.id = deviceId;
device.physicalId = (uint64_t)clDevices[i].id;
device.memory = clDevices[i].mem;
device.computeUnits = clDevices[i].cores;
devices.push_back(device);
deviceId++;
}
} catch(cl::CLException ex) {
throw DeviceManager::DeviceManagerException(ex.msg);
}
#endif
return devices;
}