[gcn,offloading] Only supported in 64-bit configurations (was: [PATCH 7/7 libgomp,amdgcn] GCN Libgomp Plugin)

Message ID 87im7ziaxi.fsf@euler.schwinge.homeip.net
State New
Headers show
Series
  • [gcn,offloading] Only supported in 64-bit configurations (was: [PATCH 7/7 libgomp,amdgcn] GCN Libgomp Plugin)
Related show

Commit Message

Thomas Schwinge Jan. 14, 2021, 7:19 p.m.
Hi!

On 2019-11-12T13:29:16+0000, Andrew Stubbs <ams@codesourcery.com> wrote:
> This patch contributes the GCN libgomp plugin, with the various

> configure and make bits to go with it.


> --- a/libgomp/plugin/configfrag.ac

> +++ b/libgomp/plugin/configfrag.ac


> +      amdgcn*)

> +     case "${target}" in

> +       x86_64-*-*)

> +         case " ${CC} ${CFLAGS} " in

> +           *" -m32 "*)

> +             PLUGIN_GCN=0


That means, for good reasons, the GCN libgomp plugin is only built in
64-bit configurations.

However, in a (standard) bi-arch x86_64-pc-linux-gnu '-m64'/'-m32' build,
the compiler will still attempt 32-bit GCN offloading code generation,
which will often fail horribly (several classes of ICEs), is untested,
and not intended to be supported, as Andrew confirmed to me months ago.
So, we shouldn't try to do that; similar to nvptx offloading, see PR65099
"nvptx offloading: hard-coded 64-bit assumptions".

As obvious, I've just pushed "[gcn offloading] Only supported in 64-bit
configurations" to master branch in commit
505caa7295b93ecdec8ac9b31595eb34dbd48c9f, and cherry-picked into
releases/gcc-10 branch in commit
d697bf91a5457dfb06b4112b89dec2e43f472830, see attached.


Grüße
 Thomas


-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Patch

From d697bf91a5457dfb06b4112b89dec2e43f472830 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Tue, 28 Apr 2020 20:43:38 +0200
Subject: [PATCH] [gcn offloading] Only supported in 64-bit configurations

Similar to nvptx offloading, see PR65099 "nvptx offloading: hard-coded 64-bit
assumptions".

	gcc/
	* config/gcn/mkoffload.c (main): Create an offload image only in
	64-bit configurations.

(cherry picked from commit 505caa7295b93ecdec8ac9b31595eb34dbd48c9f)
---
 gcc/config/gcn/mkoffload.c | 142 +++++++++++++++++++------------------
 1 file changed, 74 insertions(+), 68 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 723da108b65..76947e19f79 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -628,11 +628,6 @@  main (int argc, char **argv)
       gcc_unreachable ();
     }
 
-  gcn_s1_name = make_temp_file (".mkoffload.1.s");
-  gcn_s2_name = make_temp_file (".mkoffload.2.s");
-  gcn_o_name = make_temp_file (".mkoffload.hsaco");
-  gcn_cfile_name = make_temp_file (".c");
-
   /* Build arguments for compiler pass.  */
   struct obstack cc_argv_obstack;
   obstack_init (&cc_argv_obstack);
@@ -661,77 +656,88 @@  main (int argc, char **argv)
 	}
     }
 
-  obstack_ptr_grow (&cc_argv_obstack, "-o");
-  obstack_ptr_grow (&cc_argv_obstack, gcn_s1_name);
-  obstack_ptr_grow (&cc_argv_obstack,
-		    concat ("-mlocal-symbol-id=", offloadsrc, NULL));
-  obstack_ptr_grow (&cc_argv_obstack, NULL);
-  const char **cc_argv = XOBFINISH (&cc_argv_obstack, const char **);
-
-  /* Build arguments for assemble/link pass.  */
-  struct obstack ld_argv_obstack;
-  obstack_init (&ld_argv_obstack);
-  obstack_ptr_grow (&ld_argv_obstack, driver);
-  obstack_ptr_grow (&ld_argv_obstack, gcn_s2_name);
-  obstack_ptr_grow (&ld_argv_obstack, "-lgomp");
-
-  for (int i = 1; i < argc; i++)
-    if (strncmp (argv[i], "-l", 2) == 0
-	|| strncmp (argv[i], "-Wl", 3) == 0
-	|| strncmp (argv[i], "-march", 6) == 0)
-      obstack_ptr_grow (&ld_argv_obstack, argv[i]);
-
-  obstack_ptr_grow (&ld_argv_obstack, "-o");
-  obstack_ptr_grow (&ld_argv_obstack, gcn_o_name);
-  obstack_ptr_grow (&ld_argv_obstack, NULL);
-  const char **ld_argv = XOBFINISH (&ld_argv_obstack, const char **);
-
-  /* Clean up unhelpful environment variables.  */
-  char *execpath = getenv ("GCC_EXEC_PREFIX");
-  char *cpath = getenv ("COMPILER_PATH");
-  char *lpath = getenv ("LIBRARY_PATH");
-  unsetenv ("GCC_EXEC_PREFIX");
-  unsetenv ("COMPILER_PATH");
-  unsetenv ("LIBRARY_PATH");
-
-  /* Run the compiler pass.  */
-  fork_execute (cc_argv[0], CONST_CAST (char **, cc_argv), true);
-  obstack_free (&cc_argv_obstack, NULL);
-
-  in = fopen (gcn_s1_name, "r");
-  if (!in)
-    fatal_error (input_location, "cannot open intermediate gcn asm file");
-
-  out = fopen (gcn_s2_name, "w");
-  if (!out)
-    fatal_error (input_location, "cannot open '%s'", gcn_s2_name);
+  gcn_cfile_name = make_temp_file (".c");
 
   cfile = fopen (gcn_cfile_name, "w");
   if (!cfile)
     fatal_error (input_location, "cannot open '%s'", gcn_cfile_name);
 
-  process_asm (in, out, cfile);
-
-  fclose (in);
-  fclose (out);
-
-  /* Run the assemble/link pass.  */
-  fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true);
-  obstack_free (&ld_argv_obstack, NULL);
-
-  in = fopen (gcn_o_name, "r");
-  if (!in)
-    fatal_error (input_location, "cannot open intermediate gcn obj file");
-
-  process_obj (in, cfile);
+  /* Currently, we only support offloading in 64-bit configurations.  */
+  if (offload_abi == OFFLOAD_ABI_LP64)
+    {
+      gcn_s1_name = make_temp_file (".mkoffload.1.s");
+      gcn_s2_name = make_temp_file (".mkoffload.2.s");
+      gcn_o_name = make_temp_file (".mkoffload.hsaco");
+
+      obstack_ptr_grow (&cc_argv_obstack, "-o");
+      obstack_ptr_grow (&cc_argv_obstack, gcn_s1_name);
+      obstack_ptr_grow (&cc_argv_obstack,
+			concat ("-mlocal-symbol-id=", offloadsrc, NULL));
+      obstack_ptr_grow (&cc_argv_obstack, NULL);
+      const char **cc_argv = XOBFINISH (&cc_argv_obstack, const char **);
+
+      /* Build arguments for assemble/link pass.  */
+      struct obstack ld_argv_obstack;
+      obstack_init (&ld_argv_obstack);
+      obstack_ptr_grow (&ld_argv_obstack, driver);
+      obstack_ptr_grow (&ld_argv_obstack, gcn_s2_name);
+      obstack_ptr_grow (&ld_argv_obstack, "-lgomp");
+
+      for (int i = 1; i < argc; i++)
+	if (strncmp (argv[i], "-l", 2) == 0
+	    || strncmp (argv[i], "-Wl", 3) == 0
+	    || strncmp (argv[i], "-march", 6) == 0)
+	  obstack_ptr_grow (&ld_argv_obstack, argv[i]);
+
+      obstack_ptr_grow (&ld_argv_obstack, "-o");
+      obstack_ptr_grow (&ld_argv_obstack, gcn_o_name);
+      obstack_ptr_grow (&ld_argv_obstack, NULL);
+      const char **ld_argv = XOBFINISH (&ld_argv_obstack, const char **);
+
+      /* Clean up unhelpful environment variables.  */
+      char *execpath = getenv ("GCC_EXEC_PREFIX");
+      char *cpath = getenv ("COMPILER_PATH");
+      char *lpath = getenv ("LIBRARY_PATH");
+      unsetenv ("GCC_EXEC_PREFIX");
+      unsetenv ("COMPILER_PATH");
+      unsetenv ("LIBRARY_PATH");
+
+      /* Run the compiler pass.  */
+      fork_execute (cc_argv[0], CONST_CAST (char **, cc_argv), true);
+      obstack_free (&cc_argv_obstack, NULL);
+
+      in = fopen (gcn_s1_name, "r");
+      if (!in)
+	fatal_error (input_location, "cannot open intermediate gcn asm file");
+
+      out = fopen (gcn_s2_name, "w");
+      if (!out)
+	fatal_error (input_location, "cannot open '%s'", gcn_s2_name);
+
+      process_asm (in, out, cfile);
+
+      fclose (in);
+      fclose (out);
+
+      /* Run the assemble/link pass.  */
+      fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true);
+      obstack_free (&ld_argv_obstack, NULL);
+
+      in = fopen (gcn_o_name, "r");
+      if (!in)
+	fatal_error (input_location, "cannot open intermediate gcn obj file");
+
+      process_obj (in, cfile);
+
+      fclose (in);
+
+      xputenv (concat ("GCC_EXEC_PREFIX=", execpath, NULL));
+      xputenv (concat ("COMPILER_PATH=", cpath, NULL));
+      xputenv (concat ("LIBRARY_PATH=", lpath, NULL));
+    }
 
-  fclose (in);
   fclose (cfile);
 
-  xputenv (concat ("GCC_EXEC_PREFIX=", execpath, NULL));
-  xputenv (concat ("COMPILER_PATH=", cpath, NULL));
-  xputenv (concat ("LIBRARY_PATH=", lpath, NULL));
-
   compile_native (gcn_cfile_name, outname, collect_gcc);
 
   return 0;
-- 
2.17.1