0Pricing
CUDA Academy · Lesson

Partitioning Work Across GPUs

Domain decomposition strategies.

Partitioning Work Across GPUs is a free CUDA Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. ✨

Frequently asked questions

Is the “Partitioning Work Across GPUs” lesson free?

Yes — the full text of “Partitioning Work Across GPUs” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.

What will I learn in “Partitioning Work Across GPUs”?

Domain decomposition strategies. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CUDA Academy?

No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Partitioning Work Across GPUs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CUDA Academy lesson?

Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Enumerating and Selecting Devices
  2. Partitioning Work Across GPUs
  3. Peer-to-Peer Memory Access
  4. Multi-GPU with NCCL
← Back to CUDA Academy