0Pricing
Mojo Academy · レッスン

スレッド、ブロック、グリッド

GPUの実行モデルを学びます

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

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

The Smallest Worker

A GPU runs your kernel as many tiny workers. Each single worker is a thread, and it usually handles one piece of data.

Grouping Threads

Threads are organized into a block. Threads in the same block can cooperate and share fast on-chip memory.

All Blocks Together

All the blocks for one kernel launch form the grid. The grid is the full set of workers handling your whole problem.

A Simple Hierarchy

The model nests neatly: threads live in blocks, and blocks live in a grid. Three levels describe every launch.

Each Thread Has an ID

Every thread can ask where it sits. Its index tells it which element of the data it is responsible for.

var tid = thread_idx.x

Each Block Has an ID Too

Blocks are numbered as well. A thread combines its block id with its local id to find a unique spot.

var bid = block_idx.x

Computing a Global Index

The classic formula maps each thread to one global element. This global index is how kernels split an array.

var i = block_idx.x * block_dim.x + thread_idx.x

Choosing Block Size

You pick how many threads sit in a block. A good size keeps the hardware busy without wasting resources.

Choosing Grid Size

The grid must cover all your data. You size it so threads times blocks reach every element you need.

var blocks = (n + 255) // 256

Guarding the Edges

The grid often launches a few extra threads. A simple bounds check stops them from touching memory past the end.

if i < n:
    out[i] = a[i] + b[i]

Why This Shape Helps

Blocks let groups share memory and sync, while the grid scales to any size. The structure maps work onto hardware cleanly.

Quick Check

A thread needs the position of its element across the whole array.

Recap

Threads group into blocks, blocks form the grid, and combining their ids gives each worker a unique global index. 🧵

よくある質問

「スレッド、ブロック、グリッド」レッスンは無料ですか?

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

「スレッド、ブロック、グリッド」で何を学びますか?

GPUの実行モデルを学びます ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「スレッド、ブロック、グリッド」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. AIワークロードにGPUを使う理由
  2. スレッド、ブロック、グリッド
  3. GPUカーネル関数の記述
  4. デバイスとのデータ転送
← Mojo Academyに戻る