-
Why GPUs?
A CPU has a few powerful cores built for fast sequential work; a GPU has thousands of simpler cores that apply the same instruction to many pieces of data at once. Transit detection suits this well: it repeats one operation, comparing a transit model with the light curve, millions of times across a grid of parameters, and each evaluation is largely independent.
In GPU programming, a function called a kernel runs across a grid of thousands of threads. Threads are grouped into blocks, which run on the GPU’s streaming multiprocessors, and threads in the same block can share fast memory. CETRA’s kernels are written in CUDA C and launched from Python using PyCUDA.
A CPU has a few powerful cores; a GPU has thousands of simple ones. -
Memory matters
On a GPU, how you access memory matters at least as much as the computation. Registers and shared memory are fast but small; global memory is large but takes hundreds of clock cycles to reach; and the host computer’s memory is slower still. A kernel that keeps reading from global memory spends most of its time waiting, and threads that read neighbouring addresses together, known as coalesced access, are far more efficient.
Approximate clock cycles to access each level of GPU memory. -
Designing for the hardware
Low-level tuning can’t rescue an algorithm that is the wrong shape for the hardware. A first attempt to port TLS directly to the GPU failed: TLS sorts the light curve for every trial period, which GPUs do poorly, and sorting on the CPU instead meant constant transfers between host and GPU, making it an order of magnitude slower than TLS. CETRA was redesigned from the ground up for the GPU. CUDA C was chosen for its full control over memory and its excellent documentation. For anyone starting a similar project, Leigh suggests learning the fundamentals with Numba or CUDA before deciding whether portability justifies OpenCL. -
More on GPU programming
Watch the next video for an introduction to GPU programming and the choices behind CETRA’s implementation.