diff --git a/MainWindow.cpp b/MainWindow.cpp new file mode 100644 index 0000000..ff126e8 --- /dev/null +++ b/MainWindow.cpp @@ -0,0 +1,15 @@ +#include "MainWindow.h" +#include "ui_MainWindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + diff --git a/MainWindow.h b/MainWindow.h new file mode 100644 index 0000000..4643e32 --- /dev/null +++ b/MainWindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/MainWindow.ui b/MainWindow.ui new file mode 100644 index 0000000..b232854 --- /dev/null +++ b/MainWindow.ui @@ -0,0 +1,22 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + diff --git a/OpenCLManager.cpp b/OpenCLManager.cpp new file mode 100644 index 0000000..59e2f8c --- /dev/null +++ b/OpenCLManager.cpp @@ -0,0 +1,81 @@ +#include "OpenCLManager.h" +#include +#include + +OpenCLManager::OpenCLManager() +{ + connectToDBusSignals(); +} + +void OpenCLManager::connectToDBusSignals() { + QDBusConnection bus = QDBusConnection::systemBus(); + bus.connect(QString(), QString(), "org.freedesktop.login1.Manager", "PrepareForSleep", + this, SLOT(handleSuspendResume(bool))); +} + +void OpenCLManager::handleSuspendResume(bool isSuspending) { + if(isSuspending) + { + std::cout << "System is going to suspend. Releasing OpenCL resources..." << std::endl; + releaseOpenCLResources(); + } + else + { + std::cout << "System has resumed. Reinitializing OpenCL resources..." << std::endl; + initOpenCLResources(); + } +} + +void OpenCLManager::initOpenCLResources() { + cl_int err; + cl_platform_id platform; + cl_device_id device; + + err = clGetPlatformIDs(1, &platform, nullptr); + if(err != CL_SUCCESS) + { + std::cerr << "Failed to get OpenCL platform" << std::endl; + + return; + } + + err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, nullptr); + if(err != CL_SUCCESS) + { + std::cerr << "Failed to get OpenCL device" << std::endl; + + return; + } + + context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &err); + if(err != CL_SUCCESS) + { + std::cerr << "Failed to create OpenCL context" << std::endl; + + return; + } + + commandQueue = clCreateCommandQueue(context, device, 0, &err); + if(err != CL_SUCCESS) + { + std::cerr << "Failed to create OpenCL command queue" << std::endl; + + return; + } + + std::cout << "OpenCL resources initialized successfully." << std::endl; +} + +void OpenCLManager::releaseOpenCLResources() { + if(commandQueue) + { + clReleaseCommandQueue(commandQueue); + commandQueue = nullptr; + } + if(context) + { + clReleaseContext(context); + context = nullptr; + } + std::cout << "OpenCL resources released." << std::endl; +} diff --git a/OpenCLManager.h b/OpenCLManager.h new file mode 100644 index 0000000..ba086ba --- /dev/null +++ b/OpenCLManager.h @@ -0,0 +1,33 @@ +#ifndef OPENCLMANAGER_H +#define OPENCLMANAGER_H + +#include +#include +#include +#include +#include +#include +#include + +class OpenCLManager : public QObject +{ + Q_OBJECT + +public: + OpenCLManager(); + void connectToDBusSignals(); + +//uncrustify off +public slots: +//uncrustify on + void handleSuspendResume(bool isSuspending); + +private: + cl_context context = nullptr; + cl_command_queue commandQueue = nullptr; + + void initOpenCLResources(); + void releaseOpenCLResources(); +}; + +#endif //OPENCLMANAGER_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..34339a4 --- /dev/null +++ b/main.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +#include "MainWindow.h" +#include "OpenCLManager.h" + +#include + +int main(int argc, char* argv[]) +{ + QApplication a(argc, argv); + OpenCLManager openCLManager; + + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/untitled.pro b/untitled.pro new file mode 100644 index 0000000..0e6b9ed --- /dev/null +++ b/untitled.pro @@ -0,0 +1,25 @@ +QT += core dbus widgets + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +DEFINES += QT_DEPRECATED_WARNINGS + +SOURCES += \ + OpenCLManager.cpp \ + main.cpp \ + MainWindow.cpp + +HEADERS += \ + MainWindow.h \ + OpenCLManager.h + +FORMS += \ + MainWindow.ui + +LIBS += -lOpenCL + +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/untitled.pro.user b/untitled.pro.user new file mode 100644 index 0000000..816f4a1 --- /dev/null +++ b/untitled.pro.user @@ -0,0 +1,332 @@ + + + + + + EnvironmentId + {59306388-5219-41bd-bd6d-bb0169c1cb4c} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.13.2 GCC 64bit + Desktop Qt 5.13.2 GCC 64bit + qt.qt5.5132.gcc_64_kit + 0 + 0 + 0 + + /home/developer/host-projects/build-untitled-Desktop_Qt_5_13_2_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/developer/host-projects/build-untitled-Desktop_Qt_5_13_2_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/developer/host-projects/build-untitled-Desktop_Qt_5_13_2_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + + 3768 + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + +