[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 | ================ |
---|
[8b31efa] | 96 | **OpenCL drivers** |
---|
| 97 | |
---|
[c0d7ab3] | 98 | If you have multiple GPU devices you can tell the program which device to use. |
---|
| 99 | By default, the program looks for one GPU and one CPU device from available |
---|
| 100 | OpenCL platforms. It prefers AMD or NVIDIA drivers for GPU, and |
---|
| 101 | prefers Intel or Apple drivers for CPU. Both GPU and CPU are included on |
---|
| 102 | the assumption that CPU is always available and supports double precision. |
---|
| 103 | |
---|
| 104 | The device order is important: GPU is checked before CPU on the assumption that |
---|
| 105 | it will be faster. By examining ~/sasview.log you can see which device |
---|
| 106 | was used to run the model. |
---|
| 107 | |
---|
[8b31efa] | 108 | If you want to use a specific driver and devices, you can run the following |
---|
[c0d7ab3] | 109 | from the python console:: |
---|
| 110 | |
---|
| 111 | import pyopencl as cl |
---|
| 112 | cl.create_some_context() |
---|
| 113 | |
---|
| 114 | This will provide a menu of different OpenCL drivers available. |
---|
| 115 | When one is selected, it will say "set PYOPENCL_CTX=..." |
---|
[8b31efa] | 116 | Use that value as the value of *SAS_OPENCL=driver:device*. |
---|
| 117 | |
---|
| 118 | To use the default OpenCL device (rather than CUDA or None), |
---|
| 119 | set *SAS_OPENCL=opencl*. |
---|
| 120 | |
---|
| 121 | In batch queues, you may need to set *XDG_CACHE_HOME=~/.cache* |
---|
| 122 | (Linux only) to a different directory, depending on how the filesystem |
---|
| 123 | is configured. You should also set *SAS_DLL_PATH* for CPU-only modules. |
---|
| 124 | |
---|
| 125 | -DSAS_MODELPATH=path sets directory containing custom models |
---|
| 126 | -DSAS_OPENCL=vendor:device|cuda:device|none sets the target GPU device |
---|
| 127 | -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only) |
---|
| 128 | -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler |
---|
| 129 | -DSAS_OPENMP=1 turns on OpenMP for the DLLs |
---|
| 130 | -DSAS_DLL_PATH=path sets the path to the compiled modules |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | **CUDA drivers** |
---|
| 134 | |
---|
| 135 | If OpenCL drivers are not available on your system, but NVidia CUDA |
---|
| 136 | drivers are available, then set *SAS_OPENCL=cuda* or |
---|
| 137 | *SAS_OPENCL=cuda:n* for a particular device number *n*. If no device |
---|
| 138 | number is specified, then the CUDA drivers looks for look for |
---|
| 139 | *CUDA_DEVICE=n* or a file ~/.cuda-device containing n for the device number. |
---|
| 140 | |
---|
| 141 | In batch queues, the SLURM command *sbatch --gres=gpu:1 ...* will set |
---|
| 142 | *CUDA_VISIBLE_DEVICES=n*, which ought to set the correct device |
---|
| 143 | number for *SAS_OPENCL=cuda*. If not, then set |
---|
| 144 | *CUDA_DEVICE=$CUDA_VISIBLE_DEVICES* within the batch script. You may |
---|
| 145 | need to set the CUDA cache directory to a folder accessible across the |
---|
| 146 | cluster with *PYCUDA_CACHE_DIR* (or *PYCUDA_DISABLE_CACHE* to disable |
---|
| 147 | caching), and you may need to set environment specific compiler flags |
---|
| 148 | with *PYCUDA_DEFAULT_NVCC_FLAGS*. You should also set *SAS_DLL_PATH* |
---|
| 149 | for CPU-only modules. |
---|
| 150 | |
---|
| 151 | **No GPU support** |
---|
| 152 | |
---|
| 153 | If you don't want to use OpenCL or CUDA, you can set *SAS_OPENCL=None* |
---|
| 154 | in your environment settings, and it will only use normal programs. |
---|
| 155 | |
---|
| 156 | In batch queues, you may need to set *SAS_DLL_PATH* to a directory |
---|
| 157 | accessible on the compute node. |
---|
| 158 | |
---|
[c0d7ab3] | 159 | |
---|
| 160 | Device Testing |
---|
| 161 | ============== |
---|
| 162 | Unfortunately, not all vendors provide working OpenCL implementations |
---|
| 163 | for their GPU devices. For example, the HD 6000 Intel GPUs with |
---|
| 164 | double precision support fail for some of the double precision models. |
---|
| 165 | |
---|
| 166 | The SasView user interface provides a Fitting OpenCL Options dialog |
---|
| 167 | for selecting amongst and testing the available devices. After a |
---|
| 168 | few minutes of seeming to freeze, the application will return a list |
---|
| 169 | of model tests which have passed. The same tests can be run directly |
---|
| 170 | from the python console using:: |
---|
| 171 | |
---|
| 172 | from sasmodels.model_tests import main as model_tests |
---|
| 173 | model_tests("-v", "opencl", "all") |
---|
| 174 | |
---|
| 175 | Compiler Selection |
---|
| 176 | ================== |
---|
| 177 | For models run as normal programs, you may need to specify a compiler. |
---|
| 178 | This is done using the *SAS_COMPILER* environment variable, and the |
---|
| 179 | *SAS_OPENMP* environment variable if OpenMP support is available for |
---|
| 180 | the compiler. |
---|
| 181 | |
---|
[63602b1] | 182 | On Windows, set *SAS_COMPILER=tinycc* for the tinycc compiler, |
---|
| 183 | *SAS_COMPILER=msvc* for the Microsoft Visual C compiler, |
---|
| 184 | or *SAS_COMPILER=mingw* for the MinGW compiler. If TinyCC is available |
---|
[c0d7ab3] | 185 | on the python path (it is provided with SasView), that will be the |
---|
| 186 | default. If you want one of the other compilers, be sure to have it |
---|
| 187 | available in your *PATH* so we can find it! |
---|
| 188 | |
---|
| 189 | On Mac OS/X and Linux, set *SAS_COMPILER=unix* for the compiler. This |
---|
| 190 | will use the unix cc command to compile the model, with gcc style |
---|
| 191 | command line options. For OS/X you will need to install the Xcode |
---|
| 192 | package to make the compiler available. |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | *Document History* |
---|
| 196 | |
---|
[8b31efa] | 197 | | 2018-10-15 Paul Kienzle |
---|