Install Vulkan on Raspberry Pi 4 - Q-engineering
Q-engineering
Q-engineering
Go to content
images/empty-GT_imagea-1-.png
Install Vulkan on Raspberry Pi 4

Install Vulkan on a Raspberry Pi 4.

Introduction.

This page guides you through the installation of Vulkan on a Raspberry Pi 4. Vulkan is a low-level 3D graphics accelerator using a balanced mix of CPU and GPU instructions and optimized for parallel tasking with multiple CPU cores. Many platforms are already using Vulkan, and now the Raspberry Pi is on board too.

One important point to mention, the software is still under construction. All the hard work is done by Igalia's lago Toral. And that's not easy considering the lack of a detailed VideoCore VI datasheet. At the moment (Dec 2020), many tests have been successful. As a result of that, the Vulkan driver is merged with Mesa upstream, thereby getting an official status.

For those looking for a graphical improvement to their games on a Raspberry Pi 4, the Vulkan API is the best (and only) solution.
On the other hand, for all the people looking to use the Vulkan library to boost their deep learning frameworks, a big disappointment awaits. The API is not yet well equipped to perform tensor calculations. The required operations are currently not supported. Maybe the near future will bring us good news.

One last remark, the Vulkan API works only on the Raspberry Pi 4. The Raspberry Pi 3 has another VideoCore GPU on board which is incompatible with the version found on the Pi 4.

PiKISS.
By far, the easiest way to install Vulkan on your Raspberry Pi 4 is to use PiKISS. PiKISS is a collection of installation and configuration scripts packed in a menu structure. It works very well for both 32 and 64-bit operating systems. Complicated installations are becoming one mouse click. A tip: keep your PiKISS up to date because of the ever-changing software. Install PiKISS with the following instruction.
# install PiKISS
$ sudo apt-get install curl
$ curl -sSL https://git.io/JfAPE | bash
# or update PiKISS once installed
$ cd ~/piKiss
$ git pull
PiKISS rdy

Once PiKISS is installed, you can find the application in the system tools menu.

PiKISS menu

There are a lot of tutorials and videos on the net explaining the many features of PiKISS. We will mention this one from the maker of PiKISS.
Now that PiKISS is up and running, Vulkan can be installed. Just follow the screen dumps, and the installation will start. It will take a while. In the end, you will end up with the following screen. In fact, PiKISS follows all the steps given in this guide in just one go.

PiKISS configure

PiKISS vulkan

PiKISS vulkan ready


Installation from scratch.
Version check.
Please check your operating system before installing Vulkan on your Raspberry Pi 4. Run the command uname -a and verify your version with the screen dump below.

Version_32_64

Dependencies.
The Vulkan API has a many dependencies. Please, install the list below.
# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install libxcb-randr0-dev libxrandr-dev
$ sudo apt-get install libxcb-xinerama0-dev libxinerama-dev libxcursor-dev
$ sudo apt-get install libxcb-cursor-dev libxkbcommon-dev xutils-dev
$ sudo apt-get install xutils-dev libpthread-stubs0-dev libpciaccess-dev
$ sudo apt-get install libffi-dev x11proto-xext-dev libxcb1-dev libxcb-*dev
$ sudo apt-get install bison flex libssl-dev libgnutls28-dev x11proto-dri2-dev
$ sudo apt-get install x11proto-dri3-dev libx11-dev libxcb-glx0-dev
$ sudo apt-get install libx11-xcb-dev libxext-dev libxdamage-dev libxfixes-dev
$ sudo apt-get install libva-dev x11proto-randr-dev x11proto-present-dev
$ sudo apt-get install libclc-dev libelf-dev git build-essential mesa-utils
$ sudo apt-get install libvulkan-dev ninja-build libvulkan1 python-mako
$ sudo apt-get install libdrm-dev libxshmfence-dev libxxf86vm-dev libunwind-dev
$ sudo apt-get install valgrind libzstd-dev vulkan-tools vulkan-utils
$ sudo apt-get install ninja-build

Installation.

With the dependencies installed, the Vulkan API can be built.
# remove old versions first
$ sudo rm -rf /home/pi/mesa_vulkan
# install meson
$ sudo apt purge meson -y
$ sudo pip3 install meson
# install mako
$ sudo pip3 install mako
# install v3dv
$ cd ~
$ git clone https://gitlab.freedesktop.org/mesa/mesa.git mesa_vulkan
# build v3dv (± 30 min)
$ cd mesa_vulkan
$ CFLAGS="-mcpu=cortex-a72" \
CXXFLAGS="-mcpu=cortex-a72" \
meson --prefix /usr \
-D platforms=x11 \
-D vulkan-drivers=broadcom \
-D dri-drivers= \
-D gallium-drivers=kmsro,v3d,vc4 \
-D buildtype=release build
$ ninja -C build -j4
$ sudo ninja -C build install
# check your driver
$ glxinfo -B
# remove old versions first
$ sudo rm -rf /home/pi/mesa_vulkan
# install meson
$ sudo apt purge meson -y
$ sudo pip3 install meson
# install mako
$ sudo pip3 install mako
# install v3dv
$ cd ~
$ git clone https://gitlab.freedesktop.org/mesa/mesa.git mesa_vulkan
# build v3dv (± 30 min)
$ cd mesa_vulkan
$ CFLAGS="-mcpu=cortex-a72 -mfpu=neon-fp-armv8" \
CXXFLAGS="-mcpu=cortex-a72 -mfpu=neon-fp-armv8" \
meson --prefix /usr \
-D platforms=x11 \
-D vulkan-drivers=broadcom \
-D dri-drivers= \
-D gallium-drivers=kmsro,v3d,vc4 \
-D buildtype=release build
$ ninja -C build -j4
$ sudo ninja -C build install
# check your driver
$ glxinfo -B
If the installation was successful, the screen below shows all the relevant information after the $ glxinfo -B command.

Glxinfo

Running some examples.
Time to do some testing with the famous Sasch Willem Vulkan demos.
As mentioned, the library is still under development, so not all examples work on the current version. But still, some very impressive pictures can still be drawn. Follow the commands below to install the demo.
# install a dependency
$ sudo apt-get install libassimp-dev
# download the demos
$ git clone --recursive https://github.com/SaschaWillems/Vulkan.git  sascha-willems
$ cd sascha-willems
# download some fonts
$ python3 download_assets.py
# build the demos
$ mkdir build
$ cd build $ cmake -DCMAKE_BUILD_TYPE=Debug  .. 
$ make -j4
Go into the build/bin folder with $ cd build/bin and run some examples like:
$ ./gears
Gears

$ ./computeraytracing
RayShader

$ ./gltfscenerendering
SceneRendering

$ ./indirectdraw
IndirectDraw

Deep learning with Vulkan.
We've done some disappointing tests with the Vulkan API used as a backend in various deep learning frameworks. Alibaba's MNN and Tencent's ncnn, both use Vulkan as an accelerator for their tensor calculations. However, the current Vulkan API for the Raspberry Pi 4 does not yet support all necessary operations. In practice, the performance drops by a factor of 5 when using the Vulkan backend. See the benchmarks below.
Model
All times in mSec
MNN
CPU
MNN
Vulkan
ncnn
CPU
ncnn
Vulkan
SqueezeNet61.3431.165.9346.8
MobileNetV169.8457.271.8558.2
MobileNetV246.1425.972.2382.2
ResNet1311670.9225.71085.5
GoogleNet107.2786.5174.871124.12
ShuffleNet55.1260.940.1409.6
The Raspberry Pi 4 with 2 GByte RAM was running at a default clock speed of 1500 MHz.
MNN build with cmake -D CMAKE_BUILD_TYPE=Release -D MNN_VULKAN=ON -D MNN_BUILD_BENCHMARK=ON ..
ncnn build with cmake -D CMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake -D NCNN_VULKAN=ON -D CMAKE_BUILD_TYPE=Release ..
Raspberry 64 OS
Raspberry 32 OS
Raspberry and alt
Raspberry Pi 4
Jetson Nano
images/GithubSmall.png
images/YouTubeSmall.png
images/SDcardSmall.png
Back to content