Engineering Queue GPU’s

The College of Engineering donated some servers to the cluster primary for the use of Engineering Students. As these machines require some custom configuration they must be accessed with their own partitions.

Partitions: 
Public: shortq7-eng-gpu
Private: longq7-eng-gpu (only members of College of Engineering group)

When attempting to use the GPU’s users must make sure the correct modules are loaded.

%> module purge
%> module load slurm cuda-6.5.14-gcc-8.3.0-wi4om6a autotools

It is critical that you use a version of GCC that is less then 5 when working with these GPU’s as the CUDA Toolkit cannot inter-operate with newer versions.

Example Usage calling a simple bit of Python

add.py

# add.py
# Add with a single thread on the GPU

import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule

import numpy

# Define CUDA function
mod = SourceModule("""
__global__ void add(int *a, int *b, int *c) {
int id = blockIdx.x;

c[id] = a[id] + b[id];
}""")

func = mod.get_function("add")

# Vector size
N = 10

# Host vectors
a = numpy.array(range(0,N))
b = 1 - a
c = numpy.zeros(N)

a = a.astype(numpy.int32)
b = b.astype(numpy.int32)
c = c.astype(numpy.int32)

# Allocate on device
a_gpu = cuda.mem_alloc(a.size * a.dtype.itemsize)
b_gpu = cuda.mem_alloc(b.size * b.dtype.itemsize)
c_gpu = cuda.mem_alloc(c.size * c.dtype.itemsize)

# Copy from host to device
cuda.memcpy_htod(a_gpu, a)
cuda.memcpy_htod(b_gpu, b)

func(a_gpu, b_gpu, c_gpu, block=(1,1,1), grid=(N,1))

# Copy result to host
cuda.memcpy_dtoh(c, c_gpu)

# Display results
print("Should be %d" % N)
print("Results: %d" % numpy.sum(c))

SBATCH:
add.sbatch

#!/bin/bash
#SBATCH --gres=gpu:1
#SBATCH -c 4
module purge
module load slurm cuda-6.5.14-gcc-8.3.0-wi4om6a autotools

# Load python
module load python-3.7.3-gcc-8.3.0-3ioxabf
# Create an environment to run in in case it isn't there yet
pip install --user virtualenv

# this may not be in the path so make sure we add it
export PATH=$PATH:/home/rresnick/.local/bin
virtualenv ~/cudapython
# Activate Python Env
source ~/cudapython/bin/activate
# Install pycuda
pip install --user pycuda

# Now call your python script
python add.py
Posted in HPC