0Pricing
Mojo Academy · درس

تشريح نواة حسابية

الحلقة الداخلية الساخنة التي تنفّذ العمل

تشريح نواة حسابية درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What Is a Kernel?

A compute kernel is the small, focused routine that does the real numerical work, like adding two arrays element by element.

The Hot Inner Loop

Most of a kernel's time lives in one tight inner loop. Speed up that loop and you speed up the whole program.

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

Inputs and Outputs

A clean kernel takes its data buffers as parameters, so the same routine can run on any arrays you pass in.

fn add(a: UnsafePointer[Float32], b: UnsafePointer[Float32], out: UnsafePointer[Float32], n: Int):
    pass

Use fn for Strictness

Kernels are written with fn, not def. The strict, typed style lets Mojo compile tight machine code with no surprises.

fn kernel(n: Int):
    pass

Keep the Body Small

The fastest kernels do one thing. A short, predictable inner body is easy for the compiler to optimize aggressively.

No Surprises Inside

Avoid heavy work like allocation or I/O in the hot loop. Each iteration should be cheap and uniform for peak throughput.

Count the Work

Think in terms of total operations. A kernel over n elements does roughly n units of work, so n drives the cost.

Memory Is the Limit

Many kernels are not compute-bound but memory-bound. They wait on data, so how you move bytes often matters most.

Plan to Vectorize

Design the loop so each step can later process many elements with SIMD. A regular access pattern makes vectorizing easy.

A Tiny Saxpy Kernel

A classic kernel is saxpy: out = scale times a plus b. It is small, regular, and a great baseline to optimize.

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

Measure Before You Tune

Start with the simple correct version and time it. That number is your baseline for every optimization that follows.

Quick Check

You are about to optimize a kernel. Where does almost all of its time go?

Recap

A kernel is a small fn whose tight inner loop does the work; keep it uniform, mind memory, and measure a baseline first. 🔧

الأسئلة الشائعة

هل درس «تشريح نواة حسابية» مجاني؟

نعم — نص درس «تشريح نواة حسابية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «تشريح نواة حسابية»؟

الحلقة الداخلية الساخنة التي تنفّذ العمل تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «تشريح نواة حسابية»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تشريح نواة حسابية
  2. دمج SIMD مع الحلقات
  3. تقليل حركة الذاكرة
  4. التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية
← العودة إلى Mojo Academy