1 | # global |
---|
2 | |
---|
3 | from PyQt4 import QtGui, QtCore |
---|
4 | from sas.qtgui.Perspectives.Fitting.UI.GPUOptionsUI import Ui_GPUOptions |
---|
5 | |
---|
6 | try: |
---|
7 | _fromUtf8 = QtCore.QString.fromUtf8 |
---|
8 | except AttributeError: |
---|
9 | def _fromUtf8(s): |
---|
10 | return s |
---|
11 | |
---|
12 | try: |
---|
13 | _encoding = QtGui.QApplication.UnicodeUTF8 |
---|
14 | def _translate(context, text, disambig): |
---|
15 | return QtGui.QApplication.translate(context, text, disambig, _encoding) |
---|
16 | except AttributeError: |
---|
17 | def _translate(context, text, disambig): |
---|
18 | return QtGui.QApplication.translate(context, text, disambig) |
---|
19 | |
---|
20 | |
---|
21 | class 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 |
---|