forked from hughperkins/EasyCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviceinfo_helper.cpp
More file actions
101 lines (88 loc) · 4.21 KB
/
deviceinfo_helper.cpp
File metadata and controls
101 lines (88 loc) · 4.21 KB
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
// Copyright Hugh Perkins 2013 hughperkins at gmail
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#ifdef USE_CLEW
#include "clew.h"
#endif
#include <algorithm>
#include <string>
#include <iostream>
#include "EasyCL.h"
#include "deviceinfo_helper.h"
using namespace std;
void printDeviceInfoKB(string valuename, cl_device_id deviceId, cl_device_info name) {
cl_ulong somelong = 0;
clGetDeviceInfo(deviceId, name, sizeof(cl_ulong), &somelong, 0);
cout << valuename << ": " << (somelong/1024) << "KB" << endl;
}
void printDeviceInfoMB(string valuename, cl_device_id deviceId, cl_device_info name) {
cl_ulong somelong = 0;
clGetDeviceInfo(deviceId, name, sizeof(cl_ulong), &somelong, 0);
cout << valuename << ": " << (somelong/1024/1024) << "MB" << endl;
}
void printDeviceInfo(string valuename, cl_device_id deviceId, cl_device_info name) {
cl_ulong somelong = 0;
clGetDeviceInfo(deviceId, name, sizeof(cl_ulong), &somelong, 0);
cout << valuename << ": " << somelong << endl;
}
void printDeviceInfoArray(string valuename, cl_device_id deviceId, cl_device_info name, int length) {
cl_ulong *array = new cl_ulong[length];
clGetDeviceInfo(deviceId, name, sizeof(cl_ulong)*length, array, 0);
cout << valuename << ":";
for(int i = 0; i < length; i++) {
cout << " " << array[i];
}
cout << endl;
delete[] array;
}
void printDeviceInfoString(string valuename, cl_device_id deviceId, cl_device_info name) {
char buffer[256];
buffer[0] = 0;
clGetDeviceInfo(deviceId, name, 256, buffer, 0);
cout << valuename << ": " << buffer << endl;
}
string getDeviceInfoString(cl_device_id deviceId, cl_device_info name) {
char buffer[256];
buffer[0] = 0;
cl_int error = clGetDeviceInfo(deviceId, name, 256, buffer, 0);
if(error != CL_SUCCESS) {
if(error == CL_INVALID_DEVICE) {
throw runtime_error("Failed to obtain info for device id " + EasyCL::toString(deviceId) + ": invalid device");
} else if(error == CL_INVALID_VALUE) {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": invalid value");
} else {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": unknown error code: " + EasyCL::toString(error) );
}
}
return string(buffer);
}
int getDeviceInfoInt(cl_device_id deviceId, cl_device_info name) {
cl_ulong somelong = 0;
cl_int error = clGetDeviceInfo(deviceId, name, sizeof(cl_ulong), &somelong, 0);
if(error != CL_SUCCESS) {
if(error == CL_INVALID_DEVICE) {
throw runtime_error("Failed to obtain info for device id " + EasyCL::toString(deviceId) + ": invalid device");
} else if(error == CL_INVALID_VALUE) {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": invalid value");
} else {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": unknown error code: " + EasyCL::toString(error) );
}
}
return (int)somelong;
}
int64_t getDeviceInfoInt64(cl_device_id deviceId, cl_device_info name) {
int64_t somelong = 0;
cl_int error = clGetDeviceInfo(deviceId, name, sizeof(cl_ulong), &somelong, 0);
if(error != CL_SUCCESS) {
if(error == CL_INVALID_DEVICE) {
throw runtime_error("Failed to obtain info for device id " + EasyCL::toString(deviceId) + ": invalid device");
} else if(error == CL_INVALID_VALUE) {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": invalid value");
} else {
throw runtime_error("Failed to obtain device info " + EasyCL::toString(name) + " for device id " + EasyCL::toString(deviceId) + ": unknown error code: " + EasyCL::toString(error) );
}
}
return somelong;
}