Install Vulkan on a Raspberry Pi 4.
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.
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
Once PiKISS is installed, you can find the application in the system tools 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.
Installation from scratch.
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.
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
With the dependencies installed, the Vulkan API can be built.
If the installation was successful, the screen below shows all the relevant information after the $ glxinfo -B command.
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$ mkdir build# build the demos
$ cd build $ cmake -DCMAKE_BUILD_TYPE=Debug ..
$ make -j4
Go into the build/bin folder with $ cd build/bin and run some examples like:
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.
All times in mSec
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 ..