-
Notifications
You must be signed in to change notification settings - Fork 27
/
OpenclPlatform.cpp
85 lines (65 loc) · 2.26 KB
/
OpenclPlatform.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
GPU plot generator for Burst coin.
Author: Cryo
Bitcoin: 138gMBhCrNkbaiTCmUhP9HLU9xwn5QKZgD
Burst: BURST-YA29-QCEW-QXC3-BKXDL
Based on the code of the official miner and dcct's plotgen.
*/
#include "OpenclError.h"
#include "OpenclPlatform.h"
namespace cryo {
namespace gpuPlotGenerator {
OpenclPlatform::OpenclPlatform(const cl_platform_id& p_handle)
: m_handle(p_handle) {
}
OpenclPlatform::OpenclPlatform(const OpenclPlatform& p_other)
: m_handle(p_other.m_handle) {
}
OpenclPlatform::~OpenclPlatform() {
}
OpenclPlatform& OpenclPlatform::operator=(const OpenclPlatform& p_other) {
m_handle = p_other.m_handle;
return *this;
}
std::string OpenclPlatform::getName() const throw (std::exception) {
return getInfoString(CL_PLATFORM_NAME);
}
std::string OpenclPlatform::getVendor() const throw (std::exception) {
return getInfoString(CL_PLATFORM_VENDOR);
}
std::string OpenclPlatform::getVersion() const throw (std::exception) {
return getInfoString(CL_PLATFORM_VERSION);
}
std::string OpenclPlatform::getInfoString(const cl_platform_info& p_paramName) const throw (std::exception) {
cl_int error;
std::size_t size = 0;
error = clGetPlatformInfo(m_handle, p_paramName, 0, 0, &size);
if(error != CL_SUCCESS) {
throw OpenclError(error, "Unable to retrieve info size");
}
std::unique_ptr<char[]> buffer(new char[size]);
error = clGetPlatformInfo(m_handle, p_paramName, size, (void*)buffer.get(), 0);
if(error != CL_SUCCESS) {
throw OpenclError(error, "Unable to retrieve info value");
}
return std::string(buffer.get());
}
std::vector<std::shared_ptr<OpenclPlatform>> OpenclPlatform::list() throw (std::exception) {
std::vector<std::shared_ptr<OpenclPlatform>> list;
cl_int error;
cl_uint platformsNumber = 0;
error = clGetPlatformIDs(0, 0, &platformsNumber);
if(error != CL_SUCCESS) {
throw OpenclError(error, "Unable to retrieve the OpenCL platforms number");
}
std::unique_ptr<cl_platform_id[]> platforms(new cl_platform_id[platformsNumber]);
error = clGetPlatformIDs(platformsNumber, platforms.get(), 0);
if(error != CL_SUCCESS) {
throw OpenclError(error, "Unable to retrieve the OpenCL platforms");
}
for(cl_uint i = 0 ; i < platformsNumber ; ++i) {
list.push_back(std::shared_ptr<OpenclPlatform>(new OpenclPlatform(platforms[i])));
}
return list;
}
}}