From d55edfb8833c80dce5dbf837be12923c523c013a Mon Sep 17 00:00:00 2001 From: Henry Miskin Date: Sun, 7 Mar 2021 19:03:14 +0000 Subject: [PATCH 1/4] Add instructions for running on Pi4 --- examples/pi4_mesa_build/README.md | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 examples/pi4_mesa_build/README.md diff --git a/examples/pi4_mesa_build/README.md b/examples/pi4_mesa_build/README.md new file mode 100644 index 000000000..f767303dc --- /dev/null +++ b/examples/pi4_mesa_build/README.md @@ -0,0 +1,103 @@ +# Kompute Pi4 Mesa Build Example + +The Raspberry Pi 4 is an impressive little computer when you consider that the Broadcom GPU is able to run 2x 4K displays. This example intends to show how to get Vulkan Kompute up and running on a Raspberry Pi 4. This has huge potential for edge processing using the power of the Pi 4 GPU. + +Special thanks to [Alejandro Piñeiro](https://blogs.igalia.com/apinheiro/) and others for their work on Broadcom drivers for [Mesa](https://gitlab.freedesktop.org/mesa/mesa) which make this example possible. + +## Raspberry Pi Operating System + +For this experiment we used [RaspiOS Lite 2021-01-12](https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-01-12/2021-01-11-raspios-buster-armhf-lite.zip), though it is likely best to start with the latest available operation system from [Raspberry Pi operating system images](https://www.raspberrypi.org/software/operating-systems/). In other experiments the full Raspberry Pi operating system (with desktop environment) was found to work. However, when attempting to use Ubuntu on the Raspberry Pi we were not able to run the Python Vulkan Kompute examples. + +## Running the Pi headless + +By far the easiest way to get up and running with a Raspberry Pi is to configure it for headless operation. This removes the requirement to have a monitor, keyboard or mouse. To run headless the Pi needs access to the internet and for SSH enabled. The following guides from the Raspberry Pi foundation should help. + +- [Setting up a Raspberry Pi headless](https://www.raspberrypi.org/documentation/configuration/wireless/headless.md) +- [SSH (Secure Shell)](https://www.raspberrypi.org/documentation/remote-access/ssh/) + +## Ensure all packages are using the latest version + +``` +sudo apt-get update +sudo apt-get upgrade +``` + +## Install dependencies for building mesa and running Vulkan Kompute + +``` +sudo apt-get install + git build-essential cmake \ + python3-dev python3-mako python3-venv \ + flex bison meson ninja-build \ + libxcb-shm0-dev libxcb1-dev libxcb-*-dev \ + libx11-dev libx11-xcb-dev x11proto-dri2-dev x11proto-dri3-dev \ + libdrm-dev libxshmfence-dev libxrandr-dev libxfixes-dev \ + vulkan-tools libvulkan-dev +``` + +## Clone mesa repository + +``` +git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git +``` + +## Build mesa + +Use meson and ninja to build mesa using the Broadcom Vulkan drivers. For information on the Gallium drivers please see [V3D — The Mesa 3D Graphics Library latest documentation](https://docs.mesa3d.org/drivers/v3d.html). + +TODO: Experiment adding kmsro and vc4 gallium drivers + +``` +meson --libdir lib \ + --prefix /mesa-install \ + -D platforms=x11 \ + -D vulkan-drivers=broadcom \ + -D gallium-drivers=v3d \ + -D dri-drivers=[] \ + -D buildtype=debug \ + build + +ninja -C build +sudo ninja -C build install +``` + +## Configure preferred Vulkan driver + +Export the path for the Broadcom drivers. This command will need to be run for every new terminal session. Alternatively adding this line to `~/.bash_profile` (os similar) will export the environment variable for every terminal session. + +``` +export VK_ICD_FILENAMES=/mesa-install/share/vulkan/icd.d/broadcom_icd.armv7l.json +``` + +To confirm that mesa was configured and built correctly use. + +``` +vulkaninfo +``` + +## Clone Vulkan Kompute + +Clone Vulkan Kompute for access to the latest Python tests. + +``` +git clone https://github.com/EthicalML/vulkan-kompute.git +``` + +## Install dependencies to run the tests + +Navigate to the available tests and install required dependencies. + +``` +cd vulkan-kompute/python/test +python3 -m venv .venv +source .venv/bin/activate +pip install --upgrade pip wheel +pip install -r requirements-dev.txt +pip install git+git://github.com/EthicalML/vulkan-kompute.git@master +``` + +## Run the available tests + +``` +pytest +``` \ No newline at end of file From df79ec2f7d444c29d4ef759bfe088dac517c4f1c Mon Sep 17 00:00:00 2001 From: Henry Miskin Date: Sun, 7 Mar 2021 19:11:21 +0000 Subject: [PATCH 2/4] Fix mistake on package installation --- examples/pi4_mesa_build/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pi4_mesa_build/README.md b/examples/pi4_mesa_build/README.md index f767303dc..7aad2f39c 100644 --- a/examples/pi4_mesa_build/README.md +++ b/examples/pi4_mesa_build/README.md @@ -25,7 +25,7 @@ sudo apt-get upgrade ## Install dependencies for building mesa and running Vulkan Kompute ``` -sudo apt-get install +sudo apt-get install \ git build-essential cmake \ python3-dev python3-mako python3-venv \ flex bison meson ninja-build \ From 31ad92180c47c1235359cb15b4b5114bc36124c7 Mon Sep 17 00:00:00 2001 From: Henry Miskin Date: Sun, 14 Mar 2021 21:31:49 +0000 Subject: [PATCH 3/4] Added render permissions modification --- examples/pi4_mesa_build/README.md | 48 +++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/examples/pi4_mesa_build/README.md b/examples/pi4_mesa_build/README.md index 7aad2f39c..54337a7a3 100644 --- a/examples/pi4_mesa_build/README.md +++ b/examples/pi4_mesa_build/README.md @@ -45,8 +45,6 @@ git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git Use meson and ninja to build mesa using the Broadcom Vulkan drivers. For information on the Gallium drivers please see [V3D — The Mesa 3D Graphics Library latest documentation](https://docs.mesa3d.org/drivers/v3d.html). -TODO: Experiment adding kmsro and vc4 gallium drivers - ``` meson --libdir lib \ --prefix /mesa-install \ @@ -63,13 +61,31 @@ sudo ninja -C build install ## Configure preferred Vulkan driver -Export the path for the Broadcom drivers. This command will need to be run for every new terminal session. Alternatively adding this line to `~/.bash_profile` (os similar) will export the environment variable for every terminal session. +Export the path for the Broadcom drivers, this command will need to be run for every new terminal session. ``` export VK_ICD_FILENAMES=/mesa-install/share/vulkan/icd.d/broadcom_icd.armv7l.json ``` -To confirm that mesa was configured and built correctly use. +## Allow access to render + +In order to access the render from remote login there are two options. Both options work. + +**Option 1: provide read write access to everyone.** + +``` +sudo chmod ugo+rw /dev/dri/renderD128 +``` + +**Option 2: Change group from render to video.** + +``` +sudo chown root:video /dev/dri/renderD128 +``` + +## Confirm correct Vulkan operation + +To confirm that mesa was configured and built correctly run the following command. ``` vulkaninfo @@ -93,11 +109,31 @@ python3 -m venv .venv source .venv/bin/activate pip install --upgrade pip wheel pip install -r requirements-dev.txt -pip install git+git://github.com/EthicalML/vulkan-kompute.git@master +pip install git+git://github.com/EthicalML/vulkan-kompute.git ``` ## Run the available tests +Use the following command to run the python tests for Vulkan Kompute. + ``` pytest -``` \ No newline at end of file +``` + +If the tests pass then congratulations! You are now able to make full use of the Pi 4 Broadcom GPU for running parallel computing. If however, there are any issues with the tests they can be run in debug mode to see the Vulkan logs. + +``` +pytest --log-cli-level debug +``` + +Please share any issues with the maintainers and they will be more than happy to help. + +## Closing remarks + +To avoid the need to export `VK_ICD_FILENAMES` every time you login, it is possible to symlink the json file into the default directory. The Vulkan loader looks in the `/etc/vulkan/icd.d/` directory for `.json` files. + +``` +sudo ln -s /mesa-install/share/vulkan/icd.d/broadcom_icd.armv7l.json /etc/vulkan/icd.d/broadcom_icd.armv7l.json +``` + +As a word of warning, configuring the icd filenames in this way will stop certain tests being skipped. At the time of writing this will mean that some tests fail when running on the Pi. \ No newline at end of file From e9b7162c9d3d9493b675ac4d19e2de9d76061674 Mon Sep 17 00:00:00 2001 From: Henry Miskin Date: Sun, 14 Mar 2021 21:38:05 +0000 Subject: [PATCH 4/4] Added test skip for broadcom --- python/test/test_tensor_types.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/test/test_tensor_types.py b/python/test/test_tensor_types.py index 91866f885..fb11083fd 100644 --- a/python/test/test_tensor_types.py +++ b/python/test/test_tensor_types.py @@ -4,6 +4,7 @@ import pytest import kp import numpy as np +VK_ICD_FILENAMES = os.environ.get("VK_ICD_FILENAMES", "") def test_type_float(): @@ -82,7 +83,9 @@ def test_type_float_double_incorrect(): assert np.all(tensor_out.data() != arr_in_a * arr_in_b) -@pytest.mark.skipif("swiftshader" in os.environ.get("VK_ICD_FILENAMES", ""), +@pytest.mark.skipif("broadcom" in VK_ICD_FILENAMES, + reason="Broadcom doesn't support double") +@pytest.mark.skipif("swiftshader" in VK_ICD_FILENAMES, reason="Swiftshader doesn't support double") def test_type_double():