0Pricing
CUDA Academy · レッスン

タイルのフェーズをループする

タイルをまたいで部分和を累積します。

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

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

The Dot Product Is Split

A full row times a full column is too big for one tile. So you split that long sum into chunks of width TILE, one chunk per phase.

Counting the Phases

If the matrices are N wide and tiles are TILE wide, you need N / TILE phases to cover the whole inner dimension.

int numPhases = (N + TILE - 1) / TILE;

The Outer Phase Loop

Wrap your load-sync-compute steps in a loop over phase. Each pass slides the tile window further along the row of A and column of B.

for (int phase = 0; phase < numPhases; ++phase) {
  // load, sync, compute, sync
}

Accumulate Across Phases

The local sum variable lives outside the loop, so it keeps growing. Each phase adds its slice of the dot product to the running total.

float sum = 0.0f;
for (int phase = 0; phase < numPhases; ++phase) { ... }

Tile Offset per Phase

Each phase shifts the column you read from A and the row you read from B by phase * TILE. That is how the window advances.

As[ty][tx] = A[row*N + phase*TILE + tx];
Bs[ty][tx] = B[(phase*TILE + ty)*N + col];

Sync After Loading

Just like before, call __syncthreads() after the loads so the tile is complete before anyone computes on it.

__syncthreads();

Compute This Phase's Slice

The inner loop adds TILE products into sum, using only the freshly loaded tile. It contributes one chunk of the final dot product.

for (int k = 0; k < TILE; ++k)
  sum += As[ty][k] * Bs[k][tx];

The Second Barrier

End each phase with another __syncthreads() so no thread overwrites the tile while a slower thread is still reading it. 🚧

__syncthreads(); // before the next phase loads

Why Two Syncs Matter

One barrier guards reads-after-load, the other guards loads-after-read. Together they keep every thread in lockstep across phases.

Write the Final Sum

After all phases finish, the running sum is the complete dot product. Store it into C once, guarded by a bounds check.

if (row < N && col < N)
  C[row*N + col] = sum;

Handling Ragged Sizes

When N is not a clean multiple of TILE, load zero for out-of-range elements so the extra products add nothing to the sum.

Quick Check

Think about where the running total lives during the phase loop.

Recap

You looped over phases, shifting tiles, syncing twice, and accumulating partial sums into one total. Now let us measure how much faster it is. 📈

よくある質問

「タイルのフェーズをループする」レッスンは無料ですか?

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

「タイルのフェーズをループする」で何を学びますか?

タイルをまたいで部分和を累積します。 ブラウザで直接実行するハンズオンコードで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に戻る