Using CUDA. Oswald Haan

Size: px
Start display at page:

Download "Using CUDA. Oswald Haan"

Transcription

1 Using CUDA Oswald Haan

2 A first Example: Adding two Vectors void add( int N, float*a, float*b, float*c ) { int i; for(i=0; i<n; i++) { c[i] = a[i] + b[i]; global void add_d( int N, float *a, float *b, float *c ) { int i = threadidx.x + blockidx.x*blockdim.x; if (i < N) c[i] = a[i] + b[i]; Host code for add routine Device code for add kernel routine

3 A first Example: Adding two Vectors int main( void ) { int N = 3, i; float a[n], b[n], c[n]; int main( void ) { int N = 3, i; float a[n], b[n], c[n]; float *a_d, *b_d, *c_d; cudamalloc( &a_d, sizeof(float)*n); cudamalloc( &b_d, sizeof(float)*n); cudamalloc( &c_d, sizeof(float)*n); for(i=0; i<n; i++) { a[i] = -i; b[i] = i * i; for (i=0; i<n; i++) { a[i] = -i; b[i] = 3+i; cudamemcpy(a_d, a, sizeof(float)*n, cudamemcpyhosttodevice); cudamemcpy(b_d, b, sizeof(float)*n, cudamemcpyhosttodevice); add( N, a, b, c ); add_d<<<1,n>>>( N, a_d, b_d, c_d ); cudamemcpy(c, c_d, sizeof(float)*n, cudamemcpydevicetohost); cudafree(a_d); cudafree(b_d); cudafree(c_d); Host code for calling sequential routine Host code for calling kernel routine code in ~ohaan/cuda_kurs/add_vectors.cu

4 Managing Memory on Host and on Device float a[3], *a_d; cudamalloc( &a_d, 3*sizeof(float) ) Allocates memory for three floats at address a_d in device memory Stores this address at address &a_d in host memory a_d a_d[0] a_d[1] a_d[2] &a_d a_d a_d+1 a_d+2 name of value in memory cell a[0] a[1] a[2] name of address of memory cell a a+1 a+2 host memory device memory cudamemcpy(a_d, a, 3*sizeof(float), cudamemcpyhosttodevice); cudamemcpy(a, a_d, 3*sizeof(float), cudamemcpydevicetohost); destinationaddress source address size of data to be copied

5 Compiling CUDA codes CUDA source files must have the extension.cu Compiler nvcc is provided in the CUDA toolkit CUDA toolkit is available on GWDG s cluster frontends gwdu101, gwdu102, gwdu103 by loading the CUDA toolkit module: module load cuda80 Compiling CUDA source file add_vector.cu with nvcc add_vectors.cu o add_vectors produces executable add_vector

6 Execution environment for CUDA executables GWDG s compute cluster provides nodes with different types of NVIDIA GPUs: gwdo161-gwdo180, each with one GeForce GTX 770 dge001-dge007, each with two GeForce GTX 1080 dge008-dge014, each with four GeForce GTX 980 dge015, with two GeForce GTX 980 dte001-dte010, each with two Tesla K40m All nodes with GPU devices belong to the LSF queue gpu Jobs are managed on the compute cluster by the Load Sharing Facility (LSF), which provides commands for submitting jobs and enquiring their status

7 Submitting CUDA jobs with bsub A batch job is submitted to the queue gpu with the command bsub -q gpu -n 1 -R "rusage[ngpus_shared=1]"./add_vectors With the option n 1 it will use 1 core on a host in the queue A node in the gpu queue provides as many gpu-shares as number of cores, which is 8 for the older gwdoxxx nodes and 24 for the new dgexxx and dtexxx nodes. With -R "rusage[ngpus_shared=1] the job will share the gpu resources of the node with other jobs running on this node, which have requested gpu-shares With -R "rusage[ngpus_shared=24] the job will use the gpu resources of a node with 24 cores exclusively In order to run jobs interactively, an interactive shell can be requested by bsub -ISs -q gpu -n 1 -R "rusage[ngpus_shared=1]" /bin/bash More options for the bsub command and the description for other LSF commands can be found at -> Services-> High Performance Computing -> Docs

8 A special Queue course for this Course Submitting a job to queue kurs-gpu : bsub -q kurs-gpu -o out.%j -n 1 -R "rusage[ngpus_shared=1]"./add_vectors Submitting with a jobfile lsf.job bsub < lsf.job #!/bin/sh Starting an interactive session: bsub -ISs -q kurs-gpu -n 1 -R "rusage[ngpus_shared=1]" /bin/bash #BSUB -q course #BSUB -W 1:00 #BSUB -o out.%j #BSUB -n 1 #BSUB -R "rusage[ngpus_shared=1]"./add_vectors

9 Enquiring Device Properties cudagetdevicecount(&ndevices); Sets int ndevices to the number of devices available in the node cudagetdeviceproperties(&prop, i); Delivers in the members of the structure cudadeviceprop prop the values for various properties of device number i Definition of cudadeviceprop in the section CUDA Runtime API 5.3 of the CUDA Toolkit Documentation int main() { int ndevices; cudagetdevicecount(&ndevices); for (int i = 0; i < ndevices; i++) { cudadeviceprop prop; cudagetdeviceproperties(&prop, i); printf("device Number: %d\n", i); printf(" Device name: %s\n", prop.name);... complete code for enquiring in ~ohaan/cuda_kurs/device_properties.cu

10 Output from program device_properties.cu Device Number: 0 Device name: GeForce GTX 980 Device capability major revision number: 5 Device capability minor revision number: 2 Clock Rate (KHz): total Global Memory (byte): Shared Memory per Block (byte): total Constant Memory (byte): size of L2 cache (byte): bit Registers per Block: max. Threads per Block: 1024 number of Threads in Warp: 32 number of Multiprocessors: 16 Memory Clock Rate (KHz): Max Grid Size: Max Block Size: Memory Bus Width (bits): 256 Peak Memory Bandwidth (GB/s): Device Number: 1 Device name: GeForce GTX 980 Device capability major revision number: 5 Device capability minor revision number: 2 Clock Rate (KHz): total Global Memory (byte): Shared Memory per Block (byte): total Constant Memory (byte): size of L2 cache (byte): bit Registers per Block: max. Threads per Block: 1024 number of Threads in Warp: 32 number of Multiprocessors: 16 Memory Clock Rate (KHz): Max Grid Size: Max Block Size: Memory Bus Width (bits): 256 Peak Memory Bandwidth (GB/s):

11 GPU-Properties of different nodes GWDG node gwdo161- gwdo180 NVIDIA Modell GeForce 770 Graphics Chip Compute Capability Clock rate [MHz] Device memory [GB] Band width [GB/s] Number of SMXes CUDA cores per SMX (SP) CUDA cores per SMX (SP-SF) CUDA cores per SMX (DP) Perf. Ratio FP64/ FP32 GK :24 dge001- dge007 GeForce 1080 GP :32 dge008- dge015 GeForce 980 GM :32 dte001- dte015 Tesla K40 GK :3

12 Some Properties of different Compute Capabilities Specification Value Version Maximum x-dimension of a grid of thread blocks = Maximum y- or z-dimension of a grid of thread blocks Maximum number of threads per block 1024 Maximum x- or y-dimension of a block 1024 Maximum z-dimension of a block 64 Maximum number of resident blocks per SMX Maximum number of resident threads per SMX 2048 Number of 32-bit registers per thread 255 all specifications for compute capabilities can be found at

13 Selecting Different GPUs Compiling: nvcc -arch=[sm_30 sm_35 sm_52 sm_61] according to compute capability of target GPU Without setting this flag, nvcc compiles for compute capability 2.0 Submitting: -R "nvgen=1" selects a node with a Kepler GPU (GeForce 770 or Tesla K40 ) -R "nvgen=2" selects a node with a Maxell GPU (GeForce 980) -R "nvgen=3" selects a node with a Pascal GPU (GeForce 1080) -R tesla selects a node with Tesla K40 GPU -R "ngpus=2" selects a node with two GPUs (GeForce 980 /1080 or Tesla K40) -R "ngpus=4" selects a node with four GPUs (GeForce 980) -m "gwdo[ ]" selects one of the gwdoxxx nodes (GeForce 770 )

14 How to Use 2 GPUs simultaneously Device can be selected with cudasetdevice(device_number) Prepare two executables: exe0 including cudasetdevice(0) exe1 including cudasetdevice(1) #!/bin/sh #BSUB -q gpu #BSUB -W 1:00 #BSUB -o out.%j #BSUB -n 2 #BSUB -R "ngpus=2" #BSUB -R "rusage[ngpus_shared=24]"./exe0 > out0 &./exe1 > out1 & selects a node with 2 GPUs grants exclusive use of the GPUs starts two executables asynchronously

15 Using Unified Memory (compute capability >=3.0 CUDA version >=6.0 ) int main(void) { int N = 6, i; float *a, *b, *c; cudamallocmanaged( &a, sizeof(float)*n); cudamallocmanaged( &b, sizeof(float)*n); cudamallocmanaged( &c, sizeof(float)*n); for (i=0; i<n; i++) { a[i] = -i; b[i] = i+3; add_d<<<1,n>>>(n,a, b, c); cudadevicesynchronize(); for(i=n-3; i<n; i++) { printf( "%f + %f = %f\n", a[i], b[i], c[i] ); cudafree(a); cudafree(b); cudafree(c); allocates memory in host- and device-memory Initializes data in host-memory synchronization is necessary, because no access to unified memory from host until device is inactive reads data from device memory Host code code in ~ohaan/cuda_kurs/add_vectors_um.cu

16 Unified Memory with Static Allocation #include <stdio.h> const int N=6; device managed float a[n], b[n], c[n]; global void add_d() { int i = threadidx.x + blockidx.x*blockdim.x; if (i < N) c[i] = a[i] + b[i]; int main(void) { int i; for (int i=0; i<n; i++) { a[i] = -i; b[i] = i+3; add_d<<<1,n>>>(); cudadevicesynchronize(); for(i=n-3; i<n; i++) { printf( "%f + %f = %f\n", a[i], b[i], c[i] ); code in ~ohaan/cuda_kurs/add_vectors_um_static.cu

17 Large Vectors Maximal 1024 threads in a single block: add_d<<<1,n>>>( N, a_d, b_d, c_d ) gives unpredictable results for N > 1024 Use N_block blocks: Modify host code N_thrpb =1024; N_blks = (N+N_thrpb-1)/N_thrpb add_d<<<n_blocks,n_thrpb>>>( N, a_d, b_d, c_d ) No change in device code int i = threadidx.x + blockidx.x*blockdim.x; if (i < N) c[i] = a[i] + b[i];

18 CUDA Error Handling CUDA functions return an error code of type cudaerror_t cudaerror_t err = cudamalloc(...) which can be translated into an error message by calling cudageterrorstring(err) Errors in kernel functions can be enquired by kernel<<<grids,threads>>>(...); cudadevicesynchronize(); cudaerror_t err = cudagetlasterror();

19 cudacheckerror() from //Macro for checking cuda errors following a cuda launch or api call #define cudacheckerror() { \ cudaerror_t e=cudagetlasterror(); \ if(e!=cudasuccess) { \ printf("cuda failure %s:%d: '%s'\n \, FILE, LINE,cudaGetErrorString(e));\ macro code in ~ohaan/cuda_kurs/errchk.ut

20 Add Large Vectors with Error Checking #include "errchk.ut" int main(void) { int N = 6000, N_thrpb =1024, N_blks = (N+N_thrpb-1)/N_thrpb, i; float *a, *b, *c; printf( "N: %i, N_blks: %i, N_thrpb: %i\n", N, N_blks, N_thrpb); cudamallocmanaged( &a, sizeof(float)*n); cudacheckerror(); cudamallocmanaged( &b, sizeof(float)*n); cudacheckerror(); cudamallocmanaged( &c, sizeof(float)*n); cudacheckerror(); for (i=0; i<n; i++) { a[i] = -i; b[i] = i+3.; add_d<<<n_blks,n_thrpb>>>(n,a, b, c); cudacheckerror(); cudadevicesynchronize(); cudacheckerror(); for(i=n-3; i<n; i++) { printf( "%14e + %e = %e\n", a[i], b[i], c[i] ); cudafree(a); cudafree(b); cudafree(c); complete code in ~ohaan/cuda_kurs/add_largevectors.cu

21 3 dim Grids and Blocks can be configured with the CUDA type dim3: dim3 gdims(gdim_x,gdim_x,gdim_z); dim3 bdims(bdim_x,bdim_x,bdim_z); kernel <<<gdims,bdims>>> (...); This will launch a total number of gdim_x*gdim_x*gdim_z*bdim_x*bdim_x*bdim_z threads on the device At most (number of SMXes)*2048 threads will be executing at any time

22 Vector Addition with 3-dim Grids and Blocks global void add_d( int N, int *a, int *b, int *c ) { int gridsize = griddim.x * griddim.y * griddim.z; int blocksize = blockdim.x * blockdim.y * blockdim.z; int id_thr = threadidx.x + threadidx.y * blockdim.x + threadidx.z * blockdim.x * blockdim.y; int id_blk = blockidx.x + blockidx.y * griddim.x + blockidx.z * griddim.x * griddim.y; int i = id_thr + blocksize * id_blk; if (i < N) c[i] = a[i] + b[i];

23 Two-dimensional Arrays int main(void) { int i, j, n = 4, m = 3; int a[n][m], b[n][m], c[n][m]; int *a_d, *b_d, *c_d; size_t sizea = n*m*sizeof(int); for(i=0; i<n; i++) { for(j=0; j<m; j++) { a[i][j] = -i - j; b[i][j] = i + j + 3; cudamalloc( &a_d, sizea); cudamalloc( &b_d, sizea); cudamalloc( &c_d, sizea); cudamemcpy(a_d, a, sizea, cudamemcpyhosttodevice); cudamemcpy(b_d, b, sizea, cudamemcpyhosttodevice); dim3 block(5,5); add_d<<<1,block>>>(n, m, a_d, b_d, c_d); cudamemcpy(c, c_d, sizea, cudamemcpydevicetohost); cudafree(a_d); cudafree(b_d); cudafree(c_d); Host code complete code in ~ohaan/cuda_kurs/add_arrays.cu

24 Adding Two-dimensional Arrays global void add_d( int n, int m, int *a, int *b, int *c ) { int i, j, index; j = threadidx.x; i= threadidx.y; if( i<n && j<m ) { index = i*m + j; c[index] = a[index] + b[index] ; device code n rows i = 0,,n-1 m columns j = 0,,m-1 threadidx.y = 0,..., blockdim.y-1 array index = threadidx.x + threadidx.y*m thread index = threadidx.x + threadidx.y*blockdim.x threadidx.x = 0,..., blockdim.x-1

25 Large Two-dimensional Arrays int main(void) { int i, j, n = 10000, m = 5000; int bdim_x = 16, bdim_y = 16; int gdim_x=(m+bdim_x-1)/bdim_x, gdim_y=(n+bdim_y-1)/bdim_y; int a[n][m], b[n][m], c[n][m]; int *a_d, *b_d, *c_d; size_t sizea = n*m*sizeof(int); for(i=0; i<n; i++) { for(j=0; j<m; j++) { a[i][j] = -i - j; b[i][j] = i + j + 3; cudamalloc((void **) &a_d, sizea); cudamalloc((void **) &b_d, sizea); cudamalloc((void **) &c_d, sizea); cudamemcpy(a_d, a, sizea, cudamemcpyhosttodevice); cudamemcpy(b_d, b, sizea, cudamemcpyhosttodevice); dim3 blk(bdim_x,bdim_y), grd(gdim_x,gdim_y); add_d<<<grd,blk>>>(n, m, a_d, b_d, c_d); cudamemcpy(c, c_d, sizea, cudamemcpydevicetohost); cudafree(a_d); cudafree(b_d); cudafree(c_d); Host code complete code in ~ohaan/cuda_kurs/add_largearrays.cu

26 Adding Large Two-dimensional Arrays global void add_d( int n, int m, int *a, int *b, int *c ) { int i, j, index; j = blockidx.x*blockdim.x+threadidx.x; i = blockidx.y*blockdim.y+threadidx.y; if( i<n && j<m ) { index = i*m + j; c[index] = a[index] + b[index] ; device code j = 0,,m-1 i = 0,,n-1 n rows m columns 2-dim array index : (i,j) 2-dim thread index : (blockidx.x*blockdim.x+threadidx.x, blockidx.y*blockdim.y+threadidx.y)

27 Timing of CUDA Codes Read internal clock before and after a code segment in host code Since kernel calls from host are asynchronous, host and device must be synchronized by cudadevicesynchronize() before calling the internal clock (double) tstart = int_clock();... kernel<<<grids,threads>>>(...); cudadevicesynchronize(); (double) tend = int_clock(); printf( "cpu time : %lf \n", tend-tstart );

28 Internal Clock for Elapsed Time C-function gettimeofday returns elapsed time with microsec precision. #include <sys/time.h> double get_el_time(){ struct timeval et; gettimeofday ( &et,null); return (double)et.tv_sec +1.e+6*(double)et.tv_usec; code for get_ell_time in ~ohaan/cuda_kurs/time.ut

29 Timing of CUDA Code with CUDA Events Read internal clock before and after a code segment in host code cudaevent_t start, stop; cudaeventcreate(&start);cudaeventcreate(&stop); cudaeventrecord( start, 0 );... kernel<<<grids,threads>>>(...);... cudaeventrecord( stop, 0 ); cudaeventsynchronize( stop ); float et; cudaeventelapsedtime( &et,start, stop ); cudaeventdestroy( start );cudaeventdestroy( stop ); printf( "cpu time on device : %3.1f millisec \n", et );

30 Measuring Bandwidth for Adding Arrays GPU : GeForce GTX 1080 nominal bandwidth 320 GB/s Array size : x Performance depends on memory access method and on layout of blocks Separate memory for host and device bdim_x = 1024, bdim_y = 1 : 244 GB/s bdim_x = 32, bdim_y = 32; 242 GB/s bdim_x = 1, bdim_y = 1024; 59 GB/s code for bandwidth measurement in Unified memory bdim_x = 1024, bdim_y = 1 : ~ohaan/cuda_kurs/add_arrays_perf.cu 5 GB/s code for bandwidth measurement with um in ~ohaan/cuda_kurs/add_arrays_um_perf.cu

31 CPU 1 SMX 1 SMX n Memory Organization, Hardware View... Control unit: Schedule, dispatch Shared 32 bit registers... cache L2 cache Main memory Main memory Shared memory / L1 cache constant + texture cache Host Graphics Device Streaming Multiprocessor (SMX)

32 thread thread thread thread local mem local mem local mem local mem Device Memory, Software View... block block shared men shared men global mem constant mem texture mem

33 Types of Kernel Variables: Local Variables (scalars and arrays) defined in the scope of a kernel are local global void ker1(int laloc2,..){ int iloc1, iloc2; float aloc1[6], *aloc2; aloc2 = (float *)malloc(sizeof(float)*laloc2);... Each thread has its own set of local variables, which are placed in the register files of the SMXes, or in global memory, if there are not enough registers or if the variable is an indexed array Number of 32 bit registers per SMX 2 16 =65536 Maximal number of registers per thread 255 For the maximal number of 2048 threads per SMX number of registers per thread 32

34 Types of Kernel Variables: Global global variables (scalars and arrays) defined in the scope of the application, reside in device main memory and are shared by all threads in the kernels If allocated dynamically by calling cudamalloc() from host they can be accessed from host by cudamemcpy(...) If allocated statically by the device qualifier they can be accessed from host by cudamemcpytosymbol(...),cudamemcpyfromsymbol(...) accessing the same global variable from a kernel by different threads is not deterministic, since the order of execution for different blocks of threads is not prescribed

35 Accessing Global Variables Device memory is accessed by load/store operations for aligned memory segments of size 32, 64, or 128 Bytes If the 32 threads of a warp access 32 int or float variables lying consecutivley in memory, 4 load/store operations of 32 Byte segments serve all 32 accesses (coalescent access) Compare the performance of 2-dim array addition: blockdim.x = 32, blockdim.y = 32; 242 GB/s blockdim.x = 1, blockdim.y = 1024; 59 GB/s

36 Types of Kernel Variables: Constant constant memory variables (scalars and arrays) defined in the scope of the application, are read only, reside in device main memory are cached in the constant cache of each SMX and are shared by all threads in the kernels. Allocated on device by device constant qualifier device constant int sconst, float aconst[1024]; Can be initialized from host with cudamemcpytosymbol(aconst,a_h,1024*sizeof(float)); If all threads in a kernel read the same data, the use of constant memory variables reduces the accesses to device memory by employing the SMX s 8 kb sized constant caches.

37 Types of Kernel Variables: Shared shared variables (scalars and arrays) are defined in the scope of block of threads of a single kernel function and reside in the shared memory of the SMX executing the block of threads All threads of a block have access to a block s shared variables Threads of other blocks cannot access a block s shared variables Static allocation of one or more shared arrays in a kernel function global void ker1(...){ shared float sh_float[64]; shared int sh_int[64];... Dynamic allocation of shared memory (in one single shared array): declaration outside kernel shared float sh_array[]; allocation in host code via extended execution configuration size_t N_sh_bytes = 64*sizeof(float); ker1<<<grid,block,n_sh_bytes>>>( );

38 Device Synchronization from Host Synchroneous calls: cudamalloc, cudamemcpy,... Asynchroneous calls: kernel<<<... >>> (...), cudamemcpyasync,... A call in a host program to cudadevicesynchronize(); will synchronize all previously started activities of the device

39 Thread Synchronization from Device In a device function, threads within a block can be synchronized by calling the barrier syncthreads(); Waits until all threads in a block have reached this instruction and all accesses to global and shared memory from these threads are completed Danger of stalled execution: if (i < cut ) syncthreads(); will hang if in a block not all threads have i < cut or i>= cut Is used to coordinate memory access from threads within a single block syncthreads()cannot coordinate the execution of threads from different blocks

40 Atomic Operations Example: accumulate the content of array b into memory location a Sequential on host: for (i=0,i<n;i++) a = a + b[i] ; Parallel on kernel: if (i<n) a = a + b[i] ; If several threads modify the content of the same address, the result depends on the temporal order of their operation.

41 Atomic Operations Thread 0 Thread 1 Read r1 from a r1 = 0 Read r1 from a r1 = 0 r2 = r1 + b[0] r2 = b[0] r2 = r1 + b[1] r2 = b[1] write r2 to a a = b[0] write r2 to a a = b[1] Thread 0 Thread 1 Read r1 from a r1 = 0 r2 = r1 + b[0] r2 = b[0] write r2 to a a = b[0] Read r1 from a r1 = b[0] r2 = r1 + b[1] r2 = b[0]+b[1] write r2 to a a = b[0]+b[1]

42 Atomic Operations An atomic function performs a read-modify-write atomic operation on one 32-bit or 64-bit word residing in global or shared memory. The operation is atomic in the sense that it is guaranteed to be performed without interference from other threads Atomic add: int atomicadd(int* address, int val); Many more atomic operations are supported: cf. CUDA Toolkit Programming Guide B12

Introduction to Parallel Computing with CUDA. Oswald Haan

Introduction to Parallel Computing with CUDA. Oswald Haan Introduction to Parallel Computing with CUDA Oswald Haan ohaan@gwdg.de Schedule Introduction to Parallel Computing with CUDA Using CUDA CUDA Application Examples Using Multiple GPUs CUDA Application Libraries

More information

Lecture 3: Introduction to CUDA

Lecture 3: Introduction to CUDA CSCI-GA.3033-004 Graphics Processing Units (GPUs): Architecture and Programming Lecture 3: Introduction to CUDA Some slides here are adopted from: NVIDIA teaching kit Mohamed Zahran (aka Z) mzahran@cs.nyu.edu

More information

GPU Computing Workshop CSU Getting Started. Garland Durham Quantos Analytics

GPU Computing Workshop CSU Getting Started. Garland Durham Quantos Analytics 1 GPU Computing Workshop CSU 2013 Getting Started Garland Durham Quantos Analytics nvidia-smi 2 At command line, run command nvidia-smi to get/set GPU properties. nvidia-smi Options: -q query -L list attached

More information

Parallel Computing. Lecture 19: CUDA - I

Parallel Computing. Lecture 19: CUDA - I CSCI-UA.0480-003 Parallel Computing Lecture 19: CUDA - I Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com GPU w/ local DRAM (device) Behind CUDA CPU (host) Source: http://hothardware.com/reviews/intel-core-i5-and-i7-processors-and-p55-chipset/?page=4

More information

Lecture 15: Introduction to GPU programming. Lecture 15: Introduction to GPU programming p. 1

Lecture 15: Introduction to GPU programming. Lecture 15: Introduction to GPU programming p. 1 Lecture 15: Introduction to GPU programming Lecture 15: Introduction to GPU programming p. 1 Overview Hardware features of GPGPU Principles of GPU programming A good reference: David B. Kirk and Wen-mei

More information

CUDA Basics. July 6, 2016

CUDA Basics. July 6, 2016 Mitglied der Helmholtz-Gemeinschaft CUDA Basics July 6, 2016 CUDA Kernels Parallel portion of application: execute as a kernel Entire GPU executes kernel, many threads CUDA threads: Lightweight Fast switching

More information

Lecture 2: Introduction to CUDA C

Lecture 2: Introduction to CUDA C CS/EE 217 GPU Architecture and Programming Lecture 2: Introduction to CUDA C David Kirk/NVIDIA and Wen-mei W. Hwu, 2007-2013 1 CUDA /OpenCL Execution Model Integrated host+device app C program Serial or

More information

Register file. A single large register file (ex. 16K registers) is partitioned among the threads of the dispatched blocks.

Register file. A single large register file (ex. 16K registers) is partitioned among the threads of the dispatched blocks. Sharing the resources of an SM Warp 0 Warp 1 Warp 47 Register file A single large register file (ex. 16K registers) is partitioned among the threads of the dispatched blocks Shared A single SRAM (ex. 16KB)

More information

GPU Programming. Lecture 2: CUDA C Basics. Miaoqing Huang University of Arkansas 1 / 34

GPU Programming. Lecture 2: CUDA C Basics. Miaoqing Huang University of Arkansas 1 / 34 1 / 34 GPU Programming Lecture 2: CUDA C Basics Miaoqing Huang University of Arkansas 2 / 34 Outline Evolvements of NVIDIA GPU CUDA Basic Detailed Steps Device Memories and Data Transfer Kernel Functions

More information

Module 2: Introduction to CUDA C. Objective

Module 2: Introduction to CUDA C. Objective ECE 8823A GPU Architectures Module 2: Introduction to CUDA C 1 Objective To understand the major elements of a CUDA program Introduce the basic constructs of the programming model Illustrate the preceding

More information

Lecture 9. Outline. CUDA : a General-Purpose Parallel Computing Architecture. CUDA Device and Threads CUDA. CUDA Architecture CUDA (I)

Lecture 9. Outline. CUDA : a General-Purpose Parallel Computing Architecture. CUDA Device and Threads CUDA. CUDA Architecture CUDA (I) Lecture 9 CUDA CUDA (I) Compute Unified Device Architecture 1 2 Outline CUDA Architecture CUDA Architecture CUDA programming model CUDA-C 3 4 CUDA : a General-Purpose Parallel Computing Architecture CUDA

More information

Introduction to GPU programming. Introduction to GPU programming p. 1/17

Introduction to GPU programming. Introduction to GPU programming p. 1/17 Introduction to GPU programming Introduction to GPU programming p. 1/17 Introduction to GPU programming p. 2/17 Overview GPUs & computing Principles of CUDA programming One good reference: David B. Kirk

More information

Information Coding / Computer Graphics, ISY, LiTH. Introduction to CUDA. Ingemar Ragnemalm Information Coding, ISY

Information Coding / Computer Graphics, ISY, LiTH. Introduction to CUDA. Ingemar Ragnemalm Information Coding, ISY Introduction to CUDA Ingemar Ragnemalm Information Coding, ISY This lecture: Programming model and language Introduction to memory spaces and memory access Shared memory Matrix multiplication example Lecture

More information

GPU & High Performance Computing (by NVIDIA) CUDA. Compute Unified Device Architecture Florian Schornbaum

GPU & High Performance Computing (by NVIDIA) CUDA. Compute Unified Device Architecture Florian Schornbaum GPU & High Performance Computing (by NVIDIA) CUDA Compute Unified Device Architecture 29.02.2008 Florian Schornbaum GPU Computing Performance In the last few years the GPU has evolved into an absolute

More information

What is GPU? CS 590: High Performance Computing. GPU Architectures and CUDA Concepts/Terms

What is GPU? CS 590: High Performance Computing. GPU Architectures and CUDA Concepts/Terms CS 590: High Performance Computing GPU Architectures and CUDA Concepts/Terms Fengguang Song Department of Computer & Information Science IUPUI What is GPU? Conventional GPUs are used to generate 2D, 3D

More information

Tesla Architecture, CUDA and Optimization Strategies

Tesla Architecture, CUDA and Optimization Strategies Tesla Architecture, CUDA and Optimization Strategies Lan Shi, Li Yi & Liyuan Zhang Hauptseminar: Multicore Architectures and Programming Page 1 Outline Tesla Architecture & CUDA CUDA Programming Optimization

More information

Introduction to Numerical General Purpose GPU Computing with NVIDIA CUDA. Part 1: Hardware design and programming model

Introduction to Numerical General Purpose GPU Computing with NVIDIA CUDA. Part 1: Hardware design and programming model Introduction to Numerical General Purpose GPU Computing with NVIDIA CUDA Part 1: Hardware design and programming model Dirk Ribbrock Faculty of Mathematics, TU dortmund 2016 Table of Contents Why parallel

More information

GPU 1. CSCI 4850/5850 High-Performance Computing Spring 2018

GPU 1. CSCI 4850/5850 High-Performance Computing Spring 2018 GPU 1 CSCI 4850/5850 High-Performance Computing Spring 2018 Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University Learning Objectives

More information

An Introduction to GPU Architecture and CUDA C/C++ Programming. Bin Chen April 4, 2018 Research Computing Center

An Introduction to GPU Architecture and CUDA C/C++ Programming. Bin Chen April 4, 2018 Research Computing Center An Introduction to GPU Architecture and CUDA C/C++ Programming Bin Chen April 4, 2018 Research Computing Center Outline Introduction to GPU architecture Introduction to CUDA programming model Using the

More information

High Performance Computing and GPU Programming

High Performance Computing and GPU Programming High Performance Computing and GPU Programming Lecture 1: Introduction Objectives C++/CPU Review GPU Intro Programming Model Objectives Objectives Before we begin a little motivation Intel Xeon 2.67GHz

More information

Josef Pelikán, Jan Horáček CGG MFF UK Praha

Josef Pelikán, Jan Horáček CGG MFF UK Praha GPGPU and CUDA 2012-2018 Josef Pelikán, Jan Horáček CGG MFF UK Praha pepca@cgg.mff.cuni.cz http://cgg.mff.cuni.cz/~pepca/ 1 / 41 Content advances in hardware multi-core vs. many-core general computing

More information

Module 2: Introduction to CUDA C

Module 2: Introduction to CUDA C ECE 8823A GPU Architectures Module 2: Introduction to CUDA C 1 Objective To understand the major elements of a CUDA program Introduce the basic constructs of the programming model Illustrate the preceding

More information

CUDA Workshop. High Performance GPU computing EXEBIT Karthikeyan

CUDA Workshop. High Performance GPU computing EXEBIT Karthikeyan CUDA Workshop High Performance GPU computing EXEBIT- 2014 Karthikeyan CPU vs GPU CPU Very fast, serial, Low Latency GPU Slow, massively parallel, High Throughput Play Demonstration Compute Unified Device

More information

Scientific discovery, analysis and prediction made possible through high performance computing.

Scientific discovery, analysis and prediction made possible through high performance computing. Scientific discovery, analysis and prediction made possible through high performance computing. An Introduction to GPGPU Programming Bob Torgerson Arctic Region Supercomputing Center November 21 st, 2013

More information

Lecture 10!! Introduction to CUDA!

Lecture 10!! Introduction to CUDA! 1(50) Lecture 10 Introduction to CUDA Ingemar Ragnemalm Information Coding, ISY 1(50) Laborations Some revisions may happen while making final adjustments for Linux Mint. Last minute changes may occur.

More information

CUDA programming model. N. Cardoso & P. Bicudo. Física Computacional (FC5)

CUDA programming model. N. Cardoso & P. Bicudo. Física Computacional (FC5) CUDA programming model N. Cardoso & P. Bicudo Física Computacional (FC5) N. Cardoso & P. Bicudo CUDA programming model 1/23 Outline 1 CUDA qualifiers 2 CUDA Kernel Thread hierarchy Kernel, configuration

More information

Lecture 8: GPU Programming. CSE599G1: Spring 2017

Lecture 8: GPU Programming. CSE599G1: Spring 2017 Lecture 8: GPU Programming CSE599G1: Spring 2017 Announcements Project proposal due on Thursday (4/28) 5pm. Assignment 2 will be out today, due in two weeks. Implement GPU kernels and use cublas library

More information

Introduction to GPGPUs and to CUDA programming model

Introduction to GPGPUs and to CUDA programming model Introduction to GPGPUs and to CUDA programming model www.cineca.it Marzia Rivi m.rivi@cineca.it GPGPU architecture CUDA programming model CUDA efficient programming Debugging & profiling tools CUDA libraries

More information

Zero-copy. Table of Contents. Multi-GPU Learning CUDA to Solve Scientific Problems. Objectives. Technical Issues Zero-copy. Multigpu.

Zero-copy. Table of Contents. Multi-GPU Learning CUDA to Solve Scientific Problems. Objectives. Technical Issues Zero-copy. Multigpu. Table of Contents Multi-GPU Learning CUDA to Solve Scientific Problems. 1 Objectives Miguel Cárdenas Montes 2 Zero-copy Centro de Investigaciones Energéticas Medioambientales y Tecnológicas, Madrid, Spain

More information

CUDA Programming. Week 1. Basic Programming Concepts Materials are copied from the reference list

CUDA Programming. Week 1. Basic Programming Concepts Materials are copied from the reference list CUDA Programming Week 1. Basic Programming Concepts Materials are copied from the reference list G80/G92 Device SP: Streaming Processor (Thread Processors) SM: Streaming Multiprocessor 128 SP grouped into

More information

University of Bielefeld

University of Bielefeld Geistes-, Natur-, Sozial- und Technikwissenschaften gemeinsam unter einem Dach Introduction to GPU Programming using CUDA Olaf Kaczmarek University of Bielefeld STRONGnet Summerschool 2011 ZIF Bielefeld

More information

GPU Programming Using CUDA

GPU Programming Using CUDA GPU Programming Using CUDA Michael J. Schnieders Depts. of Biomedical Engineering & Biochemistry The University of Iowa & Gregory G. Howes Department of Physics and Astronomy The University of Iowa Iowa

More information

GPU Computing with CUDA

GPU Computing with CUDA GPU Computing with CUDA Hands-on: Shared Memory Use (Dot Product, Matrix Multiplication) Dan Melanz & Dan Negrut Simulation-Based Engineering Lab Wisconsin Applied Computing Center Department of Mechanical

More information

Information Coding / Computer Graphics, ISY, LiTH. Introduction to CUDA. Ingemar Ragnemalm Information Coding, ISY

Information Coding / Computer Graphics, ISY, LiTH. Introduction to CUDA. Ingemar Ragnemalm Information Coding, ISY Introduction to CUDA Ingemar Ragnemalm Information Coding, ISY This lecture: Programming model and language Memory spaces and memory access Shared memory Examples Lecture questions: 1. Suggest two significant

More information

GPU Programming Introduction

GPU Programming Introduction GPU Programming Introduction DR. CHRISTOPH ANGERER, NVIDIA AGENDA Introduction to Heterogeneous Computing Using Accelerated Libraries GPU Programming Languages Introduction to CUDA Lunch What is Heterogeneous

More information

Stanford University. NVIDIA Tesla M2090. NVIDIA GeForce GTX 690

Stanford University. NVIDIA Tesla M2090. NVIDIA GeForce GTX 690 Stanford University NVIDIA Tesla M2090 NVIDIA GeForce GTX 690 Moore s Law 2 Clock Speed 10000 Pentium 4 Prescott Core 2 Nehalem Sandy Bridge 1000 Pentium 4 Williamette Clock Speed (MHz) 100 80486 Pentium

More information

Programming with CUDA, WS09

Programming with CUDA, WS09 Programming with CUDA and Parallel Algorithms Waqar Saleem Jens Müller Lecture 3 Thursday, 29 Nov, 2009 Recap Motivational videos Example kernel Thread IDs Memory overhead CUDA hardware and programming

More information

GPU Computing: A Quick Start

GPU Computing: A Quick Start GPU Computing: A Quick Start Orest Shardt Department of Chemical and Materials Engineering University of Alberta August 25, 2011 Session Goals Get you started with highly parallel LBM Take a practical

More information

Lab 1 Part 1: Introduction to CUDA

Lab 1 Part 1: Introduction to CUDA Lab 1 Part 1: Introduction to CUDA Code tarball: lab1.tgz In this hands-on lab, you will learn to use CUDA to program a GPU. The lab can be conducted on the SSSU Fermi Blade (M2050) or NCSA Forge using

More information

Tutorial: Parallel programming technologies on hybrid architectures HybriLIT Team

Tutorial: Parallel programming technologies on hybrid architectures HybriLIT Team Tutorial: Parallel programming technologies on hybrid architectures HybriLIT Team Laboratory of Information Technologies Joint Institute for Nuclear Research The Helmholtz International Summer School Lattice

More information

CS377P Programming for Performance GPU Programming - I

CS377P Programming for Performance GPU Programming - I CS377P Programming for Performance GPU Programming - I Sreepathi Pai UTCS November 9, 2015 Outline 1 Introduction to CUDA 2 Basic Performance 3 Memory Performance Outline 1 Introduction to CUDA 2 Basic

More information

An Introduction to GPGPU Pro g ra m m ing - CUDA Arc hitec ture

An Introduction to GPGPU Pro g ra m m ing - CUDA Arc hitec ture An Introduction to GPGPU Pro g ra m m ing - CUDA Arc hitec ture Rafia Inam Mälardalen Real-Time Research Centre Mälardalen University, Västerås, Sweden http://www.mrtc.mdh.se rafia.inam@mdh.se CONTENTS

More information

Introduction to GPU Computing. Design and Analysis of Parallel Algorithms

Introduction to GPU Computing. Design and Analysis of Parallel Algorithms Introduction to GPU Computing Design and Analysis of Parallel Algorithms Sources CUDA Programming Guide (3.2) CUDA Best Practices Guide (3.2) CUDA Toolkit Reference Manual (3.2) CUDA SDK Examples Part

More information

HPCSE II. GPU programming and CUDA

HPCSE II. GPU programming and CUDA HPCSE II GPU programming and CUDA What is a GPU? Specialized for compute-intensive, highly-parallel computation, i.e. graphic output Evolution pushed by gaming industry CPU: large die area for control

More information

Lecture 2: CUDA Programming

Lecture 2: CUDA Programming CS 515 Programming Language and Compilers I Lecture 2: CUDA Programming Zheng (Eddy) Zhang Rutgers University Fall 2017, 9/12/2017 Review: Programming in CUDA Let s look at a sequential program in C first:

More information

Massively Parallel Algorithms

Massively Parallel Algorithms Massively Parallel Algorithms Introduction to CUDA & Many Fundamental Concepts of Parallel Programming G. Zachmann University of Bremen, Germany cgvr.cs.uni-bremen.de Hybrid/Heterogeneous Computation/Architecture

More information

Introduction to GPU Computing Using CUDA. Spring 2014 Westgid Seminar Series

Introduction to GPU Computing Using CUDA. Spring 2014 Westgid Seminar Series Introduction to GPU Computing Using CUDA Spring 2014 Westgid Seminar Series Scott Northrup SciNet www.scinethpc.ca March 13, 2014 Outline 1 Heterogeneous Computing 2 GPGPU - Overview Hardware Software

More information

Massively Parallel Computing with CUDA. Carlos Alberto Martínez Angeles Cinvestav-IPN

Massively Parallel Computing with CUDA. Carlos Alberto Martínez Angeles Cinvestav-IPN Massively Parallel Computing with CUDA Carlos Alberto Martínez Angeles Cinvestav-IPN What is a GPU? A graphics processing unit (GPU) The term GPU was popularized by Nvidia in 1999 marketed the GeForce

More information

Module 3: CUDA Execution Model -I. Objective

Module 3: CUDA Execution Model -I. Objective ECE 8823A GPU Architectures odule 3: CUDA Execution odel -I 1 Objective A more detailed look at kernel execution Data to thread assignment To understand the organization and scheduling of threads Resource

More information

Introduction to GPU Computing Using CUDA. Spring 2014 Westgid Seminar Series

Introduction to GPU Computing Using CUDA. Spring 2014 Westgid Seminar Series Introduction to GPU Computing Using CUDA Spring 2014 Westgid Seminar Series Scott Northrup SciNet www.scinethpc.ca (Slides http://support.scinet.utoronto.ca/ northrup/westgrid CUDA.pdf) March 12, 2014

More information

CUDA Lecture 2. Manfred Liebmann. Technische Universität München Chair of Optimal Control Center for Mathematical Sciences, M17

CUDA Lecture 2. Manfred Liebmann. Technische Universität München Chair of Optimal Control Center for Mathematical Sciences, M17 CUDA Lecture 2 Manfred Liebmann Technische Universität München Chair of Optimal Control Center for Mathematical Sciences, M17 manfred.liebmann@tum.de December 15, 2015 CUDA Programming Fundamentals CUDA

More information

GPU programming: CUDA basics. Sylvain Collange Inria Rennes Bretagne Atlantique

GPU programming: CUDA basics. Sylvain Collange Inria Rennes Bretagne Atlantique GPU programming: CUDA basics Sylvain Collange Inria Rennes Bretagne Atlantique sylvain.collange@inria.fr This lecture: CUDA programming We have seen some GPU architecture Now how to program it? 2 Outline

More information

Overview. Lecture 1: an introduction to CUDA. Hardware view. Hardware view. hardware view software view CUDA programming

Overview. Lecture 1: an introduction to CUDA. Hardware view. Hardware view. hardware view software view CUDA programming Overview Lecture 1: an introduction to CUDA Mike Giles mike.giles@maths.ox.ac.uk hardware view software view Oxford University Mathematical Institute Oxford e-research Centre Lecture 1 p. 1 Lecture 1 p.

More information

Cartoon parallel architectures; CPUs and GPUs

Cartoon parallel architectures; CPUs and GPUs Cartoon parallel architectures; CPUs and GPUs CSE 6230, Fall 2014 Th Sep 11! Thanks to Jee Choi (a senior PhD student) for a big assist 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ~ socket 14 ~ core 14 ~ HWMT+SIMD

More information

Introduction to CUDA CIRC Summer School 2014

Introduction to CUDA CIRC Summer School 2014 Introduction to CUDA CIRC Summer School 2014 Baowei Liu Center of Integrated Research Computing University of Rochester October 20, 2014 Introduction Overview What will you learn on this class? Start from

More information

Introduction to CUDA Programming

Introduction to CUDA Programming Introduction to CUDA Programming Steve Lantz Cornell University Center for Advanced Computing October 30, 2013 Based on materials developed by CAC and TACC Outline Motivation for GPUs and CUDA Overview

More information

Parallel Numerical Algorithms

Parallel Numerical Algorithms Parallel Numerical Algorithms http://sudalab.is.s.u-tokyo.ac.jp/~reiji/pna14/ [ 10 ] GPU and CUDA Parallel Numerical Algorithms / IST / UTokyo 1 PNA16 Lecture Plan General Topics 1. Architecture and Performance

More information

Introduction to Scientific Programming using GPGPU and CUDA

Introduction to Scientific Programming using GPGPU and CUDA Introduction to Scientific Programming using GPGPU and CUDA Day 1 Sergio Orlandini s.orlandini@cineca.it Mario Tacconi m.tacconi@cineca.it 0 Hands on: Compiling a CUDA program Environment and utility:

More information

Graph Partitioning. Standard problem in parallelization, partitioning sparse matrix in nearly independent blocks or discretization grids in FEM.

Graph Partitioning. Standard problem in parallelization, partitioning sparse matrix in nearly independent blocks or discretization grids in FEM. Graph Partitioning Standard problem in parallelization, partitioning sparse matrix in nearly independent blocks or discretization grids in FEM. Partition given graph G=(V,E) in k subgraphs of nearly equal

More information

COSC 6374 Parallel Computations Introduction to CUDA

COSC 6374 Parallel Computations Introduction to CUDA COSC 6374 Parallel Computations Introduction to CUDA Edgar Gabriel Fall 2014 Disclaimer Material for this lecture has been adopted based on various sources Matt Heavener, CS, State Univ. of NY at Buffalo

More information

Introduction to CUDA CME343 / ME May James Balfour [ NVIDIA Research

Introduction to CUDA CME343 / ME May James Balfour [ NVIDIA Research Introduction to CUDA CME343 / ME339 18 May 2011 James Balfour [ jbalfour@nvidia.com] NVIDIA Research CUDA Programing system for machines with GPUs Programming Language Compilers Runtime Environments Drivers

More information

GPU Programming Using CUDA. Samuli Laine NVIDIA Research

GPU Programming Using CUDA. Samuli Laine NVIDIA Research GPU Programming Using CUDA Samuli Laine NVIDIA Research Today GPU vs CPU Different architecture, different workloads Basics of CUDA Executing code on GPU Managing memory between CPU and GPU CUDA API Quick

More information

Learn CUDA in an Afternoon. Alan Gray EPCC The University of Edinburgh

Learn CUDA in an Afternoon. Alan Gray EPCC The University of Edinburgh Learn CUDA in an Afternoon Alan Gray EPCC The University of Edinburgh Overview Introduction to CUDA Practical Exercise 1: Getting started with CUDA GPU Optimisation Practical Exercise 2: Optimising a CUDA

More information

CUDA C/C++ BASICS. NVIDIA Corporation

CUDA C/C++ BASICS. NVIDIA Corporation CUDA C/C++ BASICS NVIDIA Corporation What is CUDA? CUDA Architecture Expose GPU parallelism for general-purpose computing Retain performance CUDA C/C++ Based on industry-standard C/C++ Small set of extensions

More information

COSC 462 Parallel Programming

COSC 462 Parallel Programming November 22, 2017 1/12 COSC 462 Parallel Programming CUDA Beyond Basics Piotr Luszczek Mixing Blocks and Threads int N = 100, SN = N * sizeof(double); global void sum(double *a, double *b, double *c) {

More information

Fundamental Optimizations in CUDA Peng Wang, Developer Technology, NVIDIA

Fundamental Optimizations in CUDA Peng Wang, Developer Technology, NVIDIA Fundamental Optimizations in CUDA Peng Wang, Developer Technology, NVIDIA Optimization Overview GPU architecture Kernel optimization Memory optimization Latency optimization Instruction optimization CPU-GPU

More information

GPU Programming. Rupesh Nasre.

GPU Programming. Rupesh Nasre. GPU Programming Rupesh Nasre. http://www.cse.iitm.ac.in/~rupesh IIT Madras July 2017 Hello World. #include int main() { printf("hello World.\n"); return 0; Compile: nvcc hello.cu Run: a.out GPU

More information

GPU Programming. Alan Gray, James Perry EPCC The University of Edinburgh

GPU Programming. Alan Gray, James Perry EPCC The University of Edinburgh GPU Programming EPCC The University of Edinburgh Contents NVIDIA CUDA C Proprietary interface to NVIDIA architecture CUDA Fortran Provided by PGI OpenCL Cross platform API 2 NVIDIA CUDA CUDA allows NVIDIA

More information

Real-time Graphics 9. GPGPU

Real-time Graphics 9. GPGPU Real-time Graphics 9. GPGPU GPGPU GPU (Graphics Processing Unit) Flexible and powerful processor Programmability, precision, power Parallel processing CPU Increasing number of cores Parallel processing

More information

CUDA C/C++ BASICS. NVIDIA Corporation

CUDA C/C++ BASICS. NVIDIA Corporation CUDA C/C++ BASICS NVIDIA Corporation What is CUDA? CUDA Architecture Expose GPU parallelism for general-purpose computing Retain performance CUDA C/C++ Based on industry-standard C/C++ Small set of extensions

More information

CUDA PROGRAMMING MODEL. Carlo Nardone Sr. Solution Architect, NVIDIA EMEA

CUDA PROGRAMMING MODEL. Carlo Nardone Sr. Solution Architect, NVIDIA EMEA CUDA PROGRAMMING MODEL Carlo Nardone Sr. Solution Architect, NVIDIA EMEA CUDA: COMMON UNIFIED DEVICE ARCHITECTURE Parallel computing architecture and programming model GPU Computing Application Includes

More information

GPU Computing: Introduction to CUDA. Dr Paul Richmond

GPU Computing: Introduction to CUDA. Dr Paul Richmond GPU Computing: Introduction to CUDA Dr Paul Richmond http://paulrichmond.shef.ac.uk This lecture CUDA Programming Model CUDA Device Code CUDA Host Code and Memory Management CUDA Compilation Programming

More information

AMS 148 Chapter 8: Optimization in CUDA, and Advanced Topics

AMS 148 Chapter 8: Optimization in CUDA, and Advanced Topics AMS 148 Chapter 8: Optimization in CUDA, and Advanced Topics Steven Reeves 1 Optimizing Data Transfers in CUDA C/C++ This section we will discuss code optimization with how to efficiently transfer data

More information

GPU CUDA Programming

GPU CUDA Programming GPU CUDA Programming 이정근 (Jeong-Gun Lee) 한림대학교컴퓨터공학과, 임베디드 SoC 연구실 www.onchip.net Email: Jeonggun.Lee@hallym.ac.kr ALTERA JOINT LAB Introduction 차례 Multicore/Manycore and GPU GPU on Medical Applications

More information

Review. Lecture 10. Today s Outline. Review. 03b.cu. 03?.cu CUDA (II) Matrix addition CUDA-C API

Review. Lecture 10. Today s Outline. Review. 03b.cu. 03?.cu CUDA (II) Matrix addition CUDA-C API Review Lecture 10 CUDA (II) host device CUDA many core processor threads thread blocks grid # threads >> # of cores to be efficient Threads within blocks can cooperate Threads between thread blocks cannot

More information

GPU programming. Dr. Bernhard Kainz

GPU programming. Dr. Bernhard Kainz GPU programming Dr. Bernhard Kainz Overview About myself Motivation GPU hardware and system architecture GPU programming languages GPU programming paradigms Pitfalls and best practice Reduction and tiling

More information

CUDA Programming. Aiichiro Nakano

CUDA Programming. Aiichiro Nakano CUDA Programming Aiichiro Nakano Collaboratory for Advanced Computing & Simulations Department of Computer Science Department of Physics & Astronomy Department of Chemical Engineering & Materials Science

More information

COSC 462. CUDA Basics: Blocks, Grids, and Threads. Piotr Luszczek. November 1, /10

COSC 462. CUDA Basics: Blocks, Grids, and Threads. Piotr Luszczek. November 1, /10 COSC 462 CUDA Basics: Blocks, Grids, and Threads Piotr Luszczek November 1, 2017 1/10 Minimal CUDA Code Example global void sum(double x, double y, double *z) { *z = x + y; } int main(void) { double *device_z,

More information

Introduc)on to GPU Programming

Introduc)on to GPU Programming Introduc)on to GPU Programming Mubashir Adnan Qureshi h3p://www.ncsa.illinois.edu/people/kindr/projects/hpca/files/singapore_p1.pdf h3p://developer.download.nvidia.com/cuda/training/nvidia_gpu_compu)ng_webinars_cuda_memory_op)miza)on.pdf

More information

CUDA programming interface - CUDA C

CUDA programming interface - CUDA C CUDA programming interface - CUDA C Presentation CUDA functions Device settings Memory (de)allocation within the device global memory data transfers between host memory and device global memory Data partitioning

More information

An Introduction to GPU Computing and CUDA Architecture

An Introduction to GPU Computing and CUDA Architecture An Introduction to GPU Computing and CUDA Architecture Sarah Tariq, NVIDIA Corporation GPU Computing GPU: Graphics Processing Unit Traditionally used for real-time rendering High computational density

More information

Basic Elements of CUDA Algoritmi e Calcolo Parallelo. Daniele Loiacono

Basic Elements of CUDA Algoritmi e Calcolo Parallelo. Daniele Loiacono Basic Elements of CUDA Algoritmi e Calcolo Parallelo References This set of slides is mainly based on: CUDA Technical Training, Dr. Antonino Tumeo, Pacific Northwest National Laboratory Slide of Applied

More information

Zero Copy Memory and Multiple GPUs

Zero Copy Memory and Multiple GPUs Zero Copy Memory and Multiple GPUs Goals Zero Copy Memory Pinned and mapped memory on the host can be read and written to from the GPU program (if the device permits this) This may result in performance

More information

CSE 160 Lecture 24. Graphical Processing Units

CSE 160 Lecture 24. Graphical Processing Units CSE 160 Lecture 24 Graphical Processing Units Announcements Next week we meet in 1202 on Monday 3/11 only On Weds 3/13 we have a 2 hour session Usual class time at the Rady school final exam review SDSC

More information

Writing and compiling a CUDA code

Writing and compiling a CUDA code Writing and compiling a CUDA code Philip Blakely Laboratory for Scientific Computing, University of Cambridge Philip Blakely (LSC) Writing CUDA code 1 / 65 The CUDA language If we want fast code, we (unfortunately)

More information

CUDA Exercises. CUDA Programming Model Lukas Cavigelli ETZ E 9 / ETZ D Integrated Systems Laboratory

CUDA Exercises. CUDA Programming Model Lukas Cavigelli ETZ E 9 / ETZ D Integrated Systems Laboratory CUDA Exercises CUDA Programming Model 05.05.2015 Lukas Cavigelli ETZ E 9 / ETZ D 61.1 Integrated Systems Laboratory Exercises 1. Enumerate GPUs 2. Hello World CUDA kernel 3. Vectors Addition Threads and

More information

CUDA Architecture & Programming Model

CUDA Architecture & Programming Model CUDA Architecture & Programming Model Course on Multi-core Architectures & Programming Oliver Taubmann May 9, 2012 Outline Introduction Architecture Generation Fermi A Brief Look Back At Tesla What s New

More information

GPGPU. Alan Gray/James Perry EPCC The University of Edinburgh.

GPGPU. Alan Gray/James Perry EPCC The University of Edinburgh. GPGPU Alan Gray/James Perry EPCC The University of Edinburgh a.gray@ed.ac.uk Contents Introduction GPU Technology Programming GPUs GPU Performance Optimisation 2 Introduction 3 Introduction Central Processing

More information

CUDA C Programming Mark Harris NVIDIA Corporation

CUDA C Programming Mark Harris NVIDIA Corporation CUDA C Programming Mark Harris NVIDIA Corporation Agenda Tesla GPU Computing CUDA Fermi What is GPU Computing? Introduction to Tesla CUDA Architecture Programming & Memory Models Programming Environment

More information

CUDA Kenjiro Taura 1 / 36

CUDA Kenjiro Taura 1 / 36 CUDA Kenjiro Taura 1 / 36 Contents 1 Overview 2 CUDA Basics 3 Kernels 4 Threads and thread blocks 5 Moving data between host and device 6 Data sharing among threads in the device 2 / 36 Contents 1 Overview

More information

Lecture 1: an introduction to CUDA

Lecture 1: an introduction to CUDA Lecture 1: an introduction to CUDA Mike Giles mike.giles@maths.ox.ac.uk Oxford University Mathematical Institute Oxford e-research Centre Lecture 1 p. 1 Overview hardware view software view CUDA programming

More information

MIC-GPU: High-Performance Computing for Medical Imaging on Programmable Graphics Hardware (GPUs)

MIC-GPU: High-Performance Computing for Medical Imaging on Programmable Graphics Hardware (GPUs) MIC-GPU: High-Performance Computing for Medical Imaging on Programmable Graphics Hardware (GPUs) CUDA API Klaus Mueller, Ziyi Zheng, Eric Papenhausen Stony Brook University Function Qualifiers Device Global,

More information

Mathematical computations with GPUs

Mathematical computations with GPUs Master Educational Program Information technology in applications Mathematical computations with GPUs CUDA Alexey A. Romanenko arom@ccfit.nsu.ru Novosibirsk State University CUDA - Compute Unified Device

More information

CSE 599 I Accelerated Computing - Programming GPUS. Advanced Host / Device Interface

CSE 599 I Accelerated Computing - Programming GPUS. Advanced Host / Device Interface CSE 599 I Accelerated Computing - Programming GPUS Advanced Host / Device Interface Objective Take a slightly lower-level view of the CPU / GPU interface Learn about different CPU / GPU communication techniques

More information

Data Parallel Execution Model

Data Parallel Execution Model CS/EE 217 GPU Architecture and Parallel Programming Lecture 3: Kernel-Based Data Parallel Execution Model David Kirk/NVIDIA and Wen-mei Hwu, 2007-2013 Objective To understand the organization and scheduling

More information

Real-time Graphics 9. GPGPU

Real-time Graphics 9. GPGPU 9. GPGPU GPGPU GPU (Graphics Processing Unit) Flexible and powerful processor Programmability, precision, power Parallel processing CPU Increasing number of cores Parallel processing GPGPU general-purpose

More information

CUDA. More on threads, shared memory, synchronization. cuprintf

CUDA. More on threads, shared memory, synchronization. cuprintf CUDA More on threads, shared memory, synchronization cuprintf Library function for CUDA Developers Copy the files from /opt/cuprintf into your source code folder #include cuprintf.cu global void testkernel(int

More information

Outline 2011/10/8. Memory Management. Kernels. Matrix multiplication. CIS 565 Fall 2011 Qing Sun

Outline 2011/10/8. Memory Management. Kernels. Matrix multiplication. CIS 565 Fall 2011 Qing Sun Outline Memory Management CIS 565 Fall 2011 Qing Sun sunqing@seas.upenn.edu Kernels Matrix multiplication Managing Memory CPU and GPU have separate memory spaces Host (CPU) code manages device (GPU) memory

More information

Fundamental CUDA Optimization. NVIDIA Corporation

Fundamental CUDA Optimization. NVIDIA Corporation Fundamental CUDA Optimization NVIDIA Corporation Outline Fermi/Kepler Architecture Kernel optimizations Launch configuration Global memory throughput Shared memory access Instruction throughput / control

More information

ECE 408 / CS 483 Final Exam, Fall 2014

ECE 408 / CS 483 Final Exam, Fall 2014 ECE 408 / CS 483 Final Exam, Fall 2014 Thursday 18 December 2014 8:00 to 11:00 Central Standard Time You may use any notes, books, papers, or other reference materials. In the interest of fair access across

More information