# Loopy: describe an array computation once, transform it into fast CPU or GPU code

> Loopy is a Python code generator for array-type computations, where a kernel is written as simple loops and then transformed under your control into vectorised, multi-threaded or GPU code, with the project stating plainly that it is not a general-purpose programming language.

**inducer/loopy** — A code generator for array-based code on CPUs and GPUs

- Repository: https://github.com/inducer/loopy
- Website: http://mathema.tician.de/software/loopy
- Stars: 639 · Forks: 81
- Language: Python
- License: MIT
- Published: 2026-10-21 · Updated: 2026-10-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/inducer-loopy

## A generator that treats optimisation as a user-driven transformation

Loopy is described as a transformation-based generator of high performance CPU and GPU code. The core idea, stated plainly in the project README, is that a computation should be described simply and then transformed into a version that gets high performance, with the transformation taking place under user control from within Python. That is the whole pitch, and it is a different bargain from writing OpenCL by hand. You write the kernel as loops over array indices, and Loopy exposes the optimisation steps as things you schedule and configure. The audience is scientific computing developers, HPC people, and anyone who has written a convolution or an n-body kernel and knows that the difference between a naive version and a fast one is a few hundred lines of fiddly index arithmetic. The licence is MIT and free for commercial, academic and private use, and the project is maintained by Andreas Kloeckner, whose name appears as the sole author in the package metadata.

## The optimisation families Loopy claims to capture

The README lists the types of optimisation the transformation machinery can express, and the list is the best single description of what the project does. Vector and multi-core parallelism in the OpenCL and CUDA model, data layout transformations from structure of arrays to array of structures, loop unrolling, loop tiling with efficient handling of boundary cases, prefetching and copy optimisations, and instruction level parallelism. That last group matters, because it means the target is not just a GPU but also vectorised CPU code where the compiler can be coaxed into using the wider registers. What the project deliberately does not do is general purpose programming: the README says Loopy is not, and does not want to be, a general-purpose programming language. Its target is array-type computations, and the list given is dense linear algebra, convolutions, n-body interactions, and PDE solvers such as finite element, finite difference and Fast-Multipole-type computations. So if your kernel is a linked list traversal or a text parser, this is the wrong tool.

## Installing from the package index, and what gets pulled in

The README states that all of Loopy's dependencies can be installed automatically from the package index after a single command.

```bash
    pip install loopy
```

The dependency list in the package metadata is more instructive than the install command. It is dominated by the toolkit the author maintains: pytools for general utilities, pymbolic for symbolic expression handling, genpy for code generation support, cgen for emitting C-like source, islpy and namedisl for the integer set library that makes polyhedral style reasoning about loop bounds possible, and codepy as the code generation front end. numpy is a direct dependency, and there is an optional extra for pyopencl for the OpenCL path. The package requires Python 3.10 or newer and is built with hatchling. The classifiers describe it as a beta with a developer, science and research audience, which is a fair self-assessment of a research code generator.

## Examples, the ISPC path and a separate test suite

The examples directory shows the range of things people do with it: a rank-one update, a sparse example, finding centres, removing global barriers, calling out to external code, and a vector types example in both OpenCL and Python. Two entries deserve attention. The first is the ispc stream harness, paired with a run-ispc-harness.sh script and a tasksys.cpp file, which shows the project supporting ISPC as a target alongside OpenCL and CUDA. The second is hello-loopy, which exists in three parallel forms, as a.py script, a.loopy file and a.cl file, which is a neat way of showing the same kernel before and after generation. The repository also carries a proto-tests/ directory, an asv.conf.json for performance benchmarking, a CITATION.cff for citation metadata, and a MEMO file. The requirements.txt lists the same toolkit packages pulled directly from GitHub rather than from the index, which is what a developer checkout uses.

## A source tree that moves faster than the released package

Maintenance here is unusually visible. The last push to the repository was on 2026-10-18, and the package metadata already declares version 2026.1, while the published releases on GitHub are v2025.2 from 2025-07-30, v2025.1 from 2025-04-02 and v2024.1 from 2024-02-16. The version scheme is calendar based, which is a reasonable convention for a research tool and means the number tells you roughly when a snapshot was cut. The practical consequence is that installing from the package index gives you something older than the source tree, and the difference is not cosmetic in a code generator, because transformations and code generation paths change. The project also ships an AGENTS.md, a .basedpyright/ directory for type checking configuration, and both GitLab and GitHub CI badges, so it is built and tested on two platforms. Documentation lives at a separate site, and the README points to a benchmarks page for the performance-oriented examples.

## Where Loopy is the wrong tool

The wrong-tool case is stated by the project itself, which is refreshing. Loopy is for array computations, so irregular data structures, pointer chasing, and anything where you would end up writing arbitrary C by hand are out of scope. Second, the transformation-based model has a cost: the effort shifts from writing the kernel to learning the transformation vocabulary, the scheduling language, and the code generation options, and for a one-off kernel that is a lot of learning for a modest gain. Third, the toolchain is heavy. numpy, an integer set library, a code generation front end, Mako for templating and, if you want OpenCL, pyopencl all have to be present, and the developer requirements pull several of them straight from GitHub, which is a sign of how tightly the pieces are versioned against each other. The alternative worth naming is writing the kernel by hand in C with compiler flags, which is what most teams do for a single kernel, and which keeps full control of the output at the cost of doing index arithmetic yourself.

## Conclusion

Adopt Loopy if you are writing array kernels for a CPU or GPU and want to experiment with transformations such as vectorisation, loop tiling and data layout changes from Python rather than by hand in C. Do not adopt it for irregular or pointer-heavy work, since the README restricts it to array-type computations and says outright that it is not a general-purpose language. Verify first that your target hardware and toolchain are supported by the code generation path you intend, and pin the version, because the package is on a calendar-style version scheme and the source of the current tree is newer than the last published release.

## FAQ

### How do I install Loopy?

The README states that all dependencies can be installed automatically from the package index with pip install loopy. The package requires Python 3.10 or newer, and there is an optional pyopencl extra for the OpenCL path.

### What kinds of computations is Loopy designed for?

The README lists dense linear algebra, convolutions, n-body interactions, and PDE solvers such as finite element, finite difference and Fast-Multipole-type computations. It also states that Loopy is not, and does not want to be, a general-purpose programming language.

### Which code generation backends does Loopy support?

The project targets vector and multi-core parallelism in the OpenCL and CUDA model, and the examples directory includes an ispc stream harness alongside the OpenCL hello-loopy example, showing ISPC as a target too.

### How do I get the latest version of Loopy?

The published GitHub releases are v2025.2, v2025.1 and v2024.1, while the package metadata in the repository already declares version 2026.1 and the last push was on 2026-10-18. Installing from the package index therefore gives you an older snapshot than the source tree.

## Sources

- [inducer/loopy on GitHub](https://github.com/inducer/loopy)
- [License: MIT](https://github.com/inducer/loopy/blob/main/LICENSE)
- [Project website](http://mathema.tician.de/software/loopy)
- [README](https://github.com/inducer/loopy/blob/main/README.md)
- [Releases](https://github.com/inducer/loopy/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/inducer-loopy
