Saltar al contenido ForoHackers

GPU programming: start here

Programación de GPU
#473 · Ophuscado · · Denunciar

A GPU is a processor built for doing the same small job on thousands of data items at once. It draws images, but it also speeds up simulation, image processing and machine learning. Programming one means thinking in massive parallelism and in memory movement, since moving data usually costs more than computing on it.

Key concepts

  • Data parallelism: one kernel or shader runs over many threads, each handling one element.
  • Execution model: threads grouped into blocks or workgroups, run in lockstep bundles; branches that diverge within a bundle slow it down.
  • Memory hierarchy: global memory is large and slow; shared or local memory is small and fast; registers are fastest.
  • Host and device: the CPU prepares data and launches work; copies across the bus must be minimised.
  • Occupancy and bandwidth: keep enough threads in flight to hide memory latency, and check whether you are limited by compute or by memory.

Vocabulary

  • Kernel: a function launched on the GPU across many threads.
  • Shader: a GPU program in the graphics pipeline, such as a vertex or fragment shader.
  • Coalescing: neighbouring threads reading neighbouring addresses so the hardware merges the loads.
  • Compute API: CUDA, OpenCL, or the compute stages of graphics APIs such as Vulkan.

What to study, in order

  1. Parallel thinking on the CPU: map, reduce and scan over arrays.
  2. Write a vector addition kernel and time it, including the copies.
  3. Implement a matrix multiplication naively, then with shared-memory tiling; measure the gap.
  4. Write a fragment shader that draws something, then a compute shader that processes an image.
  5. Use a profiler to decide whether each kernel is bound by memory or by arithmetic.

Related tags

#computer-graphics #hpc #computer-architecture #deep-learning

Inicia sesión o únete para responder.