﻿# CUDA grid-constant parameters: shared parameter identity is not writable shared memory

Understand __grid_constant__ parameter address identity, const requirements, grid lifetime, and declaration consistency before replacing per-thread parameter handling.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-cuda-grid-constant-parameter-address-lifetime/
Language: en

## Identify the parameter object

The [CUDA language extensions](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html) describe `__grid_constant__` for a const-qualified, non-reference kernel parameter. Threads in the grid observe the same parameter-object address. This concerns the identity and handling of the parameter object itself, rather than making every pointer reachable from that object refer to another memory space. Keep the object-level promise separate from the allocation and access rules of data referenced by its fields.

## Understand why taking an address matters

The [archived programming guide](https://docs.nvidia.com/cuda/archive/12.9.1/cuda-c-programming-guide/index.html#grid-constant) explains the annotation in the context of avoiding a per-thread parameter copy when an address is used. A helper receiving a parameter reference should therefore be analyzed against the chosen declaration and compiler behavior. Do not infer cost merely from source syntax: inspect generated code and resource information when deciding whether the parameter path created thread-local storage in the actual build.

## Preserve read-only and lifetime requirements

The annotated object is private to the kernel grid and has kernel lifetime. Modifying it, including mutable subobjects, is not supported by the documented contract. It is not a substitute for writable block shared memory or a persistent object that another kernel can retain by saving its address. All declarations and template specializations must agree about the annotation. A header and implementation that express different parameter contracts should be corrected before treating a successful build variant as a valid portable interface.

## Separate parameter transport from measured benefit

The [NVIDIA large-parameter article](https://developer.nvidia.com/blog/cuda-12-1-supports-large-kernel-parameters/) demonstrates read-only annotated parameter bundles and discusses a particular toolkit-era transport improvement. Those examples do not establish a universal speedup for any descriptor size or kernel. Consider a kernel passing a read-only operation descriptor to an out-of-line helper: compare its actual local-memory use and end-to-end runtime before and after the annotation while preserving the same computation.

## Record the parameter contract explicitly

Keep object type, qualifiers, declarations, helper interfaces, compiler target, and observed resource usage. Guides to [kernel launch granularity](/journal/learn-kernel-launch-granularity/) and [GPU acceptance evidence](/journal/gpu-acceptance-evidence/) provide context. Verify object lifetime and mutation assumptions first. The useful optimization preserves a well-defined parameter interface and demonstrates its effect in the compiled kernel, rather than interpreting shared address identity as permission to write, communicate across kernels, or assume another storage class.
