diff mbox series

[3/7] package/opencl-headers: new package

Message ID 20240713093700.13981-4-antoine.coutant@smile.fr
State Not Applicable
Headers show
Series Adding RustiCL | expand

Commit Message

Antoine Coutant July 13, 2024, 9:36 a.m. UTC
From: Sebastian Weyer <sebastian.weyer@smile.fr>

These headers provide the C language API headers. It is a complement to
the C++ bindings already available in opencl-clhpp. This package is
required to build opencl-icd-loader [1].

Adding opencl-icd-loader is impossible because mesa OpenCl-header
verison is too old. Indeed, mesa CL headers are not updated often and
not include the last OpenCL specification releases [2][3].

Mesa allow the use of external OpenCL-headers in some cases [4].
The CL headers installed by mesa regroups the opencl api headers [5] and
the opencl api C++ bindings [6]. They are fetched from the official
repositories manualy by mesa maintainers [7]. Those headers must be
backward compatible [8]. Thus it is possible to use them instead of mesa
CL headers to support newer version of OpenCL.

A new patch have been added to prevent the installation of OpenCL
headers by Mesa3d.

Dependencies on OpenCL-headers package have been added when an
implementation of OpenCL is selected.

[1]: https://github.com/KhronosGroup/OpenCL-ICD-Loader#dependencies
[2]: https://github.com/KhronosGroup/OpenCL-ICD-Loader/releases
[3]: https://gitlab.freedesktop.org/mesa/mesa/-/commits/main/include/CL
[4]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/24.0/include/meson.build#L133
[5]: https://github.com/KhronosGroup/OpenCL-Headers
[6]: https://github.com/KhronosGroup/OpenCL-CLHPP
[7]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/24.0/bin/khronos-update.py
[8]: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#_version_numbers

Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
Signed-off-by: Antoine Coutant <antoine.coutant@smile.fr>
---
 package/Config.in                             |  1 +
 package/mesa3d-headers/mesa3d-headers.mk      |  2 +-
 ...emove-the-installation-of-CL-headers.patch | 71 +++++++++++++++++++
 package/opencl-headers/Config.in              |  7 ++
 package/opencl-headers/opencl-headers.hash    |  3 +
 package/opencl-headers/opencl-headers.mk      | 22 ++++++
 6 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 package/mesa3d/0008-include-remove-the-installation-of-CL-headers.patch
 create mode 100644 package/opencl-headers/Config.in
 create mode 100644 package/opencl-headers/opencl-headers.hash
 create mode 100644 package/opencl-headers/opencl-headers.mk
diff mbox series

Patch

diff --git a/package/Config.in b/package/Config.in
index f7b14c57b9..7351da5e84 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1710,6 +1710,7 @@  menu "Graphics"
 	source "package/menu-cache/Config.in"
 	source "package/onevpl-intel-gpu/Config.in"
 	source "package/opencl-clhpp/Config.in"
+	source "package/opencl-headers/Config.in"
 	source "package/opencv3/Config.in"
 	source "package/opencv4/Config.in"
 	source "package/opencv4-contrib/Config.in"
diff --git a/package/mesa3d-headers/mesa3d-headers.mk b/package/mesa3d-headers/mesa3d-headers.mk
index 33c60b285f..def93c3dd3 100644
--- a/package/mesa3d-headers/mesa3d-headers.mk
+++ b/package/mesa3d-headers/mesa3d-headers.mk
@@ -61,7 +61,7 @@  MESA3D_HEADERS_DIRS += GLES GLES2
 endif
 
 ifeq ($(BR2_PACKAGE_HAS_LIBOPENCL),y)
-MESA3D_HEADERS_DIRS += CL
+MESA3D_HEADERS_DEPENDENCIES += opencl-headers opencl-clhpp
 endif
 
 define MESA3D_HEADERS_BUILD_CMDS
diff --git a/package/mesa3d/0008-include-remove-the-installation-of-CL-headers.patch b/package/mesa3d/0008-include-remove-the-installation-of-CL-headers.patch
new file mode 100644
index 0000000000..c0cbce0d12
--- /dev/null
+++ b/package/mesa3d/0008-include-remove-the-installation-of-CL-headers.patch
@@ -0,0 +1,71 @@ 
+From 619f806413c60583ba5e3f88f6ef16a60d1958e4 Mon Sep 17 00:00:00 2001
+From: Antoine Coutant <antoine.coutant@smile.fr>
+Date: Wed, 28 Feb 2024 16:04:21 +0100
+Subject: [PATCH] include: remove the installation of CL headers
+
+The CL headers installed by mesa are old and
+does not support the last versions of OpenCL.
+
+In buildroot, instead of using mesa CL headers
+use official headers from Khronos. Moreover,
+the OpenCL headers are backward compatible.
+See:
+https://github.com/KhronosGroup/OpenCL-Headers#compatibility-notes
+
+Signed-off-by: Antoine Coutant <antoine.coutant@smile.fr>
+---
+ include/meson.build                       | 28 -----------------------
+ src/gallium/frontends/rusticl/meson.build |  1 -
+ 2 files changed, 29 deletions(-)
+
+diff --git a/include/meson.build b/include/meson.build
+index a955ac71073..18f5f2d259e 100644
+--- a/include/meson.build
++++ b/include/meson.build
+@@ -110,31 +110,3 @@ if with_gallium_st_nine
+   )
+ endif
+ 
+-opencl_headers = files(
+-  'CL/cl.h',
+-  'CL/cl.hpp',
+-  'CL/cl2.hpp',
+-  'CL/cl_d3d10.h',
+-  'CL/cl_d3d11.h',
+-  'CL/cl_dx9_media_sharing.h',
+-  'CL/cl_dx9_media_sharing_intel.h',
+-  'CL/cl_egl.h',
+-  'CL/cl_ext.h',
+-  'CL/cl_ext_intel.h',
+-  'CL/cl_gl.h',
+-  'CL/cl_gl_ext.h',
+-  'CL/cl_icd.h',
+-  'CL/cl_platform.h',
+-  'CL/cl_va_api_media_sharing_intel.h',
+-  'CL/cl_version.h',
+-  'CL/opencl.h',
+-  'CL/opencl.hpp',
+-)
+-# Only install the headers if we are building a stand alone implementation and
+-# not an ICD enabled implementation
+-if with_gallium_opencl and not with_opencl_icd
+-  install_headers(
+-    opencl_headers,
+-    subdir: 'CL'
+-  )
+-endif
+diff --git a/src/gallium/frontends/rusticl/meson.build b/src/gallium/frontends/rusticl/meson.build
+index eb87dad2659..e157377404c 100644
+--- a/src/gallium/frontends/rusticl/meson.build
++++ b/src/gallium/frontends/rusticl/meson.build
+@@ -162,7 +162,6 @@ cl_c_args = [
+ rusticl_opencl_bindings_rs = rust.bindgen(
+   input : [
+     'rusticl_opencl_bindings.h',
+-    opencl_headers,
+   ],
+   output : 'rusticl_opencl_bindings.rs',
+   include_directories : [
+-- 
+2.34.1
+
diff --git a/package/opencl-headers/Config.in b/package/opencl-headers/Config.in
new file mode 100644
index 0000000000..092d8a2a4d
--- /dev/null
+++ b/package/opencl-headers/Config.in
@@ -0,0 +1,7 @@ 
+config BR2_PACKAGE_OPENCL_HEADERS
+	bool "opencl-headers"
+	depends on BR2_PACKAGE_HAS_LIBOPENCL
+	help
+	  C language headers for the OpenCL API
+
+	  https://github.com/KhronosGroup/OpenCL-Headers
diff --git a/package/opencl-headers/opencl-headers.hash b/package/opencl-headers/opencl-headers.hash
new file mode 100644
index 0000000000..928bcfb30b
--- /dev/null
+++ b/package/opencl-headers/opencl-headers.hash
@@ -0,0 +1,3 @@ 
+#Locally generated
+sha256  3c3dd236d35f4960028f4f58ce8d963fb63f3d50251d1e9854b76f1caab9a309  OpenCL-Headers-2024.05.08.tar.gz
+sha256  cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30  LICENSE
diff --git a/package/opencl-headers/opencl-headers.mk b/package/opencl-headers/opencl-headers.mk
new file mode 100644
index 0000000000..fd047f2fad
--- /dev/null
+++ b/package/opencl-headers/opencl-headers.mk
@@ -0,0 +1,22 @@ 
+################################################################################
+#
+# opencl-headers
+#
+################################################################################
+
+OPENCL_HEADERS_VERSION = 2024.05.08
+OPENCL_HEADERS_SOURCE = OpenCL-Headers-$(OPENCL_HEADERS_VERSION).tar.gz
+OPENCL_HEADERS_SITE = $(call github,KhronosGroup,OpenCL-Headers,v$(OPENCL_HEADERS_VERSION))
+OPENCL_HEADERS_LICENSE = Apache-2.0
+OPENCL_HEADERS_LICENSE_FILES = LICENSE
+OPENCL_HEADERS_INSTALL_STAGING = YES
+
+OPENCL_HEADERS_INSTALL_TARGET = NO
+
+define OPENCL_HEADERS_INSTALL_STAGING_CMDS
+	mkdir -p $(STAGING_DIR)/usr/include/CL
+	$(INSTALL) -D -m 0644 $(@D)/CL/* \
+		$(STAGING_DIR)/usr/include/CL
+endef
+
+$(eval $(generic-package))