Coder Social home page Coder Social logo

v3dlib's Introduction

V3DLib

Version 0.7.15

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.

Motivation for this Project

The Raspberry Pi's have pretty nifty on-chip capabilities for SIMD vector processing. It bothered me to no end that this is largely unused; the only thing really using it is OpenGL.

The goal of this project is to make the SIMD vector processing accessible for a larger audience, and to ease the pain of programming it.

Getting Started

Before trying to deal with any code, take a moment to view the Basics Page. This will supply you with a working model of the VideoCore and will facilitate your understanding.

Also, for starters, scan the naming conventions at the top of the Architecture and Design Page. Read the rest at your own leisure.

Compiling and Building

This assumes that you are building on a Raspberry Pi.

  • Please look at the Known Issues, so you have an idea what to expect.
  • 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

> sudo apt install libexpat1-dev                                 # You need this for one lousy include file

> git clone --depth 1 https://github.com/wimrijnders/V3DLib.git  # Get only latest commit
> cd V3DLib
> make QPU=1 DEBUG=1 all                                         # Make debug versions with hardware
                                                                 # GPU support of all examples.
    
> make QPU=1 DEBUG=1 test                                        # Build and run the tests

Code Example

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

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

using namespace V3DLib;

V3DLib::Settings settings;


void hello(Int::Ptr p) {                          // The kernel definition
  *p = 1;
}


int main(int argc, const char *argv[]) {
  settings.init(argc, argv);

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

  Int::Array array(16);                           // Allocate and initialise the array shared between ARM and GPU
  array.fill(100);

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

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

  return 0;
}

Credit where Credit is Due

This project builds upon the QPULib project, by Matthew Naylor. I fully acknowledge his work for the VideoCore IV 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.

Useful Links

References

The following works were very helpful in the development.

VideoCore IV

VideoCore VI

Tools


v3dlib's People

Contributors

doleron avatar mn416 avatar wimrijnders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v3dlib's Issues

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?

Add my work to Useful Links

Hi,
I have been doing work on VideoCore VI for a bare metal system. Your repository is one of the few public things besides Mesa/Linux on V3D on the internet.

You may find my notes on V3D and the shader language interesting.

I hope to organize my notes and code into a separate repository soon.

I bundled Mesa's disassembler and validator into a single dependency-free header file, then wrote an assembler for V3D shaders.

I also wrote a bare-bones simulator for debugging the binning phase of shaders on any platform.

It might be good to add these to the Read Me to help others find more information on V3D.

Editing framebuffer device

Hi guys,

for a few days now, I've been trying to drive an epaper display as a second framebuffer copying the main one, but the time it takes to copy and process that data using a cpu is too much for it to be practical.

I've been wondering then would it be possible to access framebuffer data (I presume it's in the GPU mem) by qpu-s and offload the processing to them?

All examples I've seen, including this lib, use a mailbox allocated GPU mem, so how should I go about accessing the preallocated fb memory, could the mailbox with different settings do that?

Any tips would be appreciated :)

P.S. I know this ain't really an issue but I couldn't find any other contact from you guys.

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
.

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.

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.

Build error on non-debug builds

When building with DEBUG=0 I get an error at

assertq(checkUniformAtTop(instrs), "_encode(): checkUniformAtTop() failed (v3d)", true);

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

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.