-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviceselectdialog.cpp
More file actions
82 lines (68 loc) · 2.52 KB
/
deviceselectdialog.cpp
File metadata and controls
82 lines (68 loc) · 2.52 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
#include "deviceselectdialog.h"
#include "canvaswidget-opencl.h"
#include "opencldeviceinfo.h"
#include <QDebug>
#include <QSettings>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
static QPushButton *makeButton(OpenCLDeviceInfo &dev)
{
QString name = QString("%1: %2").arg(dev.getPlatformName(), dev.getDeviceName()).simplified();
cl_ulong memSize = dev.getDeviceInfo<cl_ulong>(CL_DEVICE_GLOBAL_MEM_SIZE) / 0x100000;
name += QString("\n") + QString("%1MB").arg(memSize);
QPushButton *button = new QPushButton(name);
button->setAutoDefault(false);
button->setStyleSheet("text-align: left");
return button;
}
DeviceSelectDialog::DeviceSelectDialog(QWidget *parent) :
QDialog(parent)
{
setWindowTitle(tr("Select OpenCL Device"));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(3);
// layout->addWidget(new QLabel("DeviceSelect", this));
std::list<OpenCLDeviceInfo> devices = enumerateOpenCLDevices();
auto cpuDev = devices.end();
auto gpuDev = devices.end();
for (auto iter = devices.begin(); iter != devices.end(); ++iter)
{
if (cpuDev == devices.end() && iter->getType() == CL_DEVICE_TYPE_CPU)
cpuDev = iter;
else if (gpuDev == devices.end() && iter->getType() == CL_DEVICE_TYPE_GPU)
gpuDev = iter;
}
#ifndef Q_OS_MAC // Disabled due to unresolved GPU freezing in shared mode
layout->addWidget(new QLabel("Zero-copy (pick this one):"));
{
QPushButton *button = new QPushButton("OpenGL Device");
button->setStyleSheet("text-align: left");
button->setAutoDefault(false);
connect(button, &QPushButton::clicked, [this]() {
QSettings().setValue("OpenCL/Device", QVariant::fromValue<int>(0));
this->accept();
});
layout->addWidget(button);
}
#endif
layout->addWidget(new QLabel("Indirect:"));
if (cpuDev != devices.end())
{
QPushButton *button = makeButton(*cpuDev);
connect(button, &QPushButton::clicked, [this]() {
QSettings().setValue("OpenCL/Device", QVariant::fromValue<int>(CL_DEVICE_TYPE_CPU));
this->accept();
});
layout->addWidget(button);
}
if (gpuDev != devices.end())
{
QPushButton *button = makeButton(*gpuDev);
connect(button, &QPushButton::clicked, [this]() {
QSettings().setValue("OpenCL/Device", QVariant::fromValue<int>(CL_DEVICE_TYPE_GPU));
this->accept();
});
layout->addWidget(button);
}
}