تقليل حركة الذاكرة
أبقِ البيانات قريبة من وحدة الحساب
تقليل حركة الذاكرة درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Memory Matters
Modern CPUs compute far faster than they can fetch data. Often a kernel waits on memory, not on the math itself.
What Is Memory Traffic?
Memory traffic is the total bytes your kernel reads and writes. Less traffic per result usually means a faster kernel.
Touch Data Once
Reading the same value many times wastes bandwidth. Load it once, do all the work, then reuse it from a register.
var x = a[i]
var y = x * x + xFuse Your Loops
Two separate loops over the same array read it twice. Fusing them into one pass reads each element only once.
for i in range(n):
out[i] = a[i] * 2 + a[i]Keep Values in Registers
A value held in a CPU register needs no memory access. Reuse intermediate results instead of writing them out and back.
Avoid Temp Buffers
Extra temporary arrays add both stores and loads. Skip them when you can and compute straight into the final output.
Stream Sequentially
Reading memory in order lets the CPU prefetch ahead. Jumping around defeats prefetching and stalls the loop.
for i in range(n):
total += a[i]Cache Lines Travel Together
Memory arrives in fixed-size cache lines. Using every byte of a line you fetched gives you free, already-loaded data.
Compute More per Byte
Arithmetic intensity is work done per byte loaded. Raising it means each fetched value earns more compute before you move on.
Write Once, If You Can
Stores cost bandwidth too. Accumulate in a local and write the final result once rather than updating memory repeatedly.
var acc = Float32(0)
for i in range(n):
acc += a[i]
out[0] = accLess Traffic, More Speed
When the kernel waits on data, cutting reads and writes is the biggest win, often beating clever arithmetic tweaks.
Quick Check
Your kernel reads the same array in two separate loops. What single change cuts its memory traffic most?
Recap
Cut memory traffic by touching data once, fusing loops, reusing registers, streaming in order, and writing results just once. 💾
الأسئلة الشائعة
هل درس «تقليل حركة الذاكرة» مجاني؟
نعم — نص درس «تقليل حركة الذاكرة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.
ماذا ستتعلم في «تقليل حركة الذاكرة»؟
أبقِ البيانات قريبة من وحدة الحساب تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟
لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تقليل حركة الذاكرة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟
نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.