Particionando o trabalho entre GPUs
Estratégias de decomposição de domínio.
Particionando o trabalho entre GPUs é uma aula grátis de CUDA Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de CUDA Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de CUDA Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. ✨
Perguntas Frequentes
A aula “Particionando o trabalho entre GPUs” é grátis?
Sim — o texto completo de “Particionando o trabalho entre GPUs” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de CUDA Academy, atualize para CoddyKit PRO. O curso de CUDA Academy inclui 4 aulas no total.
O que vou aprender em “Particionando o trabalho entre GPUs”?
Estratégias de decomposição de domínio. Você pratica CUDA Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar CUDA Academy?
Nenhuma experiência prévia é necessária. CUDA Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Particionando o trabalho entre GPUs”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de CUDA Academy?
Sim. Cada aula de CUDA Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Enumerando e selecionando dispositivos
- Particionando o trabalho entre GPUs
- Acesso ponto a ponto à memória
- Várias GPUs com NCCL