Changeset a6cd8d1 in sasview for src/sas/qtgui/Perspectives
- Timestamp:
- Oct 24, 2017 10:33:22 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 1df1025
- Parents:
- 14fa542
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/GPUOptions.py
r14fa542 ra6cd8d1 1 1 # global 2 import os 3 import sys 4 import sasmodels 2 5 3 6 from PyQt4 import QtGui, QtCore … … 24 27 """ 25 28 29 clicked = False 30 checkBoxes = None 31 sas_open_cl = None 32 26 33 def __init__(self, parent=None): 27 34 super(GPUOptions, self).__init__(parent) 35 self.parent = parent 28 36 self.setupUi(self) 37 self.addOpenCLOptions() 38 self.createLinks() 29 39 40 def addOpenCLOptions(self): 41 """ 42 Populate the window with a list of OpenCL options 43 """ 30 44 # Get list of openCL options and add to GUI 31 cl_tuple = self._get_clinfo()45 cl_tuple = _get_clinfo() 32 46 i = 0 47 self.sas_open_cl = os.environ.get("SAS_OPENCL", "") 48 self.checkBoxes = [] 33 49 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)) 50 checkBox = QtGui.QCheckBox(self.openCLCheckBoxGroup) 51 checkBox.setGeometry(20, 20 + i, 351, 30) 52 checkBox.setObjectName(_fromUtf8(descr)) 53 checkBox.setText(_translate("GPUOptions", descr, None)) 54 if (descr == self.sas_open_cl) or (title == "None" and not self.clicked): 55 checkBox.click() 56 self.clicked = True 57 self.checkBoxes.append(checkBox) 38 58 # 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)) 59 self.openCLCheckBoxGroup.resize(391, 60 + i) 60 self.okButton.setGeometry(QtCore.QRect(20, 90 + i, 93, 28)) 61 self.resetButton.setGeometry(QtCore.QRect(120, 90 + i, 93, 28)) 62 self.testButton.setGeometry(QtCore.QRect(220, 90 + i, 93, 28)) 63 self.helpButton.setGeometry(QtCore.QRect(320, 90 + i, 93, 28)) 43 64 self.resize(440, 130 + i) 44 65 i += 30 45 66 46 def _get_clinfo(self):67 def createLinks(self): 47 68 """ 48 Reading in information about available OpenCL infrastructure 49 :return: 69 Link actions to function calls 50 70 """ 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") 71 self.testButton.clicked.connect(lambda: self.testButtonClicked()) 72 self.helpButton.clicked.connect(lambda: self.helpButtonClicked()) 73 self.openCLCheckBoxGroup.clicked.connect(lambda: self.checked()) 58 74 59 p_index = 060 for platform in platforms:61 d_index = 062 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 += 172 p_index += 175 def checked(self): 76 """ 77 Action triggered when box is selected 78 """ 79 selected_box = None 80 for box in self.checkBoxes: 81 if box.isChecked() and box.getText() != self.sas_open_cl: 82 selected_box = box 83 else: 84 box.setChecked(False) 85 if selected_box.getText(): 86 self.sas_open_cl = self.option_button[selected_box.title] 87 else: 88 self.sas_open_cl = None 73 89 74 clinfo.append(("None", "No OpenCL")) 75 return clinfo 90 def testButtonClicked(self): 91 """ 92 Run the model tests when the test button is clicked 93 """ 94 pass 95 96 def helpButtonClicked(self): 97 """ 98 Open the help menu when the help button is clicked 99 """ 100 pass 101 102 def reject(self): 103 """ 104 Close the window without modifying SAS_OPENCL 105 """ 106 self.close() 107 self.parent.gpu_options_widget = GPUOptions(self) 108 self.open() 109 110 def accept(self): 111 """ 112 Close the window after modifying the SAS_OPENCL value 113 """ 114 # If statement added to handle Reset 115 if self.sas_open_cl: 116 os.environ["SAS_OPENCL"] = self.sas_open_cl 117 else: 118 if "SAS_OPENCL" in os.environ: 119 del os.environ["SAS_OPENCL"] 120 121 # Sasmodels kernelcl doesn't exist when initiated with None 122 if 'sasmodels.kernelcl' in sys.modules: 123 sasmodels.kernelcl.ENV = None 124 125 reload(sasmodels.core) 126 super(GPUOptions, self).accept() 127 128 def closeEvent(self, event): 129 """ 130 Overwrite QDialog close method to allow for custom widget close 131 """ 132 self.reject() 133 134 135 def _get_clinfo(): 136 """ 137 Reading in information about available OpenCL infrastructure 138 :return: 139 """ 140 clinfo = [] 141 platforms = [] 142 try: 143 import pyopencl as cl 144 platforms = cl.get_platforms() 145 except ImportError: 146 print("pyopencl import failed. Using only CPU computations") 147 148 p_index = 0 149 for platform in platforms: 150 d_index = 0 151 devices = platform.get_devices() 152 for device in devices: 153 if len(devices) > 1 and len(platforms) > 1: 154 combined_index = ":".join([str(p_index), str(d_index)]) 155 elif len(platforms) > 1: 156 combined_index = str(p_index) 157 else: 158 combined_index = str(d_index) 159 clinfo.append((combined_index, ":".join([platform.name, device.name]))) 160 d_index += 1 161 p_index += 1 162 163 clinfo.append(("None", "No OpenCL")) 164 return clinfo -
src/sas/qtgui/Perspectives/Fitting/UI/GPUOptionsUI.ui
r14fa542 ra6cd8d1 14 14 <string>Dialog</string> 15 15 </property> 16 <widget class="QPushButton" name=" pushButton">16 <widget class="QPushButton" name="testButton"> 17 17 <property name="geometry"> 18 18 <rect> … … 27 27 </property> 28 28 </widget> 29 <widget class="QDialogButtonBox" name="TestButton"> 30 <property name="geometry"> 31 <rect> 32 <x>20</x> 33 <y>140</y> 34 <width>193</width> 35 <height>28</height> 36 </rect> 37 </property> 38 <property name="standardButtons"> 39 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> 40 </property> 41 </widget> 42 <widget class="QPushButton" name="pushButton_2"> 29 <widget class="QPushButton" name="helpButton"> 43 30 <property name="geometry"> 44 31 <rect> … … 50 37 </property> 51 38 <property name="text"> 52 <string>Reset</string> 39 <string>Help</string> 40 </property> 41 <property name="autoDefault"> 42 <bool>true</bool> 53 43 </property> 54 44 </widget> 55 <widget class="QGroupBox" name="openCL ButtonGroup">45 <widget class="QGroupBox" name="openCLCheckBoxGroup"> 56 46 <property name="geometry"> 57 47 <rect> … … 66 56 </property> 67 57 </widget> 58 <widget class="QPushButton" name="resetButton"> 59 <property name="geometry"> 60 <rect> 61 <x>120</x> 62 <y>140</y> 63 <width>93</width> 64 <height>28</height> 65 </rect> 66 </property> 67 <property name="text"> 68 <string>Reset</string> 69 </property> 70 </widget> 71 <widget class="QPushButton" name="okButton"> 72 <property name="geometry"> 73 <rect> 74 <x>20</x> 75 <y>140</y> 76 <width>93</width> 77 <height>28</height> 78 </rect> 79 </property> 80 <property name="text"> 81 <string>OK</string> 82 </property> 83 </widget> 68 84 </widget> 69 85 <resources/> 70 <connections/> 86 <connections> 87 <connection> 88 <sender>okButton</sender> 89 <signal>clicked()</signal> 90 <receiver>GPUOptions</receiver> 91 <slot>accept()</slot> 92 <hints> 93 <hint type="sourcelabel"> 94 <x>66</x> 95 <y>153</y> 96 </hint> 97 <hint type="destinationlabel"> 98 <x>219</x> 99 <y>88</y> 100 </hint> 101 </hints> 102 </connection> 103 <connection> 104 <sender>resetButton</sender> 105 <signal>clicked()</signal> 106 <receiver>GPUOptions</receiver> 107 <slot>reject()</slot> 108 <hints> 109 <hint type="sourcelabel"> 110 <x>166</x> 111 <y>153</y> 112 </hint> 113 <hint type="destinationlabel"> 114 <x>219</x> 115 <y>88</y> 116 </hint> 117 </hints> 118 </connection> 119 </connections> 71 120 </ui>
Note: See TracChangeset
for help on using the changeset viewer.