llvm for mesa3d
v5 cover llvm for mesa3d
Hello all,
This series provides llvm support for Mesa 3D:
Changes v1 -> v2:
The series has been simplified:
*Build only backend for target architecture by default. *Support for AMDGPU(PATCH 3/4 in v1) was removed because I cannot test it currently.
*Host: make options modified to build only llvm-config and llvm-tblgen (reduces drastically build time for host).
*Target: support only x86 currently (tested), I will test on ARM soon.
Changes v2 -> v3:
* Full installation of LLVM (tools and libLLVM.so) for the host.
* Disable Mesa 3D static linking, it now links with shared lib.
* Options to disable building each tool one by one were removed.
* Support for AMDGPU.
* Support for ARM and AArch64. *-DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) added. This fixes the error:
"No available targets are compatible with this triple" for llvmpipe.
Changes v3 -> v4:
This series is focused on OpenCL support
* Add Clang for host (needed to build libclc)
* Add Clang for target (libOpenCL needs libclang and libLLVM)
* Add libclc
* Add OpenCL support in Mesa3D
* Add package clinfo
Changes v4 -> v5:
The changes suggested after the Buildroot hackathon were applied:
* No Config.in.host for llvm and clang.
* ARM and Aarch64 now in PATCH 1
* Unnecessary comments were removed
* clang-tblgen wasn't being installed in HOST_DIR, now solved
* LLVM_TARGETS_TO_BUILD is now easily extensible for new backends
* llvm-tblgen was being installed on the target, now removed
Regards,
Valent?n
Valentin Korenblit (7):
package/llvm: new package
package/llvm: enable AMDGPU
package/mesa3d: enable llvm support
package/clang: new package
package/libclc: new package
package/mesa3d: enable OpenCL support
package/clinfo: new package
DEVELOPERS | 6 + package/Config.in | 4 + package/clang/Config.in | 9 ++ package/clang/clang.hash | 3 + package/clang/clang.mk | 71 ++++++++++++ package/clinfo/Config.in | 9 ++ package/clinfo/clinfo.hash | 2 + package/clinfo/clinfo.mk | 23 ++++ package/libclc/Config.in | 9 ++ package/libclc/libclc.hash | 3 + package/libclc/libclc.mk | 41 +++++++ package/llvm/Config.in | 37 ++++++ package/llvm/llvm.hash | 3 + package/llvm/llvm.mk | 272 +++++++++++++++++++++++++++++++++++++++++++++ package/mesa3d/Config.in | 23 ++++ package/mesa3d/mesa3d.mk | 22 +++- 16 files changed, 535 insertions(+), 2 deletions(-) create mode 100644 package/clang/Config.in create mode 100644 package/clang/clang.hash create mode 100644 package/clang/clang.mk create mode 100644 package/clinfo/Config.in create mode 100644 package/clinfo/clinfo.hash create mode 100644 package/clinfo/clinfo.mk create mode 100644 package/libclc/Config.in create mode 100644 package/libclc/libclc.hash create mode 100644 package/libclc/libclc.mk create mode 100644 package/llvm/Config.in create mode 100644 package/llvm/llvm.hash create mode 100644 package/llvm/llvm.mk
Signature · 1 line
2.14.3
PATCH v5 1/7 package/llvm: new package
This patch installs LLVM tools and libraries for the host and libLLVM.so for the target.
In order to cross-compile LLVM for the target, LLVM must be installed on the host, or at least llvm-tblgen. This is necessary as the path to host's llvm-tblgen must be specified when cross-compiling using the LLVM_TABLEGEN option. Also, a version of llvm-config that can run on the host will be required by packages that link with LLVM libraries, so we need to generate it and install it in STAGING_DIR/usr/bin.
It is important to remark why we need llvm-config(host variant) installed in STAGING dir. This tool is necessary to build applications that use LLVM, as it prints the compiler flags, linker flags and object libraries needed to link against LLVM libs.
More info: https://bugs.chromium.org/p/chromium/issues/detail?id=219369
The original idea was to compile only llvm-tblgen and llvm-config for the host, as they are the only necessary components. However, llvm-config tool does not work as expected if it is not linked with libLLVM.so, so we must also enable LLVM_LINK_LLVM_DYLIB, what builds LLVM as a single shared library and links LLVM tools with it.
More info: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224847
in comment #11.
If we don't build full LLVM for the host, it would be necessary to patch configure.ac from mesa3d if we want dynamic linking, because it uses llvm-config (host variant installed in STAGING_DIR) to get the necessary LLVM libraries to link with, which has the following problems:
- llvm-config --shared mode outputs static (even if LLVM is built as one shared library) which leads to link issues with libgallium.
- llvm-config --libs outputs all LLVM tiny libs: -lLLVMLTO, -lLLVMPasses,etc instead of the single shared library containing all LLVM components (-lLLVM-5.0)
Mesa tries to execute: llvm-config --link-shared --libs, but this outputs
llvm-config: error: libLLVM-5.0.so is missing.
Given that these problems may arise with other packages that use LLVM, it is preferable to do a full build for the host. Also, having a complete installation of LLVM on the host will also facilitate the integration of Clang front-end, which is going to be added in a future patch.
As option LLVM_BUILD_LLVM_DYLIB is enabled for the llvm target variant, a single shared library containing all LLVM components is built. This option is not compatible with BUILD_SHARED_LIBS, which generates one .so per library and is only recommended for use by LLVM developers.
Tools and utils are not built for the target. The patch aims to provide LLVM support for other packages.
The main options needed to cross-compile LLVM are the following ones:
LLVM_TABLEGENCMAKE_CROSSCOMPILINGLLVM_DEFAULT_TARGET_TRIPLELLVM_HOST_TRIPLELLVM_TARGET_ARCHLLVM_TARGETS_TO_BUILD
--- DEVELOPERS | 3 + package/Config.in | 1 + package/llvm/Config.in | 27 +++++ package/llvm/llvm.hash | 3 + package/llvm/llvm.mk | 263 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100644 package/llvm/Config.in create mode 100644 package/llvm/llvm.hash create mode 100644 package/llvm/llvm.mk
DEVELOPERS +3 -0
@@ -1887,6 +1887,9 @@ N: Tzu-Jung Lee <[email protected]> F: package/dropwatch/ F: package/tstools/ +N: Valentin Korenblit <[email protected]> +F: package/llvm/ + N: Vanya Sergeev <[email protected]> F: package/lua-periphery/
package/Config.in +1 -0
@@ -1545,6 +1545,7 @@ menu "Other" source "package/libuv/Config.in" source "package/lightning/Config.in" source "package/linux-pam/Config.in" + source "package/llvm/Config.in" if BR2_PACKAGE_LINUX_PAM comment "linux-pam plugins" source "package/libpam-radius-auth/Config.in"
package/llvm/Config.in new file +27 -0
@@ -0,0 +1,27 @@ +config BR2_PACKAGE_LLVM_ARCH_SUPPORTS + bool + default y if BR2_i386 + default y if BR2_x86_64 + default y if BR2_aarch64 + default y if BR2_arm || BR2_armeb + +config BR2_PACKAGE_LLVM_TARGET_ARCH + string + default "AArch64" if BR2_aarch64 + default "ARM" if BR2_arm || BR2_armeb + default "X86" if BR2_i386 || BR2_x86_64 + +config BR2_PACKAGE_LLVM + bool "llvm" + depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS + depends on BR2_HOST_GCC_AT_LEAST_4_8 + depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 + help + The LLVM Project is a collection of modular and reusable + compiler and toolchain technologies. + + http://llvm.org + +comment "llvm needs a toolchain w/ gcc >= 4.8, host gcc >= 4.8" + depends on !BR2_HOST_GCC_AT_LEAST_4_8 \ + || !BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
package/llvm/llvm.hash new file +3 -0
@@ -0,0 +1,3 @@ +# locally calculated +sha256 5fa7489fc0225b11821cab0362f5813a05f2bcf2533e8a4ea9c9c860168807b0 llvm-5.0.1.src.tar.xz +sha256 abd4d8794808bacb1eb6924d49efafd9ab6eef88faaaeb5d3cfa13ee3670d672 LICENSE.TXT
package/llvm/llvm.mk new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v5 1/7 package/llvm: new package
Hello,
Quoted 2 lines · Valentin Korenblit
This patch installs LLVM tools and libraries for the host and libLLVM.so for the target.
I've applied to master, after doing the following changes:
[Thomas:
- add dependency on thread and C++ and update the Config.in comment accordingly.
- make the Config.in comment depend on BR2_PACKAGE_LLVM_ARCH_SUPPORTS so that it isn't disabled on architectures where LLVM is anyway not supported.]
Also, I noticed it doesn't build on the Cortex-M4 configuration, i.e the following defconfig doesn't build:
BR2_arm=y
BR2_cortex_m4=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-cortex-m4-full-2017.11-rc1.tar.bz2" BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_13=y
BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
# BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
# BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_NPTL is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_PACKAGE_LLVM=y
Even though I don't think it makes sense to support Cortex-M4 (and is probably not possible anyway), the error is interesting:
-- Looking for __atomic_load_8 in atomic
-- Looking for __atomic_load_8 in atomic - not found CMake Error at cmake/modules/CheckAtomic.cmake:74 (message):
Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
cmake/config-ix.cmake:326 (include) CMakeLists.txt:580 (include)
So LLVM uses atomic built-ins, so probably it needs to "depends on BR2_TOOLCHAIN_HAS_ATOMIC", and link against libatomic if BR2_TOOLCHAIN_HAS_LIBATOMIC is defined.
Please watch for the autobuilders in the next few days, and look at the LLVM build failures. You will anyway be notified every day of such failures by e-mail, now that you are listed in the DEVELOPERS file.
Thanks a lot Valentin for your persistence on this LLVM work. I'm sure it will be very useful in the future, and it was a major endeavor!
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
PATCH v5 1/7 package/llvm: new package
Hi Valentin, All,
Le 04/04/2018 ? 22:50, Thomas Petazzoni a ?crit?:
Quoted 5 lines
Hello,
Quoted 2 lines · Valentin Korenblit
This patch installs LLVM tools and libraries for the host and libLLVM.so for the target.
[...]
Quoted 3 lines
Thanks a lot Valentin for your persistence on this LLVM work. I'm sure it will be very useful in the future, and it was a major endeavor!
Congratulation Valentin!
I know it was a really ambitious task to take over llvm patch series for your internship at Smile.
Next step: clang and opencl :)
See you tomorrow at work!
Best regards,
Romain
Quoted 5 lines
Best regards,
Thomas
PATCH v5 2/7 package/llvm: enable AMDGPU
In reply to Valentin KorenblitThe AMDGPU backend provides ISA code generation for AMD GPU's, starting with the R600 family up until the current GCN families.
It should not be confused with the AMDGPU Linux kernel DRM driver.
For more info: https://llvm.org/docs/AMDGPUUsage.html
---
Tested on HD6480 using Gallium Radeon R600 driver.
package/llvm/Config.in | 10 ++++++++++ package/llvm/llvm.mk | 9 +++++++++ 2 files changed, 19 insertions(+)
package/llvm/Config.in +10 -0
@@ -22,6 +22,16 @@ config BR2_PACKAGE_LLVM http://llvm.org +if BR2_PACKAGE_LLVM + +config BR2_PACKAGE_LLVM_AMDGPU + bool "AMDGPU backend" + help + Build AMDGPU target. Select this option if you are going + to install mesa3d with llvm and use Gallium Radeon driver. + +endif + comment "llvm needs a toolchain w/ gcc >= 4.8, host gcc >= 4.8" depends on !BR2_HOST_GCC_AT_LEAST_4_8 \ || !BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
package/llvm/llvm.mk +9 -0
@@ -45,6 +45,15 @@ LLVM_CONF_OPTS = -DLLVM_TARGETS_TO_BUILD="$(subst $(space),;,$(LLVM_TARGETS_TO_B HOST_LLVM_CONF_OPTS += -DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) LLVM_CONF_OPTS += -DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) +# Build AMDGPU backend +# We need to build AMDGPU backend for both host and target because +# llvm-config --targets built (host variant installed in STAGING) will +# output only $(LLVM_TARGET_ARCH) if not, and mesa3d won't build as +# it thinks AMDGPU backend is not installed on the target. +ifeq ($(BR2_PACKAGE_LLVM_AMDGPU),y) +LLVM_TARGETS_TO_BUILD += AMDGPU +endif + # Use native llvm-tblgen from host-llvm (needed for cross-compilation) LLVM_CONF_OPTS += -DLLVM_TABLEGEN=$(HOST_DIR)/bin/llvm-tblgen
Signature · 1 line
2.14.3
Thomas Petazzoni
AppliedPATCH v5 2/7 package/llvm: enable AMDGPU
Hello,
Quoted 10 lines · Valentin Korenblit
The AMDGPU backend provides ISA code generation for AMD GPU's, starting with the R600 family up until the current GCN families.
It should not be confused with the AMDGPU Linux kernel DRM driver.
For more info: https://llvm.org/docs/AMDGPUUsage.html
Signed-off-by Valentin Korenblit <[email protected]>Tested-by J?r?me Oufella <[email protected]>---
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
PATCH v5 3/7 package/mesa3d: enable llvm support
In reply to Valentin KorenblitThis patch provides LLVM support for Mesa3D, enabling llvmpipe software rasterizer if Gallium swrast is selected.
In case Gallium r600 is selected, llvm AMDGPU backend is built.
Having llvm installed also enables radeonsi Gallium driver, but it is not provided with this patch as it hasn't been tested.
It uses llvm-config (host variant) installed in STAGING_DIR/usr/bin to get LLVM libraries. Assuming that LLVM version 5.0.1 is installed, llvm-config --libs will output -lLLVM-5.0.
---
llvmpipe tested running glmark2-es2 on x86, ARM and Aarch64
package/mesa3d/Config.in | 6 ++++++ package/mesa3d/mesa3d.mk | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)
package/mesa3d/Config.in +6 -0
@@ -25,6 +25,11 @@ menuconfig BR2_PACKAGE_MESA3D if BR2_PACKAGE_MESA3D +config BR2_PACKAGE_MESA3D_LLVM + bool "llvm support" + depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS + select BR2_PACKAGE_LLVM + # inform the .mk file of gallium, dri or vulkan driver selection config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER bool
@@ -77,6 +82,7 @@ config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_R600 depends on BR2_i386 || BR2_x86_64 select BR2_PACKAGE_MESA3D_GALLIUM_DRIVER select BR2_PACKAGE_LIBDRM_RADEON + select BR2_PACKAGE_LLVM_AMDGPU if BR2_PACKAGE_MESA3D_LLVM select BR2_PACKAGE_MESA3D_NEEDS_XA help Driver for ATI/AMD Radeon R600/R700/HD5000/HD6000 GPUs.
package/mesa3d/mesa3d.mk +11 -3
@@ -32,6 +32,17 @@ ifeq ($(BR2_SHARED_STATIC_LIBS),y) MESA3D_CONF_OPTS += --disable-static endif +ifeq ($(BR2_PACKAGE_MESA3D_LLVM),y) +MESA3D_DEPENDENCIES += host-llvm llvm +MESA3D_CONF_OPTS += \ + --with-llvm-prefix=$(STAGING_DIR)/usr \ + --enable-llvm-shared-libs \ + --enable-llvm +else +# Avoid automatic search of llvm-config +MESA3D_CONF_OPTS += --disable-llvm +endif + # The Sourcery MIPS toolchain has a special (non-upstream) feature to # have "compact exception handling", which unfortunately breaks with # mesa3d, so we disable it here by passing -mno-compact-eh.
@@ -219,7 +230,4 @@ else MESA3D_CONF_OPTS += --disable-lmsensors endif -# Avoid automatic search of llvm-config -MESA3D_CONF_OPTS += --with-llvm-prefix=$(STAGING_DIR)/usr/bin - $(eval $(autotools-package))
Signature · 1 line
2.14.3
Thomas Petazzoni
AppliedPATCH v5 3/7 package/mesa3d: enable llvm support
Hello,
Quoted 8 lines · Valentin Korenblit
This patch provides LLVM support for Mesa3D, enabling llvmpipe software rasterizer if Gallium swrast is selected.
In case Gallium r600 is selected, llvm AMDGPU backend is built.
Having llvm installed also enables radeonsi Gallium driver, but it is not provided with this patch as it hasn't been tested.
Quoted 7 lines
It uses llvm-config (host variant) installed in STAGING_DIR/usr/bin to get LLVM libraries. Assuming that LLVM version 5.0.1 is installed, llvm-config --libs will output -lLLVM-5.0.
Signed-off-by Valentin Korenblit <[email protected]>Tested-by J?r?me Oufella <[email protected]>---
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
PATCH v5 4/7 package/clang: new package
In reply to Valentin KorenblitThis patch provides Clang tools and libraries for the host and libclang for the target.
Clang is needed to build libclc, which is also provided in a follup patch.
We need libclang for the target because it is used by most of OpenCL implementations.
A later patch in this series will enable Clover, the OpenCl implementation part of Mesa3D, which requires libclang.
clang-tblgen must be copied to HOST_DIR as it is not installed by default but is needed for cross-compilation: http://lists.llvm.org/pipermail/cfe-dev/2015-June/043318.html
--- DEVELOPERS | 1 + package/Config.in | 1 + package/clang/Config.in | 9 ++++++ package/clang/clang.hash | 3 ++ package/clang/clang.mk | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 package/clang/Config.in create mode 100644 package/clang/clang.hash create mode 100644 package/clang/clang.mk
DEVELOPERS +1 -0
@@ -1888,6 +1888,7 @@ F: package/dropwatch/ F: package/tstools/ N: Valentin Korenblit <[email protected]> +F: package/clang/ F: package/llvm/ N: Vanya Sergeev <[email protected]>
package/Config.in +1 -0
@@ -1479,6 +1479,7 @@ menu "Other" source "package/bctoolbox/Config.in" source "package/bdwgc/Config.in" source "package/boost/Config.in" + source "package/clang/Config.in" source "package/clapack/Config.in" source "package/classpath/Config.in" source "package/cppcms/Config.in"
package/clang/Config.in new file +9 -0
@@ -0,0 +1,9 @@ +config BR2_PACKAGE_CLANG + bool "clang" + depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS + select BR2_PACKAGE_LLVM + help + Clang is a C/C++, Objective C/C++ and OpenCL C front-end + for the LLVM compiler. + + http://clang.llvm.org
package/clang/clang.hash new file +3 -0
@@ -0,0 +1,3 @@ +# locally calculated +sha256 135f6c9b0cd2da1aff2250e065946258eb699777888df39ca5a5b4fe5e23d0ff cfe-5.0.1.src.tar.xz +sha256 de4c79665f0f5688b0ace17cba6f8e0343925bb95e0949d66d47bbd4527310d6 LICENSE.TXT
package/clang/clang.mk new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v5 4/7 package/clang: new package
All,
Quoted 5 lines · Valentin Korenblit
This patch provides Clang tools and libraries for the host and libclang for the target.
Clang is needed to build libclc, which is also provided in a follup patch.
Unsure of interest but we've been looking at using this concept below which depends on clang. I'm still working on completing what the integration looks like with the additional clang libraries but thanks again for sending this patchset out!
https://github.com/google/fuzzer-test-suite/blob/master/tutorial/libFuzzerTutorial.md
PATCH v5 5/7 package/libclc: new package
In reply to Valentin KorenblitThis patch provides libclc, an open source implementation of the library requirements of the OpenCL C programming language, as specified by the OpenCL 1.1 Specification. It is intended to be used with Mesa Clover.
It needs to be compiled with Clang, as it generates LLVM IR bitcode files containing device builtin functions for each target.
Currently, libclc supports AMDGCN, R600 and NVPTX targets.
As OpenCL kernels are built dynamically on the target using libclang and libLLVM, it is necessary to copy /usr/include/clc from STAGING_DIR to the target manually, as Buildroot doesn't include this directory.
---
This patch should not yet be applied, we must first find a place where clc headers can be stored.
DEVELOPERS | 1 + package/Config.in | 1 + package/libclc/Config.in | 9 +++++++++ package/libclc/libclc.hash | 3 +++ package/libclc/libclc.mk | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 package/libclc/Config.in create mode 100644 package/libclc/libclc.hash create mode 100644 package/libclc/libclc.mk
DEVELOPERS +1 -0
@@ -1889,6 +1889,7 @@ F: package/tstools/ N: Valentin Korenblit <[email protected]> F: package/clang/ +F: package/libclc/ F: package/llvm/ N: Vanya Sergeev <[email protected]>
package/Config.in +1 -0
@@ -281,6 +281,7 @@ comment "Graphic libraries" source "package/fbv/Config.in" source "package/freerdp/Config.in" source "package/imagemagick/Config.in" + source "package/libclc/Config.in" source "package/linux-fusion/Config.in" source "package/lite/Config.in" source "package/mesa3d/Config.in"
package/libclc/Config.in new file +9 -0
@@ -0,0 +1,9 @@ +config BR2_PACKAGE_LIBCLC + bool "libclc" + depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS + help + libclc is an open source, BSD licensed implementation of + the library requirements of the OpenCL C programming language, + as specified by the OpenCL 1.1 Specification. + + http://libclc.llvm.org/
package/libclc/libclc.hash new file +3 -0
@@ -0,0 +1,3 @@ +# locally calculated +sha256 e2f1f294f93695f2d1f87ccb9760231b435702dd0c27abeb38baa97186674d9e libclc-00236279a293b3737dee08c14f25923a889d2795.tar.gz +sha256 c66aa55d8478b45f1018500af9f433dd271444ad304d683dd49ff2a42f30dad1 LICENSE.TXT
package/libclc/libclc.mk new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v5 5/7 package/libclc: new package
Hi all,
Le 04/04/2018 ? 18:31, Valentin Korenblit a ?crit?:
Quoted 14 lines
This patch provides libclc, an open source implementation of the library requirements of the OpenCL C programming language, as specified by the OpenCL 1.1 Specification. It is intended to be used with Mesa Clover.
It needs to be compiled with Clang, as it generates LLVM IR bitcode files containing device builtin functions for each target.
Currently, libclc supports AMDGCN, R600 and NVPTX targets.
As OpenCL kernels are built dynamically on the target using libclang and libLLVM, it is necessary to copy
/usr/include/clcfromSTAGING_DIRto the target manually, as Buildroot doesn't include this directory.
Quoted 5 lines
Signed-off-by Valentin Korenblit <[email protected]>---
This patch should not yet be applied, we must first find a place where clc headers can be stored.
I'll mark remaining patches of this series "Changes requested" since Valentin is working on a v6 of this series, taking into account the llvm dependencies recently added and some other fixes.
Also he will try to find a workaround for the clc headers.
For now, clc headers must be copied to /usr/include/clc but this location is removed by Buildroot at the end of the build.
Best regards,
Romain
Quoted 107 lines
DEVELOPERS | 1 + package/Config.in | 1 + package/libclc/Config.in | 9 +++++++++ package/libclc/libclc.hash | 3 +++ package/libclc/libclc.mk | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 package/libclc/Config.in create mode 100644 package/libclc/libclc.hash create mode 100644 package/libclc/libclc.mkDEVELOPERS +1
-0@@ -1889,6 +1889,7 @@ F: package/tstools/ N: Valentin Korenblit <[email protected]> F: package/clang/ +F: package/libclc/ F: package/llvm/ N: Vanya Sergeev <[email protected]>package/Config.in +1
-0@@ -281,6 +281,7 @@ comment "Graphic libraries" source "package/fbv/Config.in" source "package/freerdp/Config.in" source "package/imagemagick/Config.in" + source "package/libclc/Config.in" source "package/linux-fusion/Config.in" source "package/lite/Config.in" source "package/mesa3d/Config.in"package/libclc/Config.in new file +9
-0@@ -0,0 +1,9 @@ +config BR2_PACKAGE_LIBCLC + bool "libclc" + depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS + help + libclc is an open source, BSD licensed implementation of + the library requirements of the OpenCL C programming language, + as specified by the OpenCL 1.1 Specification. + + http://libclc.llvm.org/package/libclc/libclc.hash new file +3
-0@@ -0,0 +1,3 @@ +# locally calculated +sha256 e2f1f294f93695f2d1f87ccb9760231b435702dd0c27abeb38baa97186674d9e libclc-00236279a293b3737dee08c14f25923a889d2795.tar.gz +sha256 c66aa55d8478b45f1018500af9f433dd271444ad304d683dd49ff2a42f30dad1 LICENSE.TXTpackage/libclc/libclc.mk new file +41
-0@@ -0,0 +1,41 @@ +################################################################################ +# +# libclc +# +################################################################################ + +# There are only two releases: release_35 and release_38, but the last +# commit is from 2 years ago. Master has some recent activity. +LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795 +LIBCLC_SITE = https://git.llvm.org/git/libclc +LIBCLC_SITE_METHOD = git +LIBCLC_LICENSE = NCSA +LIBCLC_LICENSE_FILES = LICENSE.TXT + +LIBCLC_DEPENDENCIES = host-clang host-llvm +LIBCLC_INSTALL_STAGING = YES + +# C++ compiler is used to build a small tool (prepare-builtins) for the host. +# It must be built with the C++ compiler from the host +LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \ + --prefix="/usr" \ + --pkgconfigdir="/usr/lib/pkgconfig" \ + --with-cxx-compiler=$(HOSTCXX) + +define LIBCLC_CONFIGURE_CMDS + (cd $(@D); $(TARGET_CONFIGURE_OPTS) ./configure.py $(LIBCLC_CONF_OPTS)) +endef + +define LIBCLC_BUILD_CMDS + $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) +endef + +define LIBCLC_INSTALL_TARGET_CMDS + $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) install +endef + +define LIBCLC_INSTALL_STAGING_CMDS + $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(STAGING_DIR) install +endef + +$(eval $(generic-package))
PATCH v5 6/7 package/mesa3d: enable OpenCL support
In reply to Valentin KorenblitThis patch provides Clover, the OpenCL 1.1 API implementation by Mesa for AMD GPUs. It generates libOpenCL.so.
Add --disable-opencl-icd because int Mesa 18 defaults to on. When disabled, the shared library is named libOpenCL instead of libMesaOpenCL and CL headers are installed.
---
Tested with AMD Radeon Dual (AMD SUMO + AMD CAICOS) using Gallium r600:
Piglit taken from Romain Naour's patch, setting -DPIGLIT_BUILD_CL_TESTS=ON:
http://lists.busybox.net/pipermail/buildroot/2018-February/213601.html
Results from 704 tests:
skip 94
pass 541
fail 60
crash 9
Opencl-example (100% pass):
https://cgit.freedesktop.org/~tstellar/opencl-example/
package/mesa3d/Config.in | 17 +++++++++++++++++ package/mesa3d/mesa3d.mk | 10 ++++++++++ 2 files changed, 27 insertions(+)
package/mesa3d/Config.in +17 -0
@@ -30,6 +30,23 @@ config BR2_PACKAGE_MESA3D_LLVM depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS select BR2_PACKAGE_LLVM +config BR2_PACKAGE_MESA3D_OPENCL + bool "opencl support" + depends on BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_R600 + depends on BR2_PACKAGE_MESA3D_LLVM + depends on BR2_USE_WCHAR # elfutils + depends on BR2_TOOLCHAIN_USES_UCLIBC || BR2_TOOLCHAIN_USES_GLIBC + depends on !BR2_bfin # elfutils + select BR2_PACKAGE_CLANG + select BR2_PACKAGE_ELFUTILS + select BR2_PACKAGE_LIBCLC + +comment "mesa3d OpenCL needs a uClibc or glibc toolchain w/ wchar" + depends on BR2_PACKAGE_MESA3D_LLVM + depends on !BR2_bfin + depends on !BR2_USE_WCHAR \ + || !(BR2_TOOLCHAIN_USES_UCLIBC || BR2_TOOLCHAIN_USES_GLIBC) + # inform the .mk file of gallium, dri or vulkan driver selection config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER bool
package/mesa3d/mesa3d.mk +10 -0
@@ -230,4 +230,14 @@ else MESA3D_CONF_OPTS += --disable-lmsensors endif +# Clover requires libelf +ifeq ($(BR2_PACKAGE_MESA3D_OPENCL),y) +MESA3D_DEPENDENCIES += clang elfutils libclc +MESA3D_CONF_OPTS += --enable-opencl \ + --disable-opencl-icd \ + --with-clang-libdir=$(STAGING_DIR)/usr/lib +else +MESA3D_CONF_OPTS += --disable-opencl +endif + $(eval $(autotools-package))
Signature · 1 line
2.14.3
PATCH v5 7/7 package/clinfo: new package
In reply to Valentin KorenblitThis tool allows to verify if the OpenCL environment is set up correctly and output information related to the supported OpenCL platforms.
--- DEVELOPERS | 1 + package/Config.in | 1 + package/clinfo/Config.in | 9 +++++++++ package/clinfo/clinfo.hash | 2 ++ package/clinfo/clinfo.mk | 23 +++++++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 package/clinfo/Config.in create mode 100644 package/clinfo/clinfo.hash create mode 100644 package/clinfo/clinfo.mk
DEVELOPERS +1 -0
@@ -1889,6 +1889,7 @@ F: package/tstools/ N: Valentin Korenblit <[email protected]> F: package/clang/ +F: package/clinfo/ F: package/libclc/ F: package/llvm/
package/Config.in +1 -0
@@ -1483,6 +1483,7 @@ menu "Other" source "package/clang/Config.in" source "package/clapack/Config.in" source "package/classpath/Config.in" + source "package/clinfo/Config.in" source "package/cppcms/Config.in" source "package/cracklib/Config.in" source "package/dawgdic/Config.in"
package/clinfo/Config.in new file +9 -0
@@ -0,0 +1,9 @@ +config BR2_PACKAGE_CLINFO + bool "clinfo" + depends on BR2_PACKAGE_MESA3D_OPENCL + help + clinfo is a simple command-line application that enumerates + all possible (known) properties of the OpenCL platform and + devices available on the system. + + https://github.com/Oblomov/clinfo
package/clinfo/clinfo.hash new file +2 -0
@@ -0,0 +1,2 @@ +# locally calculated +sha256 64b02e68ccff3b95437bd0bd70dcb88438c58adec16a7145a5d4e5c26a898ccf clinfo-2.2.18.03.26.tar.gz
package/clinfo/clinfo.mk new file +23 -0
@@ -0,0 +1,23 @@ +################################################################################ +# +# clinfo +# +################################################################################ + +CLINFO_VERSION = 2.2.18.03.26 +CLINFO_SITE = $(call github,Oblomov,clinfo,$(CLINFO_VERSION)) +CLINFO_LICENSE = CC0-1.0 +CLINFO_LICENSE_FILES = legalcode.txt + +# libOpenCL is needed +CLINFO_DEPENDENCIES = mesa3d + +define CLINFO_BUILD_CMDS + $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(TARGET_CONFIGURE_OPTS) +endef + +define CLINFO_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 755 $(@D)/clinfo $(TARGET_DIR)/usr/bin/clinfo +endef + +$(eval $(generic-package))
Signature · 1 line
2.14.3