



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CISC 879 Software Support for Multicore Architectures Spring 2007
Lecturer: Xiaoming Li Scribe: Scott Grauer-Gray, Pujan Kafle
Professor Xiamoming Li of the Electrical and Computer Engineering department presented an introduction to CUDA, a langauage used for GPU programming. He discussed the CUDA Programming Model, the CUDA memory model, the CUDA API, and then went on to give an example CUDA program and an application of GPU processing and CUDA in his own research with GRAVIT.
Ideas of CUDA Programming Model
The GPU - graphics processor unit - compute device with own memory (DRAM) used to execute portion of application that:
Threads that execute the kernel are organized as a grid of thread blocks
Thread Block
4-2 Lecture 4: February 21
Thread Grid
Figure 4.1: Illustration of CUDA memory model
Ideas of Memory Model
Shared memory
4-4 Lecture 4: February 21
Execution configuration
Example: the function global void Func(float* parameter);
must be called like:
Func <<< Dg, Db, Ns >>(parameter);
Built-in variables
Calculation of scalar product of 32 vector pairs of 4096 elements each
Host program:
Lecture 4: February 21 4-
Figure 4.3: Illustration of scalar product calculation using CUDA
int main(int argc, char* argv[]) { CUT_CHECK_DEVICE();
h_A = (float *)malloc(DATA_SZ); ........ cudaMalloc((void **)&d_A, DATA_SZ); ........ cudaMemcpy(d_A, h_A, DATA_SZ, cudaMemcpyHostToDevice); ........ //call to global function ProdGPU to be executed on GPU for computation of scalar products ProdGPU<<<BLOCK_N, THREAD_N>>>(d_C, d_A, d_B); .......... cudaMemcpy(h_C_GPU, d_C, RESULT_SZ, cudaMemcpyDeviceToHost); ........ CUDA_SAFE_CALL(cudaFree(d_A)); free(h_A); .......... CUT_EXIT(argc, argv); }
Kernel Function that is executed on GPU:
global void ProdGPU(float *d_C, float *d_A, float *d_B) { shared float t[THREAD_N]; // results of single threads shared float r[SLICE_N]; //slice cache; stores results of each slice const int I = threadIdx.x; //thread ID in block
//run on every pair of input vectors; each pair is in a different block in the grid for (int vec_n=blockIdx.x; vec_n < VECTOR_N; vec_n += gridDim.x) {
Lecture 4: February 21 4-
GRAVIT on the GPU
Figure 4.4: Memory use in GRAVIT
Optimization
CUDA is easy to pick up, but hard to push to limit