Docsity

CUDA C Programming: Lecture Notes on GPU Architecture and Programming, Lecture notes of Advanced Computer Architecture

Partial preview of the text

Download CUDA C Programming: Lecture Notes on GPU Architecture and Programming and more Lecture notes Advanced Computer Architecture in PDF only on Docsity!

Lecture 2 CUDA C

Programming

Kyu Ho Park March 2, 2017

Computer Architecture

Single Instruction Multiple Data (SIMD) Multiple Instruction Multiple Data (MIMD) Single Instruction Single Data (SISD) Multiple Instruction Single Data (MISD) NVIDIA GPU: SIMT(Single Instruction Multiple Thread)

Classification based on the memory organization

Multi-node with distributed

memory

(Shared nothing architecture)

Multiprocessor with shared

memory

(Shared everything architecture)

Heterogeneous Computing

[NVIDIA]

Fermi and Kepler

FERMI (Tesla c2050) KEPLER (Tesla k10) CUDA cores 448 1536 x 2 Memory 6GBytes 8GBytes Peak Performance 1.0 TFLOPS 4.6 TFLOPS Memory Bandwidth 144GBytes/s 320 Gbytes/s

Kepler and Maxwell

CUDA Architecture

 2006: Advent of NVIDIA’s GeForce 8800GTX  (^) the first GPU of CUDA Architecture  (^) for general purpose computing, ALUs complying IEEE requirements, allowing R/W of shared memory  Few months after the launch of GeForce 8800GTX, CUDA C announced.  (^) the first language for general-purpose

Hello,World!

#include <stdio.h> int main(void){ printf(“Hello, World!\n”); return 0; }

Kernel Program

#include <stdio.h> global void funct(void) { printf(“Hello from GPU!\n”); } int main(void){ funct<<<1,4>>>( ); printf(“Hello, World from CPU!\n”); cudaDeviceReset(); return 0; } Angle bracket

$nvcc test.cu and $ ./a.out

global function qualifier

 CUDA C adds the global qualifier to standard C. It alerts the compiler that a function is to be compiled to run on a device.  ‘nvcc’ sends the funct( ) to the compiler that handles device code. And it feeds main( ) to the host compiler.  CUDA nvcc compiler separates the

CUDA C Extension

  1. function type qualifiers global, device, host, device host global void function1 <<< 6,4>>>( ) { …} function1 is only executed at a device. It can be called from the host

global void function

#include <stdio .h> global void add(int a, int b, int *c) { c = a + b; } int main() { int c; int dev_c; cudaMalloc((void)&dev_c, sizeof(int)); add<<<1, 1>>>(2, 7, dev_c); cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost); printf("2 + 7 = %d\n", c); cudaFree(dev_c); return 0; }