[Buildroot] [PATCH v4 7/7] package/mesa3d: add RustiCL support
Antoine Coutant
antoine.coutant at smile.fr
Fri Feb 2 09:36:25 UTC 2024
From: Romain Naour <romain.naour at smile.fr>
To build Rusticl you need to satisfy the following build dependencies:
rustc
rustfmt (highly recommended, but only required for CI builds or when authoring patches)
bindgen
LLVM built with libclc and -DLLVM_ENABLE_DUMP=ON.
SPIRV-Tools
SPIRV-LLVM-Translator for a libLLVMSPIRVLib.so matching your version of LLVM, i.e. if you’re using LLVM 15 (libLLVM.so.15), then you need a libLLVMSPIRVLib.so.15.
See:
https://docs.mesa3d.org/rusticl.html
Since rusticl is an implementation of OpenCL, make it a provider of
OpenCL.
We need to use opencl-icd-loader in order to be able to capture API
calls and forward them to the correct implementation of OpenCL (RustiCL
in this case)
opencl-icd-loader needs to be installed in the toolchain's sysroot
as well to be able to compile packages depending on libopencl since
otherwise there's only for example libRustiOpenCL.so and no
libOpenCL.so
Many Gallium drivers are compatible with rusticl. However, tests were
performed with panfrost. Thus only panfrost is actived for the moment.
To activate another driver, make it select
BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER. The list of all
compatible drivers can be found here:
https://docs.mesa3d.org/envvars.html#envvar-RUSTICL_ENABLE
Signed-off-by: Romain Naour <romain.naour at smile.fr>
Signed-off-by: Sebastian Weyer <sebastian.weyer at smile.fr>
Signed-off-by: Antoine Coutant <antoine.coutant at smile.fr>
---
v2: change commit header -> RustiCL support is not experimental
Changes v3 -> v4:
- Add a menuconfig to select OpenCL implementation
between Clover and RustiCL
- Add BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER.
Signed-off-by: Antoine Coutant <antoine.coutant at smile.fr>
---
package/mesa3d/Config.in | 50 ++++++++++++++++++++++++++++++++++++----
package/mesa3d/mesa3d.mk | 18 +++++++++++++--
2 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/package/mesa3d/Config.in b/package/mesa3d/Config.in
index 39a4f706e2..84d281a0a9 100644
--- a/package/mesa3d/Config.in
+++ b/package/mesa3d/Config.in
@@ -44,17 +44,56 @@ comment "llvm support needs a toolchain not affected by GCC bug 64735"
depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
depends on BR2_TOOLCHAIN_HAS_GCC_BUG_64735
-# clang and libclc dependencies are satisfied by
-# BR2_PACKAGE_MESA3D_LLVM
-config BR2_PACKAGE_MESA3D_OPENCL
+menuconfig BR2_PACKAGE_MESA3D_OPENCL
bool "OpenCL support"
+ default n
depends on BR2_PACKAGE_MESA3D_LLVM
depends on BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_R600 || \
- BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_RADEONSI
+ BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_RADEONSI || \
+ BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS && \
+ BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER
select BR2_PACKAGE_LLVM_RTTI
select BR2_PACKAGE_CLANG
select BR2_PACKAGE_LIBCLC
select BR2_PACKAGE_HAS_LIBOPENCL
+ help
+ OpenCL is a standard for parallel programming of heterogeneous
+ systems (CPUs, GPUs, DSPs, FPGAs, etc.)
+
+ http://www.khronos.org/opencl/
+
+if BR2_PACKAGE_MESA3D_OPENCL
+
+# clang and libclc dependencies are satisfied by
+# BR2_PACKAGE_MESA3D_LLVM
+config BR2_PACKAGE_MESA3D_CLOVER
+ bool "Clover"
+ depends on BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_R600 || \
+ BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_RADEONSI
+
+# libclc dependency is satisfied by
+# BR2_PACKAGE_MESA3D_LLVM
+config BR2_PACKAGE_MESA3D_RUSTICL
+ bool "RustiCL"
+ depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+ depends on BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER
+ select BR2_PACKAGE_HOST_RUSTC
+ select BR2_PACKAGE_LLVM_DUMP
+ select BR2_PACKAGE_OPENCL_ICD_LOADER
+ select BR2_PACKAGE_SPIRV_TOOLS
+ select BR2_PACKAGE_SPIRV_LLVM_TRANSLATOR
+ help
+ RustiCL is an OpenCL implementation written in Rust.
+
+ By default devices are disabled in RustiCL. If you want to enable a device,
+ you need to set the environment variable RUSTICL_ENABLE to the driver you
+ are using.
+ ref: https://docs.mesa3d.org/envvars.html#envvar-RUSTICL_ENABLE
+
+endif # BR2_PACKAGE_MESA3D_OPENCL
+
+config BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER
+ bool
# inform the .mk file of gallium, dri, dri3 or vulkan driver selection
config BR2_PACKAGE_MESA3D_DRI3
@@ -160,6 +199,7 @@ config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_PANFROST
depends on (BR2_TOOLCHAIN_HAS_SYNC_4 && !BR2_RISCV_32) || !BR2_PACKAGE_XORG7 # libxshmfence
select BR2_PACKAGE_MESA3D_DRI3 if BR2_PACKAGE_XORG7
select BR2_PACKAGE_MESA3D_GALLIUM_DRIVER
+ select BR2_PACKAGE_MESA3D_RUSTICL_SUPPORTED_DRIVER
help
Mesa driver for ARM Mali Midgard and Bifrost GPUs.
@@ -396,7 +436,7 @@ config BR2_PACKAGE_PROVIDES_LIBGLES
default "mesa3d" if BR2_PACKAGE_MESA3D_OPENGL_ES && !BR2_PACKAGE_LIBGLVND
config BR2_PACKAGE_PROVIDES_LIBOPENCL
- default "mesa3d" if BR2_PACKAGE_MESA3D_OPENCL
+ default "mesa3d" if BR2_PACKAGE_MESA3D_CLOVER || BR2_PACKAGE_MESA3D_RUSTICL
endif # BR2_PACKAGE_MESA3D
diff --git a/package/mesa3d/mesa3d.mk b/package/mesa3d/mesa3d.mk
index d8d8fb8dd6..9a86fdacd7 100644
--- a/package/mesa3d/mesa3d.mk
+++ b/package/mesa3d/mesa3d.mk
@@ -58,15 +58,29 @@ else
MESA3D_CONF_OPTS += -Dllvm=disabled
endif
-# Disable opencl-icd: OpenCL lib will be named libOpenCL instead of
-# libMesaOpenCL and CL headers are installed
ifeq ($(BR2_PACKAGE_MESA3D_OPENCL),y)
MESA3D_PROVIDES += libopencl
MESA3D_DEPENDENCIES += clang libclc
+ifeq ($(BR2_PACKAGE_MESA3D_CLOVER),y)
+ifeq ($(BR2_PACKAGE_OPENCL_ICD_LOADER),y)
+MESA3D_CONF_OPTS += -Dgallium-opencl=icd
+MESA3D_DEPENDENCIES += opencl-icd-loader
+else
+# Disable opencl-icd: OpenCL lib will be named libOpenCL instead of
+# libMesaOpenCL and CL headers are installed
MESA3D_CONF_OPTS += -Dgallium-opencl=standalone
+endif
else
MESA3D_CONF_OPTS += -Dgallium-opencl=disabled
endif
+ifeq ($(BR2_PACKAGE_MESA3D_RUSTICL),y)
+MESA3D_DEPENDENCIES += host-rustc host-rust-bindgen opencl-icd-loader spirv-tools spirv-llvm-translator
+# -Drust_std=2021: known meson bug (https://github.com/mesonbuild/meson/issues/10664)
+MESA3D_CONF_OPTS += -Dgallium-rusticl=true -Drust_std=2021
+else
+MESA3D_CONF_OPTS += -Dgallium-rusticl=false
+endif
+endif
ifeq ($(BR2_PACKAGE_MESA3D_NEEDS_ELFUTILS),y)
MESA3D_DEPENDENCIES += elfutils
--
2.25.1
More information about the buildroot
mailing list