Elegir un ancho SIMD
Adapte el ancho a las lanes de su hardware.
Elegir un ancho SIMD es una lección gratuita de Mojo Academy en CoddyKit. Esta es la lección 3 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.
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. 🎯
Preguntas frecuentes
¿La lección «Elegir un ancho SIMD» es gratis?
Sí — el texto completo de «Elegir un ancho 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 «Elegir un ancho SIMD»?
Adapte el ancho a las lanes de su hardware. 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 3 de 4.
¿Cuánto tiempo toma la lección «Elegir un ancho 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