الخيوط والكتل والشبكات
نموذج تنفيذ GPU
الخيوط والكتل والشبكات درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Smallest Worker
A GPU runs your kernel as many tiny workers. Each single worker is a thread, and it usually handles one piece of data.
Grouping Threads
Threads are organized into a block. Threads in the same block can cooperate and share fast on-chip memory.
All Blocks Together
All the blocks for one kernel launch form the grid. The grid is the full set of workers handling your whole problem.
A Simple Hierarchy
The model nests neatly: threads live in blocks, and blocks live in a grid. Three levels describe every launch.
Each Thread Has an ID
Every thread can ask where it sits. Its index tells it which element of the data it is responsible for.
var tid = thread_idx.xEach Block Has an ID Too
Blocks are numbered as well. A thread combines its block id with its local id to find a unique spot.
var bid = block_idx.xComputing a Global Index
The classic formula maps each thread to one global element. This global index is how kernels split an array.
var i = block_idx.x * block_dim.x + thread_idx.xChoosing Block Size
You pick how many threads sit in a block. A good size keeps the hardware busy without wasting resources.
Choosing Grid Size
The grid must cover all your data. You size it so threads times blocks reach every element you need.
var blocks = (n + 255) // 256Guarding the Edges
The grid often launches a few extra threads. A simple bounds check stops them from touching memory past the end.
if i < n:
out[i] = a[i] + b[i]Why This Shape Helps
Blocks let groups share memory and sync, while the grid scales to any size. The structure maps work onto hardware cleanly.
Quick Check
A thread needs the position of its element across the whole array.
Recap
Threads group into blocks, blocks form the grid, and combining their ids gives each worker a unique global index. 🧵
الأسئلة الشائعة
هل درس «الخيوط والكتل والشبكات» مجاني؟
نعم — نص درس «الخيوط والكتل والشبكات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.
ماذا ستتعلم في «الخيوط والكتل والشبكات»؟
نموذج تنفيذ GPU تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟
لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «الخيوط والكتل والشبكات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟
نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا نستخدم GPU لأعباء الذكاء الاصطناعي
- الخيوط والكتل والشبكات
- كتابة دالة نواة GPU
- نقل البيانات من الجهاز وإليه