﻿# cuRAND Philox replay requires a sample-to-state map, not only a seed

Understand Philox subsequences, distribution draw consumption, persistent device state, and why a changed CUDA thread layout can change a seeded simulation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-curand-philox-state-logical-sample-mapping/
Language: en

## A seeded test changes after retuning

Consider a sampling kernel whose block layout changes during optimization. The application keeps its seed, but generated values are now attached to different simulation paths. This does not immediately establish a generator defect. The first question is which logical path owns each random state, and whether that ownership survived the launch change.

The [device API overview](https://docs.nvidia.com/cuda/curand/device-api-overview.html) discussed here concerns the legacy cuRAND device API. Its stateful interface must be distinguished from separately documented generator systems.

## Philox initialization identifies a position

For `curandStatePhilox4_32_10_t`, `curand_init` receives a seed, subsequence, and offset. The [device reference](https://docs.nvidia.com/cuda/curand/group__DEVICE.html) specifies the generator-specific overload. Treat that tuple as initialization metadata, not as a complete description of the application experiment.

A useful application design assigns subsequences to stable simulation identities. Mapping them directly to transient physical thread positions is convenient, but a later batching or sharding change can alter which identity receives which stream. Document that mapping alongside the seed.

## Output counts do not define draw schedules

Distribution calls advance generator state. The overview explicitly warns that their consumption of underlying generator values is not generally fixed. Consequently, counting returned samples is insufficient to reconstruct the internal offset after an arbitrary sequence of distribution calls.

Vector functions such as `curand_uniform4` also have their own contract. Replacing scalar calls with a vector call should be treated as a replay-sensitive algorithm change until equivalence is established for the actual implementation. Do not infer matching streams merely from an equal number of output values.

## Preserve ownership across launches

A kernel can load its assigned state, generate values, and write the updated state back. Reinitializing that state on every launch instead restarts from the initialization position. Accidentally doing so can repeat samples while producing perfectly plausible histograms.

For a regression case, record the logical identity, initialization tuple, requested distribution sequence, and persisted state lifecycle. The broader [RNG replay guide](/journal/data-guide-data-rng-state-replay/) explains why process-level seed capture alone is incomplete.

## Version records and useful comparisons

The [compatibility statement](https://docs.nvidia.com/cuda/curand/compatibility-and-versioning.html) describes source compatibility; this should not be promoted into an unrestricted bitwise replay promise across versions. Record the actual headers, toolchain, and executable artifact used by the experiment.

Compare values by logical simulation identity before comparing aggregate statistics. Only after that mapping is understood should an [inference benchmark](/journal/inference-benchmark-method/) attribute a changed result to a faster launch configuration. These checks describe an experiment design, not measured performance of a particular deployment.
