0Pricing
Mojo Academy · Ders

SIMD'yi Döngülerle Birleştirme

Çekirdeğin merkezini vektörleştirin.

SIMD'yi Döngülerle Birleştirme, CoddyKit'te ücretsiz bir Mojo Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Mojo Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Mojo Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

From Scalar to SIMD

To accelerate a kernel, swap the one-at-a-time loop for one that handles a whole pack of values per step with SIMD.

for i in range(n):
    out[i] = a[i] + b[i]

Pick a Width

Choose how many elements fit in one vector. The width is the number of lanes each step processes together.

alias width = 4

Load a Chunk

Grab several elements at once into a SIMD value with a vector load instead of reading them one by one.

var va = a.load[width=width](i)

Compute the Pack

Run the kernel's math on both chunks at once. The whole pack is added element-wise in a single operation.

var vsum = a.load[width=width](i) + b.load[width=width](i)

Store the Pack

Write the full result back with a vector store, covering every lane you just computed in one move.

out.store[width=width](i, vsum)

Step by the Width

The vectorized loop advances by the width, not by one. Each pass covers a full pack of elements.

for i in range(0, n, width):
    pass

Let vectorize Help

Mojo's vectorize helper sweeps a closure across the range in vector steps so you skip the manual bookkeeping.

from algorithm import vectorize

Write the Chunk Closure

You define a small parameterized function that handles one chunk. Mojo calls it with the right width as it sweeps.

fn body[w: Int](i: Int):
    out.store[width=w](i, a.load[width=w](i) + b.load[width=w](i))

Run vectorize

Call vectorize with your closure, the width, and the size. It loops and even handles the leftover tail for you.

vectorize[body, width](n)

Mind the Tail

When n is not a multiple of the width, a few elements remain. vectorize cleans up that tail so nothing is missed.

Same Output, More Speed

The vectorized kernel produces identical results but moves through data in big steps, so it finishes much sooner.

Quick Check

You vectorize a kernel with width 4 but n is 10. What handles the last two elements?

Recap

Vectorize a kernel by loading and storing packs, stepping by the width, and letting vectorize handle the sweep and the tail. 🚀

Sıkça Sorulan Sorular

“SIMD'yi Döngülerle Birleştirme” dersi ücretsiz mi?

Evet — “SIMD'yi Döngülerle Birleştirme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Mojo Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Mojo Academy kursu toplamda 4 dersten oluşur.

“SIMD'yi Döngülerle Birleştirme” dersinde ne öğreneceğim?

Çekirdeğin merkezini vektörleştirin. Mojo Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Mojo Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Mojo Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“SIMD'yi Döngülerle Birleştirme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Mojo Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Mojo Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Hesaplama Çekirdeğinin Anatomisi
  2. SIMD'yi Döngülerle Birleştirme
  3. Bellek Trafiğini Azaltma
  4. Önbellek Yerelliği için Döşeme
← Mojo Academy Sayfasına Dön