[c0d7ab3] | 1 | .. _gpu-setup: |
---|
| 2 | |
---|
| 3 | ******************** |
---|
| 4 | GPU Setup |
---|
| 5 | ******************** |
---|
| 6 | |
---|
[59485a4] | 7 | SAS model evaluations can run on your graphics card (GPU) or they can run |
---|
| 8 | on the processor (CPU). In general, calculations performed on the GPU |
---|
| 9 | will run faster. |
---|
| 10 | |
---|
| 11 | |
---|
[c0d7ab3] | 12 | OpenCL Installation |
---|
| 13 | ******************* |
---|
| 14 | *Warning! GPU devices do not in general offer the same level of memory |
---|
| 15 | protection as CPU devices. If your code attempts to write outside allocated |
---|
| 16 | memory buffers unpredicatable behaviour may result (eg, your video display |
---|
| 17 | may freeze, or your system may crash, etc). Do not install OpenCL drivers |
---|
| 18 | without first checking for known issues (eg, some computer manufacturers |
---|
| 19 | install modified graphics drivers so replacing these may not be a good |
---|
| 20 | idea!). If in doubt, seek advice from an IT professional before proceeding |
---|
| 21 | further.* |
---|
| 22 | |
---|
| 23 | Check if you have OpenCL already installed |
---|
| 24 | ========================================== |
---|
| 25 | |
---|
| 26 | **Windows** |
---|
| 27 | |
---|
| 28 | The following instructions are based on |
---|
| 29 | http://web.engr.oregonstate.edu/~mjb/cs475/DoIHaveOpenCL.pdf |
---|
| 30 | |
---|
| 31 | * Go to: Start -> Control Panel -> System & Security -> Administrative Tools |
---|
| 32 | * Double Click on Computer Managment |
---|
| 33 | * Click on Device Manager |
---|
| 34 | * Click open Display Adapters |
---|
| 35 | * Right-click on available adapter and select Properties |
---|
| 36 | * Click on Driver |
---|
| 37 | * Go to Driver Details |
---|
| 38 | * Scroll down and see if OpenCL is installed (look for OpenCL*.dll files) |
---|
| 39 | |
---|
| 40 | **Mac OSX** |
---|
| 41 | |
---|
| 42 | For OS X operating systems higher than 10.6 OpenCL is shipped along with |
---|
| 43 | the system. |
---|
| 44 | |
---|
| 45 | However, OpenCL has had a rocky history on Macs. Apple provide a useful |
---|
| 46 | compatibility table at https://support.apple.com/en-us/HT202823 |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | Installation |
---|
| 50 | ============ |
---|
| 51 | |
---|
| 52 | **Windows** |
---|
| 53 | |
---|
| 54 | Depending on the graphic card in your system, drivers |
---|
| 55 | can be obtained from different sources: |
---|
| 56 | |
---|
| 57 | * NVIDIA: https://developer.nvidia.com/opencl |
---|
| 58 | * AMD: http://developer.amd.com/tools-and-sdks/opencl-zone/ |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | **Mac OSX** |
---|
| 62 | |
---|
| 63 | N/A |
---|
| 64 | |
---|
| 65 | You cannot download OpenCL driver updates for your Mac. They are packaged |
---|
| 66 | with the normal quarterly OS X updates from Apple. |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | .. note:: |
---|
| 70 | Intel provides OpenCL drivers for Intel processors at |
---|
| 71 | https://software.intel.com/en-us/articles/opencl-drivers |
---|
| 72 | These can sometimes make use of special vector instructions across multiple |
---|
| 73 | processors, so it is worth installing if the GPU does not support double |
---|
| 74 | precision. You can install this driver alongside the GPU driver for NVIDIA |
---|
| 75 | or AMD. |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | GPU Selection |
---|
| 79 | ************* |
---|
| 80 | |
---|
[59485a4] | 81 | The logic for choosing the compute platform is a little bit complicated. |
---|
[c0d7ab3] | 82 | If the model has the line *single=False* then it requires double precision. |
---|
| 83 | If the GPU is single precision only, then it will try running via OpenCL |
---|
| 84 | on the CPU. If the OpenCL driver is not available for the CPU then |
---|
| 85 | it will run as a normal program on the CPU. |
---|
| 86 | |
---|
| 87 | For models with a large number of parameters or with a lot of code, |
---|
[59485a4] | 88 | the GPU may be too small to run the program effectively. In this case, you |
---|
| 89 | should try simplifying the model, maybe breaking it into several different |
---|
| 90 | models so that you don't need *IF* statements in your code. If it is still |
---|
| 91 | too big, you can set *opencl=False* in the model file and the model will |
---|
| 92 | only run as a normal program on the CPU. This will not usually be necessary. |
---|
[c0d7ab3] | 93 | |
---|
| 94 | Device Selection |
---|
| 95 | ================ |
---|
| 96 | If you have multiple GPU devices you can tell the program which device to use. |
---|
| 97 | By default, the program looks for one GPU and one CPU device from available |
---|
| 98 | OpenCL platforms. It prefers AMD or NVIDIA drivers for GPU, and |
---|
| 99 | prefers Intel or Apple drivers for CPU. Both GPU and CPU are included on |
---|
| 100 | the assumption that CPU is always available and supports double precision. |
---|
| 101 | |
---|
| 102 | The device order is important: GPU is checked before CPU on the assumption that |
---|
| 103 | it will be faster. By examining ~/sasview.log you can see which device |
---|
| 104 | was used to run the model. |
---|
| 105 | |
---|
| 106 | **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* |
---|
| 107 | **in your environment settings, and it will only use normal programs.** |
---|
| 108 | |
---|
| 109 | If you want to use one of the other devices, you can run the following |
---|
| 110 | from the python console:: |
---|
| 111 | |
---|
| 112 | import pyopencl as cl |
---|
| 113 | cl.create_some_context() |
---|
| 114 | |
---|
| 115 | This will provide a menu of different OpenCL drivers available. |
---|
| 116 | When one is selected, it will say "set PYOPENCL_CTX=..." |
---|
| 117 | Use that value as the value of *SAS_OPENCL*. |
---|
| 118 | |
---|
| 119 | Device Testing |
---|
| 120 | ============== |
---|
| 121 | Unfortunately, not all vendors provide working OpenCL implementations |
---|
| 122 | for their GPU devices. For example, the HD 6000 Intel GPUs with |
---|
| 123 | double precision support fail for some of the double precision models. |
---|
| 124 | |
---|
| 125 | The SasView user interface provides a Fitting OpenCL Options dialog |
---|
| 126 | for selecting amongst and testing the available devices. After a |
---|
| 127 | few minutes of seeming to freeze, the application will return a list |
---|
| 128 | of model tests which have passed. The same tests can be run directly |
---|
| 129 | from the python console using:: |
---|
| 130 | |
---|
| 131 | from sasmodels.model_tests import main as model_tests |
---|
| 132 | model_tests("-v", "opencl", "all") |
---|
| 133 | |
---|
| 134 | Compiler Selection |
---|
| 135 | ================== |
---|
| 136 | For models run as normal programs, you may need to specify a compiler. |
---|
| 137 | This is done using the *SAS_COMPILER* environment variable, and the |
---|
| 138 | *SAS_OPENMP* environment variable if OpenMP support is available for |
---|
| 139 | the compiler. |
---|
| 140 | |
---|
[63602b1] | 141 | On Windows, set *SAS_COMPILER=tinycc* for the tinycc compiler, |
---|
| 142 | *SAS_COMPILER=msvc* for the Microsoft Visual C compiler, |
---|
| 143 | or *SAS_COMPILER=mingw* for the MinGW compiler. If TinyCC is available |
---|
[c0d7ab3] | 144 | on the python path (it is provided with SasView), that will be the |
---|
| 145 | default. If you want one of the other compilers, be sure to have it |
---|
| 146 | available in your *PATH* so we can find it! |
---|
| 147 | |
---|
| 148 | On Mac OS/X and Linux, set *SAS_COMPILER=unix* for the compiler. This |
---|
| 149 | will use the unix cc command to compile the model, with gcc style |
---|
| 150 | command line options. For OS/X you will need to install the Xcode |
---|
| 151 | package to make the compiler available. |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | *Document History* |
---|
| 155 | |
---|
| 156 | | 2017-09-27 Paul Kienzle |
---|