diff mbox series

[RFC,1/1] mesa: fix building OpenCL programs

Message ID 20220917115642.766941-2-andrey.konovalov@linaro.org
State New
Headers show
Series mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs | expand

Commit Message

Andrey Konovalov Sept. 17, 2022, 11:56 a.m. UTC
When building an OpenCL program clover needs to locate opencl-c.h
include file. This include file location is passed via cpp args using
CLANG_RESOURCE_DIR macro. To set CLANG_RESOURCE_DIR value meson currently
uses "$(llvm-config --libdir)" which results in path to sysroot included
into CLANG_RESOURCE_DIR. Then clBuildProgram() fails with
"fatal error: 'opencl-c.h' file not found".

Work this around by using '/usr/lib' instead of the libdir value
exported by LLVM.

Microsoft/Intel CLC should suffer from the same issue, and the similar
workaround should work in this case too.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
---
 ...-meson.CLANG_RESOURCE_DIR-workaround.patch | 42 +++++++++++++++++++
 meta/recipes-graphics/mesa/mesa.inc           |  1 +
 2 files changed, 43 insertions(+)
 create mode 100644 meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch

Comments

Alexander Kanavin Sept. 17, 2022, 12:26 p.m. UTC | #1
Please send this upstream first.

Alex

On Sat 17. Sep 2022 at 12.56, Andrey Konovalov <andrey.konovalov@linaro.org>
wrote:

> When building an OpenCL program clover needs to locate opencl-c.h
> include file. This include file location is passed via cpp args using
> CLANG_RESOURCE_DIR macro. To set CLANG_RESOURCE_DIR value meson currently
> uses "$(llvm-config --libdir)" which results in path to sysroot included
> into CLANG_RESOURCE_DIR. Then clBuildProgram() fails with
> "fatal error: 'opencl-c.h' file not found".
>
> Work this around by using '/usr/lib' instead of the libdir value
> exported by LLVM.
>
> Microsoft/Intel CLC should suffer from the same issue, and the similar
> workaround should work in this case too.
>
> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> ---
>  ...-meson.CLANG_RESOURCE_DIR-workaround.patch | 42 +++++++++++++++++++
>  meta/recipes-graphics/mesa/mesa.inc           |  1 +
>  2 files changed, 43 insertions(+)
>  create mode 100644
> meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
>
> diff --git
> a/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> new file mode 100644
> index 0000000000..db60fe407f
> --- /dev/null
> +++
> b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> @@ -0,0 +1,42 @@
> +From: Andrey Konovalov <andrey.konovalov@linaro.org>
> +Date: Fri, 16 Sep 2022 16:58:20 +0000
> +Subject: [PATCH] CLANG_RESOURCE_DIR workaround
> +
> +Setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something"
> +results in clBuildProgram() error when an OpenCL program is being
> +built on the target. The reason is that $(llvm-config --libdir) output
> +includes path to the sysroot directory.
> +
> +Work this around by using '/usr/lib' instead of the libdir value
> +exported by LLVM.
> +
> +Upstream-Status: Inappropriate
> +Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> +
> +---
> +
> +--- a/src/gallium/frontends/clover/meson.build 2022-09-16
> 10:24:55.910577158 +0000
> ++++ b/src/gallium/frontends/clover/meson.build 2022-09-16
> 10:28:13.112804197 +0000
> +@@ -71,8 +71,7 @@ libclllvm = static_library(
> +     clover_opencl_cpp_args,
> +     clover_spirv_cpp_args,
> +     '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
> +-      dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool:
> 'libdir'), 'clang',
> +-      dep_llvm.version(), 'include',
> ++      '/usr/lib', 'clang', dep_llvm.version(), 'include',
> +     )),
> +   ],
> +   gnu_symbol_visibility : 'hidden',
> +--- a/src/compiler/clc/meson.build     2022-09-16 16:40:10.641735401 +0000
> ++++ b/src/compiler/clc/meson.build     2022-09-16 16:50:18.095700452 +0000
> +@@ -39,7 +39,9 @@ files_libclc = files(
> +   'clc_helpers.cpp',
> + )
> +
> +-_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@
> "'.format(clang_resource_dir)]
> ++_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
> ++                       '/usr/lib', 'clang', dep_llvm.version(), 'include'
> ++                    ))]
> + if with_microsoft_clc
> +   _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
> + endif
> diff --git a/meta/recipes-graphics/mesa/mesa.inc
> b/meta/recipes-graphics/mesa/mesa.inc
> index ea7ed4fd27..0a2fb2150d 100644
> --- a/meta/recipes-graphics/mesa/mesa.inc
> +++ b/meta/recipes-graphics/mesa/mesa.inc
> @@ -23,6 +23,7 @@ SRC_URI = "
> https://mesa.freedesktop.org/archive/mesa-${PV}.tar.xz \
>
> file://0001-Revert-egl-wayland-deprecate-drm_handle_format-and-d.patch \
>
> file://0001-swrast_kms-use-swkmsDRI2Extension-instead-of-driDRI2.patch \
>
> file://0001-nir-nir_opt_move-fix-ALWAYS_INLINE-compiler-error.patch \
> +           file://0001-meson.CLANG_RESOURCE_DIR-workaround.patch \
>             "
>
>  SRC_URI[sha256sum] =
> "22ced061eb9adab8ea35368246c1995c09723f3f71653cd5050c5cec376e671a"
> --
> 2.25.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#170828):
> https://lists.openembedded.org/g/openembedded-core/message/170828
> Mute This Topic: https://lists.openembedded.org/mt/93741466/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Richard Purdie Sept. 17, 2022, 1:57 p.m. UTC | #2
On Sat, 2022-09-17 at 14:56 +0300, Andrey Konovalov wrote:
> When building an OpenCL program clover needs to locate opencl-c.h
> include file. This include file location is passed via cpp args using
> CLANG_RESOURCE_DIR macro. To set CLANG_RESOURCE_DIR value meson currently
> uses "$(llvm-config --libdir)" which results in path to sysroot included
> into CLANG_RESOURCE_DIR. Then clBuildProgram() fails with
> "fatal error: 'opencl-c.h' file not found".
> 
> Work this around by using '/usr/lib' instead of the libdir value
> exported by LLVM.
> 
> Microsoft/Intel CLC should suffer from the same issue, and the similar
> workaround should work in this case too.
> 
> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> ---
>  ...-meson.CLANG_RESOURCE_DIR-workaround.patch | 42 +++++++++++++++++++
>  meta/recipes-graphics/mesa/mesa.inc           |  1 +
>  2 files changed, 43 insertions(+)
>  create mode 100644 meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> 
> diff --git a/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> new file mode 100644
> index 0000000000..db60fe407f
> --- /dev/null
> +++ b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
> @@ -0,0 +1,42 @@
> +From: Andrey Konovalov <andrey.konovalov@linaro.org>
> +Date: Fri, 16 Sep 2022 16:58:20 +0000
> +Subject: [PATCH] CLANG_RESOURCE_DIR workaround
> +
> +Setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something"
> +results in clBuildProgram() error when an OpenCL program is being
> +built on the target. The reason is that $(llvm-config --libdir) output
> +includes path to the sysroot directory.
> +
> +Work this around by using '/usr/lib' instead of the libdir value
> +exported by LLVM.
> +
> +Upstream-Status: Inappropriate
> +Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> +
> +---
> +
> +--- a/src/gallium/frontends/clover/meson.build	2022-09-16 10:24:55.910577158 +0000
> ++++ b/src/gallium/frontends/clover/meson.build	2022-09-16 10:28:13.112804197 +0000
> +@@ -71,8 +71,7 @@ libclllvm = static_library(
> +     clover_opencl_cpp_args,
> +     clover_spirv_cpp_args,
> +     '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
> +-      dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir'), 'clang',
> +-      dep_llvm.version(), 'include',
> ++      '/usr/lib', 'clang', dep_llvm.version(), 'include',
> +     )),
> +   ],
> +   gnu_symbol_visibility : 'hidden',
> +--- a/src/compiler/clc/meson.build	2022-09-16 16:40:10.641735401 +0000
> ++++ b/src/compiler/clc/meson.build	2022-09-16 16:50:18.095700452 +0000
> +@@ -39,7 +39,9 @@ files_libclc = files(
> +   'clc_helpers.cpp',
> + )
> + 
> +-_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)]
> ++_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
> ++                       '/usr/lib', 'clang', dep_llvm.version(), 'include'
> ++                    ))]
> + if with_microsoft_clc
> +   _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
> + endif

libdir might not be /usr/lib so this isn't always going to be
correct...

Cheers,

Richard
Andrey Konovalov Sept. 18, 2022, 11:58 a.m. UTC | #3
On 9/17/22 16:57, Richard Purdie wrote:
> On Sat, 2022-09-17 at 14:56 +0300, Andrey Konovalov wrote:
>> When building an OpenCL program clover needs to locate opencl-c.h
>> include file. This include file location is passed via cpp args using
>> CLANG_RESOURCE_DIR macro. To set CLANG_RESOURCE_DIR value meson currently
>> uses "$(llvm-config --libdir)" which results in path to sysroot included
>> into CLANG_RESOURCE_DIR. Then clBuildProgram() fails with
>> "fatal error: 'opencl-c.h' file not found".
>>
>> Work this around by using '/usr/lib' instead of the libdir value
>> exported by LLVM.
>>
>> Microsoft/Intel CLC should suffer from the same issue, and the similar
>> workaround should work in this case too.
>>
>> Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
>> ---
>>   ...-meson.CLANG_RESOURCE_DIR-workaround.patch | 42 +++++++++++++++++++
>>   meta/recipes-graphics/mesa/mesa.inc           |  1 +
>>   2 files changed, 43 insertions(+)
>>   create mode 100644 meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
>>
>> diff --git a/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
>> new file mode 100644
>> index 0000000000..db60fe407f
>> --- /dev/null
>> +++ b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
>> @@ -0,0 +1,42 @@
>> +From: Andrey Konovalov <andrey.konovalov@linaro.org>
>> +Date: Fri, 16 Sep 2022 16:58:20 +0000
>> +Subject: [PATCH] CLANG_RESOURCE_DIR workaround
>> +
>> +Setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something"
>> +results in clBuildProgram() error when an OpenCL program is being
>> +built on the target. The reason is that $(llvm-config --libdir) output
>> +includes path to the sysroot directory.
>> +
>> +Work this around by using '/usr/lib' instead of the libdir value
>> +exported by LLVM.
>> +
>> +Upstream-Status: Inappropriate
>> +Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
>> +
>> +---
>> +
>> +--- a/src/gallium/frontends/clover/meson.build	2022-09-16 10:24:55.910577158 +0000
>> ++++ b/src/gallium/frontends/clover/meson.build	2022-09-16 10:28:13.112804197 +0000
>> +@@ -71,8 +71,7 @@ libclllvm = static_library(
>> +     clover_opencl_cpp_args,
>> +     clover_spirv_cpp_args,
>> +     '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
>> +-      dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir'), 'clang',
>> +-      dep_llvm.version(), 'include',
>> ++      '/usr/lib', 'clang', dep_llvm.version(), 'include',
>> +     )),
>> +   ],
>> +   gnu_symbol_visibility : 'hidden',
>> +--- a/src/compiler/clc/meson.build	2022-09-16 16:40:10.641735401 +0000
>> ++++ b/src/compiler/clc/meson.build	2022-09-16 16:50:18.095700452 +0000
>> +@@ -39,7 +39,9 @@ files_libclc = files(
>> +   'clc_helpers.cpp',
>> + )
>> +
>> +-_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)]
>> ++_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
>> ++                       '/usr/lib', 'clang', dep_llvm.version(), 'include'
>> ++                    ))]
>> + if with_microsoft_clc
>> +   _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
>> + endif
> 
> libdir might not be /usr/lib so this isn't always going to be
> correct...

I see. Will look for a better option then just hardcoded '/usr/lib' then.

Thanks,
Andrey

> Cheers,
> 
> Richard
diff mbox series

Patch

diff --git a/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
new file mode 100644
index 0000000000..db60fe407f
--- /dev/null
+++ b/meta/recipes-graphics/mesa/files/0001-meson.CLANG_RESOURCE_DIR-workaround.patch
@@ -0,0 +1,42 @@ 
+From: Andrey Konovalov <andrey.konovalov@linaro.org>
+Date: Fri, 16 Sep 2022 16:58:20 +0000
+Subject: [PATCH] CLANG_RESOURCE_DIR workaround
+
+Setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something"
+results in clBuildProgram() error when an OpenCL program is being
+built on the target. The reason is that $(llvm-config --libdir) output
+includes path to the sysroot directory.
+
+Work this around by using '/usr/lib' instead of the libdir value
+exported by LLVM.
+
+Upstream-Status: Inappropriate
+Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
+
+---
+
+--- a/src/gallium/frontends/clover/meson.build	2022-09-16 10:24:55.910577158 +0000
++++ b/src/gallium/frontends/clover/meson.build	2022-09-16 10:28:13.112804197 +0000
+@@ -71,8 +71,7 @@ libclllvm = static_library(
+     clover_opencl_cpp_args,
+     clover_spirv_cpp_args,
+     '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
+-      dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir'), 'clang',
+-      dep_llvm.version(), 'include',
++      '/usr/lib', 'clang', dep_llvm.version(), 'include',
+     )),
+   ],
+   gnu_symbol_visibility : 'hidden',
+--- a/src/compiler/clc/meson.build	2022-09-16 16:40:10.641735401 +0000
++++ b/src/compiler/clc/meson.build	2022-09-16 16:50:18.095700452 +0000
+@@ -39,7 +39,9 @@ files_libclc = files(
+   'clc_helpers.cpp',
+ )
+ 
+-_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)]
++_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
++                       '/usr/lib', 'clang', dep_llvm.version(), 'include'
++                    ))]
+ if with_microsoft_clc
+   _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
+ endif
diff --git a/meta/recipes-graphics/mesa/mesa.inc b/meta/recipes-graphics/mesa/mesa.inc
index ea7ed4fd27..0a2fb2150d 100644
--- a/meta/recipes-graphics/mesa/mesa.inc
+++ b/meta/recipes-graphics/mesa/mesa.inc
@@ -23,6 +23,7 @@  SRC_URI = "https://mesa.freedesktop.org/archive/mesa-${PV}.tar.xz \
            file://0001-Revert-egl-wayland-deprecate-drm_handle_format-and-d.patch \
            file://0001-swrast_kms-use-swkmsDRI2Extension-instead-of-driDRI2.patch \
            file://0001-nir-nir_opt_move-fix-ALWAYS_INLINE-compiler-error.patch \
+           file://0001-meson.CLANG_RESOURCE_DIR-workaround.patch \
            "
 
 SRC_URI[sha256sum] = "22ced061eb9adab8ea35368246c1995c09723f3f71653cd5050c5cec376e671a"