Seyed Masoud Hosseini · Overview · Study log · Ideas · Transcript · RSS feed

Parallel Computing & CUDA · Lecture 19 of 19 · 1:08:18

Lecture 19: Accessing Memory + Course Wrap Up

Stanford CS149 I Parallel Computing I 2023 I Lecture 19 - Accessing Memory + Course Wrap Up on YouTube

Study guide

What this lecture covers

This final lecture of the course opens up a topic the class had treated abstractly until now: how DRAM actually works underneath the cache hierarchy. It explains why memory access time is not fixed, walking through the physical steps a DRAM chip takes to turn stored charge into bits on a bus, and then shows how techniques like banking, interleaving and stacked high-bandwidth memory hide that latency and multiply bandwidth. This builds directly on the course's recurring theme that parallelism is comparatively easy while getting data to processors efficiently is the hard problem.

The second half is a more informal wrap-up and audience Q&A. The instructor summarizes the course's big lessons about specialization and scheduling, describes a research project that parallelizes game-engine simulation for AI training, and gives practical advice on choosing next courses, getting involved in research, and navigating early career decisions at Stanford. After watching, you should be able to explain why DRAM access patterns matter for bandwidth and describe the main techniques (bulk transfers, bank pipelining, request reordering, stacked memory) used to make memory systems efficient.

Key ideas

  • DRAM access time is variable: unlike a simple mental model of "memory," accessing a DRAM chip takes different amounts of time depending on whether the requested data is already staged in the chip's row buffer.
  • Reading data is a multi-step process: precharge (readying bit lines), row activation (copying a row's charge into the row buffer, which destroys the original value), and column selection (reading specific bytes out of the row buffer onto the data pins).
  • Row buffer locality is fast, row switches are slow: a second access to the same open row only needs a column selection; switching to a different row requires writing the current row back first, then precharging and activating the new one.
  • Banks enable pipelining: a DRAM chip replicates its array, row buffer and control logic into multiple banks so the controller can precharge and activate one bank while transferring data from another, hiding much of the latency.
  • Interleaving and channels multiply bandwidth: striping consecutive bytes of a cache line across multiple DRAM chips (and using multiple memory channels) lets a system use its full bus width instead of bottlenecking on one chip's eight data pins.
  • The memory controller reorders requests: it buffers cache misses from multiple cores or applications and reorders them to maximize row-buffer hits and bank-level pipelining, trading some latency for higher bandwidth.
  • Stacked, high-bandwidth memory shortens the physical distance: placing DRAM dies directly on the same package as the processor, connected via through-silicon vias, allows far wider buses (thousands of bits) and much higher bandwidth than a conventional board-level memory bus.
  • The course's overall lesson: identifying parallelism is usually the easy part; scheduling that parallelism and moving data efficiently is where most of the difficulty and payoff lie, and specialization can make otherwise inefficient software dramatically faster.

Walkthrough

Why DRAM access time isn't fixed (0:05)

The lecture reframes memory as a physical array of capacitor-based cells on a DRAM chip, each storing a bit as a voltage. It introduces the basic structure: a limited number of data pins (commonly eight per chip) and a row buffer that temporarily holds one row's worth of bits. Because the chip can only expose data that has been copied into the row buffer, access time depends heavily on whether the requested byte is already there.

Reading a row: precharge, activate, column select (6:11)

The lecture details the three-step process for reading data: precharging the bit lines to a known voltage (about 10 nanoseconds), activating the target row to copy its charge into the row buffer (another roughly 10 nanoseconds, which destructively reads the original cells), and then selecting the desired columns to move those bits onto the memory bus. A follow-up point clarifies that reading an adjacent byte in the same row is much faster, since it skips precharge and activation and only needs a new column selection, while switching to a different row requires writing the current row's data back first.

Pipelining across banks and using bulk transfers (13:18)

A class discussion identifies that memory bus utilization is low if only a fraction of each transfer's cycles are used, and works toward two standard fixes: bulk, contiguous transfers that amortize overhead, and pipelining latency by working on multiple requests at once. The lecture explains that DRAM chips implement pipelining by replicating their array, row buffer and pins into separate banks, so the controller can precharge and activate one bank while transferring data from another. Interleaving addresses across banks and across multiple chips in a DIMM (dual in-line memory module) lets a 64-bit bus be built from several 8-bit chips, and striping consecutive bytes across them is what makes a full cache-line transfer efficient.

The memory controller schedules requests (26:35)

The lecture explains that the memory controller receives cache misses from potentially many cores and applications, buffers them, and reorders them to maximize row-buffer hits and bank-level pipelining rather than serving them strictly in arrival order. This trades some added latency for higher achievable bandwidth, which matters more for bandwidth-bound systems like GPUs than for latency-sensitive real-time workloads. The lecture also covers how DDR (double data rate) memory sends data on both the rising and falling clock edges, and how dual-channel configurations double bandwidth by running two independent buses in parallel; it briefly notes that extra memory chips are sometimes added purely for error-correcting redundancy.

Stacked, high-bandwidth memory (35:45)

To go beyond what board-level wiring can support, the lecture describes stacking DRAM dies directly on the same silicon package as the processor, connected through vertical through-silicon vias instead of board traces. This shortens the physical distance data must travel, making it economical to build memory buses thousands of bits wide instead of 64 bits, at the cost of limited total capacity (a fixed number of gigabytes) compared to conventional DRAM reached over a traditional bus. The lecture connects this directly to the course's earlier flash attention assignment, noting that the optimization was partly designed to keep intermediate matrices inside this smaller, much faster stacked memory rather than spilling to conventional DRAM.

Course wrap-up: lessons, a research example, and next steps (41:51)

The lecture closes with a summary of recurring course themes: most modern devices are heterogeneous multi-core systems, well-optimized code can be dramatically faster than naive code (citing the course's own SIMD and specialized-hardware assignments), and identifying parallelism is usually easier than scheduling it or getting data to processors efficiently. As an example of applying these ideas, the instructor describes a lab project that rewrote game-engine simulation to run thousands of reinforcement-learning training environments in lockstep on a single GPU, replacing large GPU clusters and cutting some training runs from hours to seconds. The remainder is informal advice on follow-on courses, how to get involved in research, and general guidance on early-career decisions, offered as practical next steps for students finishing the course.

Before you watch

  • Review how the cache hierarchy and cache misses work, since this lecture picks up right where a last-level cache miss hands off to the memory controller.
  • Recall the course's flash attention assignment; the lecture references it directly when explaining stacked high-bandwidth memory.
  • No new algorithmic prerequisites are needed for the wrap-up and Q&A portion.

Check your understanding

  1. Why does accessing a different row in the same DRAM chip take longer than accessing more data from the currently open row?
  2. What are precharge, row activation and column selection, and what does each step accomplish?
  3. How do banks and interleaving let a memory system pipeline requests and use its full bus width?
  4. What tradeoff does a memory controller make when it buffers and reorders cache-miss requests?
  5. Why does stacking DRAM directly on the processor package allow much wider, higher-bandwidth memory buses?

From the YouTube description

How DRAM works, suggestions for post-cs149 topics

To follow along with the course, visit the course website:
https://gfxcourses.stanford.edu/cs149/fall23/

Kayvon Fatahalian
Associate Professor of Computer Science, Stanford University
https://graphics.stanford.edu/~kayvonf/

Kunle Olukotun
Cadence Design Systems Professor, Professor of Electrical Engineering and of Computer Science, Stanford University
https://engineering.stanford.edu/people/oyekunle-olukotun

Learn more about the online course and how to enroll: https://online.stanford.edu/courses/cs149-parallel-computing

To view all online courses and programs offered by Stanford, visit: https://online.stanford.edu/

← Lecture 18: Hardware Specialization