﻿# Check legacy default-stream ordering in mixed CUDA code

Check per-compilation-unit default-stream settings and preserve explicit data dependencies before changing hidden CUDA ordering.

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

A library helper serializes otherwise independent CUDA work after a rebuild. One compilation unit may use legacy default-stream behavior while another expects a per-thread default stream. Read the compiled contract and actual stream arguments before adding more streams or removing a dependency that the program previously relied on implicitly.

## Identify implicit stream operations

Trace helper calls that omit a stream or pass the default handle. Include library wrappers and memory operations, not only visible kernel launches. Record the relevant CUDA context. An explicit stream in the outer serving loop does not establish that every internal operation uses it, and an innocent diagnostic can introduce default-stream work between unrelated submissions.

## Recover compilation-unit settings

CUDA documents default-stream selection per compilation unit through the compiler option or applicable pre-header definition. A top-level build intention does not retroactively change a prebuilt dependency's contract. Preserve compiler commands and library provenance. Mixing components can therefore change ordering even when source-level calls still look identical to the previous release.

## Read the legacy relationship

The documented legacy default stream synchronizes with blocking streams in the same context. Streams created as nonblocking have a different relationship. Per-thread default streams also have specific interaction with an explicitly used legacy stream. Avoid reducing this to a rule that every stream is always independent or that default-stream behavior necessarily means the host blocked at the call.

## Keep true data dependencies

Removing implicit serialization can expose a race if the application accidentally depended on it. Draw the actual producer, consumer and buffer-reuse requirements before changing build settings or flags. Use supported explicit dependencies for needed relationships. A faster trace with wrong data is not evidence that the original synchronization was merely avoidable overhead.

## Compare a mixed-component fixture

Use an isolated harmless pair of translation units with recorded settings and independent checked work. Observe the intended ordering, then compare a deliberately explicit dependency path for shared data. Acceptance connects the behavior to the compiled stream contract. It does not guarantee overlap on saturated hardware, certify every prebuilt library or justify globally changing default-stream mode without validating the application's previous implicit dependencies.

## Primary references

[CUDA Default-stream Synchronization](https://docs.nvidia.com/cuda/cuda-runtime-api/stream-sync-behavior.html).

[CUDA Compiler Driver Options](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/).

[CUDA Asynchronous Execution](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/asynchronous-execution.html).

Related reading: [CUDA streams: express dependencies before asking for overlap](/journal/learn-stream-ordering-dependencies/); [CUDA event dependencies: connecting producer and consumer streams](/journal/learn-cross-stream-event-dependency/).
