﻿# Read shared-memory carveout as a preference rather than an exact partition

Treat shared-memory carveout as an architecture-dependent preference, separate from allocation and any measured cache tradeoff.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-perf-shared-carveout-hint/
Language: en

A tuning experiment requests a shared-memory carveout percentage and assumes the remaining on-chip capacity is an exact cache partition. CUDA documents the function setting as a preference. Interpret its scope and the target architecture before attributing a timing change to a precise physical split that the application did not actually establish.

## Identify the shared resource

On applicable architectures, shared memory and cache capacity draw from a related on-chip resource. This is separate from global device memory and an application's KV-cache allocation. Increasing a scratchpad preference does not reserve more model-weight VRAM. Name the hardware resource and function affected so that similarly named application caches do not enter the explanation.

## Read the hint contract

cudaFuncAttributePreferredSharedMemoryCarveout expresses a shared-memory preference as a percentage on supported devices. The driver can choose a different ratio when required to execute the function. Therefore, a successful API return confirms an accepted request, not a promise that a continuously variable physical partition equals the requested percentage. Keep the requested setting separate from observed execution resources.

## Check architectural choices

Architecture tuning guides describe supported carveout capacities rather than an arbitrary byte-by-byte partition. Use the guide for the actual target and inspect applicable device and function attributes. Do not transfer a capacity table between architectures or infer an exact cache size by subtracting a requested percentage from an unrelated marketing total.

## Separate allocation from preference

The function's dynamic shared-memory allowance and the launch's requested bytes remain distinct controls. A carveout preference does not replace an explicit allocation contract or correct an oversized launch. First establish that the kernel's storage requirements and launch are valid. Only then can a preference experiment address the balance between scratchpad capacity, residency and cache behavior.

## Compare a meaningful workload

Use the same kernel, input distribution and valid outputs while varying only a justified preference. Inspect launch resources and cache-related evidence alongside normal execution time. A gain for a reuse-heavy tile can change when a different shape relies more on cache locality. Record the target and workload with the result. The conclusion is an observed tradeoff under a hint contract, not a universally optimal partition or guaranteed application speedup.

## Primary references

[CUDA Runtime Execution Control](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__EXECUTION.html).

[NVIDIA Ampere Architecture Tuning Guide](https://docs.nvidia.com/cuda/ampere-tuning-guide/index.html).

[CUDA Runtime Device Management](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__DEVICE.html).

Related reading: [Shared-memory bank conflicts: why padding can change access](/journal/learn-shared-memory-bank-conflicts/); [GPU occupancy and register pressure: a coupled resource decision](/journal/learn-occupancy-register-pressure/).
