Prefer to read without ads? Become a member — from $10/month — and support the work. Already a member? Log in to read ad-free on this device.

14.6 Multiple GPUs and Scalability

Because the computational density is so high, N-Body scales well across multiple GPUs. Portable pinned memory is used to hold the body descriptions, so they can easily be referenced by all GPUs in the system; and for a system containing k GPUs, each GPU is assigned N/k forces to compute5. Our multi-GPU implementation of N-body is featured in Chapter 9. The rows are evenly divided among GPUs, the input data is broadcast to all GPUs via portable pinned memory, and each GPU computes its output independently.

CUDA applications that use multiple GPUs can be multi-threaded or single-threaded; Chapter 9 includes optimized N-body implementations that illustrate both approaches.

For N-body, the single- and multi-threaded implementations have the same performance, since there is little work for the CPU to do. Table 14-3 summarizes the scalability of the multithreaded implementation for a problem size of 96K bodies and up to 4 GPUs. The efficiency is the percentage of measured performance as compared to perfect scaling.

Number of GPUs Performance (billions of body-body interactions per second) Efficiency
1 44.1 100%
2 85.6 97.0%
3 124.2 93.4%
4 161.5 91.6%

Table 14-3. N-body Scalability

There is room for improvement over this result, since the performance results reported here include allocation and freeing of device memory on each GPU, for each timestep.

These figures are from the original four-GK104 test rig, and single-GPU throughput has grown enormously since. On a GeForce RTX 3060 (Ampere), the same single-GPU code path sustains about 298 billion body-body interactions per second for 96K bodies—about 6.7× the 44.1 billion of a single GK104, and more than the 161.5 billion all four underclocked GK104s delivered together. That last comparison is a statement about generational hardware, not an argument against scaling out: N-body’s high computational density—the very property that let it scale near-linearly across the four GK104s in Table 14-3—applies just as well to modern parts, so several RTX 3060s would multiply that 298 billion figure much as the table multiplies the GK104 result. A faster single GPU raises the problem size at which a second GPU yields a net speedup; it does not remove the reason large simulations and machine-learning workloads are spread across many GPUs at once.


  1. Our implementation requires that N be evenly divisible by k, a constraint that should be easy to meet by padding with bodies with mass==0.↩︎