









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!










Many slides adapted from the slides of Hwu & Kirk at UIUC; and NVIDIA CUDAtutorials
Is done on the host (CPU)
programming environment, compilers and libraries - Profiler, emulator
Declspecs - global, device, shared,local, constant - Keywords - threadIdx, blockIdx - Intrinsics - __syncthreads - Runtime API - Memory, symbol,execution management - Function launch device float filter[N];global void convolve (float *image) { shared float region[M];... region[threadIdx] = image[i];__syncthreads()... // Allocate GPU memoryvoid *myimage = cudaMalloc(bytes)// 100 blocks, 10 threads per blockconvolve<<<100, 10>>> (myimage);
© David Kirk/NVIDIA and Wen-mei W. Hwu, 2007-2009ECE 498AL, University of Illinois, Urbana-Champaign Host Kernel 1 Kernel 2 Device Grid 1 Block(0, 0) Block(1, 0) Block(0, 1) Block(1, 1) Grid 2 Courtesy: NDVIA Block (1, 1)^ Thread (0,1,0) Thread(1,1,0) Thread(2,1,0) Thread(3,1,0) Thread(0,0,0) Thread(1,0,0) Thread(2,0,0) Thread(3,0,0) (0,0,1) (1,0,1) (2,0,1) (3,0,1)
Each thread uses IDs to decidewhat data to work on
Block ID: 1D or 2D - Thread ID: 1D, 2D, or 3D - Simplifies memoryaddressing when processingmultidimensional data - Image processing - Solving PDEs on volumes - …
direction specifies locations (host or device) ofsrc and dst
Blocks CPU thread: returns after the copy iscomplete - Doesn’t start copying until previous CUDA callscomplete
cudaMemcpyHostToDevice
cudaMemcpyDeviceToHost - cudaMemcpyDeviceToDevice
Host variables – hDevice variables – dAllocate and get pointeron host and deviceCopy the data from hostto device (notice theorder of arguments)From device-to-devicefrom device-to-hostFree
Kernels designated by function qualifier: global
Function called from host and executed on device - Must return void - Other CUDA function qualifiers device - Function called from device and run on device - Cannot be called from host code host - Function called from host and executed on host (default) - host and device qualifiers can be combinedto generate both CPU and GPU code
control returns to CPU immediately
control returns to CPU after copy completes
copy starts after all previous CUDA calls havecompleted
blocks until all previous CUDA calls complete