Idein / py-videocore

Python library for GPGPU on Raspberry Pi
MIT License
792 stars 89 forks source link

PyVideoCore

This is work in progress project. Backward compatibility is not guaranteed.

PyVideoCore is a Python library for GPGPU on Raspberry Pi boards. The Raspberry Pi SoC integrates Broadcom VideoCore IV graphics core. It has 12 quad processor units (QPU) which is a dual-issue 16 way (4 way pipelined and 4 way true) SIMD processor. Read the following guide thoroughly to study its architecture.

Several QPU assemblers are written by pioneers (hermanhermitage <https://github.com/hermanhermitage/videocoreiv-qpu/blob/master/qpu-tutorial/qpuasm.md>, petewarden <https://github.com/jetpacapp/qpu-asm>, elorimer <https://github.com/elorimer/rpi-playground/tree/master/QPU/assembler>_ and so on). There is also an implementation of OpenCL for QPU: VC4CL <https://github.com/doe300/VC4CL>.

PyVideoCore's QPU assembler is different from theirs in terms of that its assembly language is implemented as an Internal DSL of Python language. This makes GPGPU programming on Raspberry Pi relatively easier in the sense that

Requirements

Installation

::

$ git clone https://github.com/nineties/py-videocore.git
$ cd py-videocore
$ python setup.py install

Note that PyVideoCore does not work with the CPU-side OpenGL graphics stack, so configure your pi to use the legacy (original non-GL desktop) driver by the sudo raspi-config command (it just comments out all the dtoverlay=vc4-kms-v3d and dtoverlay=vc4-fkms-v3d lines in /boot/config.txt).

Depending on your running kernel version, PyVideoCore allocates memory through /dev/vcsm or /dev/vcsm-cma, which are the devices of the VCSM (VideoCore shared memory service) and the VCSM-CMA (contiguous memory allocator) drivers, respectively. To access the devices, you need to belong to the video group or need to be the root user. If you choose the former, run the following command and re-login.

::

$ sudo usermod --append --groups video $USER

The plain VCSM driver allocates memory in the GPU-side memory, of which size can be configured by the gpu_mem=XXX option in /boot/config.txt (e.g. gpu_mem=128 for 128 MB). This can also be done via the sudo raspi-config command.

On the other hand, the VCSM-CMA driver allocates memory in the CPU-side CMA memory, of which size can be configured by the dtoverlay=cma,cma-XXX option in /boot/config.txt (e.g. dtoverlay=cma,cma-128 for 128 MB).

Nevertheless, VideoCore IV QPUs can access arbitrary portions of the main memory, which may make your system unstable and even break your pi, so beware of bugs in the programs.

Getting Started

::

$ python examples/hello_world.py

Running Tests

::

$ nosetests -v

Documentation

TBD

Tutorials

In japanese.

Records

License

Code and documentation are released under MIT license <https://github.com/nineties/py-videocore/blob/master/LICENSE>__


.. [#appendix] Supplementary information and errata list. <https://github.com/nineties/py-videocore/blob/master/APPENDIX.rst>__