CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 20 - GPUs

Chris Fletcher
UC Berkeley, Spring 2026

Types of Parallelism

ILPTLPDLP
Easiest to program✅ sequential code❌ explicit sync, races✅ for regular arrays
Most flexible✅ unrelated/irregular programs
Most efficient (tasks/s/area, energy/task)✅ one fetch drives many units

From Graphics to GP-GPUs

GPGPUs in a Nutshell

Weaving: the warp is the parallel threads in lockstep; the weft is the instruction sequence across them.

DAXPY: C vs. CUDA

void daxpy(int n, double a,
           double *x, double *y) {
  for (int i = 0; i < n; i++)
    y[i] = a * x[i] + y[i];
}
// host
int nblocks = (n + 255) / 256;
daxpy<<<nblocks, 256>>>(n, 2.0, x, y);

// device: run by every µthread
__device__
void daxpy(int n, double a,
           double *x, double *y) {
  int i = blockIdx.x * blockDim.x
        + threadIdx.x;
  if (i < n) y[i] = a * x[i] + y[i];
}

Hardware Execution Model

Costs of the SIMT illusion

Check Your Understanding

1. 128 threads per block, n = 300. How many blocks, and how many threads in the last block are disabled?
⌈300/128⌉ = 3 blocks (384 threads). The last block covers 256–383, so 84 are off.
2. Why do GPUs need dynamic coalescing hardware when the Cray-1 didn't?
Vector ISAs have explicit unit-stride/strided loads. In SIMT each µthread issues its own scalar access, so hardware must merge a warp's addresses at run time.

SIMT Warp Scheduling

GPU Memory Hierarchy

LevelScope
Private local memoryPer thread (spills, private stack)
Shared memoryPer block: fast on-chip scratchpad for cooperation
Global memoryPer application: off-chip DRAM, all blocks

Conditionals and Branch Divergence

DAXPY in PTX (parameter loads trimmed):

mad.lo.s32         %r1, %r3, %r4, %r5;     // i = blockIdx.x*blockDim.x + tid
setp.ge.s32        %p1, %r1, %r2;          // i >= n ?
@%p1 bra           $L__BB0_2;
mul.wide.s32       %rd5, %r1, 8;           // byte offset
ld.global.f64      %fd2, [%rd6];           // x[i]
ld.global.f64      %fd3, [%rd7];           // y[i]
fma.rn.f64         %fd4, %fd1, %fd2, %fd3; // a*x[i] + y[i]
st.global.f64      [%rd7], %fd4;
$L__BB0_2: ret;

Divergent if-else: PTX and B300 SASS

if (X[i] != 0)
  X[i] = X[i] - Y[i];
else
  X[i] = Z[i];
  • PTX: plain branches, no masks
  • SASS: BSSY opens barrier B1 and names the rejoin address
  • BSYNC B1: threads meet, then run shared code together
  • Nested loops use B0, B2
// PTX
setp.eq.f64   %p2, %fd1, 0d0000000000000000;
@%p2 bra      $L__BB1_3;        // else path
ld.global.f64 %fd3, [%rd12];    // then: Y[i]
sub.f64       %fd4, %fd1, %fd3;
st.global.f64 [%rd1], %fd4;
bra.uni       $L__BB1_4;
$L__BB1_3:
ld.global.f64 %fd2, [%rd9];     // else: Z[i]
st.global.f64 [%rd1], %fd2;
$L__BB1_4: ret;
// SASS, with shared work after the if-else
BSSY.RECONVERGENT B1, 0x1b70     // open B1
DSETP.NEU.AND P0, PT, R24, RZ, PT
@P0 BRA 0xe40                    // split
...                              // both paths
BSYNC.RECONVERGENT B1            // rejoin
STG.E.64 desc[UR6][R6.64], R24   // whole warp

NVIDIA Blackwell B300

ResourceB300
Compute capability10.3 (sm_103)
SMs148
Registers per SM65,536 × 32b (256 KB)
Threads per SM2,048 (64 warps), ≤ 32 blocks
Threads per block1,024
Shared memory per SM228 KiB (227 KiB per block)
L2126.5 MiB
HBM~268 GiB, 7,680-bit interface
Max SM clock / power2,032 MHz / 1,100 W
  • Huge register file: up to 64 warps stay resident, switched every cycle with no save/restore
  • Registers often cap occupancy: 64 regs/thread → 1,024 threads (32 warps) per SM
  • 8 GPUs per node, all-to-all NVLink (18 links per GPU into a switched fabric)

Tensor Cores and Tensor Memory

Check Your Understanding

1. A B300 SM has 65,536 registers and holds ≤ 2,048 threads. At 128 registers per thread, how many warps fit, and why is the register file so large?
512 threads = 16 warps. Vertical multithreading keeps every resident warp's state on chip so the scheduler switches every cycle with no save/restore.
2. 31 threads take THEN and 1 takes ELSE. How many paths run, and where do threads rejoin in B300 SASS?
Both paths, one after the other. They rejoin at BSYNC.RECONVERGENT B1, closing the barrier opened by BSSY.RECONVERGENT B1.