0Pricing
Mojo Academy · Ders

Matmul Oluşturma: Adım Adım

Saf döngülerden gerçek bir çekirdeğe.

Matmul Oluşturma: Adım Adım, 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.

What Matmul Computes

Matrix multiply, or matmul, combines an M by K matrix with a K by N matrix to produce an M by N result. It is the heart of AI math.

The Dot Product Rule

Each output cell is a dot product: walk across one row of A and down one column of B, multiplying and summing as you go.

Three Nested Loops

The naive version uses three loops over i, j, and k. The outer two pick the output cell, the inner one sums the products.

for i in range(M):
    for j in range(N):
        for k in range(K):
            C[i, j] += A[i, k] * B[k, j]

Start Each Cell at Zero

Before accumulating, set each result cell to zero. Otherwise old or garbage values pollute your sum.

C[i, j] = 0.0

Accumulate the Sum

The inner k loop keeps a running accumulator. Summing into a local variable is often faster than touching C every step.

var acc: Float32 = 0.0
for k in range(K):
    acc += A[i, k] * B[k, j]
C[i, j] = acc

Use fn for Speed

Write the kernel with fn and typed arguments. Strict types let Mojo compile tight machine code with no dynamic overhead.

fn matmul(A: Matrix, B: Matrix, C: Matrix):
    pass

Why Naive Is Slow

The basic triple loop does the right math but reads B by column, jumping through memory. Poor locality wastes cache and time.

Loop Order Matters

Reordering to i, k, j keeps the inner loop walking memory in straight lines. Better access patterns can speed matmul a lot.

for i in range(M):
    for k in range(K):
        for j in range(N):
            C[i, j] += A[i, k] * B[k, j]

The Inner Loop Is the Target

Nearly all the time lives in the innermost loop. That hot inner loop is exactly where vectorizing and tuning pay off.

Correctness First

Get the simple version right and save its output. It becomes the reference you compare every faster kernel against.

A Path to a Real Kernel

From here you add SIMD, tiling, and parallelism. Each step keeps the same result but raises throughput toward peak hardware speed.

Quick Check

Why is the textbook triple-loop matmul often slow in practice?

Recap

Matmul sums a dot product per output cell with three loops; start cells at zero, accumulate locally, and mind loop order for cache. 🔢

Sıkça Sorulan Sorular

“Matmul Oluşturma: Adım Adım” dersi ücretsiz mi?

Evet — “Matmul Oluşturma: Adım Adım” 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.

“Matmul Oluşturma: Adım Adım” dersinde ne öğreneceğim?

Saf döngülerden gerçek bir çekirdeğe. 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.

“Matmul Oluşturma: Adım Adım” 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. Mojo'da Tensör Modellemesi
  2. Matmul Oluşturma: Adım Adım
  3. İç Çarpımı Eniyileştirme
  4. Sayısal Doğruluğu Doğrulama
← Mojo Academy Sayfasına Dön