Joshua-Riek / ubuntu-rockchip

Ubuntu 22.04 and 24.04 for Rockchip RK35XX Devices
https://joshua-riek.github.io/ubuntu-rockchip-download/
GNU General Public License v3.0
1.83k stars 198 forks source link

Add OpenCL support to the images #879

Closed HeyMeco closed 1 week ago

HeyMeco commented 2 weeks ago

For the current Noble based images with 6.1 Kernel we need Mali DDK g18p0-01eac0. (5.10 should support the latest DDK)

The fix I did was to install this releases deb since it does all the configuration: https://github.com/tsukumijima/libmali-rockchip/releases/tag/v1.9-1-2d267b0

libmali-valhall-g610-g13p0-x11-wayland-gbm_1.9-1_arm64.deb


We already have the mali firmware included but in the future it would be better to also have the OpenCL ICD loader installed and libmali added to ICD during the build process so it works out of the box.


To get the right driver DDK version, such as "g21p0-01eac0" you have to look in the file kernel/drivers/gpu/arm/bifrost/Kbuild: "MALI_RELEASE_NAME ?= '"g21p0-01eac0"'".

Context: This is needed for HDR Tone-Mapping in upstream Jellyfin which supports RK3588 VPU HW acceleration

Joshua-Riek commented 1 week ago

g21p0-01eac0 does not support wayland so I reverted support for this blob in the kernel, so g18p0-01eac0 is included by default. I'm confused on what the problem is and what exactly is being requested to change.

HeyMeco commented 1 week ago

@Joshua-Riek the firmware for g18p0… is included yes but for example if you install clinfo you can see that the OpenCL aspect is missing in the image.

HeyMeco commented 1 week ago

Maybe this page with the section for Orange Pi 5 (but applies to all) does a better job explaining what needs to be done. Besides having the driver/firmware in the image. https://llm.mlc.ai/docs/install/gpu.html#orange-pi-5-rk3588-based-sbc

Joshua-Riek commented 1 week ago

I see, it's been a while since I messed with the Mali blobs, but i worry installing this may break hardware acceleration with panfork. This will need some testing then it must be built and packaged on Launchpad, i have the Mali blob managed by another package so this will need some hacking.

HeyMeco commented 1 week ago

opencl & the deb do not interfere with panfork as the solution I went with for example is just a mirror of jeffycn’s rockchip mali blob and only builds a „one click install for it“. It’s action is also open source so maybe it would make sense to take it to launchpad and just use the deb from before january for anything that needs g18 and other kernels can use the most recent one

Joshua-Riek commented 1 week ago

Got it, from taking a quick look it should be easy to add to Launchpad, i'm testing the build process now. But I will need to add a hack to remove the mali_csffw.bin blob as it's handled by another package.

Joshua-Riek commented 1 week ago

Oh yikes, the repo is over 8GB, this will cause problems with Launchpad as the limit is 8GB.

HeyMeco commented 1 week ago

Oh yikes, the repo is over 8GB, this will cause problems with Launchpad as the limit is 8GB.

Why do you not just make the build process do: Download and install libmali-g610.so

cd /usr/lib && sudo wget https://github.com/JeffyCN/mirrors/raw/libmali/lib/aarch64-linux-gnu/libmali-valhall-g610-g6p0-x11-wayland-gbm.so

(Check if file mali_csffw.bin exist under path /lib/firmware, if not download it with command:)

cd /lib/firmware && sudo wget https://github.com/JeffyCN/mirrors/raw/libmali/firmware/g610/mali_csffw.bin

Download OpenCL ICD loader and manually add libmali to ICD

sudo apt update
sudo apt install mesa-opencl-icd
sudo mkdir -p /etc/OpenCL/vendors
echo "/usr/lib/libmali-valhall-g610-g6p0-x11-wayland-gbm.so" | sudo tee /etc/OpenCL/vendors/mali.icd

Download and install libOpenCL sudo apt install ocl-icd-opencl-dev Download and install dependencies for Mali OpenCL

sudo apt install libxcb-dri2-0 libxcb-dri3-0 libwayland-client0 libwayland-server0 libx11-xcb1 

Download and install clinfo to check if OpenCL successfully installed sudo apt install clinfo

since you already have the firmware and do not need the whole repo to add OpenCL

Joshua-Riek commented 1 week ago

This is insightful, thank you very much. I can create a minimal package with the libmali-valhall-g610-g6p0-x11-wayland-gbm.so file and add the path to /etc/OpenCL/vendors/mali.icd when the package is installed.

Joshua-Riek commented 1 week ago

I will likely add this to the mali-g610-firmware package on Launchpad. https://launchpad.net/~jjriek/+archive/ubuntu/panfork-mesa/+packages

Joshua-Riek commented 1 week ago

I see libmali-valhall-g610-g6p0-x11-wayland-gbm.so and libmali-valhall-g610-g13p0-x11-wayland-gbm.so any idea which one works better / is newer?

HeyMeco commented 1 week ago

I only know g13p0 is the right one in this case. The versioning scheme is… something.

Joshua-Riek commented 1 week ago

It looks like I don't need to package anything, it already exists, simply download libmali-g610-x11 from apt and OpenCL should be working.

HeyMeco commented 1 week ago

For testing you can use geekbench6 --gpu which does OpenCL RK3588 should score 3500 +-100. Example: https://browser.geekbench.com/v6/compute/2329271

HeyMeco commented 1 week ago

@Joshua-Riek the issue is that there is two different DDK versions and the ones since 2024 are based on version 21 and are NOT compatible with g18 which is used by Kernel 6.1. / 5.10 can use the most recent

Joshua-Riek commented 1 week ago

Got it, the libmali-g610-x11 package has an older blob that seems to be compatible with g18. I'm running the geekbench test now to confirm it's working as expected.

Joshua-Riek commented 1 week ago

Yup, working as expected, see the results below. https://browser.geekbench.com/v6/compute/2349029

I will include these blobs by default for future builds as implemented in https://github.com/Joshua-Riek/ubuntu-rockchip/commit/b8be8d65220469a0285a245dfd65191fc2edee3c so OpenCL will work out of the box.

HeyMeco commented 1 week ago

I think I even found the maybe just a difference between g6p0 and g13p0. One is OpenCL 2.1 the other 3.0

source: https://www.roselladb.com/install-opencl-orangepi5-debian-ubuntu.htm

Joshua-Riek commented 1 week ago

Good find, i would assume OpenCL 3.0 is newer, so using the g13p0 blob would be best.

Joshua-Riek commented 1 week ago

With the latest nightly build OpenCL should be working out of the box.

https://github.com/Joshua-Riek/ubuntu-rockchip/actions/runs/9573838480

I'm testing the images now to confirm.

KylinDemons commented 1 week ago

May I ask, does this nightly build which you mean that opencl included support for noble kernel 6.1 version?

Joshua-Riek commented 1 week ago

Yup, if you have a currently installed system you can simply enter sudo apt-get install libmali-g610-x11 to install the mesa blobs required for OpenCL.

As for testing, I can confirm the latest nightly builds of Ubuntu 22.04 and 24.04. Both now work with OpenCL out of the box.

KylinDemons commented 1 week ago

Yup, if you have a currently installed system you can simply enter sudo apt-get install libmali-g610-x11 to install the mesa blobs required for OpenCL.

As for testing, I can confirm the latest nightly builds of Ubuntu 22.04 and 24.04. Both now work with OpenCL out of the box.

Thank you. I appreciate your work!