0Pricing
CUDA Academy · レッスン

ストリームを作成して使う

独立した作業キューに処理を発行します。

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

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

Independent Work Queues

A non-default stream is your own work queue. Two streams run independently, so the GPU can make progress on both at once. 🧵

The Stream Handle

A stream lives in a cudaStream_t handle. You create it once, pass it to your calls, and destroy it when you are done.

cudaStream_t stream;

Creating a Stream

Call cudaStreamCreate to make a fresh stream. It allocates the queue the driver uses to schedule that stream's work.

cudaStreamCreate(&stream);

Launching a Kernel in a Stream

A kernel's launch config has a fourth argument: shared memory size, then the stream. Pass your stream to queue the kernel there.

kernel<<<grid, block, 0, stream>>>(d_data);

Two Streams, Two Tasks

Put one job on streamA and another on streamB. With no dependency between them, the GPU is free to run both concurrently.

kA<<<g, b, 0, streamA>>>(a);
kB<<<g, b, 0, streamB>>>(d);

Async by Nature

Stream calls are asynchronous: the host returns immediately and keeps going. The GPU works through the queue on its own time.

Waiting on One Stream

Use cudaStreamSynchronize to block the host until just that stream finishes, instead of waiting on the whole device.

cudaStreamSynchronize(stream);

Checking Without Blocking

Want a peek? cudaStreamQuery returns cudaSuccess if the stream is done and cudaErrorNotReady if it is still busy, without stalling you.

cudaStreamQuery(stream);

Cleaning Up

When a stream is no longer needed, release it with cudaStreamDestroy. Pending work still completes before the handle is freed.

cudaStreamDestroy(stream);

Non-Blocking Streams

Create a stream with the cudaStreamNonBlocking flag so it does not implicitly synchronize with the legacy default stream.

cudaStreamCreateWithFlags(&s, cudaStreamNonBlocking);

More Streams, More Overlap

Spreading independent chunks over several streams lets the scheduler keep the engines fed. Beyond a few, returns diminish as hardware fills up.

Quick Check

How do you queue a kernel into a specific stream?

Recap

You can now create streams, launch kernels in them, sync or query, and destroy them. Independent streams unlock real concurrency. ✨

よくある質問

「ストリームを作成して使う」レッスンは無料ですか?

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

「ストリームを作成して使う」で何を学びますか?

独立した作業キューに処理を発行します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「ストリームを作成して使う」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. デフォルトストリームの落とし穴
  2. ストリームを作成して使う
  3. 計測と同期にイベントを使う
  4. コピーと計算をオーバーラップさせる
← CUDA Academyに戻る