자막
음성

Lec 21 · GPGPU (범용 GPU 컴퓨팅)과 CUDA programming model

정밀 정리 · 검증 2026-09-25 00:17

1개요

1.1GPGPU 의 배경: graphics 의 FLOP·bandwidth 요구와 throughput 지향 설계, 초기 GPGPU 에서 CUDA·OpenCL 로.
1.2CPU vs GPU: latency 최적화 vs massive TLP·throughput, warp 기반 SIMT, fine-grained multithreading 으로 latency hiding.
1.3CUDA 모델: kernel·grid·thread block·thread 계층, block 독립성과 atomic, memory space(register/local/shared/global/constant/texture), cudaMemcpy.
1.4마지막에 C for CUDA 문법(__global__, <<< >>>, threadIdx 등). 슬라이드 32–41(vector_add 예제, branch divergence, dynamic warp formation)은 다음 시간.

2섹션별 정리 상황·문제 → 원인 → 해결

2.10:58–2:37GPGPU 란
상황·문제병렬 아키텍처 두 번째 파트로 GPGPU 를 다룸.
원인GPU 는 게임·3D modeling 용이지만 연산 능력이 매우 큼.
해결GPGPU(general-purpose computing on GPUs) = 병렬성이 충분한 일반 workload 를 GPU 로 계산.
  • GPGPU = general purpose computing on graphics processing units
p.1
2.1.1 · p.1 · 0:38
p.2
2.1.2 · p.2 · 1:39
2.1.r.1Wikipedia: General-purpose computing on GPUs ↗ · GPGPU 역사, CUDA·OpenCL 개요
2.22:37–5:37NVIDIA 실시간 그래픽 데모
상황·문제단일 GPU 가 실시간 rendering 하는 NVIDIA 데모 영상을 재생.
원인Zoom 으로는 해상도·부드러움이 떨어짐.
해결강의 노트의 링크로 직접 보라고 안내. 화면 뒤의 대량 연산을 생각해 보라는 취지.
  • all of this is being rendered by a single GPU
p.3
2.2.1 · p.3 · 2:35
2.2.r.1YouTube: NVIDIA Marbles at Night | RTX Demo ↗ · 슬라이드 3 의 데모 영상
2.35:37–8:41GPU 가 빨라야 하는 이유: FLOP·bandwidth 요구
상황·문제full HD 화면은 약 2 million pixel, 50–100 Hz refresh, vertex 당 10–100 연산, fragment 당 더 많은 연산.
원인이 연산은 CPU core 의 add·multiply·compare 와 본질적으로 같은 숫자 계산이며, data 공급도 필요.
해결GPU 는 높은 FLOP 과 memory hierarchy 전반의 높은 bandwidth 를 갖추게 됨 → 다른 계산에도 활용 가능.
  • vertex = 3D 공간의 점, 이후 단계에서 fragment 로 변환
  • GPU 는 CPU 와 같은 종류의 연산을 훨씬 높은 rate 로 수행
p.4
2.3.1 · p.4 · 5:42
2.48:41–11:04graphics workload 의 특성: throughput 최적화
상황·문제graphics workload 는 task·data 수준의 massive parallelism 을 가짐.
원인사람은 millisecond 단위로 인지, 하드웨어는 nanosecond 단위 → 6 orders of magnitude gap.
해결개별 연산 latency 보다 ms 안에 끝내는 총 연산량(throughput)을 최대화하도록 GPU 를 설계.
  • latency of individual operations 는 덜 중요
  • GPU 는 throughput 최대화에 최적화
p.5
2.4.1 · p.5 · 9:07
2.511:04–12:20graphics pipeline
상황·문제vertex 에서 triangle 을 거쳐 framebuffer(GPU DRAM)에 그림을 얻는 pipeline.
원인오랫동안 쓰인 graphics workload 의 공통 추상화.
해결초기 GPU 는 이 연산만을 위해 만들어졌고, 성능이 커지며 general purpose 용도가 검토됨.
  • framebuffer = GPU 의 DRAM memory
p.6
2.5.1 · p.6 · 11:03
2.5.r.1Wikipedia: Graphics pipeline ↗ · vertex → rasterization → fragment 단계
2.612:20–14:26초기 GPGPU (SIGGRAPH 2004)
상황·문제초기 GPU 는 graphics 연산만 이해해 general purpose 계산에 비친화적.
원인알고리즘을 graphics API 연산으로 다시 표현해야 해 번거롭고 usability 가 제한됨.
해결그래도 physics simulation 등에서 좋은 성능 → CUDA 개발로 이어짐. 1저자 Ian Buck 은 NVIDIA 에서 CUDA 개발에 참여.
  • Buck et al., SIGGRAPH'04
  • graphics 연산으로 위장해 계산 결과를 얻는 방식
p.7
2.6.1 · p.7 · 12:15
2.6.r.1Buck et al., Brook for GPUs (SIGGRAPH 2004) ↗ · 슬라이드 7 의 원 논문 페이지
2.6.r.2Wikipedia: CUDA ↗ · Ian Buck 의 Brook 이 CUDA 로 이어진 과정
2.714:26–19:53CUDA 와 OpenCL
상황·문제GPU 계산을 위한 programming language 가 필요.
원인CUDA 는 C/C++ 에 extension 을 더한 NVIDIA 전용 환경이라 AMD GPU 등에서 못 씀.
해결CUDA: thread 를 대량 생성해 각자 작은 계산, host(CPU)-GPU data 이동·sync·memory 관리는 programmer 가 명시. 대안으로 OpenCL(Apple 시작, Khronos 유지), 최근 AMD ROCm.
  • CUDA 는 heterogeneous architecture 를 지원한 초기 언어
  • OpenCL 은 CUDA 와 실행 모델이 유사하나 용어가 다르고 CUDA 만큼 성공하지 못함
  • CUDA 환경: compiler, runtime, library, emulation, profiling 도구
p.8
2.7.1 · p.8 · 14:26
p.9
2.7.2 · p.9 · 18:05
2.7.r.1Wikipedia: CUDA ↗ · Ian Buck 의 Brook 이 CUDA 로 이어진 과정
2.7.r.2Wikipedia: OpenCL ↗ · Apple 이 시작, Khronos 가 유지하는 표준
2.7.r.3Wikipedia: ROCm ↗ · AMD 의 CUDA 대안 software stack
2.819:53–25:09GPU 성능과 활용: 딥러닝·슈퍼컴퓨터
상황·문제GFLOPS 기준 고성능 GPU 가 CPU 보다 throughput 이 훨씬 큼 (2019년까지 그래프).
원인throughput 이 전부는 아니어서 CPU 에 맞는 task 와 GPU 에 맞는 task 가 따로 있음.
해결두 processor 에 workload 를 나눠 매핑. 딥러닝 성공 3요소 = data, 새 ML 기법, GPU. Summit 에서 GPU 가 peak 의 95% 이상(tensor core FP16 포함 99.7%).
  • Summit: CPU 9,000개 이상, GPU 27,000개 이상
  • top 10 슈퍼컴퓨터 중 6개가 GPU 가속, 1위(Fujitsu)는 ARM CPU 만 사용
  • Google·Amazon·Microsoft·Facebook data center 에서도 사용
p.10
2.8.1 · p.10 · 19:53
p.11
2.8.2 · p.11 · 21:00
p.12
2.8.3 · p.12 · 22:00
2.8.r.1Wikipedia: Summit (supercomputer) ↗ · POWER9 9,216개·V100 27,648개 구성
2.8.r.2Wikipedia: Fugaku ↗ · 강의에서 언급한 Fujitsu ARM 기반, GPU 없는 1위 시스템
2.925:09–32:21CPU vs GPU 설계 목표
상황·문제CPU 와 GPU 는 서로 다른 목적에 최적화됨.
원인CPU 는 single thread latency 최소화(out-of-order, 큰 cache, 복잡한 control). GPU 는 thread 당 latency 보다 massive TLP 로 throughput.
해결GPU 는 수많은 thread 를 hardware 로 penalty 없이 전환해 latency 를 숨김(register 를 core 에 유지). serial 부분은 CPU, parallel 부분은 GPU 로 heterogeneous 실행.
  • SM 당 최대 2,048 thread 동시 실행 (GA100)
  • CPU context switch 는 OS 가 수행해 수백 cycle overhead
  • thread 수는 register·bandwidth 등 자원으로 제한
p.13
2.9.1 · p.13 · 25:12
p.14
2.9.2 · p.14 · 31:50
2.9.r.1Wikipedia: Heterogeneous computing ↗ · 서로 다른 종류의 processor 를 함께 쓰는 구성
2.1032:21–38:32control overhead 최소화: warp·A100 SM·tensor core
상황·문제CPU 는 ALU 를 늘릴수록 활용도를 위해 control logic 도 복잡해짐.
원인GPU 는 같은 instruction 을 여러 thread 가 실행 → control 하나로 여러 ALU 구동.
해결warp(예: 32 thread)=hardware 가 만든 사실상의 SIMD 연산. die area 를 compute 에 투자. A100 SM 에 tensor core(FMA 전용, 256 FMA/cycle).
  • A100: 108 SM, single precision 약 20 TFLOPS, FP16 312 TFLOPS (강의 발언; 슬라이드 원문은 1080 SM)
  • SM 당 tensor core 4개, 두 matrix 곱 + 세 번째 matrix 누산
  • 딥러닝 연산 대부분이 matrix multiply-accumulate
p.15
2.10.1 · p.15 · 32:21
p.16
2.10.2 · p.16 · 34:30
2.10.r.1NVIDIA Blog: NVIDIA Ampere Architecture In-Depth ↗ · A100 108 SM, FP32 19.5 TFLOPS, Tensor 312 TFLOPS, L2 40 MB
2.10.r.2Wikipedia: Volta (microarchitecture) ↗ · tensor core 의 4x4 FP16 matrix FMA 설명
2.10.r.3Wikipedia: Multiply–accumulate operation (FMA) ↗ · FMA = 곱셈 후 누산을 한 번의 rounding 으로
2.1138:32–45:24warp 와 SIMT 실행 모델
상황·문제warp = 같은 instruction 을 다른 data 에 실행하는 thread 집합, common PC 공유.
원인hardware scheduler 가 준비된 warp 중 1~2개를 SIMD pipeline 에 보냄. programmer 는 vector 가 아니라 thread 로 작성(SPMD).
해결SIMT: thread 를 hardware 가 warp 로 묶어 실행. SIMD 대비 thread 별 다른 처리(branch)가 쉬움, warp 를 유연하게 구성.
  • warp 는 직물의 세로 실(textile)에서 유래, OpenCL 은 wavefront
  • resource 할당·scheduling 은 OS 가 아니라 hardware
  • SIMD 는 [VLD,VLD,VADD,VST]+VLEN, SIMT 는 scalar [LD,LD,ADD,ST]+NumThreads
p.17
2.11.1 · p.17 · 38:32
p.18
2.11.2 · p.18 · 40:24
p.19
2.11.3 · p.19 · 43:24
2.11.r.1Wikipedia: Single instruction, multiple threads ↗ · SIMT 와 32-thread warp 개념
2.11.r.2Wikipedia: Single instruction, multiple data ↗ · SIMT 와 대비되는 SIMD 개념
2.1245:24–53:05latency hiding 과 memory hierarchy 비교
상황·문제cache miss 난 warp 는 data 가 올 때까지 block 됨. GPU 는 cache hit rate 가 낮고 GDDR·on-chip 경로 latency 가 김.
원인모든 thread 의 register 가 register file 에 있어 warp 전환에 비용이 없음(fine-grained multithreading).
해결warp 가 충분하면 다른 warp 실행으로 memory latency 를 숨겨 compute 활용도 유지. 대신 GPU 는 bandwidth 집약적이고 per-thread cache 는 작음.
  • 초반 ramp up 구간은 idle cycle 이 생김
  • GPU memory 는 latency 보다 bandwidth 에 최적화 (CPU 는 DDR3/4/5)
  • DRAM bandwidth 1.5 TB/s 수준, A100 cache 40 MB (강의 발언)
p.20
2.12.1 · p.20 · 45:24
p.21
2.12.2 · p.21 · 47:24
p.22
2.12.3 · p.22 · 50:22
2.1353:05–59:58thread 계층: kernel·thread block·grid
상황·문제많은 thread 를 동시에 실행하려면 실행 계층이 필요.
원인warp 는 hardware 개념이라 programmer 에게 노출되지 않음.
해결kernel(GPU 함수) → grid → thread block → thread. block 은 SM 하나에, thread 는 SP 하나에 매핑. launch 때 grid·block 차원 지정, threadIdx·blockIdx 로 data 를 나눔.
  • block(예: 256 thread)은 hardware 가 warp 0, 1, … 로 분할
  • shared memory 는 block 내 thread 가 공유
  • 예: y 방향 2 block × x 방향 3 block, block 당 5×3 thread
p.23
2.13.1 · p.23 · 53:13
p.24
2.13.2 · p.24 · 53:51
p.25
2.13.3 · p.25 · 56:10
p.26
2.13.4 · p.26 · 57:28
2.13.r.1Wikipedia: Thread block (CUDA programming) ↗ · grid·block·warp 계층과 threadIdx/blockIdx 인덱싱
2.1459:58–1:04:07thread block 은 독립적이어야 함
상황·문제block·thread 의 실행 순서는 알 수 없음.
원인block 간 synchronization(공유 lock)은 deadlock 을 쉽게 유발.
해결block 간 coordination 은 shared variable + atomic operation(shared queue pointer 는 OK)으로. atomic 남용은 serialization 병목.
  • 예: 1 million 개 숫자 합산을 여러 block 이 atomic 으로 누적
  • 독립성 덕분에 성능이 잘 scale
  • grid 전체가 GPU 하나에서 실행
p.27
2.14.1 · p.27 · 1:01:50
p.28
2.14.2 · p.28 · 1:03:52
2.151:04:07–1:10:25CUDA memory space 와 memory model
상황·문제GPU 는 register 와 memory 뿐인 CPU 보다 memory space 가 복잡.
원인register·local(thread 전용), shared(block 내, programmer 관리 on-chip scratchpad), global(모든 thread), constant·texture(GPU 는 read only).
해결host 는 global·constant·texture 만 접근. CPU↔GPU data 는 cudaMemcpy 로 명시적으로 복사(GPU 0/1 지정 가능).
  • shared memory 는 cache 와 달리 programmer 가 global 에서 직접 복사
  • texture memory 는 graphics 용이라 GPGPU 에선 무시 가능
  • thread 간 통신은 global 또는 shared memory 로
p.29
2.15.1 · p.29 · 1:04:07
p.30
2.15.2 · p.30 · 1:09:42
2.15.r.1NVIDIA CUDA C++ Best Practices Guide ↗ · memory space(shared/global/constant/texture/local)와 cudaMemcpy 전송
2.15.r.2Wikipedia: Scratchpad memory ↗ · CUDA shared memory 를 scratchpad 로 설명
2.161:10:25–1:13:50질의응답·출석 확인
상황·문제질문: thread block 하나를 SM 두 개에 나눠 실행할 수 있나 → 불가, block 하나는 SM 하나에만 매핑. 이후 출석 확인.
2.171:13:50–1:18:34C for CUDA 문법
상황·문제CUDA 는 C/C++ 에 최소한의 extension 만 추가.
원인host(CPU)와 device(GPU) 코드, memory 위치, launch 구성을 구분해야 함.
해결__global__(CPU 가 호출, GPU 실행), __device__(GPU 내부 호출), __constant__/__shared__, <<<grid_dim, block_dim>>> 로 launch, __syncthreads() 는 block 내 sync 만.
  • dim3 grid_dim(100, 50) → 5,000 block, dim3 block_dim(4, 8, 8) → block 당 256 thread
  • blockIdx.x/.y/.z, threadIdx 로 ID 참조
  • vector 예제는 다음 시간(Thursday)으로
p.31
2.17.1 · p.31 · 1:13:50
2.17.r.1CUDA — Wikipedia ↗ · CUDA programming model 개요

3핵심 개념

3.1GPGPU(범용 GPU 컴퓨팅)
graphics 용 GPU 로 병렬성이 충분한 일반 계산을 수행.
3.1.r.1Wikipedia: General-purpose computing on GPUs ↗ · GPGPU 역사, CUDA·OpenCL 개요
3.2CUDA
NVIDIA 의 C/C++ 기반 GPU programming 언어·환경. NVIDIA 전용.
3.2.r.1Wikipedia: CUDA ↗ · Ian Buck 의 Brook 이 CUDA 로 이어진 과정
3.3OpenCL
Apple 이 시작, Khronos 가 유지하는 royalty-free 병렬 표준. CUDA 와 모델 유사.
3.3.r.1Wikipedia: OpenCL ↗ · Apple 이 시작, Khronos 가 유지하는 표준
3.4throughput(처리량) vs latency(지연)
GPU 는 개별 연산 latency 보다 ms 안에 끝내는 총 연산량을 최대화.
3.5heterogeneous computing(이종 컴퓨팅)
serial 부분은 CPU, parallel 부분은 GPU 로 나눠 실행.
3.5.r.1Wikipedia: Heterogeneous computing ↗ · 서로 다른 종류의 processor 를 함께 쓰는 구성
3.6SM(streaming multiprocessor, 스트리밍 멀티프로세서)
GPU core 묶음. thread block 하나는 SM 하나에만 매핑.
3.6.r.1NVIDIA Blog: NVIDIA Ampere Architecture In-Depth ↗ · A100 108 SM, FP32 19.5 TFLOPS, Tensor 312 TFLOPS, L2 40 MB
3.7tensor core(텐서 코어)
matrix FMA 전용 unit. A100 에서 256 FMA/cycle, SM 당 4개.
3.7.r.1Wikipedia: Volta (microarchitecture) ↗ · tensor core 의 4x4 FP16 matrix FMA 설명
3.7.r.2Wikipedia: Multiply–accumulate operation (FMA) ↗ · FMA = 곱셈 후 누산을 한 번의 rounding 으로
3.8warp(워프)
같은 instruction 을 실행하는 thread 집합(32), common PC. OpenCL 은 wavefront.
3.8.r.1Wikipedia: Single instruction, multiple threads ↗ · SIMT 와 32-thread warp 개념
3.9SIMT(single instruction multiple thread)
thread 로 programming(SPMD), hardware 가 warp 로 묶어 SIMD 처럼 실행.
3.9.r.1Wikipedia: Single instruction, multiple threads ↗ · SIMT 와 32-thread warp 개념
3.10fine-grained multithreading(FGMT, 세밀한 멀티스레딩)
register 를 register file 에 유지해 warp 를 cycle 단위로 바꿔 latency 를 숨김.
3.11thread block(스레드 블록)·grid(그리드)
programmer 가 지정하는 thread 묶음과 그 묶음. block 은 서로 독립이어야 함.
3.11.r.1Wikipedia: Thread block (CUDA programming) ↗ · grid·block·warp 계층과 threadIdx/blockIdx 인덱싱
3.12atomic operation(원자적 연산)
block 간 shared variable 갱신용 (atomicAdd 등). 과용 시 serialization.
3.13shared memory(공유 메모리)
block 내 thread 가 공유하는 on-chip scratchpad, programmer 가 직접 관리.
3.13.r.1Wikipedia: Scratchpad memory ↗ · CUDA shared memory 를 scratchpad 로 설명
3.14cudaMemcpy
host(CPU) memory 와 device(GPU) memory 사이 명시적 복사 함수.
3.14.r.1NVIDIA CUDA C++ Best Practices Guide ↗ · memory space(shared/global/constant/texture/local)와 cudaMemcpy 전송

4스스로 확인

4.1GPU 가 개별 연산 latency 를 덜 중시해도 되는 이유는?
답
사람은 ms 단위로 인지, 하드웨어는 ns 단위라 6 orders of magnitude 여유가 있어 throughput 이 중요.
4.2GPU 의 context switch 가 사실상 무료인 이유는?
답
모든 thread 의 register 값이 core 의 register file 에 남아 있어 memory 로 옮길 필요가 없고 hardware 가 전환.
4.3warp 와 thread block 의 차이는?
답
thread block 은 programmer 가 지정, warp(32 thread)는 hardware 가 block 을 나눈 단위로 programmer 에 노출되지 않음.
4.4block 간 lock 을 쓰면 안 되는 이유와 대안은?
답
block 실행 순서를 알 수 없어 deadlock 위험. atomic operation 으로 shared variable 을 갱신.
4.5host 가 접근할 수 있는 GPU memory space 는?
답
global, constant, texture memory. register·local·shared 는 불가.
4.6dim3 grid_dim(100, 50), block_dim(4, 8, 8) 의 block·thread 수는?
답
5,000 block, block 당 256 thread.

5참고 자료

5.1Wikipedia: General-purpose computing on GPUs ↗ · GPGPU 역사, CUDA·OpenCL 개요
5.2Wikipedia: CUDA ↗ · Ian Buck 의 Brook 이 CUDA 로 이어진 과정
5.3NVIDIA Blog: NVIDIA Ampere Architecture In-Depth ↗ · A100 108 SM, FP32 19.5 TFLOPS, Tensor 312 TFLOPS, L2 40 MB
5.4Wikipedia: Single instruction, multiple threads ↗ · SIMT 와 32-thread warp 개념
5.5Wikipedia: Thread block (CUDA programming) ↗ · grid·block·warp 계층과 threadIdx/blockIdx 인덱싱
5.6NVIDIA CUDA C++ Best Practices Guide ↗ · memory space(shared/global/constant/texture/local)와 cudaMemcpy 전송

7한국어판 강의자료

단축키
Ctrl K · s자료 검색
[ ]이전·다음 강의
Space영상 재생·정지
j k다음·이전 section
n p다음·이전 slide
b강의 목록 접기·펴기
t맨 위
/강의 검색
Esc닫기