SIMD型を知る
複数の値をまとめて処理するベクトルです
「SIMD型を知る」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
One Value at a Time Is Slow
A normal Int holds a single number, so math happens one value at a time. For AI you often need to crunch many numbers at once.
Meet SIMD
SIMD means Single Instruction, Multiple Data: one operation applied to a whole pack of numbers in a single step.
A Vector of Values
In Mojo the SIMD type holds several values of the same kind together, like a tiny fixed-size vector handled as one unit.
var v = SIMD[DType.float32, 4](1, 2, 3, 4)Two Type Parameters
A SIMD type takes two parameters in brackets: the element DType and how many lanes it holds, like SIMD[DType.int32, 4].
alias Pack = SIMD[DType.int32, 4]DType Picks the Element Kind
The first parameter is a DType such as float32 or int32. It decides what each lane stores and how big it is.
var x = SIMD[DType.float32, 4](0.5, 1.5, 2.5, 3.5)Width Is the Lane Count
The second parameter is the width: the number of values packed side by side. A width of 4 means four numbers travel together.
var four = SIMD[DType.int32, 4](10, 20, 30, 40)Width Is a Power of Two
SIMD widths are powers of two like 1, 2, 4, 8, or 16. This maps cleanly onto the lanes your CPU offers.
var eight = SIMD[DType.float32, 8](0)A Scalar Is Width One
Even a plain number is really a SIMD of width 1 in Mojo. Scalars and vectors share the same underlying type.
var one = SIMD[DType.float32, 1](3.14)Indexing the Lanes
You can read a single lane by index just like a list. Lane 0 is the first value in the vector.
var v = SIMD[DType.int32, 4](5, 6, 7, 8)
print(v[0])Fill Every Lane at Once
Passing one value fills all lanes with it. This is a quick way to make a SIMD vector of constant values.
var zeros = SIMD[DType.float32, 4](0)Why SIMD Is Fast
Because the CPU acts on a whole pack in one instruction, SIMD does more work per cycle. That is the heart of vectorization.
Quick Check
You declare SIMD[DType.float32, 4]. What do those two parameters mean?
Recap
SIMD packs several same-typed values into one vector set by a DType and a power-of-two width, so one instruction touches them all. 🚀
よくある質問
「SIMD型を知る」レッスンは無料ですか?
はい。「SIMD型を知る」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「SIMD型を知る」で何を学びますか?
複数の値をまとめて処理するベクトルです ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「SIMD型を知る」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- SIMD型を知る
- 要素単位のSIMD演算
- SIMD幅の選択
- ループのベクトル化