İç Çarpımı Eniyileştirme
Skaler çarpımı vektörleştirin ve döngüyü açın.
İç Çarpımı Eniyileştirme, CoddyKit'te ücretsiz bir Mojo Academy dersidir. Bu, 4 dersinin 3. 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.
The Dot Product Core
The inner product multiplies two sequences element by element and adds the results. Speeding it up speeds your whole matmul.
var acc: Float32 = 0.0
for k in range(K):
acc += a[k] * b[k]One Lane at a Time Is Slow
A plain loop handles a single pair per step. Modern CPUs can do many at once, so scalar code leaves lanes idle.
Enter SIMD
A SIMD value packs several numbers and applies one operation to all of them together, doing real work in parallel per instruction.
var v = SIMD[DType.float32, 4](1, 2, 3, 4)Load a Chunk at Once
Instead of one float, load a whole SIMD-width slice of each array in a single move, ready for vector math.
var va = a.load[width=4](k)
var vb = b.load[width=4](k)Multiply Whole Vectors
Multiplying two SIMD values yields a vector of products in one step. The element-wise work happens across all lanes together.
var prod = va * vb # 4 products at onceAccumulate Into a Vector
Keep a SIMD accumulator and add each product vector into it. You delay the final sum until the loop is done.
var acc = SIMD[DType.float32, 4](0)
acc += va * vbStep by the Width
The loop now advances by the SIMD width, not by one. Four lanes wide means a quarter as many iterations.
for k in range(0, K, 4):
acc += a.load[width=4](k) * b.load[width=4](k)Reduce at the End
After the loop, collapse the lane accumulator into one number with a horizontal reduce, giving the final dot product.
var total = acc.reduce_add()Unrolling the Loop
Unrolling processes several widths per iteration, cutting loop overhead and exposing more independent work to the CPU.
Handle the Remainder
If K is not a multiple of the width, a few elements are left over. A small tail loop finishes them one at a time.
for k in range(K - K % 4, K):
total += a[k] * b[k]Let Mojo Help
Mojo offers the vectorize helper to apply a width-parameterized body across a range, handling stepping and the tail for you.
Quick Check
After a SIMD-width dot product loop, why do you call reduce_add at the end?
Recap
Vectorize the inner product by loading SIMD chunks, multiplying lanes together, accumulating, then reduce; unroll and clean up the tail. ⚡
Sıkça Sorulan Sorular
“İç Çarpımı Eniyileştirme” dersi ücretsiz mi?
Evet — “İç Çarpımı Eniyileş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.
“İç Çarpımı Eniyileştirme” dersinde ne öğreneceğim?
Skaler çarpımı vektörleştirin ve döngüyü açın. 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 3. dersidir.
“İç Çarpımı Eniyileş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
- Mojo'da Tensör Modellemesi
- Matmul Oluşturma: Adım Adım
- İç Çarpımı Eniyileştirme
- Sayısal Doğruluğu Doğrulama