diff mbox

Fwd: [RFC][gomp4] Offloading patches (2/3): Add tables generation

Message ID 53AD1E09.4010803@codesourcery.com
State New
Headers show

Commit Message

Bernd Schmidt June 27, 2014, 7:32 a.m. UTC
On 06/19/2014 12:19 PM, Ilya Verbin wrote:
> On 18 Jun 16:22, Bernd Schmidt wrote:
>> What I think you need to do is
>> For the first compiler:
>> --enable-as-accelerator-for=x86_64-pc-linux-gnu
>> --target=x86_64-intelmic-linux-gnu --prefix=/somewhere
>>
>> No --enable-accelerator options at all. This should work, if it
>> doesn't let me know what you find in /somewhere after installation
>> for both compilers.
>
> It doesn't work without --enable-accelerator:
>
> --enable-as-accelerator-for requires --enable-accelerator
> make[1]: *** [configure-gcc] Error 1

Sorry for the delayed reply, I was travelling. There seem to be some 
thinkos in the configure script and Makefile; can you try the following 
(don't forget to regenerate configure)? It seems to work for ptx (with 
some additional changes to allow ptx builds without --enable-accelerator).


Bernd

Comments

Ilya Verbin July 7, 2014, 2:50 p.m. UTC | #1
On 27 Jun 09:32, Bernd Schmidt wrote:
> Sorry for the delayed reply, I was travelling. There seem to be some
> thinkos in the configure script and Makefile; can you try the
> following (don't forget to regenerate configure)? It seems to work
> for ptx (with some additional changes to allow ptx builds without
> --enable-accelerator).

Thank you for you patch.

1) I tried to build accel compiler as a native x86_64-intelmic-linux-gnu compiler.  Then I installed host's x86_64-pc-linux-gnu into the same prefix.
In this case the are no collisions between the executables (cc1, etc.), but lib64 is common to both.  So libgomp.so from the host compiler overwrites libgomp.so from the accel compiler, but they need to be different.

2) Or should I build accel compiler as a cross from x86_64-pc-linux-gnu to x86_64-intelmic-linux-gnu?  Will it help to distinguish the libs?
Such a cross build will require additional changes to config files, since currently it can't find some of the binutils (--with-ar=/usr/bin/ar didn't help):
/bin/sh: line 7: x86_64-intelmic-linux-gnu-ar: command not found
make[2]: *** [libgcc.a] Error 127

Thanks,
  -- Ilya
Bernd Schmidt July 7, 2014, 3:03 p.m. UTC | #2
On 07/07/2014 04:50 PM, Ilya Verbin wrote:
> 2) Or should I build accel compiler as a cross from
> x86_64-pc-linux-gnu to x86_64-intelmic-linux-gnu?

Yes, that's the general idea.

> Will it help to distinguish the libs?

Is libgomp the only problematic one? (Does the accel compiler even need 
one?) It seems to be installed in /usr/lib rather than in a gcc-specific 
directory, which is a little surprising to me. It may be necessary to 
give the accel compiler a different sysroot to avoid library clashes.


Bernd
Jakub Jelinek July 7, 2014, 3:14 p.m. UTC | #3
On Mon, Jul 07, 2014 at 05:03:07PM +0200, Bernd Schmidt wrote:
> On 07/07/2014 04:50 PM, Ilya Verbin wrote:
> >2) Or should I build accel compiler as a cross from
> >x86_64-pc-linux-gnu to x86_64-intelmic-linux-gnu?
> 
> Yes, that's the general idea.
> 
> >Will it help to distinguish the libs?
> 
> Is libgomp the only problematic one? (Does the accel compiler even need
> one?) It seems to be installed in /usr/lib rather than in a gcc-specific
> directory, which is a little surprising to me. It may be necessary to give
> the accel compiler a different sysroot to avoid library clashes.

We need a libgomp for the offload targets to be different from the host
libgomp even on targets like mic, because there are various omp_* functions
that should behave differently.  Or the host libgomp needs to have a way how
to query whether it is invoked as offloading target library.
At least omp_is_default_device should return 0 when invoked inside of the
offloaded program (but, note that e.g. sshing into Intel MIC and running
there a program linked against -lgomp should return 1, because in that
case the MIC is the host device).
Other than that single function, I think on MIC/HSAIL that is the only thing
that needs to change, for PTX where you supposedly want to support more than
one team it is also the omp_get_num_teams and omp_get_team_num functions.

And yes, you need libgomp for the offloading targets, because at least in
OpenMP you can call lots of omp_* functions in the target regions, and can
use most of the #pragma omp * directives that actually need to have runtime
support too.  For offloading targets where you right now can't link stuff
I'm afraid you'll need to inline the parts of libgomp compiled for the PTX
(or HSAIL) targets manually during compilation (but what do you do for math
library functions, C functions etc.)?

	Jakub
Jakub Jelinek July 7, 2014, 3:22 p.m. UTC | #4
On Mon, Jul 07, 2014 at 05:14:27PM +0200, Jakub Jelinek wrote:
> We need a libgomp for the offload targets to be different from the host
> libgomp even on targets like mic, because there are various omp_* functions
> that should behave differently.  Or the host libgomp needs to have a way how
> to query whether it is invoked as offloading target library.
> At least omp_is_default_device should return 0 when invoked inside of the
> offloaded program (but, note that e.g. sshing into Intel MIC and running
> there a program linked against -lgomp should return 1, because in that
> case the MIC is the host device).
> Other than that single function, I think on MIC/HSAIL that is the only thing
> that needs to change, for PTX where you supposedly want to support more than
> one team it is also the omp_get_num_teams and omp_get_team_num functions.

E.g. to use the same libgomp.so the solution could be for mkoffload to add
omp_is_default_device and omp_is_default_device_ functions to the binary,
where it will therefore override the symbol from libgomp.so.

	Jakub
Ilya Verbin July 10, 2014, 6:24 p.m. UTC | #5
On 07 Jul 17:03, Bernd Schmidt wrote:
> Is libgomp the only problematic one? (Does the accel compiler even
> need one?) It seems to be installed in /usr/lib rather than in a
> gcc-specific directory, which is a little surprising to me. It may
> be necessary to give the accel compiler a different sysroot to avoid
> library clashes.

In the MIC case, not only libgomp is the problematic one.  Since, in general,
all libraries can be compiled for the MIC target, which can have an instruction
set that differs from the host's.

When mkoffload runs the accel compiler, it sets the LIBRARY_PATH env var,
telling where to find the libraries.  So, the question is how to specify this
installation directory for the accel's libraries during the configuration?
I tried the --libdir option for configure, but it affects only 'lib', but doesn't
affect 'lib64', because the path to 64 bit libs is determined in configure by
executing `$CC -print-multi-os-directory`, which returns "../lib64".

Probably I should somehow modify the spec string, so that under
ifdef ACCEL_COMPILER the multilib_os_dir will contain "../lib64/gcc/triplet",
instead of "../lib64"?

Thanks,
  -- Ilya
Bernd Schmidt July 10, 2014, 6:26 p.m. UTC | #6
On 07/10/2014 08:24 PM, Ilya Verbin wrote:
> On 07 Jul 17:03, Bernd Schmidt wrote:
>> Is libgomp the only problematic one? (Does the accel compiler even
>> need one?) It seems to be installed in /usr/lib rather than in a
>> gcc-specific directory, which is a little surprising to me. It may
>> be necessary to give the accel compiler a different sysroot to avoid
>> library clashes.
>
> In the MIC case, not only libgomp is the problematic one.  Since, in general,
> all libraries can be compiled for the MIC target, which can have an instruction
> set that differs from the host's.
>
> When mkoffload runs the accel compiler, it sets the LIBRARY_PATH env var,
> telling where to find the libraries.  So, the question is how to specify this
> installation directory for the accel's libraries during the configuration?
> I tried the --libdir option for configure, but it affects only 'lib', but doesn't
> affect 'lib64', because the path to 64 bit libs is determined in configure by
> executing `$CC -print-multi-os-directory`, which returns "../lib64".
>
> Probably I should somehow modify the spec string, so that under
> ifdef ACCEL_COMPILER the multilib_os_dir will contain "../lib64/gcc/triplet",
> instead of "../lib64"?

I suspect you'll need to specify a --with-sysroot when building the mic 
toolchain. That'll contain all the pieces required for that toolchain, 
separate from whatever is installed for the host.


Bernd
diff mbox

Patch

Index: configure.ac
===================================================================
--- configure.ac	(revision 435407)
+++ configure.ac	(working copy)
@@ -905,15 +905,12 @@  AC_SUBST(enable_accelerator)
 AC_ARG_ENABLE(as-accelerator-for,
 [AS_HELP_STRING([--enable-as-accelerator-for], [build compiler as accelerator target for given host])],
 [
-  if test $enable_accelerator = no; then
-    echo "--enable-as-accelerator-for requires --enable-accelerator"
-    exit 1;
-  fi
   AC_DEFINE(ACCEL_COMPILER, 1,
    [Define if this compiler should be built and used as the target
     device compiler for OpenACC.])
   enable_as_accelerator=yes
-  tool_prefix=${enable_as_accelerator_for}-accel-${enable_accelerator}
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
   accel_dir_suffix=/accel/${target_noncanonical}
   real_target_noncanonical=${enable_as_accelerator_for}
   ALL_ACCEL=all-accel
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 435407)
+++ Makefile.in	(working copy)
@@ -69,7 +69,6 @@  program_transform_name := @program_trans
 
 # Normally identical to target_noncanonical, except for compilers built
 # as accelerator targets.
-tool_prefix = @tool_prefix@
 accel_dir_suffix = @accel_dir_suffix@
 
 # Directory where sources are, from where we are.
@@ -777,7 +776,7 @@  BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir)
 
 # Actual name to use when installing a native compiler.
 GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
-GCC_TARGET_INSTALL_NAME := $(tool_prefix)-$(shell echo gcc|sed '$(program_transform_name)')
+GCC_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcc|sed '$(program_transform_name)')
 CPP_INSTALL_NAME := $(shell echo cpp|sed '$(program_transform_name)')
 GCOV_INSTALL_NAME := $(shell echo gcov|sed '$(program_transform_name)')
 
@@ -3247,25 +3246,21 @@  install-common: native lang.install-comm
 # Install the driver program as $(target_noncanonical)-gcc,
 # $(target_noncanonical)-gcc-$(version), and also as gcc if native.
 install-driver: installdirs xgcc$(exeext)
-	-install_name=$(GCC_INSTALL_NAME); \
-	if test "@enable_as_accelerator@" = "yes" ; then \
-	  install_name=$(GCC_TARGET_INSTALL_NAME); \
-	fi; \
-	rm -f $(DESTDIR)$(bindir)/$${install_name}$(exeext); \
-	$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$${install_name}$(exeext)
+	-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
+	-$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
 	-if test "@enable_as_accelerator@" != "yes" ; then \
-	  if [ "$(GCC_INSTALL_NAME)" != "$(tool_prefix)-gcc-$(version)" ]; then \
-	    rm -f $(DESTDIR)$(bindir)/$(tool_prefix)-gcc-$(version)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(tool_prefix)-gcc-$(version)$(exeext) ); \
-	  fi; \
-	  if [ ! -f gcc-cross$(exeext) ] \
-	     && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
-	    rm -f $(DESTDIR)$(bindir)/$(tool_prefix)-gcc-tmp$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(tool_prefix)-gcc-tmp$(exeext) && \
-	      mv -f $(tool_prefix)-gcc-tmp$(exeext) $(GCC_TARGET_INSTALL_NAME)$(exeext) ); \
-	  fi; \
+	if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
+	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
+	  ( cd $(DESTDIR)$(bindir) && \
+	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
+	fi; \
+	if [ ! -f gcc-cross$(exeext) ] \
+	    && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
+	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(exeext); \
+	  ( cd $(DESTDIR)$(bindir) && \
+	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-tmp$(exeext) && \
+	    mv -f $(target_noncanonical)-gcc-tmp$(exeext) $(GCC_TARGET_INSTALL_NAME)$(exeext) ); \
+	fi; \
 	fi
 
 # Install the info files.