[committed] amdgcn: Pass -mstack-size through to runtime

Message ID 03830517-e578-4ee7-b652-e82e6b5a6614@codesourcery.com
State Repeat Merge
Headers
Series [committed] amdgcn: Pass -mstack-size through to runtime |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Andrew Stubbs Feb. 6, 2023, 5:22 p.m. UTC
  The -mstack-size option has been marked obsolete in favour of setting an 
environment variable at runtime ("GCN_STACK_SIZE"), but some testcases 
still need the option set or they have stack overflow. I could change 
them to use the envvar, but my testing setup uses remote execute which 
doesn't support that yet, and means I would skip my own tests (not ideal).

This patch causes the testcase to automatically set GCN_STACK_SIZE 
itself, in a hidden constructor (only if it's not already set), and 
therefore bypasses the problem. I'm leaving the documentation saying 
-mstack-size is obsolete because this fix only works for offload tests, 
and it's still not the preferred user solution.

Committed to mainline. I'll backport to OG12 shortly.

Andrew
amdgcn: Pass -mstack-size through to runtime

But only for the offload case.

gcc/ChangeLog:

	* config/gcn/mkoffload.cc (gcn_stack_size): New global variable.
	(process_asm): Create a constructor for GCN_STACK_SIZE.
	(main): Parse the -mstack-size option.
  

Comments

Tobias Burnus Feb. 7, 2023, 7:40 a.m. UTC | #1
On 06.02.23 18:22, Andrew Stubbs wrote:
> The -mstack-size option has been marked obsolete in favour of setting
> an environment variable at runtime ("GCN_STACK_SIZE"), [...] but my
> testing setup uses remote execute which doesn't support that yet, and
> means I would skip my own tests (not ideal).

Namely, the problem with remote testing is that DejaGNU's setenv does
not work. This is a reoccurring theme but still unsolved, cf.

https://lists.gnu.org/archive/html/dejagnu/2008-07/msg00000.html

https://lists.gnu.org/archive/html/dejagnu/2019-11/msg00000.html

Now, only someone needs to find the time to fix DejaGNU ...

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 9c262f974be..9493f89fec3 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -117,6 +117,8 @@  uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;  // Default GPU architecture.
 uint32_t elf_flags =
     (EF_AMDGPU_FEATURE_XNACK_ANY_V4 | EF_AMDGPU_FEATURE_SRAMECC_ANY_V4);
 
+static int gcn_stack_size = 0;  /* Zero means use default.  */
+
 /* Delete tempfiles.  */
 
 void
@@ -662,6 +664,18 @@  process_asm (FILE *in, FILE *out, FILE *cfile)
     }
   fprintf (cfile, "\n};\n\n");
 
+  /* Set the stack size if the user configured a value.  */
+  if (gcn_stack_size)
+    fprintf (cfile,
+	     "static __attribute__((constructor))\n"
+	     "void configure_stack_size (void)\n"
+	     "{\n"
+	     "  const char *val = getenv (\"GCN_STACK_SIZE\");\n"
+	     "  if (!val || val[0] == '\\0')\n"
+	     "    setenv (\"GCN_STACK_SIZE\", \"%d\", true);\n"
+	     "}\n\n",
+	     gcn_stack_size);
+
   obstack_free (&fns_os, NULL);
   for (i = 0; i < dims_count; i++)
     free (dims[i].name);
@@ -920,6 +934,10 @@  main (int argc, char **argv)
 	elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX908;
       else if (strcmp (argv[i], "-march=gfx90a") == 0)
 	elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX90a;
+#define STR "-mstack-size="
+      else if (startswith (argv[i], STR))
+	gcn_stack_size = atoi (argv[i] + strlen (STR));
+#undef STR
     }
 
   if (!(fopenacc ^ fopenmp))