source: sasview/src/sas/qtgui/Perspectives/Fitting/GPUOptions.py @ 14fa542

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 14fa542 was 14fa542, checked in by krzywon, 7 years ago

Auto-populate OpenCL dialog with available options to finalize GUI.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1# global
2
3from PyQt4 import QtGui, QtCore
4from sas.qtgui.Perspectives.Fitting.UI.GPUOptionsUI import Ui_GPUOptions
5
6try:
7    _fromUtf8 = QtCore.QString.fromUtf8
8except AttributeError:
9    def _fromUtf8(s):
10        return s
11
12try:
13    _encoding = QtGui.QApplication.UnicodeUTF8
14    def _translate(context, text, disambig):
15        return QtGui.QApplication.translate(context, text, disambig, _encoding)
16except AttributeError:
17    def _translate(context, text, disambig):
18        return QtGui.QApplication.translate(context, text, disambig)
19
20
21class GPUOptions(QtGui.QDialog, Ui_GPUOptions):
22    """
23    OpenCL Dialog to modify the OpenCL options
24    """
25
26    def __init__(self, parent=None):
27        super(GPUOptions, self).__init__(parent)
28        self.setupUi(self)
29
30        # Get list of openCL options and add to GUI
31        cl_tuple = self._get_clinfo()
32        i = 0
33        for title, descr in cl_tuple:
34            button = QtGui.QRadioButton(self.openCLButtonGroup)
35            button.setGeometry(20, 20 + i, 351, 30)
36            button.setObjectName(_fromUtf8(title))
37            button.setText(_translate("GPUOptions", descr, None))
38            # Expand group and shift items down as more are added
39            self.openCLButtonGroup.resize(391, 60 + i)
40            self.pushButton.setGeometry(QtCore.QRect(220, 90 + i, 93, 28))
41            self.TestButton.setGeometry(QtCore.QRect(20, 90 + i, 193, 28))
42            self.pushButton_2.setGeometry(QtCore.QRect(320, 90 + i, 93, 28))
43            self.resize(440, 130 + i)
44            i += 30
45
46    def _get_clinfo(self):
47        """
48        Reading in information about available OpenCL infrastructure
49        :return:
50        """
51        clinfo = []
52        platforms = []
53        try:
54            import pyopencl as cl
55            platforms = cl.get_platforms()
56        except ImportError:
57            print("pyopencl import failed. Using only CPU computations")
58
59        p_index = 0
60        for platform in platforms:
61            d_index = 0
62            devices = platform.get_devices()
63            for device in devices:
64                if len(devices) > 1 and len(platforms) > 1:
65                    combined_index = ":".join([str(p_index), str(d_index)])
66                elif len(platforms) > 1:
67                    combined_index = str(p_index)
68                else:
69                    combined_index = str(d_index)
70                clinfo.append((combined_index, ":".join([platform.name, device.name])))
71                d_index += 1
72            p_index += 1
73
74        clinfo.append(("None", "No OpenCL"))
75        return clinfo
Note: See TracBrowser for help on using the repository browser.