flâneur

A Tiny Compiler for Data-Parallel Kernels — Andrew Healey

healeycodes.com · 1,290 words · saved by 1 readers

Exploring how compilers lower ordinary loops into explicit data-parallel kernels.

A lot of fast code starts as a boring loop. Modern hardware can perform the same operation on multiple values at once (e.g. SIMD and SIMT), and sometimes we write code directly for those execution models but other times, a compiler starts with regular-looking code and rewrites it so multiple loop iterations can run together. I built a tiny compiler (~180LOC of Python) to understand what that transformation looks like. My compiler lowers kernels (rewrites them into a simpler, more explicit form where data parallelism is visible). The input is a small hand-written AST, and the output is a…

saved by

related reading