Changeset ced1bff in sasview for src/sas


Ignore:
Timestamp:
Oct 25, 2017 2:57:22 AM (6 years ago)
Author:
krzywon
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:
0bb1397
Parents:
c82fd8f
Message:

Enable OpenCL tests and display results in new window.

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/GPUOptions.py

    rc82fd8f rced1bff  
    33import sys 
    44import sasmodels 
     5import json 
     6import platform 
    57 
    68from PyQt4 import QtGui, QtCore, QtWebKit 
    79from sas.qtgui.Perspectives.Fitting.UI.GPUOptionsUI import Ui_GPUOptions 
     10from sas.qtgui.Perspectives.Fitting.UI.GPUTestResultsUI import Ui_GPUTestResults 
    811 
    912try: 
     
    5760            # Expand group and shift items down as more are added 
    5861            self.openCLCheckBoxGroup.resize(391, 60 + i) 
    59             self.okButton.setGeometry(QtCore.QRect(20, 90 + i, 93, 28)) 
    60             self.resetButton.setGeometry(QtCore.QRect(120, 90 + i, 93, 28)) 
    61             self.testButton.setGeometry(QtCore.QRect(220, 90 + i, 93, 28)) 
    62             self.helpButton.setGeometry(QtCore.QRect(320, 90 + i, 93, 28)) 
    63             self.resize(440, 130 + i) 
     62            self.label.setGeometry(QtCore.QRect(20, 90 + i, 391, 37)) 
     63            self.okButton.setGeometry(QtCore.QRect(20, 127 + i, 93, 28)) 
     64            self.resetButton.setGeometry(QtCore.QRect(120, 127 + i, 93, 28)) 
     65            self.testButton.setGeometry(QtCore.QRect(220, 127 + i, 93, 28)) 
     66            self.helpButton.setGeometry(QtCore.QRect(320, 127 + i, 93, 28)) 
     67            self.resize(440, 167 + i) 
    6468            i += 30 
    6569 
     
    9195            self.sas_open_cl = None 
    9296 
     97    def set_open_cl(self): 
     98        """ 
     99        Set openCL value when tests run or OK button clicked 
     100        """ 
     101        no_opencl_msg = False 
     102        if self.sas_open_cl: 
     103            os.environ["SAS_OPENCL"] = self.sas_open_cl 
     104            if self.sas_open_cl.lower() == "none": 
     105                no_opencl_msg = True 
     106        else: 
     107            if "SAS_OPENCL" in os.environ: 
     108                del os.environ["SAS_OPENCL"] 
     109        # Sasmodels kernelcl doesn't exist when initiated with None 
     110        if 'sasmodels.kernelcl' in sys.modules: 
     111            sasmodels.kernelcl.ENV = None 
     112        reload(sasmodels.core) 
     113        return no_opencl_msg 
     114 
    93115    def testButtonClicked(self): 
    94116        """ 
    95         Run the model tests when the test button is clicked 
    96         """ 
    97         # TODO: Do something 
    98         pass 
     117        Run sasmodels check from here and report results from 
     118        """ 
     119 
     120        no_opencl_msg = self.set_open_cl() 
     121 
     122        # Only import when tests are run 
     123        from sasmodels.model_test import model_tests 
     124 
     125        try: 
     126            from sasmodels.kernelcl import environment 
     127            env = environment() 
     128            clinfo = [(ctx.devices[0].platform.vendor, 
     129                       ctx.devices[0].platform.version, 
     130                       ctx.devices[0].vendor, 
     131                       ctx.devices[0].name, 
     132                       ctx.devices[0].version) 
     133                      for ctx in env.context] 
     134        except ImportError: 
     135            clinfo = None 
     136 
     137        failures = [] 
     138        tests_completed = 0 
     139        for test in model_tests(): 
     140            try: 
     141                test() 
     142            except Exception: 
     143                failures.append(test.description) 
     144 
     145            tests_completed += 1 
     146 
     147        info = { 
     148            'version': sasmodels.__version__, 
     149            'platform': platform.uname(), 
     150            'opencl': clinfo, 
     151            'failing tests': failures, 
     152        } 
     153 
     154        msg_info = 'OpenCL tests results' 
     155 
     156        msg = str(tests_completed) + ' tests completed.\n' 
     157        if len(failures) > 0: 
     158            msg += str(len(failures)) + ' tests failed.\n' 
     159            msg += 'Failing tests: ' 
     160            msg += json.dumps(info['failing tests']) 
     161            msg += "\n" 
     162        else: 
     163            msg += "All tests passed!\n" 
     164 
     165        msg += "\nPlatform Details:\n\n" 
     166        msg += "Sasmodels version: " 
     167        msg += info['version'] + "\n" 
     168        msg += "\nPlatform used: " 
     169        msg += json.dumps(info['platform']) + "\n" 
     170        if no_opencl_msg: 
     171            msg += "\nOpenCL driver: None" 
     172        else: 
     173            msg += "\nOpenCL driver: " 
     174            msg += json.dumps(info['opencl']) + "\n" 
     175        GPUTestResults(self, msg, msg_info) 
    99176 
    100177    def helpButtonClicked(self): 
     
    120197        Close the window after modifying the SAS_OPENCL value 
    121198        """ 
    122         # If statement added to handle Reset 
    123         if self.sas_open_cl: 
    124             os.environ["SAS_OPENCL"] = self.sas_open_cl 
    125         else: 
    126             if "SAS_OPENCL" in os.environ: 
    127                 del os.environ["SAS_OPENCL"] 
    128  
    129         # Sasmodels kernelcl doesn't exist when initiated with None 
    130         if 'sasmodels.kernelcl' in sys.modules: 
    131             sasmodels.kernelcl.ENV = None 
    132  
    133         reload(sasmodels.core) 
     199        self.set_open_cl() 
    134200        super(GPUOptions, self).reject() 
    135201 
     
    140206        self.close() 
    141207        self.parent.gpu_options_widget = GPUOptions(self) 
     208 
     209 
     210class GPUTestResults(QtGui.QDialog, Ui_GPUTestResults): 
     211    """ 
     212    OpenCL Dialog to modify the OpenCL options 
     213    """ 
     214    def __init__(self, parent, msg, title): 
     215        super(GPUTestResults, self).__init__(parent) 
     216        self.setupUi(self) 
     217        self.resultsText.setText(_translate("GPUTestResults", msg, None)) 
     218        self.open() 
    142219 
    143220 
  • src/sas/qtgui/Perspectives/Fitting/UI/GPUOptionsUI.ui

    ra6cd8d1 rced1bff  
    88    <y>0</y> 
    99    <width>440</width> 
    10     <height>178</height> 
     10    <height>211</height> 
    1111   </rect> 
    1212  </property> 
     
    1717   <property name="geometry"> 
    1818    <rect> 
    19      <x>220</x> 
    20      <y>140</y> 
     19     <x>120</x> 
     20     <y>170</y> 
    2121     <width>93</width> 
    2222     <height>28</height> 
     
    3131    <rect> 
    3232     <x>320</x> 
    33      <y>140</y> 
     33     <y>170</y> 
    3434     <width>93</width> 
    3535     <height>28</height> 
     
    5959   <property name="geometry"> 
    6060    <rect> 
    61      <x>120</x> 
    62      <y>140</y> 
     61     <x>220</x> 
     62     <y>170</y> 
    6363     <width>93</width> 
    6464     <height>28</height> 
     
    7373    <rect> 
    7474     <x>20</x> 
    75      <y>140</y> 
     75     <y>170</y> 
    7676     <width>93</width> 
    7777     <height>28</height> 
     
    8080   <property name="text"> 
    8181    <string>OK</string> 
     82   </property> 
     83  </widget> 
     84  <widget class="QLabel" name="label"> 
     85   <property name="geometry"> 
     86    <rect> 
     87     <x>20</x> 
     88     <y>132</y> 
     89     <width>391</width> 
     90     <height>37</height> 
     91    </rect> 
     92   </property> 
     93   <property name="font"> 
     94    <font> 
     95     <pointsize>8</pointsize> 
     96    </font> 
     97   </property> 
     98   <property name="text"> 
     99    <string>WARNING: Running tests can take a few minutes!</string> 
     100   </property> 
     101   <property name="alignment"> 
     102    <set>Qt::AlignCenter</set> 
    82103   </property> 
    83104  </widget> 
Note: See TracChangeset for help on using the changeset viewer.