0Pricing
Mojo Academy · Aula

Escolhendo uma largura SIMD

Associe a largura às pistas do seu hardware.

Escolhendo uma largura SIMD é uma aula grátis de Mojo Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Mojo Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Mojo Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em 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. 🎯

Perguntas Frequentes

A aula “Escolhendo uma largura SIMD” é grátis?

Sim — o texto completo de “Escolhendo uma largura SIMD” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Mojo Academy, atualize para CoddyKit PRO. O curso de Mojo Academy inclui 4 aulas no total.

O que vou aprender em “Escolhendo uma largura SIMD”?

Associe a largura às pistas do seu hardware. Você pratica Mojo Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Mojo Academy?

Nenhuma experiência prévia é necessária. Mojo Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Escolhendo uma largura SIMD”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Mojo Academy?

Sim. Cada aula de Mojo Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Conheça o tipo SIMD
  2. Matemática SIMD elemento a elemento
  3. Escolhendo uma largura SIMD
  4. Vetorizando um laço
← Voltar para Mojo Academy