inducer/pyopencl

OpenCL integration for Python, plus shiny features

PyOpenCL – Pythonic access to OpenCL GPUs and accelerators

What it is – PyOpenCL is a Python library that lets you write code that runs on any OpenCL‑compatible device (GPUs, CPUs, FPGAs, etc.). It mirrors the full OpenCL API while adding Python‑friendly features such as automatic error conversion, reference‑counted objects (RAII‑style cleanup), and NumPy‑compatible array handling.

Why it matters for AI/ML – Modern machine‑learning workloads often rely on massive parallelism. PyOpenCL gives Python developers a way to tap that parallel power without leaving the language, making it possible to prototype custom kernels, accelerate data‑preprocessing, or implement niche neural‑network operations that aren’t covered by higher‑level frameworks.

Key features (as described in the README)

  • RAII‑style resource management – Objects are freed automatically when they go out of scope, reducing memory‑leak bugs.
  • Complete OpenCL coverage – Every OpenCL call and query is exposed, so you can use the full feature set of the underlying driver.
  • Automatic error handling – OpenCL error codes are turned into Python exceptions, simplifying debugging.
  • Speed – The core bindings are written in C++ (C++17) and use nanobind for low‑overhead interfacing, so the convenience layer adds virtually no runtime cost.
  • Cross‑platform support – Tested with the OpenCL implementations from Apple, AMD, and NVIDIA.
  • Easy installation – Binary wheels are provided for Linux, macOS, and Windows via PyPI and Conda‑Forge; a simple Conda‑based install also pulls in a working OpenCL runtime.
  • Open source – MIT‑licensed, free for commercial and academic use.

Typical workflow

  1. Create a context that selects a device (GPU, CPU, etc.).
  2. Write an OpenCL kernel as a string or load from a file.
  3. Build the kernel using the provided program object.
  4. Allocate buffers (often as NumPy arrays) and transfer data.
  5. Launch the kernel with a global and local work‑size.
  6. Read results back into Python objects.

Getting started – The README points to a four‑step Conda install guide and links to comprehensive documentation and a wiki for deeper examples.

Who uses it – Researchers, data‑scientists, and engineers who need fine‑grained control over GPU computation while staying in Python, especially when they want to write custom kernels that aren’t available in higher‑level libraries.

Where to find it – Source code, issue tracker, and releases are on GitHub (github.com/inducer/pyopencl). Binary packages are on PyPI and Conda‑Forge.


All details above are taken directly from the repository’s README.

Related

  • Project
  • Project
  • Project
  • Project
  • Project