0Pricing
CUDA Academy · レッスン

計測と同期にイベントを使う

cudaEventで処理を計測し、順序を制御します。

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

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

What Is an Event?

A CUDA event is a marker you drop into a stream. The GPU records when it reaches that point, letting you time and order work. ⏱️

The Event Handle

Events use a cudaEvent_t handle, just like streams. You create it, record it, query it, and destroy it when finished.

cudaEvent_t start, stop;

Creating Events

Call cudaEventCreate for each event you need. Timing usually wants two: one before the work and one after.

cudaEventCreate(&start);
cudaEventCreate(&stop);

Recording an Event

cudaEventRecord places the event into a stream. The GPU stamps it the moment it finishes everything queued before it.

cudaEventRecord(start, stream);

Timing a Kernel

Record start, launch your kernel, then record stop, all in the same stream. The gap between them is the real GPU execution time.

cudaEventRecord(start, s);
kernel<<<g, b, 0, s>>>(d);
cudaEventRecord(stop, s);

Waiting for an Event

Events are async, so the host must wait. cudaEventSynchronize blocks until the given event has actually been recorded on the GPU.

cudaEventSynchronize(stop);

Measuring Elapsed Time

cudaEventElapsedTime returns the milliseconds between two recorded events. This is far more accurate than a host-side CPU clock.

float ms;
cudaEventElapsedTime(&ms, start, stop);

Why Not the CPU Clock?

Host timers include launch overhead and miss true GPU timing. Events sit inside the stream, so they capture exactly what the device did.

Cross-Stream Ordering

Events also synchronize streams. cudaStreamWaitEvent makes one stream pause until an event recorded in another has happened.

cudaStreamWaitEvent(streamB, eventA, 0);

Building Dependencies

With stream-wait-event you express a dependency: streamB starts its work only after streamA reaches its event, without blocking the host.

Cleaning Up Events

Free events you no longer need with cudaEventDestroy. Like streams, they are cheap but should not be leaked in long-running apps.

cudaEventDestroy(start);
cudaEventDestroy(stop);

Quick Check

Which function gives you the time between two events?

Recap

Events let you time GPU work precisely and order one stream after another. They are your tool for measuring and coordinating overlap. 🎯

よくある質問

「計測と同期にイベントを使う」レッスンは無料ですか?

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

「計測と同期にイベントを使う」で何を学びますか?

cudaEventで処理を計測し、順序を制御します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「計測と同期にイベントを使う」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

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