forked from SaschaWillems/OpenCLCapsViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviceinfo.h
More file actions
139 lines (126 loc) · 3.77 KB
/
deviceinfo.h
File metadata and controls
139 lines (126 loc) · 3.77 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
*
* OpenCL hardware capability viewer
*
* Copyright (C) 2021 by Sascha Willems (www.saschawillems.de)
*
* This code is free software, you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3 as published by the Free Software Foundation.
*
* Please review the following information to ensure the GNU Lesser
* General Public License version 3 requirements will be met:
* http://opensource.org/licenses/lgpl-3.0.html
*
* The code is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU LGPL 3.0 for more details.
*
*/
#ifndef DEVICEINFO_H
#define DEVICEINFO_H
#include "CL/cl.h"
#include "CL/cl_ext.h"
#include "openclutils.h"
#include "displayutils.h"
#include "platforminfo.h"
#include "openclfunctions.h"
#include <unordered_map>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <QVariantMap>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#ifdef __ANDROID__
#include <sys/system_properties.h>
#endif
struct DeviceExtension
{
QString name;
cl_version version;
};
typedef std::function<QString(QVariant)> DisplayFn;
struct DeviceInfoValueDescriptor
{
cl_device_info name;
clValueType valueType;
DisplayFn displayFunction = nullptr;
DeviceInfoValueDescriptor();
DeviceInfoValueDescriptor(cl_device_info name, clValueType valueType, DisplayFn displayFunction = nullptr);
};
struct DeviceInfoValueDetailValue
{
QString name;
QString detail;
QVariant value;
DisplayFn displayFunction = nullptr;
DeviceInfoValueDetailValue(QString name, QVariant value, DisplayFn displayFunction = nullptr);
DeviceInfoValueDetailValue(QString name, QString detail, QVariant value, DisplayFn displayFunction = nullptr);
QString getDisplayValue();
};
struct DeviceInfoValue
{
QString name;
QVariant value;
QString extension;
qint32 enumValue;
DisplayFn displayFunction = nullptr;
std::vector<DeviceInfoValueDetailValue> detailValues;
DeviceInfoValue(cl_device_info info, QVariant value, QString extension, DisplayFn displayFunction = nullptr);
void addDetailValue(QString name, QVariant value, DisplayFn displayFunction = nullptr);
void addDetailValue(QString name, QString detail, QVariant value, DisplayFn displayFunction = nullptr);
QString getDisplayValue();
};
struct DeviceImageChannelTypeInfo
{
cl_mem_flags memFlags = 0;
void addFlag(cl_mem_flags flag) {
memFlags |= flag;
}
};
struct DeviceImageChannelOrderInfo
{
std::unordered_map<cl_channel_type, DeviceImageChannelTypeInfo> channelTypes;
};
struct DeviceImageTypeInfo
{
std::unordered_map<cl_channel_order, DeviceImageChannelOrderInfo> channelOrders;
};
// Contains values to uniquely identify the device when talking to the database
struct DeviceIdentifier
{
QString name;
QString gpuName;
QString deviceVersion;
QString driverVersion;
};
class DeviceInfo
{
private:
QString getDeviceInfoString(cl_device_info info);
bool extensionSupported(const char* name);
void readDeviceInfoValue(DeviceInfoValueDescriptor descriptor, QString extension = "");
void readDeviceIdentifier();
void readDeviceInfo();
void readOpenCLVersion();
void readExtensions();
void readExtensionInfo();
void readSupportedImageFormats();
public:
DeviceInfo();
cl_device_id deviceId;
PlatformInfo* platform;
DeviceIdentifier identifier;
qint32 clVersionMajor;
qint32 clVersionMinor;
std::vector<DeviceInfoValue> deviceInfo;
std::vector<DeviceExtension> extensions;
std::unordered_map<cl_mem_object_type, DeviceImageTypeInfo> imageTypes;
void read();
QJsonObject toJson();
};
#endif // DEVICEINFO_H