-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevice.cpp
66 lines (59 loc) · 1.41 KB
/
device.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
#include "device.h"
namespace GPGPU_LIB
{
Device::Device(cl::Device dev, int idPrm, bool sharesRAMPrm, bool isCPUPrm )
{
sharesRAM = sharesRAMPrm;
device = dev;
id = idPrm;
isCPU = isCPUPrm;
cl_int op;
if (id != -1)
{
name = device.getInfo<CL_DEVICE_NAME>(&op);
if (op != CL_SUCCESS)
{
throw std::invalid_argument(std::string("error: device name query") + getErrorString(op));
}
// trim whitespace
name.erase(name.begin(), std::find_if(name.begin(), name.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
name.erase(std::find_if(name.rbegin(), name.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), name.end());
simpleName = name;
name += " (";
name += device.getInfo<CL_DEVICE_VERSION>(&op);
name += " )";
if (op != CL_SUCCESS)
{
throw std::invalid_argument(std::string("error: device opencl version query") + getErrorString(op));
}
if (sharesRAM)
{
name += "[has direct access to RAM]";
}
std::string clVer = device.getInfo<CL_DEVICE_OPENCL_C_VERSION>(&op);
if (op != CL_SUCCESS)
{
throw std::invalid_argument(std::string("error: device opencl-c version query") + getErrorString(op));
}
if (clVer.size() < 10)
ver = 120;
else
{
if (clVer[9] >= '3')
ver = 300;
else if (clVer[9] >= '2')
ver = 200;
else
ver = 120;
}
}
else
{
name = "";
}
}
}