0Pricing
CUDA Academy · Lesson

The Default Stream Trap

How stream 0 serializes everything.

The Default Stream Trap is a free CUDA Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is a Stream?

A stream is an ordered queue of GPU work. Operations in the same stream run one after another, in the order you issued them. ⏳

The Default Stream

If you never name a stream, every call lands in the default stream, also called stream 0. It is where all your work has secretly been running.

Why It Is a Trap

The default stream is synchronizing: it blocks until other streams finish, and they wait for it. Nothing overlaps, so your GPU sits idle between steps.

Everything Serializes

Issue a copy, a kernel, then another copy on stream 0 and they run strictly back to back. The GPU can never start step two before step one ends.

cudaMemcpy(d_a, h_a, n, cudaMemcpyHostToDevice);
kernel<<<grid, block>>>(d_a);
cudaMemcpy(h_a, d_a, n, cudaMemcpyDeviceToHost);

Wasted Hardware

Modern GPUs have separate engines for compute and for copying. On the default stream those engines take turns instead of working together.

The Hidden Cost of Copies

Data transfers over PCIe are slow. When copies cannot overlap with compute, that transfer time is added directly onto your total runtime.

Implicit Synchronization

Many default-stream calls are blocking on the host too. cudaMemcpy returns only after the copy is done, stalling your CPU.

The Legacy Behavior

By default, work in any stream waits for stream 0, and stream 0 waits for them. This legacy rule quietly destroys concurrency you thought you had.

A Telltale Profile

In a profiler the default-stream trap shows up as a single busy lane with gaps, while copy and compute engines sit idle waiting for each other.

The Way Out

The fix is to issue independent work on separate streams. Then copies and kernels can run at the same time and fill those idle gaps.

Per-Thread Default Streams

Compiling with --default-stream per-thread gives each host thread its own default stream, easing the trap without rewriting every call.

nvcc --default-stream per-thread app.cu -o app

Quick Check

Why does putting all work on the default stream hurt performance?

Recap

The default stream serializes your GPU work and blocks overlap. To go faster, you will move independent tasks onto their own streams next. 🚀

Frequently asked questions

Is the “The Default Stream Trap” lesson free?

Yes — the full text of “The Default Stream Trap” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Default Stream Trap”?

How stream 0 serializes everything. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CUDA Academy?

No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Default Stream Trap” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CUDA Academy lesson?

Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Default Stream Trap
  2. Creating and Using Streams
  3. Events for Timing and Sync
  4. Overlapping Copy and Compute
← Back to CUDA Academy