diff mbox series

[v4,09/11] package/libclc: new package

Message ID 20180329113346.10367-10-valentin.korenblit@smile.fr
State Superseded
Headers show
Series llvm for mesa3d | expand

Commit Message

Valentin Korenblit March 29, 2018, 11:33 a.m. UTC
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/clc from STAGING_DIR to the
target manually, as Buildroot doesn't include this directory.

Signed-off-by: Valentin Korenblit <valentin.korenblit@smile.fr>
---
 DEVELOPERS               |  1 +
 package/Config.in        |  1 +
 package/libclc/Config.in |  9 +++++++++
 package/libclc/libclc.mk | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 package/libclc/Config.in
 create mode 100644 package/libclc/libclc.mk

Comments

Thomas Petazzoni April 1, 2018, 9:29 p.m. UTC | #1
Hello,

On Thu, 29 Mar 2018 13:33:44 +0200, Valentin Korenblit wrote:
> 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/clc from STAGING_DIR to the
> target manually, as Buildroot doesn't include this directory.

I don't see where your .mk file is doing this. And it wouldn't work
because Buildroot removes $(TARGET_DIR)/usr/include entirely in its
target-finalize step.

When you say "manually", do you mean that you have to
copy /usr/include/clc from your build machine to your target once the
target has booted ? If that's the case, then we really have a problem
here, the target should just work.

> +LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795
> +LIBCLC_SITE = https://git.llvm.org/git/libclc
> +LIBCLC_SITE_METHOD = git

I assume they don't have a stable release you could use ?

This lacks LICENSE and LICENSE_FILES.

> +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, simply use
> +# HOSTCXX_NOCCACHE.

Why not HOSTCXX ?

> +LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \

Why are you using the version in HOST_DIR, and not the one in
STAGING_DIR ?

Best regards,

Thomas
Valentin Korenblit April 3, 2018, 12:27 p.m. UTC | #2
Hello Thomas,

On 01/04/2018 23:29, Thomas Petazzoni wrote:
> Hello,
>
> On Thu, 29 Mar 2018 13:33:44 +0200, Valentin Korenblit wrote:
>> 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/clc from STAGING_DIR to the
>> target manually, as Buildroot doesn't include this directory.
> I don't see where your .mk file is doing this. And it wouldn't work
> because Buildroot removes $(TARGET_DIR)/usr/include entirely in its
> target-finalize step.
>
> When you say "manually", do you mean that you have to
> copy /usr/include/clc from your build machine to your target once the
> target has booted ? If that's the case, then we really have a problem
> here, the target should just work.

Exactly, I was doing it manually after booting. Mesa uses pkg-config to
get the includedir of libclc: https://pastebin.com/adzL8vd4

Do you think it is ok to override configure.ac from Mesa to specify
another path? And in that case, where should I place all these headers?

>
>> +LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795
>> +LIBCLC_SITE = https://git.llvm.org/git/libclc
>> +LIBCLC_SITE_METHOD = git
> I assume they don't have a stable release you could use ?

There is release_38, but the last commit is from 2 years ago. Master
has some recent activity.

>
> This lacks LICENSE and LICENSE_FILES.
>
>> +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, simply use
>> +# HOSTCXX_NOCCACHE.
> Why not HOSTCXX ?
>
>> +LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \
> Why are you using the version in HOST_DIR, and not the one in
> STAGING_DIR ?

I will check this.

>
> Best regards,
>
> Thomas

Best regards,

Valentin
Thomas Petazzoni April 3, 2018, 3:17 p.m. UTC | #3
Hello,

On Tue, 3 Apr 2018 14:27:16 +0200, Valentin Korenblit wrote:

> >> 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.  
> > I don't see where your .mk file is doing this. And it wouldn't work
> > because Buildroot removes $(TARGET_DIR)/usr/include entirely in its
> > target-finalize step.
> >
> > When you say "manually", do you mean that you have to
> > copy /usr/include/clc from your build machine to your target once the
> > target has booted ? If that's the case, then we really have a problem
> > here, the target should just work.  
> 
> Exactly, I was doing it manually after booting. Mesa uses pkg-config to
> get the includedir of libclc: https://pastebin.com/adzL8vd4
> 
> Do you think it is ok to override configure.ac from Mesa to specify
> another path? And in that case, where should I place all these headers?

Most likely yes, they should be in another folder, but I would need to
have a look. Could you push to some public Git repository the latest
status of your LLVM patch series, so that I can do a build, and see
what it looks like ?

> >> +LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795
> >> +LIBCLC_SITE = https://git.llvm.org/git/libclc
> >> +LIBCLC_SITE_METHOD = git  
> > I assume they don't have a stable release you could use ?  
> 
> There is release_38, but the last commit is from 2 years ago. Master
> has some recent activity.

OK. Then just add a comment above that says exactly this.

> >> +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, simply use
> >> +# HOSTCXX_NOCCACHE.  
> > Why not HOSTCXX ?

Did you notice this comment as well ? :-)

> >> +LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \  
> > Why are you using the version in HOST_DIR, and not the one in
> > STAGING_DIR ?  
> 
> I will check this.

OK. Thanks!

Thomas
Valentin Korenblit April 3, 2018, 4:26 p.m. UTC | #4
Hello Thomas,

On 03/04/2018 17:17, Thomas Petazzoni wrote:
> Hello,
>
> On Tue, 3 Apr 2018 14:27:16 +0200, Valentin Korenblit wrote:
>
>>>> 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.
>>> I don't see where your .mk file is doing this. And it wouldn't work
>>> because Buildroot removes $(TARGET_DIR)/usr/include entirely in its
>>> target-finalize step.
>>>
>>> When you say "manually", do you mean that you have to
>>> copy /usr/include/clc from your build machine to your target once the
>>> target has booted ? If that's the case, then we really have a problem
>>> here, the target should just work.
>> Exactly, I was doing it manually after booting. Mesa uses pkg-config to
>> get the includedir of libclc: https://pastebin.com/adzL8vd4
>>
>> Do you think it is ok to override configure.ac from Mesa to specify
>> another path? And in that case, where should I place all these headers?
> Most likely yes, they should be in another folder, but I would need to
> have a look. Could you push to some public Git repository the latest
> status of your LLVM patch series, so that I can do a build, and see
> what it looks like ?

I've just done it: https://github.com/vkorenblit/buildroot , branch llvm-v5.

>>>> +LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795
>>>> +LIBCLC_SITE = https://git.llvm.org/git/libclc
>>>> +LIBCLC_SITE_METHOD = git
>>> I assume they don't have a stable release you could use ?
>> There is release_38, but the last commit is from 2 years ago. Master
>> has some recent activity.
> OK. Then just add a comment above that says exactly this.

Done

>
>>>> +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, simply use
>>>> +# HOSTCXX_NOCCACHE.
>>> Why not HOSTCXX ?
> Did you notice this comment as well ? :-)

Changed it to HOSTCXX.

>
>>>> +LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \
>>> Why are you using the version in HOST_DIR, and not the one in
>>> STAGING_DIR ?
>> I will check this.

We need to use HOST_DIR because for compiling libclc a full installation of llvm/clang
is necessary. When STAGING_DIR is specified, the build stops as it cannot found llvm
binaries.

> OK. Thanks!
>
> Thomas

Best regards and thanks,

Valentin
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 47aa2dd82a..6bcafb6d2a 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1860,6 +1860,7 @@  F:	package/tstools/
 
 N:	Valentin Korenblit <valentin.korenblit@smile.fr>
 F:	package/clang/
+F:	package/libclc/
 F:	package/llvm/
 
 N:	Vanya Sergeev <vsergeev@gmail.com>
diff --git a/package/Config.in b/package/Config.in
index 4d32d749fb..bc2228ed17 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -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"
diff --git a/package/libclc/Config.in b/package/libclc/Config.in
new file mode 100644
index 0000000000..797f090bfc
--- /dev/null
+++ b/package/libclc/Config.in
@@ -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/
diff --git a/package/libclc/libclc.mk b/package/libclc/libclc.mk
new file mode 100644
index 0000000000..b8b4dca273
--- /dev/null
+++ b/package/libclc/libclc.mk
@@ -0,0 +1,38 @@ 
+################################################################################
+#
+# libclc
+#
+################################################################################
+
+LIBCLC_VERSION = 00236279a293b3737dee08c14f25923a889d2795
+LIBCLC_SITE = https://git.llvm.org/git/libclc
+LIBCLC_SITE_METHOD = git
+
+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, simply use
+# HOSTCXX_NOCCACHE.
+LIBCLC_CONF_OPTS = --with-llvm-config=$(HOST_DIR)/usr/bin/llvm-config \
+	--prefix="/usr" \
+	--pkgconfigdir="/usr/lib/pkgconfig" \
+	--with-cxx-compiler='$(HOSTCXX_NOCCACHE)'
+
+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))