メモリトラフィックの削減
データを計算処理の近くに保持します
「メモリトラフィックの削減」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Memory Matters
Modern CPUs compute far faster than they can fetch data. Often a kernel waits on memory, not on the math itself.
What Is Memory Traffic?
Memory traffic is the total bytes your kernel reads and writes. Less traffic per result usually means a faster kernel.
Touch Data Once
Reading the same value many times wastes bandwidth. Load it once, do all the work, then reuse it from a register.
var x = a[i]
var y = x * x + xFuse Your Loops
Two separate loops over the same array read it twice. Fusing them into one pass reads each element only once.
for i in range(n):
out[i] = a[i] * 2 + a[i]Keep Values in Registers
A value held in a CPU register needs no memory access. Reuse intermediate results instead of writing them out and back.
Avoid Temp Buffers
Extra temporary arrays add both stores and loads. Skip them when you can and compute straight into the final output.
Stream Sequentially
Reading memory in order lets the CPU prefetch ahead. Jumping around defeats prefetching and stalls the loop.
for i in range(n):
total += a[i]Cache Lines Travel Together
Memory arrives in fixed-size cache lines. Using every byte of a line you fetched gives you free, already-loaded data.
Compute More per Byte
Arithmetic intensity is work done per byte loaded. Raising it means each fetched value earns more compute before you move on.
Write Once, If You Can
Stores cost bandwidth too. Accumulate in a local and write the final result once rather than updating memory repeatedly.
var acc = Float32(0)
for i in range(n):
acc += a[i]
out[0] = accLess Traffic, More Speed
When the kernel waits on data, cutting reads and writes is the biggest win, often beating clever arithmetic tweaks.
Quick Check
Your kernel reads the same array in two separate loops. What single change cuts its memory traffic most?
Recap
Cut memory traffic by touching data once, fusing loops, reusing registers, streaming in order, and writing results just once. 💾
よくある質問
「メモリトラフィックの削減」レッスンは無料ですか?
はい。「メモリトラフィックの削減」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「メモリトラフィックの削減」で何を学びますか?
データを計算処理の近くに保持します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「メモリトラフィックの削減」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- コンピュートカーネルの構造
- SIMDとループの組み合わせ
- メモリトラフィックの削減
- キャッシュ局所性のためのタイリング