تقسيم العمل بين وحدات GPU
استراتيجيات تقسيم المجال
تقسيم العمل بين وحدات GPU درس مجاني في CUDA Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في CUDA Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة CUDA Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Many GPUs, One Job
Two GPUs can finish a job in roughly half the time, but only if you split the work. The art is partitioning: deciding which GPU handles which part.
Domain Decomposition
The classic strategy is to cut the data, not the code. With domain decomposition each GPU gets its own slice of the array or grid to process.
Slicing an Array
For a 1D array, just divide its length. Give the first chunk of elements to GPU 0 and the next chunk to GPU 1, and so on.
int chunk = n / count;Computing Each Offset
Every GPU needs the start of its slice. The offset for device d is simply d times the chunk size, marking where its data begins.
int offset = d * chunk;Allocate Per Device
Each GPU needs its own buffer. Set the device, then cudaMalloc space just for that card's slice instead of the whole array.
cudaSetDevice(d);
cudaMalloc(&dptr[d], chunk * sizeof(float));Copy Only the Slice
Upload to each GPU only the portion it owns. Copy from host[offset] into that device's buffer so no card holds data it will not touch.
Launch on Every Device
Loop over the GPUs, set each current, and launch the kernel on its slice. The launches are asynchronous, so all cards start working in parallel.
Gather the Results Back
When kernels finish, copy each device's output back into the right spot of the host array using its offset. The pieces reassemble into one result.
Mind the Leftover
If n does not divide evenly, the last GPU must handle the remainder. Give it the extra elements so nothing in the array is skipped.
int last = n - offset;Watch the Boundaries
Stencil and neighbor operations read across slice edges. Those halo regions must be shared between GPUs, or results at the borders go wrong.
Balance the Load
If one GPU is faster, an even split wastes it. Good load balancing gives the stronger card a bigger slice so both finish at the same time.
Quick Check
Recall the standard way to spread one large dataset across several GPUs.
Recap
You split data into slices, allocate and copy per device, launch on each, then gather results. Mind the remainder and halos. Next: copying directly GPU to GPU. ✨
الأسئلة الشائعة
هل درس «تقسيم العمل بين وحدات GPU» مجاني؟
نعم — نص درس «تقسيم العمل بين وحدات GPU» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة CUDA Academy، انتقل إلى CoddyKit PRO. تتضمن دورة CUDA Academy 4 دروس في المجموع.
ماذا ستتعلم في «تقسيم العمل بين وحدات GPU»؟
استراتيجيات تقسيم المجال تتمرن على CUDA Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ CUDA Academy؟
لا تُشترط خبرة سابقة. CUDA Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تقسيم العمل بين وحدات GPU»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس CUDA Academy هذا؟
نعم. كل درس في CUDA Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- حصر الأجهزة واختيارها
- تقسيم العمل بين وحدات GPU
- الوصول إلى الذاكرة من نظير إلى نظير
- استخدام وحدات GPU متعددة مع NCCL