Conozca el tipo SIMD
Un vector de valores procesados conjuntamente.
Conozca el tipo SIMD es una lección gratuita de Mojo Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Mojo Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Mojo Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 🚀
Preguntas frecuentes
¿La lección «Conozca el tipo SIMD» es gratis?
Sí — el texto completo de «Conozca el tipo SIMD» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Mojo Academy, actualiza a CoddyKit PRO. El curso de Mojo Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Conozca el tipo SIMD»?
Un vector de valores procesados conjuntamente. Practicas Mojo Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Mojo Academy?
No se requiere experiencia previa. Mojo Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Conozca el tipo SIMD»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Mojo Academy?
Sí. Cada lección de Mojo Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Conozca el tipo SIMD
- Cálculo SIMD elemento a elemento
- Elegir un ancho SIMD
- Vectorizar un bucle