0Pricing
CUDA Academy · บทเรียน

การแบ่งงานข้าม GPU

กลยุทธ์การแยกโดเมน

การแบ่งงานข้าม GPU เป็นบทเรียน CUDA Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส CUDA Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส CUDA Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การแบ่งงานข้าม GPU”

กลยุทธ์การแยกโดเมน คุณปฏิบัติ CUDA Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน CUDA Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน CUDA Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การแบ่งงานข้าม GPU” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน CUDA Academy นี้ได้ไหม

ได้ บทเรียน CUDA Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การแจกแจงและเลือกอุปกรณ์
  2. การแบ่งงานข้าม GPU
  3. การเข้าถึงหน่วยความจำแบบเพียร์ทูเพียร์
  4. หลาย GPU ด้วย NCCL
← กลับไปที่ CUDA Academy