|
|
# GPU Accelerated Computation with Python on Shark
|
|
|
|
|
|
## Environment
|
|
|
Conda can be used to create a dedicated python environment for GPU computing.
|
|
|
|
|
|
The following example code will create a conda environment named shark-gpu which can be used to train tensorflow models on the GPU.
|
|
|
|
|
|
Installation of the tensorflow-gpu meta-module automatically takes care of dependencies such as the cuda libraries.
|
|
|
|
|
|
The setGPU module is installed (via pip as not conda package exists for it) to enable for automatic selection of a free GPU:
|
|
|
```
|
|
|
conda create -n shark-gpu python=3.6 # create a new conda environment
|
|
|
source activate shark-gpu # activate the environment
|
|
|
conda install cython tensorflow-gpu # install tensorflow
|
|
|
pip install setGPU # install setGPU
|
|
|
```
|
|
|
|
|
|
## Accessing a GPU node
|
|
|
|
|
|
### Scheduling a GPU job using SGE
|
|
|
To schedule a job on a GPU enable node, add the following line to the parameters section of your qsub submission script:
|
|
|
```#$ -l gpu=1```
|
|
|
|
|
|
### Using a GPU from a qlogin session
|
|
|
To qlogin to a GPU enabled node:
|
|
|
```qlogin -l gpu=1```
|
|
|
You will then be able to use the GPU from an interactive session such as Jupyter notebook.
|
|
|
|
|
|
|
|
|
## Running Code On The GPU
|
|
|
Ensure that you are using the new conda environment:
|
|
|
```source activate shark-gpu```
|
|
|
|
|
|
Your python code needs to specify which of the GPU cards on a specific node should be used.
|
|
|
The setGPU module automates this process. Adding the line
|
|
|
```import setGPU```
|
|
|
to the imports section of your python script will automatically select a free GPU node and use it for computation.
|
|
|
|
|
|
You should see a message such as
|
|
|
```setGPU: Setting GPU to: 0```
|
|
|
in your program output which tells you that the GPU in slot 0 has been selected.
|
|
|
Any GPU specific code will now be run on this GPU. |
|
|
\ No newline at end of file |