0Pricing
CUDA Academy · レッスン

ダブルバッファリングのパイプライン

データを分割し、GPUに継続的に供給します。

「ダブルバッファリングのパイプライン」はCoddyKit上の無料CUDA Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはCUDA Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 CUDA Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

The Idle GPU Problem

Copy a huge array, then run a kernel, then copy back. During each copy the GPU sits idle, and during compute the transfer engines sit idle.

Split the Work

The fix starts with breaking one giant array into smaller chunks. Each chunk can be copied and processed on its own, opening the door to overlap.

Two Buffers, Two Lanes

Double buffering uses two device buffers and two streams. While stream A computes on one chunk, stream B copies in the next.

Overlap Copy and Compute

The magic is concurrency: a transfer and a kernel run at the same time on different chunks. Transfer time hides behind useful compute.

Pinned Memory Required

This only works if the host data lives in pinned memory. Pageable buffers force blocking copies, and the whole pipeline collapses back to serial.

The Pipeline Loop

You iterate over chunks, and on each step you issue an async copy in, a kernel, and an async copy out, all on the same stream.

cudaMemcpyAsync(d_in, h_in + off, csz, H2D, s);
proc<<<g, b, 0, s>>>(d_in, d_out);
cudaMemcpyAsync(h_out + off, d_out, csz, D2H, s);

Alternate the Streams

Assign each chunk to a stream by alternating them. Even chunks go to stream 0, odd chunks to stream 1, so neighbors overlap cleanly.

cudaStream_t s = streams[i % 2];

Why Two Is Enough

Two streams already overlap copy with compute. More buffers add depth but bring diminishing returns and extra memory cost, so start with two.

Drain at the End

After queuing every chunk, wait for all work to finish before reading results. A simple cudaDeviceSynchronize drains every stream at once.

cudaDeviceSynchronize();

The Speedup

With copy hidden behind compute, total time drops toward the cost of just the longer of the two, not their sum. That is the real win. 🚀

When It Wins Most

Double buffering shines when transfer time and compute time are roughly balanced. If one utterly dominates, focus your effort on shrinking that side first.

Quick Check

What is the core benefit of a double-buffering pipeline?

Recap

Chunk the data, use two pinned buffers and streams, and overlap copy with compute. Sync at the end and watch transfer time vanish. 🎉

よくある質問

「ダブルバッファリングのパイプライン」レッスンは無料ですか?

はい。「ダブルバッファリングのパイプライン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、CUDA Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 CUDA Academyコースには全4レッスンが含まれています。

「ダブルバッファリングのパイプライン」で何を学びますか?

データを分割し、GPUに継続的に供給します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

CUDA Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのCUDA Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「ダブルバッファリングのパイプライン」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このCUDA Academyレッスンでコードを書いて実行できますか?

はい。すべてのCUDA Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ページ可能メモリが遅い理由
  2. cudaMallocHostでピン留めメモリを使う
  3. ストリーム内でcudaMemcpyAsyncを使う
  4. ダブルバッファリングのパイプライン
← CUDA Academyに戻る