デフォルトストリームの落とし穴
stream 0がすべてを直列化する仕組みを学びます。
「デフォルトストリームの落とし穴」はCoddyKit上の無料CUDA Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはCUDA Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 CUDA Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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 appQuick 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. 🚀
よくある質問
「デフォルトストリームの落とし穴」レッスンは無料ですか?
はい。「デフォルトストリームの落とし穴」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、CUDA Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 CUDA Academyコースには全4レッスンが含まれています。
「デフォルトストリームの落とし穴」で何を学びますか?
stream 0がすべてを直列化する仕組みを学びます。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
CUDA Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのCUDA Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「デフォルトストリームの落とし穴」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このCUDA Academyレッスンでコードを書いて実行できますか?
はい。すべてのCUDA Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- デフォルトストリームの落とし穴
- ストリームを作成して使う
- 計測と同期にイベントを使う
- コピーと計算をオーバーラップさせる