التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية
قسّم العمل إلى كتل تلائم الذاكرة المخبئية
التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Cache Idea
The CPU keeps recently used data in a small, fast cache. Hits are quick; misses force a slow trip to main memory.
What Is Locality?
Cache locality means reusing data that is already nearby in the cache before it gets evicted to make room.
Big Data Spills the Cache
If your kernel sweeps a huge array, early elements are evicted before you reuse them, causing repeated cache misses.
Tile the Work
Tiling splits a big loop into small blocks that fit in cache, so each block's data stays hot while you use it.
alias tile = 64An Outer and Inner Loop
Tiling turns one loop into two: an outer loop over blocks and an inner loop over the elements inside each block.
for t in range(0, n, tile):
for i in range(t, min(t + tile, n)):
out[i] = a[i] * 2One Block at a Time
Each block is small enough to live in cache. You finish all its work before moving on, so reuse stays cheap.
Great for Matrices
Matrix multiply reuses rows and columns heavily. Blocking a matmul into tiles keeps reused data in cache and cuts misses.
Pick the Tile Size
The best tile fills the cache without overflowing it. Too small wastes reuse; too large spills, so you tune the size.
Tile Then Vectorize
Tiling and SIMD stack well. Vectorize the inner loop of each block to get cache locality and vector speed together.
for t in range(0, n, tile):
vectorize[body, width](min(tile, n - t))Mind the Edges
The last block may be smaller than a full tile. Clamp its range with min so you never read past the buffer.
var end = min(t + tile, n)Measure the Gain
Tiling can help a lot or a little depending on sizes. Always benchmark a few tile values on your real data to choose.
Quick Check
Your kernel keeps missing cache because it sweeps a huge array end to end. What technique helps?
Recap
Tiling blocks a big loop so each chunk fits in cache; tune the tile size, vectorize the inner loop, and clamp the edges. 🧱
الأسئلة الشائعة
هل درس «التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية» مجاني؟
نعم — نص درس «التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.
ماذا ستتعلم في «التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية»؟
قسّم العمل إلى كتل تلائم الذاكرة المخبئية تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟
لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟
نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تشريح نواة حسابية
- دمج SIMD مع الحلقات
- تقليل حركة الذاكرة
- التقسيم إلى كتل لتحسين محلية الذاكرة المخبئية