GPU Guide

From Storrs HPC Wiki
Revision as of 15:47, 11 April 2017 by Eds08006 (talk | contribs) (List GPU capabilities)
Jump to: navigation, search

The following assumes you are already connected to the cluster.

Basic CUDA compilation

For some types of GPU work like compiling code, one needs to load the CUDA module.

One can list the available CUDA versions using:

$ module available cuda

--------------------------------------------------- /apps2/Modules/3.2.6/modulefiles ----------------------------------------------------
cuda/6.5.14 cuda/7.0    cuda/7.5    cuda/8.0

At the time of writing version 8.0 is the latest we have installed, so we can load it using:

module load cuda/8.0

To compile with CUDA using the NVidia CUDA compiler:

nvcc {MYFILE.cu} -o {OUTPUT_FILE}

Using GPUs Interactively

Assign one of the GPU nodes using fisbatch:

module load cuda/8.0
fisbatch --partition=gpu -c <numprocs> --gres=gpu:<numgpus>

Where <numprocs> needs to be replaced by the number of CPU processors you need, and <numgpus> needs to be replaced by the number of GPUs you need.

Then run the deviceQuery sample program to get useful information about the GPU information like memory, processor cores, etc:

$ /apps2/cuda/8.0/samples/1_Utilities/deviceQuery/deviceQuery
/apps2/cuda/8.0/samples/1_Utilities/deviceQuery/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "Tesla K40m"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    3.5
  Total amount of global memory:                 11440 MBytes (11995578368 bytes)
  (15) Multiprocessors, (192) CUDA Cores/MP:     2880 CUDA Cores
  GPU Max Clock rate:                            745 MHz (0.75 GHz)
  Memory Clock rate:                             3004 Mhz
  Memory Bus Width:                              384-bit
  L2 Cache Size:                                 1572864 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Enabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 3 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = Tesla K40m
Result = PASS

Then, exist your interactive session.

$ exit
[screen is terminating]
Connection to gpu01 closed.
FISBATCH -- exiting job

Running GPU jobs

  • If you need to use just 1 GPU in EXCLUSIVE mode, your script (e.g. gpu.sh) should be:
 #!/bin/bash
 #SBATCH -o <stdout> 
 #SBATCH -e <stderr>
 #SBATCH -p gpu
 #SBATCH --gres=gpu:1
 
 {COMMAND}

The submit the script by sbatch:

sbatch gpu.sh
  • Else, if you need between 2 or more GPU's in EXCLUSIVE mode, your script (e.g. gpu.sh) should be:
 #!/bin/bash
 #SBATCH -o <stdout> 
 #SBATCH -e <stderr>
 #SBATCH --partition=gpu
 #SBATCH --gres=gpu:<numgpus>
 
 {COMMAND}

The submit the script by sbatch:

sbatch gpu.sh

Here all the stdout results of the {COMMAND} will go to the file <stdout> and all the stderr results will go to the file <stderr>.

For example, this will use 8 available GPU's in the cluster in EXCLUSIVE mode:

$ cat gpu.sh
 #!/bin/bash
 #SBATCH -o gpu-%J.out # replaced <stdout>
 #SBATCH -e gpu-%J.out # replaced <stderr>, the filename can ben different from <stdout>
 #SBATCH -p gpu
 #SBATCH --gres=gpu:8 # replaced <numgpus>
 
 /apps2/cuda/7.5.18/samples/1_Utilities/deviceQuery/deviceQuery # replaced {COMMAND}, you can put any commands you want here.
$ sbatch gpu.sh

Using nsight on the the cluster(not recommend)

To use the eclipse-like tool, nsight supported by CUDA, you need the X Window to be available on your computer. When you login with the X Window feature, please follow:

$ module load cuda/7.5
$ fisbatch -c <numporcs> -p gpu --gres=gpu:<numgpus>
FISBATCH -- the maximum time for the interactive screen is limited to 6 hours. You can add QoS to overwrite it.
FISBATCH -- waiting for JOBID 20248 to start on cluster=cluster and partition=Westmere
!
FISBATCH -- Connecting to head node (cn35)
[xxx00000@cn35 ~]$ nsight

Then, the nsight GUI will pop up. When you finish using nsight, please DO NOT FORGET to EXIT from the nodes so that the other users can use it.

[xxx00000@cn35 ~]$ exit
[screen is terminating]
Connection to cn35 closed.
FISBATCH -- exiting job

Other resources