SIMD幅の選択
ハードウェアのレーン数に合った幅を選びます
「SIMD幅の選択」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Width Decides Throughput
The SIMD width is how many lanes you process per instruction. Picking it well is key to real performance.
Hardware Has Fixed Lanes
Your CPU has vector registers of a fixed size. A good SIMD width matches the lanes that hardware can run at once.
Too Narrow Wastes Power
A width of 1 ignores the CPU's vector units entirely. You leave most of the chip's throughput sitting idle.
var slow = SIMD[DType.float32, 1](2.0)Too Wide Spills Over
If a width is larger than the hardware supports, Mojo splits it into smaller chunks. That still works but adds overhead.
Let Mojo Tell You
Mojo can report the ideal width for a type on this machine through simdwidthof, so you do not have to guess.
from sys import simdwidthof
alias w = simdwidthof[DType.float32]()Use It as a Parameter
Because simdwidthof is known at compile time, you can feed it straight into a SIMD type as its width.
alias Vec = SIMD[DType.float32, simdwidthof[DType.float32]()]Width Depends on DType
Smaller elements fit more lanes in the same register. So float32 usually gets a bigger native width than float64.
Portable by Design
Using simdwidthof means your code adapts to each machine automatically. The same source stays fast and portable.
Multiples of Width Are Easy
Data that comes in clean multiples of your width vectorizes neatly, with no leftover lanes to handle as a remainder.
Mind the Leftovers
When a count is not a multiple of the width, a few tail elements remain. You finish those with a small scalar step.
Start with the Native Width
A safe default is simdwidthof for your DType. Measure later, but the native width is almost always a strong start.
Quick Check
You want a SIMD width that fits this CPU's float32 lanes without hardcoding a guess. What helps?
Recap
Match the SIMD width to the hardware: simdwidthof gives the native lane count per DType, and a scalar tail cleans up leftover elements. 🎯
よくある質問
「SIMD幅の選択」レッスンは無料ですか?
はい。「SIMD幅の選択」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「SIMD幅の選択」で何を学びますか?
ハードウェアのレーン数に合った幅を選びます ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「SIMD幅の選択」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- SIMD型を知る
- 要素単位のSIMD演算
- SIMD幅の選択
- ループのベクトル化