Skip to content

Commit dce460a

Browse files
committed
GPU selection + saving working
1 parent f54f924 commit dce460a

File tree

8 files changed

+68
-39
lines changed

8 files changed

+68
-39
lines changed

CM_Config/LibraryHandler.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ find_package(Qt6 REQUIRED COMPONENTS Widgets Gui Core)
55

66
pkg_check_modules(LIBPCI REQUIRED libpci)
77
include_directories(${LIBPCI_INCLUDE_DIRS})
8-
link_directories(${LIBPCI_LIBRARY_DIRS})
8+
link_directories(${LIBPCI_LIBRARY_DIRS})
9+
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")

Sources/AppGUI/SharedData/UnitSelectorData.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#ifndef RUNASGPU_UNITSELECTORDATA_HPP
22
#define RUNASGPU_UNITSELECTORDATA_HPP
33

4+
#include <vector>
5+
46
#include <RunAsGPU/Shared/GraphicalUnit.hpp>
57

68
namespace UnitSelectorData {
79

810
extern GraphicalUnit unitSelected;
9-
extern GraphicalUnit defaultUnit;
1011

1112
}
1213

Sources/AppGUI/UI/MainWindow.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
#include "Model/AppListModel.hpp"
1313
#include "Model/AppListDelegate.hpp"
1414
#include "RunAsGPU/Shared/Shared.hpp"
15+
#include "UnitSelectorData.hpp"
1516

1617
#include <filesystem>
1718
#include <fstream>
1819
#include <iostream>
20+
#include <algorithm>
1921

2022
namespace fs = std::filesystem;
2123

@@ -105,9 +107,10 @@ int get_default_gpu(const std::vector<GraphicalUnit> &gpu_list) {
105107
}
106108

107109
int gpuUnit;
110+
std::vector<GraphicalUnit> gpu_list;
108111

109112
void Ui_MainWindow::performLogic(QMainWindow* window) const {
110-
std::vector<GraphicalUnit> gpu_list = Runner::ListGraphicalUnits();
113+
gpu_list = Runner::ListGraphicalUnits();
111114
if (gpu_list.empty()) {
112115
std::cerr << "GPU list empty, exiting..." << std::endl;
113116
std::abort();
@@ -191,9 +194,23 @@ void Ui_MainWindow::performLogic(QMainWindow* window) const {
191194
Ui_UnitSelector ui;
192195
ui.setupUi(&dialog);
193196

194-
std::vector<GraphicalUnit> gList = Runner::ListGraphicalUnits();
195-
ui.gpuList = gList;
196-
197197
int rc = dialog.exec();
198+
if (rc == QDialog::Accepted) {
199+
auto it = std::find_if(gpu_list.begin(), gpu_list.end(), [&](const GraphicalUnit &gpu) {
200+
return gpu.vendor == UnitSelectorData::unitSelected.vendor && gpu.product == UnitSelectorData::unitSelected.product;
201+
});
202+
203+
if (it != gpu_list.end()) {
204+
gpuUnit = std::distance(gpu_list.begin(), it);
205+
206+
if (ui.choiceDefUnit->isChecked()) {
207+
std::cout << "Default GPU selected: " << std::hex << UnitSelectorData::unitSelected.product << std::endl;
208+
save_default_gpu(gpu_list, gpuUnit);
209+
}
210+
211+
labelUnitSelected->setText("Selected GPU: " + QString::fromStdString(UnitSelectorData::unitSelected.fullName));
212+
} else
213+
QMessageBox::warning(nullptr, "GPU Find Error", "The selected GPU was not found from its list.");
214+
}
198215
});
199216
}

Sources/AppGUI/UI/MainWindow.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ class Ui_MainWindow
3434
centralwidget->setObjectName("centralwidget");
3535
btnRun = new QPushButton(centralwidget);
3636
btnRun->setObjectName("btnRun");
37-
btnRun->setGeometry(QRect(530, 310, 111, 34));
37+
btnRun->setGeometry(QRect(540, 310, 111, 34));
3838
appList = new QListView(centralwidget);
3939
appList->setObjectName("appList");
4040
appList->setGeometry(QRect(10, 20, 641, 281));
4141
appList->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
4242
appList->setWordWrap(true);
4343
btnApplicationAdd = new QPushButton(centralwidget);
4444
btnApplicationAdd->setObjectName("btnApplicationAdd");
45-
btnApplicationAdd->setGeometry(QRect(0, 310, 121, 34));
45+
btnApplicationAdd->setGeometry(QRect(10, 310, 121, 34));
4646
btnUnitSelector = new QPushButton(centralwidget);
4747
btnUnitSelector->setObjectName("btnUnitSelector");
48-
btnUnitSelector->setGeometry(QRect(130, 310, 88, 34));
48+
btnUnitSelector->setGeometry(QRect(140, 310, 88, 34));
4949
labelUnitSelected = new QLabel(centralwidget);
5050
labelUnitSelected->setObjectName("labelUnitSelected");
5151
labelUnitSelected->setGeometry(QRect(10, 350, 631, 71));

Sources/AppGUI/UI/MainWindow.ui

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
</property>
3434
<property name="windowIcon">
3535
<iconset>
36-
<normaloff>RunAsGPU_Icon.png</normaloff>RunAsGPU_Icon.png</iconset>
36+
<normaloff>../../../../../.designer/backup/RunAsGPU_Icon.png</normaloff>../../../../../.designer/backup/RunAsGPU_Icon.png</iconset>
3737
</property>
3838
<widget class="QWidget" name="centralwidget">
3939
<widget class="QPushButton" name="btnRun">
4040
<property name="geometry">
4141
<rect>
42-
<x>530</x>
42+
<x>540</x>
4343
<y>310</y>
4444
<width>111</width>
4545
<height>34</height>
@@ -68,7 +68,7 @@
6868
<widget class="QPushButton" name="btnApplicationAdd">
6969
<property name="geometry">
7070
<rect>
71-
<x>0</x>
71+
<x>10</x>
7272
<y>310</y>
7373
<width>121</width>
7474
<height>34</height>
@@ -81,7 +81,7 @@
8181
<widget class="QPushButton" name="btnUnitSelector">
8282
<property name="geometry">
8383
<rect>
84-
<x>130</x>
84+
<x>140</x>
8585
<y>310</y>
8686
<width>88</width>
8787
<height>34</height>
@@ -103,9 +103,6 @@
103103
<property name="text">
104104
<string>Selected GPU: {{UNIT}}</string>
105105
</property>
106-
<property name="wordWrap">
107-
<bool>true</bool>
108-
</property>
109106
</widget>
110107
</widget>
111108
<widget class="QStatusBar" name="statusbar"/>

Sources/AppGUI/UI/UnitSelector.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
#include <QStandardItemModel>
2+
13
#include "UnitSelector.hpp"
4+
#include "RunAsGPU/Shared/Runner.hpp"
5+
6+
#include <UnitSelectorData.hpp>
7+
8+
std::vector<GraphicalUnit> gpuList;
29

310
void Ui_UnitSelector::performLogic() const {
4-
}
11+
self->setFixedSize(self->size());
12+
13+
gpuList = Runner::ListGraphicalUnits();
14+
QStandardItemModel *model = new QStandardItemModel(unit_list);
15+
16+
for (const auto &gpu : gpuList) {
17+
QStandardItem *item = new QStandardItem(QString::fromStdString(gpu.fullName));
18+
model->appendRow(item);
19+
}
20+
21+
unit_list->setModel(model);
22+
unit_list->setSelectionMode(QAbstractItemView::SingleSelection);
23+
24+
QObject::connect(choiceSelect, &QDialogButtonBox::accepted, self, [&]() {
25+
QModelIndex index = unit_list->currentIndex();
26+
27+
if (index.isValid()) {
28+
int gpuIndex = index.row();
29+
UnitSelectorData::unitSelected = gpuList[gpuIndex];
30+
} else
31+
QMessageBox::warning(self, "GPU Selection", "No GPU selected.");
532

6-
void Ui_UnitSelector::onItemSelect(bool accept) const {
33+
self->accept();
34+
});
35+
QObject::connect(choiceSelect, &QDialogButtonBox::rejected, self, [&]() {
36+
self->reject();
37+
});
738
}

Sources/AppGUI/UI/UnitSelector.hpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ QT_BEGIN_NAMESPACE
1616

1717
class Ui_UnitSelector {
1818
public:
19+
QDialog *self;
1920
QDialogButtonBox *choiceSelect{};
2021
QListView *unit_list{};
2122
QCheckBox *choiceDefUnit;
2223

23-
std::vector<GraphicalUnit> gpuList;
24-
2524
void setupUi(QDialog *UnitSelector) {
2625
if (UnitSelector->objectName().isEmpty())
2726
UnitSelector->setObjectName("UnitSelector");
2827
UnitSelector->resize(400, 300);
28+
self = UnitSelector;
2929
choiceSelect = new QDialogButtonBox(UnitSelector);
3030
choiceSelect->setObjectName("choiceSelect");
3131
choiceSelect->setGeometry(QRect(50, 250, 341, 32));
@@ -40,22 +40,6 @@ class Ui_UnitSelector {
4040
choiceDefUnit->setGeometry(QRect(0, 240, 161, 22));
4141

4242
retranslateUi(UnitSelector);
43-
QObject::connect(choiceSelect, &QDialogButtonBox::accepted, UnitSelector, [&]() {
44-
QModelIndex index = unit_list->currentIndex();
45-
46-
if (index.isValid()) {
47-
int gpuIndex = index.row();
48-
GraphicalUnit unit = gpuList.at(gpuIndex);
49-
} else
50-
QMessageBox::warning(UnitSelector, "GPU Selection", "No valid GPU selected.");
51-
52-
onItemSelect(true);
53-
UnitSelector->accept();
54-
});
55-
QObject::connect(choiceSelect, &QDialogButtonBox::rejected, UnitSelector, [&]() {
56-
onItemSelect(false);
57-
UnitSelector->reject();
58-
});
5943

6044
QMetaObject::connectSlotsByName(UnitSelector);
6145

@@ -69,8 +53,6 @@ class Ui_UnitSelector {
6953

7054
void performLogic() const;
7155

72-
void onItemSelect(bool accept) const;
73-
7456
};
7557

7658
namespace Ui {

Sources/AppGUI/UnitSelectorData.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
namespace UnitSelectorData {
44

55
GraphicalUnit unitSelected;
6-
GraphicalUnit defaultUnit;
76

87
}

0 commit comments

Comments
 (0)