What is GPU shared memory?

Small, fast memory inside each GPU SM that threads of the same block can share. The program decides what is stored there.

Field: GPU Programming

Japanese name: シェアードメモリ

Basic use and tiling

In CUDA a variable is declared with __shared__, and the storage exists only while the block runs. The classic use is tiled matrix multiplication: the threads of a block cooperatively load a small tile of each matrix from global memory into shared memory, wait at __syncthreads() until everyone has finished, and then reuse the tile many times. With a tile of side T, global-memory reads drop to roughly 1/T. Convolutions, reductions and matrix transposes use it as well.

Capacity and how many blocks can run

Shared memory is a limited per-SM resource, and on many GPUs it shares the same storage as the L1 cache, with a configurable split. A block that uses a lot of shared memory reduces how many blocks can reside on an SM at once, weakening the GPU's ability to hide memory latency. Shared memory is also divided into 32 banks; if threads in a warp access different addresses in the same bank, the accesses are serialized (a bank conflict). Padding an array by one extra column is a common fix.

Confusing names

OpenCL calls the equivalent memory "local memory", and AMD GPUs call it the LDS (Local Data Share). CUDA's own "local memory", by contrast, is per-thread storage for variables that do not fit in registers; it physically resides in DRAM, is slow and is something else entirely. The term also differs from operating-system shared memory, where several processes map the same memory region, and from shared-memory multiprocessors, so context matters.

Try it: questions about GPU shared memory

What is a characteristic of CUDA shared memory?

  1. AA large main memory shared by all GPUs and the CPU
  2. BAn area where GPU memory is shared with the hard disk
  3. CA small, fast on-chip memory shared by threads of the same block and managed explicitly by the program
Show answer and explanation

Answer: C. A small, fast on-chip memory shared by threads of the same block and managed explicitly by the program

Shared memory is fast memory inside each SM, tens to a few hundred KB per block depending on the GPU, and can be read and written much faster than global memory (the GPU's DRAM). Threads in the same block can place and share data in it, so it is used to load data from global memory once and reuse it many times, or to pass intermediate results between threads. Unlike a cache, the program decides what goes there.

Which describes a bank conflict in CUDA shared memory?

  1. ATwo GPUs using the same bank account
  2. BRunning out of shared memory capacity so the program stops
  3. CShared memory is split into 32 banks, and when several threads of a warp access different addresses in the same bank at once, the accesses are serialized
Show answer and explanation

Answer: C. Shared memory is split into 32 banks, and when several threads of a warp access different addresses in the same bank at once, the accesses are serialized

Shared memory consists of 32 banks assigned in rotation every 4 bytes, and each bank can serve only one address per access. If the 32 threads of a warp use different banks, one access suffices, but two threads hitting different addresses in the same bank split it into two. Reading every 32nd 4-byte element, for example, piles all threads onto one bank and splits the access into 32. When all threads read the same address, it is broadcast and there is no conflict.

Books on GPU Programming Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary