0Pricing
CUDA Academy · Lección

Partición del trabajo entre GPU

Estrategias de descomposición del dominio

Partición del trabajo entre GPU es una lección gratuita de CUDA Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de CUDA Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de CUDA Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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. ✨

Preguntas frecuentes

¿La lección «Partición del trabajo entre GPU» es gratis?

Sí — el texto completo de «Partición del trabajo entre GPU» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de CUDA Academy, actualiza a CoddyKit PRO. El curso de CUDA Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Partición del trabajo entre GPU»?

Estrategias de descomposición del dominio Practicas CUDA Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar CUDA Academy?

No se requiere experiencia previa. CUDA Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Partición del trabajo entre GPU»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de CUDA Academy?

Sí. Cada lección de CUDA Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Enumeración y selección de dispositivos
  2. Partición del trabajo entre GPU
  3. Acceso entre pares a la memoria
  4. Varias GPU con NCCL
← Volver a CUDA Academy