All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs
@ 2022-09-17 11:56 Andrey Konovalov
  2022-09-17 11:56 ` [RFC][PATCH 1/1] mesa: " Andrey Konovalov
  2022-09-17 16:38 ` [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: " Khem Raj
  0 siblings, 2 replies; 8+ messages in thread
From: Andrey Konovalov @ 2022-09-17 11:56 UTC (permalink / raw)
  To: openembedded-core; +Cc: Andrey Konovalov

This fixes the errors like:

-----8<-----
dragonboard-845c:~$ clinfo
<snip>
   Max work group size                             1024
=== CL_PROGRAM_BUILD_LOG ===
<built-in>:1:10: fatal error: 'opencl-c.h' file not found
   Preferred work group size multiple (kernel)     <getWGsizes:1504: create ker>
   Preferred / native vector sizes
     char                                                16 / 16
<snip>
-----8<----- 

Here clinfo runs on target board and produces correct output except for
the "Preferred work group size multiple (kernel)" item. This is the only
item which requires clinfo to build and run a small OpenCL kernel. But
building OpenCL program fails as clover can't find the include file.

The reason is that the include search path is set at mesa build time by
setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something" and
passing it in cpp args. This results in path to sysroot included into
CLANG_RESOURCE_DIR:

-----8<-----
dragonboard-845c:~$ strace clinfo 2>&1|grep include
newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
newfstatat(AT_FDCWD, "/usr/local/include", 0xfffffc3bad68, 0) = -1 ENOENT (No s>
newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
newfstatat(AT_FDCWD, "/usr/include", {st_mode=S_IFDIR|0755, st_size=12288, ...}>
openat(AT_FDCWD, "/usr/include/opencl-c.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No>
-----8<----- 

Hence clover fails to locate /usr/lib/clang/14.0.6/include/opencl-c.h.

Microsoft/Intel CLC *should* have the same problem, as the code in
compiler/clc/clc_helpers.cpp is pretty close to the one in
gallium/frontends/clover/llvm/invocation.cpp. Except for the case when 
the contents of opencl-c.h is compiled into the CLC library (seems to be 
the most common configuration for Windows), and the problem with locating
the include file on the target fs doesn't exist.

This patch is RFC for two reasons:
* I am not sure if using hardcoded "/usr/lib" is good enough
* The compiler/clc/clc_helpers.cpp part is not tested. Maybe splitting
  the patch into two - the clover and the Microsoft/Intel CLC parts separated -
  would make more sense.

Last note for those to try reproducing the build with clover:
clover uses libclc from meta-clang. meta-clang master branch has moved to
clang 15.0.0 recently, which breaks mesa build as the mesa fixes to account
for clang 15.0.0 changes have been merged into mesa main branch, but have not
yet made it into the last mesa release.
My temporary solution is rolling meta-clang back to the commit just before the
14.0.6 -> 15.0.0 update, and cherry-picking "llvm-config: Replace TARGET_*
flags with normal equivalent flags". The latter is not required in my case,
it just makes llvm-config wrapper from meta-clang (the one used in this build)
to look closer to the llvm-config wrapper from oe-core.

Andrey Konovalov (1):
  mesa: fix building OpenCL programs

 ...-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

-- 
2.25.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC][PATCH 1/1] mesa: fix building OpenCL programs
  2022-09-17 11:56 [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs Andrey Konovalov
@ 2022-09-17 11:56 ` Andrey Konovalov
  2022-09-17 12:26   ` [OE-core] " Alexander Kanavin
  2022-09-17 13:57   ` Richard Purdie
  2022-09-17 16:38 ` [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: " Khem Raj
  1 sibling, 2 replies; 8+ messages in thread
From: Andrey Konovalov @ 2022-09-17 11:56 UTC (permalink / raw)
  To: openembedded-core; +Cc: Andrey Konovalov

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



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 1/1] mesa: fix building OpenCL programs
  2022-09-17 11:56 ` [RFC][PATCH 1/1] mesa: " Andrey Konovalov
@ 2022-09-17 12:26   ` Alexander Kanavin
  2022-09-18 11:55     ` Andrey Konovalov
  2022-09-17 13:57   ` Richard Purdie
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Kanavin @ 2022-09-17 12:26 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 4416 bytes --]

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]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>

[-- Attachment #2: Type: text/html, Size: 6239 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 1/1] mesa: fix building OpenCL programs
  2022-09-17 11:56 ` [RFC][PATCH 1/1] mesa: " Andrey Konovalov
  2022-09-17 12:26   ` [OE-core] " Alexander Kanavin
@ 2022-09-17 13:57   ` Richard Purdie
  2022-09-18 11:58     ` Andrey Konovalov
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Purdie @ 2022-09-17 13:57 UTC (permalink / raw)
  To: Andrey Konovalov, openembedded-core

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs
  2022-09-17 11:56 [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs Andrey Konovalov
  2022-09-17 11:56 ` [RFC][PATCH 1/1] mesa: " Andrey Konovalov
@ 2022-09-17 16:38 ` Khem Raj
  2022-09-18 12:06   ` Andrey Konovalov
  1 sibling, 1 reply; 8+ messages in thread
From: Khem Raj @ 2022-09-17 16:38 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: openembedded-core

On Sat, Sep 17, 2022 at 4:56 AM Andrey Konovalov
<andrey.konovalov@linaro.org> wrote:
>
> This fixes the errors like:
>
> -----8<-----
> dragonboard-845c:~$ clinfo
> <snip>
>    Max work group size                             1024
> === CL_PROGRAM_BUILD_LOG ===
> <built-in>:1:10: fatal error: 'opencl-c.h' file not found
>    Preferred work group size multiple (kernel)     <getWGsizes:1504: create ker>
>    Preferred / native vector sizes
>      char                                                16 / 16
> <snip>
> -----8<-----
>
> Here clinfo runs on target board and produces correct output except for
> the "Preferred work group size multiple (kernel)" item. This is the only
> item which requires clinfo to build and run a small OpenCL kernel. But
> building OpenCL program fails as clover can't find the include file.
>
> The reason is that the include search path is set at mesa build time by
> setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something" and
> passing it in cpp args. This results in path to sysroot included into
> CLANG_RESOURCE_DIR:
>
> -----8<-----
> dragonboard-845c:~$ strace clinfo 2>&1|grep include
> newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
> newfstatat(AT_FDCWD, "/usr/local/include", 0xfffffc3bad68, 0) = -1 ENOENT (No s>
> newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
> newfstatat(AT_FDCWD, "/usr/include", {st_mode=S_IFDIR|0755, st_size=12288, ...}>
> openat(AT_FDCWD, "/usr/include/opencl-c.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No>
> -----8<-----
>
> Hence clover fails to locate /usr/lib/clang/14.0.6/include/opencl-c.h.
>
> Microsoft/Intel CLC *should* have the same problem, as the code in
> compiler/clc/clc_helpers.cpp is pretty close to the one in
> gallium/frontends/clover/llvm/invocation.cpp. Except for the case when
> the contents of opencl-c.h is compiled into the CLC library (seems to be
> the most common configuration for Windows), and the problem with locating
> the include file on the target fs doesn't exist.
>
> This patch is RFC for two reasons:
> * I am not sure if using hardcoded "/usr/lib" is good enough
> * The compiler/clc/clc_helpers.cpp part is not tested. Maybe splitting
>   the patch into two - the clover and the Microsoft/Intel CLC parts separated -
>   would make more sense.
>
> Last note for those to try reproducing the build with clover:
> clover uses libclc from meta-clang. meta-clang master branch has moved to
> clang 15.0.0 recently, which breaks mesa build as the mesa fixes to account
> for clang 15.0.0 changes have been merged into mesa main branch, but have not
> yet made it into the last mesa release.
> My temporary solution is rolling meta-clang back to the commit just before the
> 14.0.6 -> 15.0.0 update, and cherry-picking "llvm-config: Replace TARGET_*
> flags with normal equivalent flags". The latter is not required in my case,
> it just makes llvm-config wrapper from meta-clang (the one used in this build)
> to look closer to the llvm-config wrapper from oe-core.
>
> Andrey Konovalov (1):
>   mesa: fix building OpenCL programs
>
>  ...-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
>

I am not able to find the patch with above changes. Did you miss sending it ?


> --
> 2.25.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#170827): https://lists.openembedded.org/g/openembedded-core/message/170827
> Mute This Topic: https://lists.openembedded.org/mt/93741464/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 1/1] mesa: fix building OpenCL programs
  2022-09-17 12:26   ` [OE-core] " Alexander Kanavin
@ 2022-09-18 11:55     ` Andrey Konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: Andrey Konovalov @ 2022-09-18 11:55 UTC (permalink / raw)
  To: Alexander Kanavin; +Cc: openembedded-core

On 9/17/22 15:26, Alexander Kanavin wrote:
> Please send this upstream first.

Oops... For some reason I was under impression that this is OE build specific.
Good point!

Thanks,
Andrey

> Alex
> 
> On Sat 17. Sep 2022 at 12.56, Andrey Konovalov <andrey.konovalov@linaro.org <mailto: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 <mailto: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 <mailto: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 <mailto: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
>     <https://mesa.freedesktop.org/archive/mesa-$%7BPV%7D.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
> 
> 
>     
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 1/1] mesa: fix building OpenCL programs
  2022-09-17 13:57   ` Richard Purdie
@ 2022-09-18 11:58     ` Andrey Konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: Andrey Konovalov @ 2022-09-18 11:58 UTC (permalink / raw)
  To: Richard Purdie, openembedded-core

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs
  2022-09-17 16:38 ` [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: " Khem Raj
@ 2022-09-18 12:06   ` Andrey Konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: Andrey Konovalov @ 2022-09-18 12:06 UTC (permalink / raw)
  To: Khem Raj; +Cc: openembedded-core

On 9/17/22 19:38, Khem Raj wrote:
> On Sat, Sep 17, 2022 at 4:56 AM Andrey Konovalov
> <andrey.konovalov@linaro.org> wrote:
>>
>> This fixes the errors like:
>>
>> -----8<-----
>> dragonboard-845c:~$ clinfo
>> <snip>
>>     Max work group size                             1024
>> === CL_PROGRAM_BUILD_LOG ===
>> <built-in>:1:10: fatal error: 'opencl-c.h' file not found
>>     Preferred work group size multiple (kernel)     <getWGsizes:1504: create ker>
>>     Preferred / native vector sizes
>>       char                                                16 / 16
>> <snip>
>> -----8<-----
>>
>> Here clinfo runs on target board and produces correct output except for
>> the "Preferred work group size multiple (kernel)" item. This is the only
>> item which requires clinfo to build and run a small OpenCL kernel. But
>> building OpenCL program fails as clover can't find the include file.
>>
>> The reason is that the include search path is set at mesa build time by
>> setting CLANG_RESOURCE_DIR to "$(llvm-config --libdir)something" and
>> passing it in cpp args. This results in path to sysroot included into
>> CLANG_RESOURCE_DIR:
>>
>> -----8<-----
>> dragonboard-845c:~$ strace clinfo 2>&1|grep include
>> newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
>> newfstatat(AT_FDCWD, "/usr/local/include", 0xfffffc3bad68, 0) = -1 ENOENT (No s>
>> newfstatat(AT_FDCWD, "/workdir/master.test/build-rpb/tmp-rpb-glibc/work/armv8-2>
>> newfstatat(AT_FDCWD, "/usr/include", {st_mode=S_IFDIR|0755, st_size=12288, ...}>
>> openat(AT_FDCWD, "/usr/include/opencl-c.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No>
>> -----8<-----
>>
>> Hence clover fails to locate /usr/lib/clang/14.0.6/include/opencl-c.h.
>>
>> Microsoft/Intel CLC *should* have the same problem, as the code in
>> compiler/clc/clc_helpers.cpp is pretty close to the one in
>> gallium/frontends/clover/llvm/invocation.cpp. Except for the case when
>> the contents of opencl-c.h is compiled into the CLC library (seems to be
>> the most common configuration for Windows), and the problem with locating
>> the include file on the target fs doesn't exist.
>>
>> This patch is RFC for two reasons:
>> * I am not sure if using hardcoded "/usr/lib" is good enough
>> * The compiler/clc/clc_helpers.cpp part is not tested. Maybe splitting
>>    the patch into two - the clover and the Microsoft/Intel CLC parts separated -
>>    would make more sense.
>>
>> Last note for those to try reproducing the build with clover:
>> clover uses libclc from meta-clang. meta-clang master branch has moved to
>> clang 15.0.0 recently, which breaks mesa build as the mesa fixes to account
>> for clang 15.0.0 changes have been merged into mesa main branch, but have not
>> yet made it into the last mesa release.
>> My temporary solution is rolling meta-clang back to the commit just before the
>> 14.0.6 -> 15.0.0 update, and cherry-picking "llvm-config: Replace TARGET_*
>> flags with normal equivalent flags". The latter is not required in my case,
>> it just makes llvm-config wrapper from meta-clang (the one used in this build)
>> to look closer to the llvm-config wrapper from oe-core.
>>
>> Andrey Konovalov (1):
>>    mesa: fix building OpenCL programs
>>
>>   ...-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
>>
> 
> I am not able to find the patch with above changes. Did you miss sending it ?

Yes, I did...
Will see if I can find something better then hardcoded '/usr/lib', and submit
the patch to https://gitlab.freedesktop.org/mesa/mesa

Thanks,
Andrey

>> --
>> 2.25.1
>>
>>
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#170827): https://lists.openembedded.org/g/openembedded-core/message/170827
>> Mute This Topic: https://lists.openembedded.org/mt/93741464/1997914
>> Group Owner: openembedded-core+owner@lists.openembedded.org
>> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
>> -=-=-=-=-=-=-=-=-=-=-=-
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-18 12:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-17 11:56 [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: fix building OpenCL programs Andrey Konovalov
2022-09-17 11:56 ` [RFC][PATCH 1/1] mesa: " Andrey Konovalov
2022-09-17 12:26   ` [OE-core] " Alexander Kanavin
2022-09-18 11:55     ` Andrey Konovalov
2022-09-17 13:57   ` Richard Purdie
2022-09-18 11:58     ` Andrey Konovalov
2022-09-17 16:38 ` [OE-core] [RFC][PATCH 0/1] mesa: clover | Microsoft/Intel CLC: " Khem Raj
2022-09-18 12:06   ` Andrey Konovalov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.