C++ library for programming the VideoCore GPU on all Raspberry Pi's.

Related tags

Video V3DLib
Overview

V3DLib

Version 0.2.8

V3DLib is a C++ library for creating programs to run on the VideoCore GPU's of all versions of the Raspberry Pi.

Prior to the Pi 4, this meant compiling for just the VideoCore IV GPU. The Pi 4, however, has a VideoCore VI GPU which, although related, is significantly different. V3DLib compiles and assembles for both versions of the VideoCore GPU.

Kernel programs compile dynamically, so that a given program can run unchanged on any version of the RaspBerry Pi. The kernels are generated inline and offloaded to the GPU's at runtime.


Recent Release Notes

  • External library CmdParameter has changed. Please run ./script/install.sh when upgrading from a version <= 0.0.8.
  • Upping the version - The API is still a moving target and keeps on breaking. Officially, I should be changing the major version continually, but with the project freshly released and having exactly two users, I consider this overkill. I'll up the minor version periodically as a compromise.

First Release

When I started this project, I resolved to release at the point that all examples would compile and run on the VideoCore VI. I have finally reached this point.


NOTE: This means that V3DLib has reached a level of mimimum viability. It is by no means feature-complete and can definitely use some refactoring and cleanup.


However, there are caveats.

There are some parts which will compile perfectly but not run properly; notably the Mandelbrot demo will run sometimes on a VideoCore VI, and otherwise hang. This is in part due to issues in the linux kernel, see the Issues page. There are also some unit tests which have the same problem, these are disabled when running on VideoCore VI.

I haven't been able to resolve these issues and I am waiting for a kernel update with fixes. All code for the VideoCore IV compiles and runs fine.

Credit where Credit is Due

This project builds upon the QPULib project, by Matthew Naylor. I fully acknowledge his work for the Videcore 4 and am grateful for what he has achieved in setting up the compilation and assembly.

QPULib, however, is no longer under development, and I felt the need to expand it to support the VideoCore VI as well. Hence, V3DLib was conceived.

The Programming Language

V3DLib contains a high-level programming language for easing the pain of GPU-programming. The following is an example of the language (the 'Hello' example):

#include "V3DLib.h"
#include "Support/Settings.h"

using namespace V3DLib;

V3DLib::Settings settings;


// Define function that runs on the GPU.
void hello(Ptr p) {
  *p = 1;
}


int main(int argc, const char *argv[]) {
  auto ret = settings.init(argc, argv);
  if (ret != CmdParameters::ALL_IS_WELL) return ret;

  // Construct kernel
  auto k = compile(hello);

  // Allocate and initialise array shared between ARM and GPU
  SharedArray array(16);
  array.fill(100);

  // Invoke the kernel
  k.load(&array);
  settings.process(k);

  // Display the result
  for (int i = 0; i < array.size(); i++) {
    printf("%i: %i\n", i, array[i]);
  }
  return 0;
}

Getting Started

This assumes that you are building on a Raspberry Pi.

For more extensive details on building, see Build Instructions.

Fair Warning: The first build can take a long time, especially on older Pi's. See the Build Instructions for details.

> sudo apt-get install git                                       # If not done already
> git clone --depth 1 https://github.com/wimrijnders/V3DLib.git  # get only latest commit
> cd V3DLib

# As long as the files don't change, you need to run this script only once.
> script/install.sh                                              # Pull in and build external library
# After this, it's sufficient to do just the following line for a build

> make QPU=1 DEBUG=1 all                                         # Make debug version with hardware
                                                                 # GPU support.

> make QPU=1 DEBUG=1 test                                        # Build and run the tests

Useful Links

References

The following works were very helpful in the development.

VideoCore IV

VideoCore VI

Tools


Comments
  • Seg Fault on examples

    Seg Fault on examples

    I was interested in trying out some things with this on my RPI4, but I am getting segfaults running the examples after following the build instructions.

    Linux Version: 5.10.11-v8+ #1399 SMP PREEMPT Thu Jan 28 12:14:03 GMT 2021 aarch64

    Tried with both: dtoverlay=vc4-fkms-v3d and dtoverlay=vc4-kms-v3d

    Hello, ID, GCD, tri, Rot3D, etc all result in 'Segmentation Fault', with and without sudo

    detectPlatform gives me:

    Platform: Raspberry Pi 4 Model B Rev 1.2
    Chip version: BCM2835
    This is a pi platform.
    GPU: v3d (VideoCore VI)
    
    Cmdline param's:
      Reset Scheduler  : false
      Reset GPU        : false
    
    Revision        : 4.2.14.0
    Number of cores : 1
    MMU             : yes
    TFU             : yes
    TSY             : yes
    MSO             : yes
    L3C             : no (0kb)
    
    Core index 0:
      Revision      : 4.2
      VPM size      : 8
      Num slices    : 2
      Num TMU's     : 2 (all slices)
      Num QPU's     : 8 (all slices)
      Num semaphores: 0
      BCG int       : no
      Override TMU  : no
    
    Status Registers:
      GMP_STATUS: 0
      CSD_STATUS: 0
    Error Registers:
      FDBG0     : 0
      FDBGB     : 0
      FDBGR     : 0
      FDBGS     : 0
      STAT      : 0
    MMUC_CONTROL: 1
    MMU_CTL     : 60d0c01
      Fields:
        Cap exceeded   : false
          ... abort    : true
          ... int      : true
          ... exception: false
        Pt invalid     : false
          ... abort    : true
          ... int      : true
          ... exception: false
          ... enable   : true
        Write violation: false
          ... abort    : true
          ... int      : true
          ... exception: false
        TLB:
          ... clearing    : false
          ... stats clear : false
          ... clear       : false
          ... stats enable: false
        Enable: true
    
    opened by csr-kick 42
  • Failed to build on Raspberry PI buster - 64 bits

    Failed to build on Raspberry PI buster - 64 bits

    Hi!

    I was able to build/run the examples using buster 32 bits smoothly. However, when I tried to compile on Raspberry OS buster 64 bits I got the following output:

    pi@raspberrypi:~ $ uname -m
    aarch64
    pi@raspberrypi:~ $ gcc --version
    gcc (Debian 8.3.0-6) 8.3.0
    Copyright (C) 2018 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    pi@raspberrypi:~ $ git clone --depth 1 https://github.com/wimrijnders/V3DLib.git
    Cloning into 'V3DLib'...
    remote: Enumerating objects: 770, done.
    remote: Counting objects: 100% (770/770), done.
    remote: Compressing objects: 100% (672/672), done.
    remote: Total 770 (delta 86), reused 636 (delta 83), pack-reused 0
    Receiving objects: 100% (770/770), 4.54 MiB | 4.67 MiB/s, done.
    Resolving deltas: 100% (86/86), done.
    pi@raspberrypi:~ $ cd V3DLib/
    pi@raspberrypi:~/V3DLib $ script/install.sh 
    Cloning into 'CmdParameter'...
    remote: Enumerating objects: 199, done.
    remote: Counting objects: 100% (199/199), done.
    remote: Compressing objects: 100% (107/107), done.
    remote: Total 620 (delta 127), reused 140 (delta 85), pack-reused 421
    Receiving objects: 100% (620/620), 224.67 KiB | 824.00 KiB/s, done.
    Resolving deltas: 100% (393/393), done.
    Already on 'master'
    Your branch is up to date with 'origin/master'.
    From https://github.com/wimrijnders/CmdParameter
     * branch            master     -> FETCH_HEAD
    Already up to date.
    rm -rf obj obj-debug generated
    Compiling Lib/TypedParameter.cpp
    Compiling Lib/Types/Types.cpp
    Compiling Lib/Types/NoneParameter.cpp
    Compiling Lib/Types/IntParameter.cpp
    Compiling Lib/Types/OptionParameter.cpp
    Compiling Lib/Types/StringParameter.cpp
    Compiling Lib/Types/UnnamedParameter.cpp
    Compiling Lib/Types/UnsignedIntParameter.cpp
    Compiling Lib/Types/PositiveIntParameter.cpp
    Compiling Lib/Types/PositiveFloatParameter.cpp
    Compiling Lib/DefAction.cpp
    Compiling Lib/CmdParameters.cpp
    Compiling Lib/DefParameter.cpp
    Compiling Lib/CmdValidation.cpp
    Creating obj-debug/libCmdParameter.a
    Compiling Examples/Simple.cpp
    Linking obj-debug/bin/Simple...
    Compiling Examples/Actions.cpp
    Linking obj-debug/bin/Actions...
    Compiling Lib/TypedParameter.cpp
    Compiling Lib/Types/Types.cpp
    Compiling Lib/Types/NoneParameter.cpp
    Compiling Lib/Types/IntParameter.cpp
    Compiling Lib/Types/OptionParameter.cpp
    Compiling Lib/Types/StringParameter.cpp
    Compiling Lib/Types/UnnamedParameter.cpp
    Compiling Lib/Types/UnsignedIntParameter.cpp
    Compiling Lib/Types/PositiveIntParameter.cpp
    Compiling Lib/Types/PositiveFloatParameter.cpp
    Compiling Lib/DefAction.cpp
    Compiling Lib/CmdParameters.cpp
    Compiling Lib/DefParameter.cpp
    Compiling Lib/CmdValidation.cpp
    Creating obj/libCmdParameter.a
    Compiling Examples/Simple.cpp
    Linking obj/bin/Simple...
    Compiling Examples/Actions.cpp
    Linking obj/bin/Actions...
    pi@raspberrypi:~/V3DLib $ script/gen.sh 
    pi@raspberrypi:~/V3DLib $ make QPU=1 DEBUG=1 all 
    Building for QPU
    Building on a Pi platform
    Compiling Lib/vc4/RegisterMap.cpp
    Compiling Lib/vc4/RegAlloc.cpp
    Compiling Lib/vc4/SourceTranslate.cpp
    Compiling Lib/vc4/Invoke.cpp
    In file included from Lib/Common/BufferObject.h:6,
                     from Lib/Common/SharedArray.h:4,
                     from Lib/vc4/Invoke.h:5,
                     from Lib/vc4/Invoke.cpp:1:
    Lib/Support/HeapManager.h: In member function ‘int V3DLib::HeapManager::num_free_ranges() const’:
    Lib/Support/HeapManager.h:22:57: warning: conversion from ‘std::vector<V3DLib::HeapManager::FreeRange>::size_type’ {aka ‘long unsigned int’} to ‘int’ may change value [-Wconversion]
      int num_free_ranges() const { return m_free_ranges.size(); }
                                           ~~~~~~~~~~~~~~~~~~^~
    Lib/vc4/Invoke.cpp: In function ‘void V3DLib::invoke(int, V3DLib::SharedArray<unsigned int>&, int, V3DLib::Seq<int>*)’:
    Lib/vc4/Invoke.cpp:56:47: error: cast from ‘uint32_t*’ {aka ‘unsigned int*’} to ‘uint32_t’ {aka ‘unsigned int’} loses precision [-fpermissive]
         codeMem[offset++] = (uint32_t) paramsPtr[i];
                                                   ^
    Lib/vc4/Invoke.cpp:57:36: error: cast from ‘uint32_t*’ {aka ‘unsigned int*’} to ‘uint32_t’ {aka ‘unsigned int’} loses precision [-fpermissive]
         codeMem[offset++] = (uint32_t) qpuCodePtr;
                                        ^~~~~~~~~~
    Lib/vc4/Invoke.cpp:63:57: error: cast from ‘uint32_t*’ {aka ‘unsigned int*’} to ‘uint32_t’ {aka ‘unsigned int’} loses precision [-fpermissive]
       unsigned result = execute_qpu(mb, numQPUs, (uint32_t) launchMsgsPtr, 1, QPU_TIMEOUT);
                                                             ^~~~~~~~~~~~~
    In file included from Lib/vc4/Invoke.h:5,
                     from Lib/vc4/Invoke.cpp:1:
    Lib/Common/SharedArray.h: In instantiation of ‘T* V3DLib::SharedArray<T>::getPointer() [with T = unsigned int]’:
    Lib/vc4/Invoke.cpp:39:45:   required from here
    Lib/Common/SharedArray.h:55:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         return (T *) m_phyaddr;
                ^~~~~~~~~~~~~~~
    make: *** [Makefile:172: obj/qpu-debug/Lib/vc4/Invoke.o] Error 1
    pi@raspberrypi:~/V3DLib $ 
    

    As a quick workaround, I changed the makefile to include the -fpermissive flag and it allowed me to build/run just like on the 32 bit OS. But I think that it may not be the best solution. I`m investigating the code to check if it is possible to replace those int32 by something more portable.

    opened by doleron 15
  • CmdParameter Does not Compile

    CmdParameter Does not Compile

    on Raspberry Pi 4B Linux raspberrypi 5.10.103-v8+ #1529 SMP PREEMPT aarch64 GNU/Linux gcc/g++ version 8.3 I get the following:

    pi@raspberrypi:~/CmdParameter $ make DEBUG=1 test Compiling Tests/testMain.cpp Compiling Tests/testCmdLine.cpp Compiling Tests/testParams.cpp Compiling Tests/testActions.cpp Compiling Tests/testOptions.cpp Compiling Tests/Support/cout_redirect.cpp Compiling Tests/Support/Settings.cpp Compiling Tests/TestData/TestParameters.cpp Tests/TestData/TestParameters.cpp: In member function ‘CmdParameters::List& TestParameters::parameters()’: Tests/TestData/TestParameters.cpp:86:81: error: binding reference of type ‘CmdParameters::List&’ {aka ‘TypedParameter::List&’} to ‘const TypedParameter::List’ discards qualifiers CmdParameters::List &TestParameters::parameters() { return definition.parameters(); } ~~~~~~~~~~~~~~~~~~~~~^~ make: *** [Makefile:133: obj-debug/Tests/TestData/TestParameters.o] Error 1 Anyone know how to fix this? Thanks.

    opened by cadencetech 0
  • Potentially non-parallel build

    Potentially non-parallel build

    Calling make directly within your Makefile to build Mesa potentially prevents parallel multi-processor builds, at least it does for me. You should use $(MAKE) instead. See warning: jobserver unavailable: using -j1. Add '+' to parent make rule for details.

    I haven't tried this directly on a Raspberry Pi, but rather build your library with a cross compiler (which requires a couple of additional changes). This way a full initial build of V3DLib only takes 90 seconds on my machine.

    opened by cspanier 0
  • Build error on non-debug builds

    Build error on non-debug builds

    When building with DEBUG=0 I get an error at https://github.com/wimrijnders/V3DLib/blob/6988cce3b00d859fdc59a8a9eed3f62bbc0d3a31/Lib/v3d/KernelDriver.cpp#L735 stating that checkUniformAtTop is not defined. In fact the function is defined in the same file above within a preprocessor #if directive:

    #ifdef DEBUG
    bool checkUniformAtTop(V3DLib::Instr::List const &instrs) {
    ...
    #endif
    
    opened by cspanier 2
  • Conflicting Complex class with Cimg library

    Conflicting Complex class with Cimg library

    Hello, I have been using V3DLib for some research to make my program run fasted on Rpi4, I am so grateful for your work in this, but field. It has been running fine until now, but when I included CImg.h library to load image data to my code, I am getting a bunch of errors like these: Lib/Source/Complex.h:8:7: error: expected identifier before numeric constant 8 | class Complex; | ^~~~~~~ Lib/Source/Complex.h:8:7: error: expected unqualified-id before numeric constant Lib/Source/Complex.h:18:15: error: expected unqualified-id before numeric constant 18 | ComplexExpr(Complex const &rhs); | ^~~~~~~ V3DLib also has its own Complex class in source and I think it is conflicting with cimg library. Is there any work around for this?

    opened by Pranshu195 0
  • Failed to build on Raspberry Pi4

    Failed to build on Raspberry Pi4

    I tried to build V3DLib on my Raspberry Pi4 but I got error message as below. Can you please advise? Thanks.

    #make QPU=1 DEBUG=1 all ... make: *** No rule to make target '../CmdParameter/obj-debug/libCmdParameter.a', needed by 'obj/qpu-debug/bin/HeatMap'. Stop

    Attached full building logs:

    build_full_logs.txt .

    opened by tvutonyguo 4
Owner
null
Vulkan Video Sample Application demonstrating an end-to-end, all-Vulkan, processing of h.264/5 compressed video content.

This project is a Vulkan Video Sample Application demonstrating an end-to-end, all-Vulkan, processing of h.264/5 compressed video content. The application decodes the h.264/5 compressed content using an HW accelerated decoder, the decoded YCbCr frames are processed with Vulkan Graphics and then presented via the Vulkan WSI.

NVIDIA DesignWorks Samples 132 Dec 15, 2022
OpenShot Video Library (libopenshot) is a free, open-source C++ library dedicated to delivering high quality video editing, animation, and playback solutions to the world

OpenShot Video Library (libopenshot) is a free, open-source C++ library dedicated to delivering high quality video editing, animation, and playback solutions to the world

OpenShot Studios, LLC 936 Jan 4, 2023
Vireo is a lightweight and versatile video processing library written in C++11

Overview Vireo is a lightweight and versatile video processing library that powers our video transcoding service, deep learning recognition systems an

Twitter 875 Jan 2, 2023
A simple but powerful multimedia player library designed for Qt Quick.

QtMediaPlayer A simple but powerful multimedia player library designed for Qt Quick. Features Full-featured multimedia player Cross-platform: support

Yuhang Zhao 16 Nov 29, 2022
FFmpeg library inspector

ffmpeg-lib-info Prints the license, version, and configuration for FFmpeg libraries.

Zeranoe 3 Jun 7, 2021
Color composite video code from ESP_8_BIT as an Arduino library

ESP_8_BIT Color Composite Video Out Library Purpose The composite video generation code from ESP_8_BIT extracted and packaged into a standalone Arduin

Roger Cheng 84 Dec 25, 2022
webrtc c++ library for mediasoup with full sfu c++ demo

项目说明: 本项目是基于mediasoup v3 版本 webrtc m84版本 的sfu的js版本修改成的c++版本,支持和js版本一样的完整demo功能,但是本项目是直接把worker进程代码集成 到了demo可以直接代码级别的调用,支持VC2019,xcode,CLion的开发环境,可以直接断

null 119 Dec 20, 2022
theora-player is an embeddable theora video player C++ library based on the libtheora sample. It has no audio support at this moment.

theora-player Description theora-player is an embeddable theora video player C++ library based on the libtheora sample. It has no audio support at thi

Fire Falcom 2 Jun 18, 2022
A UE4 plugin used ffmpeg library to record/publish game viewport output and in-game audio.

Streaming A UE4 plugin used ffmpeg library to record/publish game viewport output and in-game audio. GPL license beacuse used ffmpeg. Structures GameV

Luo Yu 3 Aug 3, 2022
Video game library manager with support for wide range of 3rd party libraries and game emulation support, providing one unified interface for your games.

An open source video game library manager and launcher with support for 3rd party libraries like Steam, GOG, Origin, Battle.net and Uplay. Includes game emulation support, providing one unified interface for your games.

Josef Nemec 4.8k Jan 3, 2023
DTV is a library that provides a simple interface for generating video files from a C++ application

Direct to Video (DTV) What does DTV do? DTV is a library that provides a simple interface for generating video files from a C++ application. It uses F

Ange Yaghi 133 Dec 30, 2022
✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

null 6.6k Jan 8, 2023
Distributed (Deep) Machine Learning Community 682 Dec 28, 2022
Prueba del Raspberry PI PICO con un display Raspberry PI TFT 3.5"

Raspberry-PI-PICO-display-RPI35 Prueba del Raspberry PI PICO con un display Raspberry PI TFT 3.5" Con ayuda de la libreria https://github.com/khoih-pr

null 1 Nov 10, 2021
🐸 Coqui STT is an open source Speech-to-Text toolkit which can run in real time on devices ranging from a Raspberry Pi 4 to high power GPU servers

Coqui STT ( ?? STT) is an open-source deep-learning toolkit for training and deploying speech-to-text models. ?? STT is battle tested in both producti

Coqui.ai 1.7k Jan 2, 2023
DeepSpeech is an open source embedded (offline, on-device) speech-to-text engine which can run in real time on devices ranging from a Raspberry Pi 4 to high power GPU servers.

Project DeepSpeech DeepSpeech is an open-source Speech-To-Text engine, using a model trained by machine learning techniques based on Baidu's Deep Spee

Mozilla 20.8k Jan 9, 2023
4eisa40 GPU computing : exploiting the GPU to execute advanced simulations

GPU-computing 4eisa40 GPU computing : exploiting the GPU to execute advanced simulations Activities Parallel programming Algorithms Image processing O

Ecam 4MIN repositories 2 Jan 10, 2022
Raspberry Pi Pico Arduino core, for all RP2040 boards

Arduino-Pico Raspberry Pi Pico Arduino core, for all RP2040 boards This is a port of the RP2040 (Raspberry Pi Pico processor) to the Arduino ecosystem

Earle F. Philhower, III 929 Jan 5, 2023
RaspberryPiCM4Handheld7Inch - A single source for all of the information around my Raspberry Pi CM4 7" Handheld

Raspberry Pi CM4 Handheld 7 - Aegis" A repository for the Aegis, a 7" Raspberry Pi CM4 handheld device. NOTE: This is still a work in progress. The de

null 245 Dec 22, 2022