In order to successfully complete this assignment you must do the required reading, watch the provided videos and complete all instructions. The embedded survey form must be entirely filled out and submitted on or before 11:59pm on Sunday February 28. Students must come to class the next day prepared to discuss the material covered in this assignment.
from IPython.display import YouTubeVideo
YouTubeVideo("IzU4AVcMFys",width=640,height=360)
from IPython.display import YouTubeVideo
YouTubeVideo("lQVV5JCd74I",width=640,height=360)
✅ QUESTION: What does the acronym GPGPU stand for?
Put your answer to the above question here
✅ QUESTION: What is the name of the CUDA command that allocates memory on the GPU?
Put your answer to the above question here
✅ QUESTION: What is the name of the CUDA command that copies memory from the CPU to the GPU?
Put your answer to the above question here
✅ QUESTION: What is the difference between the "HOST" and the "DEVICE" in CUDA terminology?
Put your answer to the above question here
Here is a video on how to use CUDA on the HPCC. Note that this video was made in 2019 so most of the software versions are out of date. Everything else should basically work fine.
from IPython.display import YouTubeVideo
YouTubeVideo("gzkKtcRpA6A",width=640,height=360)
Commands from the video
ssh dev-intel16-k80
module load powertools
getexample cuda
cd cuda
module load CUDA
nvcc -o simple_cuda simple.cu
./simple.cu
✅ DO THIS: Here is the code as it was modified in the video. See if you can get it working.
!mkdir NCode
mkdir: cannot create directory ‘NCode’: File exists
%%writefile NCode/simple.cu
#include "cuda.h"
#include <iostream>
#define CUDA_CALL(x) {cudaError_t cuda_error__ = (x); if (cuda_error__) std::cout << "CUDA error: " << #x << " returned " << cudaGetErrorString(cuda_error__) << std::endl;}
__global__ void theKernel(float * our_array)
{
//This is array flattening, (Array Width * Y Index + X Index)
int index = (gridDim.x * blockDim.x) * \
(blockIdx.y * blockDim.y + threadIdx.y) + \
(blockIdx.x * blockDim.x + threadIdx.x);
our_array[index] = (float) index;
}
void printGrid(float an_array[16][16])
{
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
std::cout << an_array[i][j];
std::cout << " ";
}
std::cout << std::endl;
}
}
int main()
{
float our_array[16][16];
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
our_array[i][j] = i;
}
}
//STEP 1: ALLOCATE
float * our_array_d;
int size = sizeof(float)*256;
CUDA_CALL(cudaMalloc((void **) &our_array_d, size));
//STEP 2: TRANSFER
CUDA_CALL(cudaMemcpy(our_array_d, our_array, size, cudaMemcpyHostToDevice));
//STEP 3: SET UP
dim3 blockSize(8,8,1);
dim3 gridSize(2,2,1);
//STEP 4: RUN
theKernel <<<gridSize, blockSize>>> (our_array_d);
//STEP 5: TRANSFER
printGrid(our_array);
CUDA_CALL(cudaMemcpy(our_array, our_array_d, size, cudaMemcpyDeviceToHost));
std::cout << "--------------------" << std::endl;
printGrid(our_array);
}
Overwriting NCode/simple.cu
#Compile Cuda
!nvcc -o simple_cuda NCode/simple.cu
nvcc: Command not found.
#Run Example
!./simple_cuda
./simple_cuda: Command not found.
The following video shows you how to schedule basic CUDA jobs on the HPCC.
from IPython.display import YouTubeVideo
YouTubeVideo("-y0ysuxbEa8",width=640,height=360)
Since making the above video I have learned that CUDA jobs work best if you include srun
before the Cuda command. For example, I reccomend modifying the ./simple_cuda
command line with the following
srun time ./simple_cuda
✅ QUESTION: What SLURM command should you add to your submission script to request a GPU?
Put your answer to the above question here.
✅ QUESTION: What module command do you need to include in your submission script to run CUDA programs?
Put your answer to the above question here.
Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credits for the assignment!
If you have trouble with the embedded form, please make sure you log on with your MSU google account at googleapps.msu.edu and then click on the direct link above.
✅ Assignment-Specific QUESTION: Where you able to get the example code to run on the HPCC? If not, where did you get stuck?
Put your answer to the above question here
✅ QUESTION: Summarize what you did in this assignment.
Put your answer to the above question here
✅ QUESTION: What questions do you have, if any, about any of the topics discussed in this assignment after working through the jupyter notebook?
Put your answer to the above question here
✅ QUESTION: How well do you feel this assignment helped you to achieve a better understanding of the above mentioned topic(s)?
Put your answer to the above question here
✅ QUESTION: What was the most challenging part of this assignment for you?
Put your answer to the above question here
✅ QUESTION: What was the least challenging part of this assignment for you?
Put your answer to the above question here
✅ QUESTION: What kind of additional questions or support, if any, do you feel you need to have a better understanding of the content in this assignment?
Put your answer to the above question here
✅ QUESTION: Do you have any further questions or comments about this material, or anything else that's going on in class?
Put your answer to the above question here
✅ QUESTION: Approximately how long did this pre-class assignment take?
Put your answer to the above question here
from IPython.display import HTML
HTML(
"""
<iframe
src="https://cmse.msu.edu/cmse401-pc-survey"
width="100%"
height="500px"
frameborder="0"
marginheight="0"
marginwidth="0">
Loading...
</iframe>
"""
)
To get credit for this assignment you must fill out and submit the above survey from on or before the assignment due date.
Written by Dr. Dirk Colbry, Michigan State University
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.