ทำความรู้จักชนิดข้อมูล SIMD
เวกเตอร์ของค่าที่ประมวลผลพร้อมกัน
ทำความรู้จักชนิดข้อมูล SIMD เป็นบทเรียน Mojo Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Mojo Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ทำความรู้จักชนิดข้อมูล SIMD”
เวกเตอร์ของค่าที่ประมวลผลพร้อมกัน คุณปฏิบัติ Mojo Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Mojo Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Mojo Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “ทำความรู้จักชนิดข้อมูล SIMD” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Mojo Academy นี้ได้ไหม
ได้ บทเรียน Mojo Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ทำความรู้จักชนิดข้อมูล SIMD
- คณิตศาสตร์ SIMD แบบรายสมาชิก
- การเลือกความกว้าง SIMD
- การทำเวกเตอร์ให้กับลูป