Homework 0

Due Friday, Sept 11, 11pm EST

The goal of this homework is to get you acquainted with the course, the computing environment, and with CUDA, our first parallel computing platform, and for us to get acquainted with you.

Grading

This homework will be graded on a pass / fail basis and will count towards your participation grade. 

Part 1: Class forum & news blog

Register for the class forum. Please use your full name in the Name field of your profile.  Once your account has been approved by the forum admins, go to General Discussion --> Introductions and create a new post. In this post, introduce yourself to the class, making sure to include your name, affiliation within Harvard, and an interesting tidbit about yourself.

Sign up to the course News Blog. On this news feed we will tell you when lecture videos and slides are online, if class is canceled due to snow, and other important announcements. To sign up you need to obtain a newsreader (also called a feedreader, or RSS aggregator) and subscribe to RSS feed. This will enable you to get instant updates instead of visiting this course web site each time. Two free services I recommend are Google Reader and Bloglines. There are also stand-alone applications you can install on your computer, and a few Firefox add-ons. 

Part 2: Computing environment

The login host for the SEAS GPU cluster we'll be using is resonance.seas.harvard.edu.  The host itself is a 2-way Intel Xeon host running at 3.0 GHz, with 8 GB of RAM, running CentOS v5.2 Linux.  From resonance, you can access the GPU cluster, which consists of 16 compute nodes, each with a single quad core CPU, two NVIDIA Tesla T10 GPUs, and 16 GB RAM.  For this class we'll be using version 2.2 of CUDA.


The cluster uses the Sun Grid Engine (SGE), a batch queuing system, for managing batch jobs.  For now we'll be accessing the cluster interactively with a script that avoids SGE commands; however, in the future you'll need to use SGE to submit batch jobs.  For more details on the cluster and an example of submitting CUDA batch jobs to resonance, see this write-up


Apply for a SEAS account.  A SEAS account is required to access the cluster.  If you do not already have one, complete this online application.  

Added (9/2/09): Use 'CUDA' for 'research group' in the application form to indicate that you are a student in this course and need access to the resonance cluster. Do not wait until the last minute, since there is some turn-around time. 

There will be a gap between getting a SEAS account and getting access to 'resonance'. These two access controls are handled separately and manually. Please wait a few days before contacting SEAS IT if you cannot access 'resonance' immediately with your SEAS credentials. The best way to contact the IT staff responsible for resonance is ircshelp@seas.harvard.edu.

Setup SSH keys.  With your SEAS username and password, login to login.seas.harvard.edu via SSH and install SSH keys (Windows users can use PuTTY or Cygwin).  Follow these instructions to setup SSH keys.  With the public key properly installed in your home directory (e.g. at login.seas.harvard.edu), you can ssh directly to resonance.seas.harvard.edu.  To avoid password logins when accessing GPU nodes from resonance, make sure to enable SSH agent forwarding when you logon; this is an option under Putty, and is invoked with the '-A' option for ssh.

Initiate an interactive session on a GPU-equipped node.  To initiate the session, login to resonance and execute the following command: 

    gpu-login  

This will reserve a full compute node (2 GPUs, 4 processor cores) for interactive use, for 1 hour (this setup may change in the future, depending on class size and system usage).

Setup your environment for CUDA.  The cluster has a convenient interface for setting up application-specific environments.  To add the correct entries to your PATH and LD_LIBRARY_PATH environment variables for development with CUDA and gcc, simply invoke

    module load compilers/gcc/4.3.3
    module load mpi/openmpi/1.2.8/gnu
    module load packages/cuda/2.2

I recommend adding these lines to your ~/.bashrc ~/.bash_profile (updated 09/03/09) file so that you don't have to invoke this at every login

    if echo $HOSTNAME | grep -e '\(resonance\|nikola\)\.seas' -e '^cuda'; then
       module load compilers/gcc/4.3.3
       module load mpi/openmpi/1.2.8/gnu
       module load packages/cuda/2.2
    fi
    (updated 09/10/09)                                                                             
  
Install CUDA on your own machine [optional].  While not required for the course, you can also develop CUDA code on your own machine.  However note that in the end, all homework submissions must compile and run on the cluster.  For those of you that are interested in developing locally, here is a list of NVIDIA cards that support CUDA and the main CUDA download page, where you can download the appropriate driver, toolkit, and SDK for your system.    

Some useful links.  If you're not comfortable working in a *nix environment, here are some cheat sheets of useful shell, GDB (GNU Debugger), and Emacs (text editor) commands, and an introduction to using GDB within Emacs.

Part 3: Compiling and running a simple CUDA example

Download some example code (example.cu in homework0.zip) to your working directory on resonance.  This simple example takes an input string from the command line and mangles it according the current system date and time, on both the CPU and GPU.  The code demonstrates some simple aspects of CUDA, including device initialization and error checking with libcutil (in the CUDA SDK), transfers between host and device memory, and CUDA kernel invocation.

Compile the code as

    nvcc example.cu -o example -I$CUDASDK_HOME/common/inc \
      $CUDASDK_HOME/lib/linux -lcutil

    nvcc example.cu -o example -I$CUDASDK_HOME/common/inc \
      -L$CUDASDK_HOME/lib -lcutil

        (updated 09/03/09)

and invoke from the command line:

    ./example -string="<str>" {-device=<dev>} ,

where <str> is the input string, and, optionally, <dev> is the device number.

For submission, just run the example as

    ./example -string="<title of your favorite movie" &> example.out

to write the results to example.out,inserting the title of your favorite movie as appropriate. 

Part 4: C programming questions

Since there is a significant programming component in the course, most of which will be in C/C++ and CUDA, and since we'll likely have a class with diverse programming backgrounds, here are a few questions to gauge your C/C++ programming experience.  You should be able to answer these without compiling anything.

1.  What is the output of the following program?

    #include <stdlib.h>
    #include <stdio.h>
    #define print_int(str) printf("%s : %d\n",#str,(str))
    int main(){
        int y = 100;
        int *p;
        p = malloc(sizeof(int));
        *p = 10;
        y = y / *p; 
        print_int(y);
        return 0;
    }

2.  What's wrong with the following C code?

    #include <stdlib.h>
    int main(){
        int* a, b;
        a = malloc(sizeof(int));
        b = a;
        *b = 10;
        return 0;
    }

3.  Why does the program below output "f is NOT 1"?

    #include <stdio.h>
    int main(){
        float f=0.f;
        int i;
        for(i=0;i<10;i++)
            f = f + 0.1f;
        if(f == 1.f)
            printf("f is 1\n");
        else
            printf("f is NOT 1\n");
        return 0;
    }

Problems adapted from C Puzzles, Gowri Kumar.

Part 5: Survey

Please take a few minutes to complete the survey at the end of this homework. Your responses will help us making the course better. It will also allow us to get you access to the 53 Church Street instructional computing labs.

Submission

Send an email entitled "CS264: PS0 Submission" to dale@eecs.harvard.edu with a zip file attachment containing example.out from part 3 and your answers to questions in part 4 (in either a .txt, .doc, or .pdf file).





Introductory survey
























Less comfortable Very comfortable