0Pricing
CUDA Academy · レッスン

コアレスアクセスとストライドアクセス

スレッドとアドレスの対応が重要な理由を学びます。

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

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

It Is All About Mapping

Coalescing depends on which address each thread touches. The map from thread to address decides whether one transaction serves the whole warp.

The Coalesced Pattern

When neighboring threads read neighboring addresses, the warp covers one contiguous run. That tidy layout is a coalesced access.

int i = blockIdx.x * blockDim.x + threadIdx.x;
float v = data[i];

Why It Wins

Thread 0 hits index 0, thread 1 hits index 1, and so on. All 32 addresses fall in one aligned line, so the GPU needs a single transaction.

Enter the Stride

A stride is a fixed gap between the addresses successive threads touch. The moment that gap grows past one element, coalescing starts to break.

float v = data[i * stride];

Strided Reads Spread Out

With a stride of 2, thread 0 reads 0, thread 1 reads 2, thread 2 reads 4. The warp now spans twice the memory, so it needs more transactions.

The Cost Scales Up

Double the stride and you roughly double the lines touched. Big strides can push a warp toward many transactions while using only a sliver of each line.

A Common Trap

Giving each thread a whole column of a row-major matrix creates a huge stride. It looks neat in code but quietly scatters every warp.

float v = matrix[threadIdx.x * width + row];

Transpose the Mapping

Often the fix is just swapping which index varies fastest with the thread. Let consecutive threads walk consecutive memory and the reads coalesce again.

float v = matrix[row * width + threadIdx.x];

Offsets Hurt Too

Even a coalesced pattern suffers if it starts mid-line. A misaligned offset shifts the warp across a boundary, splitting one read into two.

Think in Warps

To judge a pattern, do not picture one thread. Picture all 32 lanes at once and ask how many lines their addresses cover together. 🔍

The Rule of Thumb

Make the fastest-changing index follow threadIdx.x. That single habit keeps most of your global reads coalesced for free.

Quick Check

Pick the access pattern that coalesces best.

Recap

You saw that coalesced reads keep neighbors together while a stride scatters them across lines. Keep threadIdx.x driving the fastest index. 🎉

よくある質問

「コアレスアクセスとストライドアクセス」レッスンは無料ですか?

はい。「コアレスアクセスとストライドアクセス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと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. Structure of ArraysとArray of Structs
  4. 実効帯域幅を測定する
← CUDA Academyに戻る