May 31 2021: I wrote this repository in hope it could be useful for anyone else, but this was a very temporary project for me. I am no longer working on this subject and have no time to maintain it. So this repository is now archived.
This repository contains a sample python program which runs GPU computations (OpenGL) in headless mode (no display).
The program initializes an OpenGL context using EGL (and, optionally, GBM).
It will connect to kernel DRM interface file at /dev/dri/<something>
.
Then, to test if it works, it calls very basic OpenGL drawing functions to draw a blue rectangle, and writes a ppm image file.
In any case, you need appropriate GPU drivers, with libGL and libEGL. If you use a recent Nvidia driver, this will probably be enough. Otherwise (intel integrated GPU for example), the program will try load libgbm.
For example on an ubuntu OS with a mesa-compatible GPU, the following should work:
$ apt install libgl1-mesa-dri libegl1-mesa libgbm1
You need PyOpenGL and numpy:
$ pip install wheel
$ pip install pyopengl numpy
On my machine, I also had to fix file [python_dir]/site-packages/OpenGL/raw/EGL/_types.py
,
by applying this modification.
It may be already fixed in your pyopengl distribution when you read this.
For more optimized transfers between PyOpenGL and numpy, do:
$ pip install Cython
$ pip install PyOpenGL_accelerate
To run the program, just type
$ ./main.py
The code is mostly based on the following sample codes and documentation:
- This gist
- khronos group doc about EGL+GBM
- tensorflow/lucid sample python code, very useful reference for a Python version
- stackoverflow answers such as this one