What is Constant memory?
In CUDA, a small region for values that do not change during a kernel. Reads are faster the fewer distinct addresses the threads of a warp read, and fastest when every thread reads the same address.
Japanese name: 定数メモリ
In CUDA, a small region for values that do not change during a kernel. Reads are faster the fewer distinct addresses the threads of a warp read, and fastest when every thread reads the same address.
Japanese name: 定数メモリ
CUDA constant memory is a region that a kernel can only read. Its values are either fixed at compile time or written by the host program before the kernel is launched. A variable is declared outside any function with the __constant__ specifier. The capacity is small, so it does not suit large data. The values written remain available across kernel launches.
According to the CUDA guides, each SM has a read-only cache for constant memory. When every thread of a warp reads the same address, the read can be about as fast as reading a register. When the threads of a warp read different addresses, the reads are carried out one address after another. The cost grows in proportion to the number of distinct addresses the warp reads. If 32 threads read the same address, that is 1 address; if all 32 differ, it is 32.
It suits data whose values are used by all threads alike. Examples are the coefficients of an image filter and the parameters of a simulation. It does not suit tables in which each thread looks up a different place. OpenCL also has constant memory, defined as a region that does not change while a kernel executes. In OpenCL, the host allocates and initializes this region.
Answer: A. When all threads of a warp read the same address (one read is broadcast to all)
Constant memory is a small region that does not change during a kernel and has its own cache. When every thread in a warp reads the same address, one read is broadcast to all of them, which is very fast. It suits values every thread uses, such as image filter coefficients or simulation parameters. Scattered addresses split the reads and make it slower instead.
No. In CUDA it is read-only from device code. To change a value, the host program writes to it.
They are used differently. Shared memory is a per-block work area that is read and written while the kernel runs. Constant memory is read-only, and every thread sees the same contents.
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.