Changeset a6cd8d1 in sasview for src/sas/qtgui/Perspectives/Fitting/GPUOptions.py
- 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
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.