Skip to content

Week 12 (April 2)

Donna Calhoun edited this page Apr 5, 2018 · 20 revisions

Tuesday

  • Tips on homework; discussion of projects

Accessing GPUs for programming in CUDA.

We will be working on the Redhawk cluster to access GPUs.

Thursday

Logging into Redhawk

ssh <yourname>@redhawk.boisestate.edu
  • Set up an ssh key to avoid being asked to enter your password each time.

  • Create a .bashrc file.

Here is a minimal example that you should find useful.

# .bashrc file   
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific aliases and functions
module load gcc/4.8.1
module load slurm 
module load openmpi/gcc-4.8.1/cuda75/1.10.1
module load cuda75/toolkit/7.5
module load python/3.5.1
# source ~/.bash_alias
export PATH=.:${PATH}

In this file, there are commands to

* Load the CUDA toolkit which is needed to compile CUDA programs.  (Note: version 8.0 is not compatible with the installed driver;  so we only load version 7.5). 
* Load OpenMPI (an MPI implementation; alternative to MPICH)
* Load the version of gcc needed to compile CUDA ( version ~ 4.8).  

Here is a simple .bash_alias file:

# .bash_alias
alias ls="ls -F --color"
alias rm="rm -i"
alias cp="cp -i"

Introduction to programming in CUDA

A CUDA program looks very much like a C program, but with some strange "kernel" commands. Here is a very simple Hello, World program that calls the CUDA kernel

#include <stdio.h>

__global__ void kernel( void ) 
{
    /* Do something fun! */
}

int main(void) 
{
    kernel<<<1,1>>>();        /* Call a CUDA kernel */
    printf( "Hello, World!\n" );
}

We create this file and save it with an extension .cu to indicate that it should be compiled as a CUDA file. To compile this, we use the NVIDIA compiler nvcc:

$ nvcc -o simple_kernel simple_kernel.cu

There are many simple examples like this on the Nvidia Cuda by Example webpage. These examples are explained in more detail in the book Cuda By Example (Sanders and Kandrot).

Clone this wiki locally