تجنّب تعارضات البنوك
لماذا يمكن للحشو تسريع الوصول إلى الذاكرة المشتركة.
تجنّب تعارضات البنوك درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Shared Memory Has Banks
Shared memory is split into 32 banks, one for each thread in a warp. Spreading accesses across them lets all 32 threads read at full speed.
How Addresses Map
Consecutive 4-byte words land in consecutive banks, wrapping around after 32. So word 0 is bank 0, word 32 is bank 0 again.
What a Bank Conflict Is
A bank conflict happens when two threads in a warp hit the same bank but different words. The hardware must serialize those accesses.
Serialization Costs Speed
An N-way conflict turns one fast access into N slow ones. A 32-way conflict can make shared memory as slow as if it were single-file. 🐢
The Happy Case: Stride One
When each thread reads tile[threadIdx.x], every thread hits a distinct bank. That is conflict-free and runs at full bandwidth.
float v = tile[threadIdx.x];The Trap: Stride of 32
Reading with a stride of 32 sends every thread to the same bank. That is the worst case, a full 32-way conflict.
float v = tile[threadIdx.x * 32];Even Strides Hurt Too
Any even stride that shares a factor with 32 causes partial conflicts. A stride of 2, for example, gives a 2-way conflict across the warp.
The Broadcast Exception
Good news: if all threads read the same address, the hardware broadcasts it in one shot. Same word is fine, only same bank with different words conflicts.
Padding to the Rescue
For 2D tiles, add one extra column with +1 padding. This shifts each row so column accesses no longer all land in one bank.
__shared__ float tile[32][33];Why +1 Works
The extra column makes the row length coprime with 32. Now stepping down a column visits a different bank each time, killing the conflict.
Profile, Do Not Guess
Bank conflicts are invisible in source code. Use Nsight Compute to measure shared-memory conflicts before spending effort fixing them.
Quick Check
Let us check what makes shared access fast.
Recap
You learned that shared memory has 32 banks, that same-bank different-word access serializes, and that +1 padding fixes column conflicts. Next: dynamic shared memory. 🎯
الأسئلة الشائعة
هل درس «تجنّب تعارضات البنوك» مجاني؟
نعم — نص درس «تجنّب تعارضات البنوك» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «تجنّب تعارضات البنوك»؟
لماذا يمكن للحشو تسريع الوصول إلى الذاكرة المشتركة. تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تجنّب تعارضات البنوك»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تعريف مصفوفات __shared__
- المزامنة باستخدام __syncthreads
- تجنّب تعارضات البنوك
- الذاكرة المشتركة الديناميكية