* [PATCH 1/2] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c'
@ 2022-12-19 20:40 Thomas Schwinge
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
2023-01-20 20:26 ` [og12] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
0 siblings, 2 replies; 6+ messages in thread
From: Thomas Schwinge @ 2022-12-19 20:40 UTC (permalink / raw)
To: tdevries, amonakov, gcc-patches; +Cc: Thomas Schwinge
... to document the status quo re implicit (via 'need_softstack_decl',
'need_unisimt_decl') and explicit declarations of '__nvptx_stacks',
'__nvptx_uni'.
gcc/testsuite/
* gcc.target/nvptx/softstack-decl-1.c: New.
* gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
---
.../gcc.target/nvptx/softstack-decl-1.c | 20 +++++++++++++
.../gcc.target/nvptx/uniform-simt-decl-1.c | 29 +++++++++++++++++++
2 files changed, 49 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
create mode 100644 gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
new file mode 100644
index 00000000000..c502eacc1b3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options {-save-temps -O0 -msoft-stack} } */
+
+extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
+
+void *f()
+{
+ /* Implicit '__nvptx_stacks' usage for frame; per 'init_softstack_frame':
+ { dg-final { scan-assembler-times {mov\.u64 %fstmp2, __nvptx_stacks;} 1 } }
+ */
+ void *stack_array[123];
+ /* Explicit '__nvptx_stacks' usage. */
+ stack_array[5] = __nvptx_stacks[0];
+ return stack_array[5];
+}
+
+/* The implicit (via 'need_softstack_decl') and explicit declarations of
+ '__nvptx_stacks' are both emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
+*/
diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
new file mode 100644
index 00000000000..486456ab243
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options {-save-temps -O0 -muniform-simt} } */
+
+extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
+
+enum memmodel
+{
+ MEMMODEL_RELAXED = 0,
+};
+
+int a = 0;
+
+int f (void)
+{
+ /* Explicit '__nvptx_uni' usage. */
+ __builtin_printf("%u\n", __nvptx_uni[0]);
+
+ /* Implicit '__nvptx_uni' usage; per 'nvptx_init_unisimt_predicate':
+ { dg-final { scan-assembler-times {mov\.u64 %r[0-9]+, __nvptx_uni;} 1 } }
+ */
+ int expected = 1;
+ return __atomic_compare_exchange_n (&a, &expected, 0, 0, MEMMODEL_RELAXED,
+ MEMMODEL_RELAXED);
+}
+
+/* The implicit (via 'need_unisimt_decl') and explicit declarations of
+ '__nvptx_uni' are both emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
+*/
--
2.25.1
-----------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni'
2022-12-19 20:40 [PATCH 1/2] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
@ 2022-12-19 20:40 ` Thomas Schwinge
2023-01-11 11:44 ` [PING] " Thomas Schwinge
` (2 more replies)
2023-01-20 20:26 ` [og12] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
1 sibling, 3 replies; 6+ messages in thread
From: Thomas Schwinge @ 2022-12-19 20:40 UTC (permalink / raw)
To: tdevries, amonakov, gcc-patches; +Cc: Thomas Schwinge
As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704):
ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"',
'ptxas' has an inscrutable error mode for duplicate declarations:
ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static'
ptxas fatal : Ptx assembly aborted due to errors
nvptx-as: ptxas returned 255 exit status
ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static'
ptxas fatal : Ptx assembly aborted due to errors
nvptx-as: ptxas returned 255 exit status
This is inscrutable, because (a) what is "cannot be resolved by a '.static'"
supposed to tell me (there is no '.static' in PTX?), and (b) why arent't
repeated declaration just verified to match the first, but otherwise a no-op
(like in other programming languages)?
gcc/
* config/nvptx/nvptx.cc (nvptx_assemble_undefined_decl): Notice
'__nvptx_stacks', '__nvptx_uni' declarations.
(nvptx_file_end): Don't emit duplicate declarations for those.
gcc/testsuite/
* gcc.target/nvptx/softstack-decl-1.c: Make 'dg-do assemble',
adjust.
* gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
---
gcc/config/nvptx/nvptx.cc | 14 ++++++++++++--
gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c | 8 ++++----
.../gcc.target/nvptx/uniform-simt-decl-1.c | 8 ++++----
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 8e49dd9c647..b93a253ab31 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -180,9 +180,11 @@ static GTY(()) tree global_lock_var;
/* True if any function references __nvptx_stacks. */
static bool need_softstack_decl;
+static bool have_softstack_decl;
/* True if any function references __nvptx_uni. */
static bool need_unisimt_decl;
+static bool have_unisimt_decl;
static int nvptx_mach_max_workers ();
@@ -2571,6 +2573,13 @@ nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl)
TREE_TYPE (decl), size ? tree_to_shwi (size) : 0,
DECL_ALIGN (decl), true);
nvptx_assemble_decl_end ();
+
+ static tree softstack_id = get_identifier ("__nvptx_stacks");
+ static tree unisimt_id = get_identifier ("__nvptx_uni");
+ if (DECL_NAME (decl) == softstack_id)
+ have_softstack_decl = true;
+ else if (DECL_NAME (decl) == unisimt_id)
+ have_unisimt_decl = true;
}
/* Output a pattern for a move instruction. */
@@ -6002,7 +6011,7 @@ nvptx_file_end (void)
write_shared_buffer (asm_out_file, gang_private_shared_sym,
gang_private_shared_align, gang_private_shared_size);
- if (need_softstack_decl)
+ if (need_softstack_decl && !have_softstack_decl)
{
write_var_marker (asm_out_file, false, true, "__nvptx_stacks");
/* 32 is the maximum number of warps in a block. Even though it's an
@@ -6011,7 +6020,8 @@ nvptx_file_end (void)
fprintf (asm_out_file, ".extern .shared .u%d __nvptx_stacks[32];\n",
POINTER_SIZE);
}
- if (need_unisimt_decl)
+
+ if (need_unisimt_decl && !have_unisimt_decl)
{
write_var_marker (asm_out_file, false, true, "__nvptx_uni");
fprintf (asm_out_file, ".extern .shared .u32 __nvptx_uni[32];\n");
diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
index c502eacc1b3..2415f6adb1f 100644
--- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
+++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do assemble } */
/* { dg-options {-save-temps -O0 -msoft-stack} } */
extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
@@ -14,7 +14,7 @@ void *f()
return stack_array[5];
}
-/* The implicit (via 'need_softstack_decl') and explicit declarations of
- '__nvptx_stacks' are both emitted:
- { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
+/* Of the implicit (via 'need_softstack_decl') and explicit declarations of
+ '__nvptx_stacks', only one is emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 1 } }
*/
diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
index 486456ab243..5a975bdb269 100644
--- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
+++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do assemble } */
/* { dg-options {-save-temps -O0 -muniform-simt} } */
extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
@@ -23,7 +23,7 @@ int f (void)
MEMMODEL_RELAXED);
}
-/* The implicit (via 'need_unisimt_decl') and explicit declarations of
- '__nvptx_uni' are both emitted:
- { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
+/* Of the implicit (via 'need_unisimt_decl') and explicit declarations of
+ '__nvptx_uni', only one is emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 1 } }
*/
--
2.25.1
-----------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PING] [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni'
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
@ 2023-01-11 11:44 ` Thomas Schwinge
2023-01-20 20:30 ` [og12] " Thomas Schwinge
2023-05-12 9:34 ` [PATCH 2/2] " Thomas Schwinge
2 siblings, 0 replies; 6+ messages in thread
From: Thomas Schwinge @ 2023-01-11 11:44 UTC (permalink / raw)
To: tdevries, amonakov, gcc-patches
Hi!
Ping.
Grüße
Thomas
On 2022-12-19T21:40:07+0100, I wrote:
> As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704):
> ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"',
> 'ptxas' has an inscrutable error mode for duplicate declarations:
>
> ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> This is inscrutable, because (a) what is "cannot be resolved by a '.static'"
> supposed to tell me (there is no '.static' in PTX?), and (b) why arent't
> repeated declaration just verified to match the first, but otherwise a no-op
> (like in other programming languages)?
>
> gcc/
> * config/nvptx/nvptx.cc (nvptx_assemble_undefined_decl): Notice
> '__nvptx_stacks', '__nvptx_uni' declarations.
> (nvptx_file_end): Don't emit duplicate declarations for those.
> gcc/testsuite/
> * gcc.target/nvptx/softstack-decl-1.c: Make 'dg-do assemble',
> adjust.
> * gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
> ---
> gcc/config/nvptx/nvptx.cc | 14 ++++++++++++--
> gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c | 8 ++++----
> .../gcc.target/nvptx/uniform-simt-decl-1.c | 8 ++++----
> 3 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
> index 8e49dd9c647..b93a253ab31 100644
> --- a/gcc/config/nvptx/nvptx.cc
> +++ b/gcc/config/nvptx/nvptx.cc
> @@ -180,9 +180,11 @@ static GTY(()) tree global_lock_var;
>
> /* True if any function references __nvptx_stacks. */
> static bool need_softstack_decl;
> +static bool have_softstack_decl;
>
> /* True if any function references __nvptx_uni. */
> static bool need_unisimt_decl;
> +static bool have_unisimt_decl;
>
> static int nvptx_mach_max_workers ();
>
> @@ -2571,6 +2573,13 @@ nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl)
> TREE_TYPE (decl), size ? tree_to_shwi (size) : 0,
> DECL_ALIGN (decl), true);
> nvptx_assemble_decl_end ();
> +
> + static tree softstack_id = get_identifier ("__nvptx_stacks");
> + static tree unisimt_id = get_identifier ("__nvptx_uni");
> + if (DECL_NAME (decl) == softstack_id)
> + have_softstack_decl = true;
> + else if (DECL_NAME (decl) == unisimt_id)
> + have_unisimt_decl = true;
> }
>
> /* Output a pattern for a move instruction. */
> @@ -6002,7 +6011,7 @@ nvptx_file_end (void)
> write_shared_buffer (asm_out_file, gang_private_shared_sym,
> gang_private_shared_align, gang_private_shared_size);
>
> - if (need_softstack_decl)
> + if (need_softstack_decl && !have_softstack_decl)
> {
> write_var_marker (asm_out_file, false, true, "__nvptx_stacks");
> /* 32 is the maximum number of warps in a block. Even though it's an
> @@ -6011,7 +6020,8 @@ nvptx_file_end (void)
> fprintf (asm_out_file, ".extern .shared .u%d __nvptx_stacks[32];\n",
> POINTER_SIZE);
> }
> - if (need_unisimt_decl)
> +
> + if (need_unisimt_decl && !have_unisimt_decl)
> {
> write_var_marker (asm_out_file, false, true, "__nvptx_uni");
> fprintf (asm_out_file, ".extern .shared .u32 __nvptx_uni[32];\n");
> diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> index c502eacc1b3..2415f6adb1f 100644
> --- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do assemble } */
> /* { dg-options {-save-temps -O0 -msoft-stack} } */
>
> extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
> @@ -14,7 +14,7 @@ void *f()
> return stack_array[5];
> }
>
> -/* The implicit (via 'need_softstack_decl') and explicit declarations of
> - '__nvptx_stacks' are both emitted:
> - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
> +/* Of the implicit (via 'need_softstack_decl') and explicit declarations of
> + '__nvptx_stacks', only one is emitted:
> + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 1 } }
> */
> diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> index 486456ab243..5a975bdb269 100644
> --- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do assemble } */
> /* { dg-options {-save-temps -O0 -muniform-simt} } */
>
> extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
> @@ -23,7 +23,7 @@ int f (void)
> MEMMODEL_RELAXED);
> }
>
> -/* The implicit (via 'need_unisimt_decl') and explicit declarations of
> - '__nvptx_uni' are both emitted:
> - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
> +/* Of the implicit (via 'need_unisimt_decl') and explicit declarations of
> + '__nvptx_uni', only one is emitted:
> + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 1 } }
> */
> --
> 2.25.1
-----------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [og12] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c'
2022-12-19 20:40 [PATCH 1/2] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
@ 2023-01-20 20:26 ` Thomas Schwinge
1 sibling, 0 replies; 6+ messages in thread
From: Thomas Schwinge @ 2023-01-20 20:26 UTC (permalink / raw)
To: gcc-patches; +Cc: tdevries, amonakov
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
Hi!
On 2022-12-19T21:40:06+0100, Thomas Schwinge <thomas@codesourcery.com> wrote:
> ... to document the status quo re implicit (via 'need_softstack_decl',
> 'need_unisimt_decl') and explicit declarations of '__nvptx_stacks',
> '__nvptx_uni'.
For now pushed to devel/omp/gcc-12 branch in
commit 703ebfdb483fdade316ceb003a0d57ca132a090b
"Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c'",
see attached.
Grüße
Thomas
-----------------
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-gcc.target-nvptx-softstack-decl-1.c-gcc.target-n.patch --]
[-- Type: text/x-diff, Size: 3363 bytes --]
From 703ebfdb483fdade316ceb003a0d57ca132a090b Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 19 Dec 2022 17:10:52 +0100
Subject: [PATCH] Add 'gcc.target/nvptx/softstack-decl-1.c',
'gcc.target/nvptx/uniform-simt-decl-1.c'
... to document the status quo re implicit (via 'need_softstack_decl',
'need_unisimt_decl') and explicit declarations of '__nvptx_stacks',
'__nvptx_uni'.
gcc/testsuite/
* gcc.target/nvptx/softstack-decl-1.c: New.
* gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
---
gcc/testsuite/ChangeLog.omp | 3 ++
.../gcc.target/nvptx/softstack-decl-1.c | 20 +++++++++++++
.../gcc.target/nvptx/uniform-simt-decl-1.c | 29 +++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
create mode 100644 gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 7339bf41482..5b3d9fe416b 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,5 +1,8 @@
2023-01-20 Thomas Schwinge <thomas@codesourcery.com>
+ * gcc.target/nvptx/softstack-decl-1.c: New.
+ * gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
+
* gcc.target/nvptx/nvptx.exp
(check_effective_target_default_ptx_isa_version_at_least_6_0):
New.
diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
new file mode 100644
index 00000000000..c502eacc1b3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options {-save-temps -O0 -msoft-stack} } */
+
+extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
+
+void *f()
+{
+ /* Implicit '__nvptx_stacks' usage for frame; per 'init_softstack_frame':
+ { dg-final { scan-assembler-times {mov\.u64 %fstmp2, __nvptx_stacks;} 1 } }
+ */
+ void *stack_array[123];
+ /* Explicit '__nvptx_stacks' usage. */
+ stack_array[5] = __nvptx_stacks[0];
+ return stack_array[5];
+}
+
+/* The implicit (via 'need_softstack_decl') and explicit declarations of
+ '__nvptx_stacks' are both emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
+*/
diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
new file mode 100644
index 00000000000..486456ab243
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options {-save-temps -O0 -muniform-simt} } */
+
+extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
+
+enum memmodel
+{
+ MEMMODEL_RELAXED = 0,
+};
+
+int a = 0;
+
+int f (void)
+{
+ /* Explicit '__nvptx_uni' usage. */
+ __builtin_printf("%u\n", __nvptx_uni[0]);
+
+ /* Implicit '__nvptx_uni' usage; per 'nvptx_init_unisimt_predicate':
+ { dg-final { scan-assembler-times {mov\.u64 %r[0-9]+, __nvptx_uni;} 1 } }
+ */
+ int expected = 1;
+ return __atomic_compare_exchange_n (&a, &expected, 0, 0, MEMMODEL_RELAXED,
+ MEMMODEL_RELAXED);
+}
+
+/* The implicit (via 'need_unisimt_decl') and explicit declarations of
+ '__nvptx_uni' are both emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
+*/
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [og12] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni'
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
2023-01-11 11:44 ` [PING] " Thomas Schwinge
@ 2023-01-20 20:30 ` Thomas Schwinge
2023-05-12 9:34 ` [PATCH 2/2] " Thomas Schwinge
2 siblings, 0 replies; 6+ messages in thread
From: Thomas Schwinge @ 2023-01-20 20:30 UTC (permalink / raw)
To: gcc-patches; +Cc: tdevries, amonakov
[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]
Hi!
On 2022-12-19T21:40:07+0100, Thomas Schwinge <thomas@codesourcery.com> wrote:
> As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704):
> ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"',
> 'ptxas' has an inscrutable error mode for duplicate declarations:
>
> ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> This is inscrutable, because (a) what is "cannot be resolved by a '.static'"
> supposed to tell me (there is no '.static' in PTX?), and (b) why arent't
> repeated declaration just verified to match the first, but otherwise a no-op
> (like in other programming languages)?
For now pushed to devel/omp/gcc-12 branch in
commit ea52f1ca16870e4228f8044588b1bf958d4723b0
"nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni'",
see attached.
Grüße
Thomas
-----------------
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-nvptx-Prevent-emitting-duplicate-declarations-for-__.patch --]
[-- Type: text/x-diff, Size: 6569 bytes --]
From ea52f1ca16870e4228f8044588b1bf958d4723b0 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 19 Dec 2022 17:19:19 +0100
Subject: [PATCH] nvptx: Prevent emitting duplicate declarations for
'__nvptx_stacks', '__nvptx_uni'
As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704):
ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"',
'ptxas' has an inscrutable error mode for duplicate declarations:
ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static'
ptxas fatal : Ptx assembly aborted due to errors
nvptx-as: ptxas returned 255 exit status
ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static'
ptxas fatal : Ptx assembly aborted due to errors
nvptx-as: ptxas returned 255 exit status
This is inscrutable, because (a) what is "cannot be resolved by a '.static'"
supposed to tell me (there is no '.static' in PTX?), and (b) why arent't
repeated declaration just verified to match the first, but otherwise a no-op
(like in other programming languages)?
gcc/
* config/nvptx/nvptx.cc (nvptx_assemble_undefined_decl): Notice
'__nvptx_stacks', '__nvptx_uni' declarations.
(nvptx_file_end): Don't emit duplicate declarations for those.
gcc/testsuite/
* gcc.target/nvptx/softstack-decl-1.c: Make 'dg-do assemble',
adjust.
* gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
---
gcc/ChangeLog.omp | 4 ++++
gcc/config/nvptx/nvptx.cc | 14 ++++++++++++--
gcc/testsuite/ChangeLog.omp | 4 ++++
gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c | 8 ++++----
.../gcc.target/nvptx/uniform-simt-decl-1.c | 8 ++++----
5 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 382cd5c80c2..127b450644b 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,5 +1,9 @@
2023-01-20 Thomas Schwinge <thomas@codesourcery.com>
+ * config/nvptx/nvptx.cc (nvptx_assemble_undefined_decl): Notice
+ '__nvptx_stacks', '__nvptx_uni' declarations.
+ (nvptx_file_end): Don't emit duplicate declarations for those.
+
* config/nvptx/nvptx.md (nvptx_uniform_warp_check): Make fit for
non-full-warp execution.
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index da735cf82ff..9c284ed5b01 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -181,9 +181,11 @@ static GTY(()) tree global_lock_var;
/* True if any function references __nvptx_stacks. */
static bool need_softstack_decl;
+static bool have_softstack_decl;
/* True if any function references __nvptx_uni. */
static bool need_unisimt_decl;
+static bool have_unisimt_decl;
static int nvptx_mach_max_workers ();
@@ -2572,6 +2574,13 @@ nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl)
TREE_TYPE (decl), size ? tree_to_shwi (size) : 0,
DECL_ALIGN (decl), true);
nvptx_assemble_decl_end ();
+
+ static tree softstack_id = get_identifier ("__nvptx_stacks");
+ static tree unisimt_id = get_identifier ("__nvptx_uni");
+ if (DECL_NAME (decl) == softstack_id)
+ have_softstack_decl = true;
+ else if (DECL_NAME (decl) == unisimt_id)
+ have_unisimt_decl = true;
}
/* Output a pattern for a move instruction. */
@@ -6052,7 +6061,7 @@ nvptx_file_end (void)
write_shared_buffer (asm_out_file, gang_private_shared_sym,
gang_private_shared_align, gang_private_shared_size);
- if (need_softstack_decl)
+ if (need_softstack_decl && !have_softstack_decl)
{
write_var_marker (asm_out_file, false, true, "__nvptx_stacks");
/* 32 is the maximum number of warps in a block. Even though it's an
@@ -6061,7 +6070,8 @@ nvptx_file_end (void)
fprintf (asm_out_file, ".extern .shared .u%d __nvptx_stacks[32];\n",
POINTER_SIZE);
}
- if (need_unisimt_decl)
+
+ if (need_unisimt_decl && !have_unisimt_decl)
{
write_var_marker (asm_out_file, false, true, "__nvptx_uni");
fprintf (asm_out_file, ".extern .shared .u32 __nvptx_uni[32];\n");
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 5b3d9fe416b..c942c34dc70 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,5 +1,9 @@
2023-01-20 Thomas Schwinge <thomas@codesourcery.com>
+ * gcc.target/nvptx/softstack-decl-1.c: Make 'dg-do assemble',
+ adjust.
+ * gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
+
* gcc.target/nvptx/softstack-decl-1.c: New.
* gcc.target/nvptx/uniform-simt-decl-1.c: Likewise.
diff --git a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
index c502eacc1b3..2415f6adb1f 100644
--- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
+++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do assemble } */
/* { dg-options {-save-temps -O0 -msoft-stack} } */
extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
@@ -14,7 +14,7 @@ void *f()
return stack_array[5];
}
-/* The implicit (via 'need_softstack_decl') and explicit declarations of
- '__nvptx_stacks' are both emitted:
- { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
+/* Of the implicit (via 'need_softstack_decl') and explicit declarations of
+ '__nvptx_stacks', only one is emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 1 } }
*/
diff --git a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
index 486456ab243..5a975bdb269 100644
--- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
+++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do assemble } */
/* { dg-options {-save-temps -O0 -muniform-simt} } */
extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
@@ -23,7 +23,7 @@ int f (void)
MEMMODEL_RELAXED);
}
-/* The implicit (via 'need_unisimt_decl') and explicit declarations of
- '__nvptx_uni' are both emitted:
- { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
+/* Of the implicit (via 'need_unisimt_decl') and explicit declarations of
+ '__nvptx_uni', only one is emitted:
+ { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 1 } }
*/
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni'
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
2023-01-11 11:44 ` [PING] " Thomas Schwinge
2023-01-20 20:30 ` [og12] " Thomas Schwinge
@ 2023-05-12 9:34 ` Thomas Schwinge
2 siblings, 0 replies; 6+ messages in thread
From: Thomas Schwinge @ 2023-05-12 9:34 UTC (permalink / raw)
To: tdevries, amonakov, gcc-patches
Hi!
On 2022-12-19T21:40:07+0100, Thomas Schwinge <thomas@codesourcery.com> wrote:
> As I have reported to Nvidia in 2022-12-01 'NVIDIA Incident Report (3891704):
> ptxas: Duplicate declaration error: "cannot be resolved by a '.static'"',
> 'ptxas' has an inscrutable error mode for duplicate declarations:
>
> ptxas softstack-decl-1.o, line 11; error : '.extern' variable '__nvptx_stacks' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> ptxas uniform-simt-decl-1.o, line 12; error : '.extern' variable '__nvptx_uni' cannot be resolved by a '.static'
> ptxas fatal : Ptx assembly aborted due to errors
> nvptx-as: ptxas returned 255 exit status
>
> This is inscrutable, because (a) what is "cannot be resolved by a '.static'"
> supposed to tell me (there is no '.static' in PTX?), and (b) why arent't
> repeated declaration just verified to match the first, but otherwise a no-op
> (like in other programming languages)?
Since my report, this had its 'Status changed [...] to "Closed - Fixed"'
(2023-01-28), with comment:
| [...] fix should be available in a later release.
| The compiler was modified to allow duplicate declaration of extern symbol. You will not see an error for this case.
| The documentation is also being changed to reflect this new change.
I've not yet verified the CUDA/'ptxas'-level fix, but I suggest to
retract my GCC-level proposed change:
> --- a/gcc/config/nvptx/nvptx.cc
> +++ b/gcc/config/nvptx/nvptx.cc
> +static bool have_softstack_decl;
> +static bool have_unisimt_decl;
> @@ -2571,6 +2573,13 @@ nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl)
> TREE_TYPE (decl), size ? tree_to_shwi (size) : 0,
> DECL_ALIGN (decl), true);
> nvptx_assemble_decl_end ();
> +
> + static tree softstack_id = get_identifier ("__nvptx_stacks");
> + static tree unisimt_id = get_identifier ("__nvptx_uni");
> + if (DECL_NAME (decl) == softstack_id)
> + have_softstack_decl = true;
> + else if (DECL_NAME (decl) == unisimt_id)
> + have_unisimt_decl = true;
> }
> @@ -6002,7 +6011,7 @@ nvptx_file_end (void)
> write_shared_buffer (asm_out_file, gang_private_shared_sym,
> gang_private_shared_align, gang_private_shared_size);
>
> - if (need_softstack_decl)
> + if (need_softstack_decl && !have_softstack_decl)
> {
> write_var_marker (asm_out_file, false, true, "__nvptx_stacks");
> /* 32 is the maximum number of warps in a block. Even though it's an
> @@ -6011,7 +6020,8 @@ nvptx_file_end (void)
> fprintf (asm_out_file, ".extern .shared .u%d __nvptx_stacks[32];\n",
> POINTER_SIZE);
> }
> - if (need_unisimt_decl)
> +
> + if (need_unisimt_decl && !have_unisimt_decl)
> {
> write_var_marker (asm_out_file, false, true, "__nvptx_uni");
> fprintf (asm_out_file, ".extern .shared .u32 __nvptx_uni[32];\n");
..., and suggest that we instead fix up duplicate declarations in the
nvptx-tools 'as', and once GCC depends on a nvptx-tools version with that
addressed, we still change the test cases from "compile" to "assemble" as
proposed:
> --- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do assemble } */
> /* { dg-options {-save-temps -O0 -msoft-stack} } */
>
> extern void *__nvptx_stacks[32] __attribute__((shared,nocommon));
> --- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do assemble } */
> /* { dg-options {-save-temps -O0 -muniform-simt} } */
>
> extern unsigned __nvptx_uni[32] __attribute__((shared,nocommon));
..., but (obviously) without the following changes:
> --- a/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/softstack-decl-1.c
> -/* The implicit (via 'need_softstack_decl') and explicit declarations of
> - '__nvptx_stacks' are both emitted:
> - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 2 } }
> +/* Of the implicit (via 'need_softstack_decl') and explicit declarations of
> + '__nvptx_stacks', only one is emitted:
> + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_stacks\[32\];} 1 } }
> --- a/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> +++ b/gcc/testsuite/gcc.target/nvptx/uniform-simt-decl-1.c
> -/* The implicit (via 'need_unisimt_decl') and explicit declarations of
> - '__nvptx_uni' are both emitted:
> - { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 2 } }
> +/* Of the implicit (via 'need_unisimt_decl') and explicit declarations of
> + '__nvptx_uni', only one is emitted:
> + { dg-final { scan-assembler-times {(?n)\.extern .* __nvptx_uni\[32\];} 1 } }
Grüße
Thomas
-----------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-12 9:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 20:40 [PATCH 1/2] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
2022-12-19 20:40 ` [PATCH 2/2] nvptx: Prevent emitting duplicate declarations for '__nvptx_stacks', '__nvptx_uni' Thomas Schwinge
2023-01-11 11:44 ` [PING] " Thomas Schwinge
2023-01-20 20:30 ` [og12] " Thomas Schwinge
2023-05-12 9:34 ` [PATCH 2/2] " Thomas Schwinge
2023-01-20 20:26 ` [og12] Add 'gcc.target/nvptx/softstack-decl-1.c', 'gcc.target/nvptx/uniform-simt-decl-1.c' Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).