キャッシュ局所性のためのタイリング
キャッシュに収まる単位に処理を分割します
「キャッシュ局所性のためのタイリング」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
The Cache Idea
The CPU keeps recently used data in a small, fast cache. Hits are quick; misses force a slow trip to main memory.
What Is Locality?
Cache locality means reusing data that is already nearby in the cache before it gets evicted to make room.
Big Data Spills the Cache
If your kernel sweeps a huge array, early elements are evicted before you reuse them, causing repeated cache misses.
Tile the Work
Tiling splits a big loop into small blocks that fit in cache, so each block's data stays hot while you use it.
alias tile = 64An Outer and Inner Loop
Tiling turns one loop into two: an outer loop over blocks and an inner loop over the elements inside each block.
for t in range(0, n, tile):
for i in range(t, min(t + tile, n)):
out[i] = a[i] * 2One Block at a Time
Each block is small enough to live in cache. You finish all its work before moving on, so reuse stays cheap.
Great for Matrices
Matrix multiply reuses rows and columns heavily. Blocking a matmul into tiles keeps reused data in cache and cuts misses.
Pick the Tile Size
The best tile fills the cache without overflowing it. Too small wastes reuse; too large spills, so you tune the size.
Tile Then Vectorize
Tiling and SIMD stack well. Vectorize the inner loop of each block to get cache locality and vector speed together.
for t in range(0, n, tile):
vectorize[body, width](min(tile, n - t))Mind the Edges
The last block may be smaller than a full tile. Clamp its range with min so you never read past the buffer.
var end = min(t + tile, n)Measure the Gain
Tiling can help a lot or a little depending on sizes. Always benchmark a few tile values on your real data to choose.
Quick Check
Your kernel keeps missing cache because it sweeps a huge array end to end. What technique helps?
Recap
Tiling blocks a big loop so each chunk fits in cache; tune the tile size, vectorize the inner loop, and clamp the edges. 🧱
よくある質問
「キャッシュ局所性のためのタイリング」レッスンは無料ですか?
はい。「キャッシュ局所性のためのタイリング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「キャッシュ局所性のためのタイリング」で何を学びますか?
キャッシュに収まる単位に処理を分割します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「キャッシュ局所性のためのタイリング」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- コンピュートカーネルの構造
- SIMDとループの組み合わせ
- メモリトラフィックの削減
- キャッシュ局所性のためのタイリング