* nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
[not found] ` <87o801see9.fsf@euler.schwinge.homeip.net>
@ 2022-06-15 21:18 ` Thomas Schwinge
2022-07-05 14:59 ` [PING] " Thomas Schwinge
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Thomas Schwinge @ 2022-06-15 21:18 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 4882 bytes --]
Hi Tom!
On 2022-05-13T16:20:14+0200, I wrote:
> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>> I've tested this using (recommended) driver 470.94 on boards:
>
>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>
>>> Do you use separate (nvptx-none offload target only?) builds for
>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>> multilib configuration?
>>
>> Neither, I'm using --target_board=unix/foffload= for that.
>
> ACK, I see. So these flags then only affect GCC/nvptx code generation
> for the actual user code (here: GCC libgomp test cases), but for the
> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
> the latter especially relevant for OpenMP), it uses PTX code from one of
> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>
> Meaning, one can't just use such a flag for "completely building code"
> for a specific configuration. Random example,
> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
> libraries aren't being built for '-march=sm_75' multilib,
> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
> which isn't '-march=sm_75'.
>
>
>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>> etc., I suppose?) Should we add a few representative configurations to
>>> be built by default? And/or, should we have a way to 'configure' per
>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>> few other targets?)? (I see there's also a new
>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>> which way: again, combinatorial explosion is a problem, of course...
>>
>> As far as I know, the gcc build doesn't finish when switching default to
>> higher than sm_35, so there's little point to go to a multilib setup at
>> this point. But once we fix that, we could reconsider, otherwise,
>> things are likely to regress again.
>
> As far as I remember, several issues have been fixed. Still waiting for
> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
> or something similar, but that PR104489 issue is being worked around by
> "Limit HFmode support to mexperimental", if I got that right.
>
> Now I'm not suggesting we should now enable all or any random GCC/nvptx
> multilibs, to get all these variants of GCC/nvptx target libraries built;
> especially also given that GCC/nvptx code generation currently doesn't
> make too much use of the new capabilities.
>
> However, we do have a specific request that a customer would like to be
> able to change at GCC 'configure' time the GCC/nvptx default multilib
> (including that being used for building corresponding GCC/nvptx target
> libraries).
>
> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
> GCC 'configure'-time '--with-multilib-list=[...]', or
> '--with-multilib-generator=[...]', and I suppose we could be doing
> something similar? But before starting implementing, I'd like your
> input, as you'll be the one to approve in the end. And/or, maybe you've
> already made up your own ideas about that?
So, instead of "random GCC/nvptx multilib configuration" (last
paragraph), I've come up with a way to implement our customer's request
(second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
I think I've implemented this in a way so that "random GCC/nvptx multilib
configuration" may eventually be implemented on top of that. For easy
review/testing I've split my changes into three commits, see attached
"nvptx: Make default '-misa=sm_30' explicit",
"nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
"nvptx: Allow '--with-arch' to override the default '-misa'".
To the best of my knowledge, the first two patches do not change any
user-visible behavior (I generally 'diff'ed target libraries, and
compared a good number of 'gcc -print-multi-directory [flags]'), and
likewise with the third patch, given implicit (default) or explicit
'--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
'-misa=sm_70' multilib variants are used for implicit (default) or
explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
are used for explicit lower '-misa'.
What do you think, OK to push to master branch?
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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-06-15 21:18 ` nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup) Thomas Schwinge
@ 2022-07-05 14:59 ` Thomas Schwinge
2022-07-13 8:42 ` [PING^2] " Thomas Schwinge
2024-12-06 9:01 ` 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
2024-12-06 9:07 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main logic (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
2 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2022-07-05 14:59 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 5077 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-06-15T23:18:10+0200, I wrote:
> Hi Tom!
>
> On 2022-05-13T16:20:14+0200, I wrote:
>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>
>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>
>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>> multilib configuration?
>>>
>>> Neither, I'm using --target_board=unix/foffload= for that.
>>
>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>> for the actual user code (here: GCC libgomp test cases), but for the
>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>> the latter especially relevant for OpenMP), it uses PTX code from one of
>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>
>> Meaning, one can't just use such a flag for "completely building code"
>> for a specific configuration. Random example,
>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>> libraries aren't being built for '-march=sm_75' multilib,
>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>> which isn't '-march=sm_75'.
>>
>>
>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>> etc., I suppose?) Should we add a few representative configurations to
>>>> be built by default? And/or, should we have a way to 'configure' per
>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>> few other targets?)? (I see there's also a new
>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>> which way: again, combinatorial explosion is a problem, of course...
>>>
>>> As far as I know, the gcc build doesn't finish when switching default to
>>> higher than sm_35, so there's little point to go to a multilib setup at
>>> this point. But once we fix that, we could reconsider, otherwise,
>>> things are likely to regress again.
>>
>> As far as I remember, several issues have been fixed. Still waiting for
>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>> or something similar, but that PR104489 issue is being worked around by
>> "Limit HFmode support to mexperimental", if I got that right.
>>
>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>> especially also given that GCC/nvptx code generation currently doesn't
>> make too much use of the new capabilities.
>>
>> However, we do have a specific request that a customer would like to be
>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>> (including that being used for building corresponding GCC/nvptx target
>> libraries).
>>
>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>> GCC 'configure'-time '--with-multilib-list=[...]', or
>> '--with-multilib-generator=[...]', and I suppose we could be doing
>> something similar? But before starting implementing, I'd like your
>> input, as you'll be the one to approve in the end. And/or, maybe you've
>> already made up your own ideas about that?
>
> So, instead of "random GCC/nvptx multilib configuration" (last
> paragraph), I've come up with a way to implement our customer's request
> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>
> I think I've implemented this in a way so that "random GCC/nvptx multilib
> configuration" may eventually be implemented on top of that. For easy
> review/testing I've split my changes into three commits, see attached
> "nvptx: Make default '-misa=sm_30' explicit",
> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
> "nvptx: Allow '--with-arch' to override the default '-misa'".
>
> To the best of my knowledge, the first two patches do not change any
> user-visible behavior (I generally 'diff'ed target libraries, and
> compared a good number of 'gcc -print-multi-directory [flags]'), and
> likewise with the third patch, given implicit (default) or explicit
> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
> '-misa=sm_70' multilib variants are used for implicit (default) or
> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
> are used for explicit lower '-misa'.
>
> What do you think, OK to push to master branch?
>
>
> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^2] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-07-05 14:59 ` [PING] " Thomas Schwinge
@ 2022-07-13 8:42 ` Thomas Schwinge
2022-07-20 12:46 ` [PING^3] " Thomas Schwinge
0 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2022-07-13 8:42 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 5265 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-07-05T16:59:23+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-06-15T23:18:10+0200, I wrote:
>> Hi Tom!
>>
>> On 2022-05-13T16:20:14+0200, I wrote:
>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>
>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>
>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>> multilib configuration?
>>>>
>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>
>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>> for the actual user code (here: GCC libgomp test cases), but for the
>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>
>>> Meaning, one can't just use such a flag for "completely building code"
>>> for a specific configuration. Random example,
>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>> libraries aren't being built for '-march=sm_75' multilib,
>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>> which isn't '-march=sm_75'.
>>>
>>>
>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>> few other targets?)? (I see there's also a new
>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>
>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>> things are likely to regress again.
>>>
>>> As far as I remember, several issues have been fixed. Still waiting for
>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>> or something similar, but that PR104489 issue is being worked around by
>>> "Limit HFmode support to mexperimental", if I got that right.
>>>
>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>> especially also given that GCC/nvptx code generation currently doesn't
>>> make too much use of the new capabilities.
>>>
>>> However, we do have a specific request that a customer would like to be
>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>> (including that being used for building corresponding GCC/nvptx target
>>> libraries).
>>>
>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>> something similar? But before starting implementing, I'd like your
>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>> already made up your own ideas about that?
>>
>> So, instead of "random GCC/nvptx multilib configuration" (last
>> paragraph), I've come up with a way to implement our customer's request
>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>
>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>> configuration" may eventually be implemented on top of that. For easy
>> review/testing I've split my changes into three commits, see attached
>> "nvptx: Make default '-misa=sm_30' explicit",
>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>
>> To the best of my knowledge, the first two patches do not change any
>> user-visible behavior (I generally 'diff'ed target libraries, and
>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>> likewise with the third patch, given implicit (default) or explicit
>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>> '-misa=sm_70' multilib variants are used for implicit (default) or
>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>> are used for explicit lower '-misa'.
>>
>> What do you think, OK to push to master branch?
>>
>>
>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^3] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-07-13 8:42 ` [PING^2] " Thomas Schwinge
@ 2022-07-20 12:46 ` Thomas Schwinge
2022-07-27 15:48 ` [PING^4] " Thomas Schwinge
0 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2022-07-20 12:46 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 5463 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-07-13T10:42:44+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-07-05T16:59:23+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-06-15T23:18:10+0200, I wrote:
>>> Hi Tom!
>>>
>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>
>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>
>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>> multilib configuration?
>>>>>
>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>
>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>
>>>> Meaning, one can't just use such a flag for "completely building code"
>>>> for a specific configuration. Random example,
>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>> which isn't '-march=sm_75'.
>>>>
>>>>
>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>> few other targets?)? (I see there's also a new
>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>
>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>> things are likely to regress again.
>>>>
>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>> or something similar, but that PR104489 issue is being worked around by
>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>
>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>> make too much use of the new capabilities.
>>>>
>>>> However, we do have a specific request that a customer would like to be
>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>> (including that being used for building corresponding GCC/nvptx target
>>>> libraries).
>>>>
>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>> something similar? But before starting implementing, I'd like your
>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>> already made up your own ideas about that?
>>>
>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>> paragraph), I've come up with a way to implement our customer's request
>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>
>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>> configuration" may eventually be implemented on top of that. For easy
>>> review/testing I've split my changes into three commits, see attached
>>> "nvptx: Make default '-misa=sm_30' explicit",
>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>
>>> To the best of my knowledge, the first two patches do not change any
>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>> likewise with the third patch, given implicit (default) or explicit
>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>> are used for explicit lower '-misa'.
>>>
>>> What do you think, OK to push to master branch?
>>>
>>>
>>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^4] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-07-20 12:46 ` [PING^3] " Thomas Schwinge
@ 2022-07-27 15:48 ` Thomas Schwinge
2022-08-06 19:20 ` [PING^5] " Thomas Schwinge
0 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2022-07-27 15:48 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 5671 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-07-20T14:46:03+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-07-13T10:42:44+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-07-05T16:59:23+0200, I wrote:
>>> Hi Tom!
>>>
>>> Ping.
>>>
>>>
>>> Grüße
>>> Thomas
>>>
>>>
>>> On 2022-06-15T23:18:10+0200, I wrote:
>>>> Hi Tom!
>>>>
>>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>>
>>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>>
>>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>>> multilib configuration?
>>>>>>
>>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>>
>>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>>
>>>>> Meaning, one can't just use such a flag for "completely building code"
>>>>> for a specific configuration. Random example,
>>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>>> which isn't '-march=sm_75'.
>>>>>
>>>>>
>>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>>> few other targets?)? (I see there's also a new
>>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>>
>>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>>> things are likely to regress again.
>>>>>
>>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>>> or something similar, but that PR104489 issue is being worked around by
>>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>>
>>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>>> make too much use of the new capabilities.
>>>>>
>>>>> However, we do have a specific request that a customer would like to be
>>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>>> (including that being used for building corresponding GCC/nvptx target
>>>>> libraries).
>>>>>
>>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>>> something similar? But before starting implementing, I'd like your
>>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>>> already made up your own ideas about that?
>>>>
>>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>>> paragraph), I've come up with a way to implement our customer's request
>>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>>
>>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>>> configuration" may eventually be implemented on top of that. For easy
>>>> review/testing I've split my changes into three commits, see attached
>>>> "nvptx: Make default '-misa=sm_30' explicit",
>>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>>
>>>> To the best of my knowledge, the first two patches do not change any
>>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>>> likewise with the third patch, given implicit (default) or explicit
>>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>>> are used for explicit lower '-misa'.
>>>>
>>>> What do you think, OK to push to master branch?
>>>>
>>>>
>>>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^5] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-07-27 15:48 ` [PING^4] " Thomas Schwinge
@ 2022-08-06 19:20 ` Thomas Schwinge
2022-08-16 15:13 ` [PING^6] " Thomas Schwinge
2022-09-18 8:53 ` [PING^5] " Tom de Vries
0 siblings, 2 replies; 16+ messages in thread
From: Thomas Schwinge @ 2022-08-06 19:20 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 5889 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-07-27T17:48:58+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-07-20T14:46:03+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-07-13T10:42:44+0200, I wrote:
>>> Hi Tom!
>>>
>>> Ping.
>>>
>>>
>>> Grüße
>>> Thomas
>>>
>>>
>>> On 2022-07-05T16:59:23+0200, I wrote:
>>>> Hi Tom!
>>>>
>>>> Ping.
>>>>
>>>>
>>>> Grüße
>>>> Thomas
>>>>
>>>>
>>>> On 2022-06-15T23:18:10+0200, I wrote:
>>>>> Hi Tom!
>>>>>
>>>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>>>
>>>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>>>
>>>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>>>> multilib configuration?
>>>>>>>
>>>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>>>
>>>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>>>
>>>>>> Meaning, one can't just use such a flag for "completely building code"
>>>>>> for a specific configuration. Random example,
>>>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>>>> which isn't '-march=sm_75'.
>>>>>>
>>>>>>
>>>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>>>> few other targets?)? (I see there's also a new
>>>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>>>
>>>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>>>> things are likely to regress again.
>>>>>>
>>>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>>>> or something similar, but that PR104489 issue is being worked around by
>>>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>>>
>>>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>>>> make too much use of the new capabilities.
>>>>>>
>>>>>> However, we do have a specific request that a customer would like to be
>>>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>>>> (including that being used for building corresponding GCC/nvptx target
>>>>>> libraries).
>>>>>>
>>>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>>>> something similar? But before starting implementing, I'd like your
>>>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>>>> already made up your own ideas about that?
>>>>>
>>>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>>>> paragraph), I've come up with a way to implement our customer's request
>>>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>>>
>>>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>>>> configuration" may eventually be implemented on top of that. For easy
>>>>> review/testing I've split my changes into three commits, see attached
>>>>> "nvptx: Make default '-misa=sm_30' explicit",
>>>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>>>
>>>>> To the best of my knowledge, the first two patches do not change any
>>>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>>>> likewise with the third patch, given implicit (default) or explicit
>>>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>>>> are used for explicit lower '-misa'.
>>>>>
>>>>> What do you think, OK to push to master branch?
>>>>>
>>>>>
>>>>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^6] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-08-06 19:20 ` [PING^5] " Thomas Schwinge
@ 2022-08-16 15:13 ` Thomas Schwinge
2022-08-30 13:44 ` [PING^7] " Thomas Schwinge
2022-09-18 8:53 ` [PING^5] " Tom de Vries
1 sibling, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2022-08-16 15:13 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 6117 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-08-06T21:20:38+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-07-27T17:48:58+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-07-20T14:46:03+0200, I wrote:
>>> Hi Tom!
>>>
>>> Ping.
>>>
>>>
>>> Grüße
>>> Thomas
>>>
>>>
>>> On 2022-07-13T10:42:44+0200, I wrote:
>>>> Hi Tom!
>>>>
>>>> Ping.
>>>>
>>>>
>>>> Grüße
>>>> Thomas
>>>>
>>>>
>>>> On 2022-07-05T16:59:23+0200, I wrote:
>>>>> Hi Tom!
>>>>>
>>>>> Ping.
>>>>>
>>>>>
>>>>> Grüße
>>>>> Thomas
>>>>>
>>>>>
>>>>> On 2022-06-15T23:18:10+0200, I wrote:
>>>>>> Hi Tom!
>>>>>>
>>>>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>>>>
>>>>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>>>>
>>>>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>>>>> multilib configuration?
>>>>>>>>
>>>>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>>>>
>>>>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>>>>
>>>>>>> Meaning, one can't just use such a flag for "completely building code"
>>>>>>> for a specific configuration. Random example,
>>>>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>>>>> which isn't '-march=sm_75'.
>>>>>>>
>>>>>>>
>>>>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>>>>> few other targets?)? (I see there's also a new
>>>>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>>>>
>>>>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>>>>> things are likely to regress again.
>>>>>>>
>>>>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>>>>> or something similar, but that PR104489 issue is being worked around by
>>>>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>>>>
>>>>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>>>>> make too much use of the new capabilities.
>>>>>>>
>>>>>>> However, we do have a specific request that a customer would like to be
>>>>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>>>>> (including that being used for building corresponding GCC/nvptx target
>>>>>>> libraries).
>>>>>>>
>>>>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>>>>> something similar? But before starting implementing, I'd like your
>>>>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>>>>> already made up your own ideas about that?
>>>>>>
>>>>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>>>>> paragraph), I've come up with a way to implement our customer's request
>>>>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>>>>
>>>>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>>>>> configuration" may eventually be implemented on top of that. For easy
>>>>>> review/testing I've split my changes into three commits, see attached
>>>>>> "nvptx: Make default '-misa=sm_30' explicit",
>>>>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>>>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>>>>
>>>>>> To the best of my knowledge, the first two patches do not change any
>>>>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>>>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>>>>> likewise with the third patch, given implicit (default) or explicit
>>>>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>>>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>>>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>>>>> are used for explicit lower '-misa'.
>>>>>>
>>>>>> What do you think, OK to push to master branch?
>>>>>>
>>>>>>
>>>>>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PING^7] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-08-16 15:13 ` [PING^6] " Thomas Schwinge
@ 2022-08-30 13:44 ` Thomas Schwinge
0 siblings, 0 replies; 16+ messages in thread
From: Thomas Schwinge @ 2022-08-30 13:44 UTC (permalink / raw)
To: Tom de Vries, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 6355 bytes --]
Hi Tom!
Ping.
Grüße
Thomas
On 2022-08-16T17:13:42+0200, I wrote:
> Hi Tom!
>
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-08-06T21:20:38+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-07-27T17:48:58+0200, I wrote:
>>> Hi Tom!
>>>
>>> Ping.
>>>
>>>
>>> Grüße
>>> Thomas
>>>
>>>
>>> On 2022-07-20T14:46:03+0200, I wrote:
>>>> Hi Tom!
>>>>
>>>> Ping.
>>>>
>>>>
>>>> Grüße
>>>> Thomas
>>>>
>>>>
>>>> On 2022-07-13T10:42:44+0200, I wrote:
>>>>> Hi Tom!
>>>>>
>>>>> Ping.
>>>>>
>>>>>
>>>>> Grüße
>>>>> Thomas
>>>>>
>>>>>
>>>>> On 2022-07-05T16:59:23+0200, I wrote:
>>>>>> Hi Tom!
>>>>>>
>>>>>> Ping.
>>>>>>
>>>>>>
>>>>>> Grüße
>>>>>> Thomas
>>>>>>
>>>>>>
>>>>>> On 2022-06-15T23:18:10+0200, I wrote:
>>>>>>> Hi Tom!
>>>>>>>
>>>>>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>>>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>>>>>
>>>>>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>>>>>
>>>>>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>>>>>> multilib configuration?
>>>>>>>>>
>>>>>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>>>>>
>>>>>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>>>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>>>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>>>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>>>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>>>>>
>>>>>>>> Meaning, one can't just use such a flag for "completely building code"
>>>>>>>> for a specific configuration. Random example,
>>>>>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>>>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>>>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>>>>>> which isn't '-march=sm_75'.
>>>>>>>>
>>>>>>>>
>>>>>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>>>>>> few other targets?)? (I see there's also a new
>>>>>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>>>>>
>>>>>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>>>>>> things are likely to regress again.
>>>>>>>>
>>>>>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>>>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>>>>>> or something similar, but that PR104489 issue is being worked around by
>>>>>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>>>>>
>>>>>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>>>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>>>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>>>>>> make too much use of the new capabilities.
>>>>>>>>
>>>>>>>> However, we do have a specific request that a customer would like to be
>>>>>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>>>>>> (including that being used for building corresponding GCC/nvptx target
>>>>>>>> libraries).
>>>>>>>>
>>>>>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>>>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>>>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>>>>>> something similar? But before starting implementing, I'd like your
>>>>>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>>>>>> already made up your own ideas about that?
>>>>>>>
>>>>>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>>>>>> paragraph), I've come up with a way to implement our customer's request
>>>>>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>>>>>
>>>>>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>>>>>> configuration" may eventually be implemented on top of that. For easy
>>>>>>> review/testing I've split my changes into three commits, see attached
>>>>>>> "nvptx: Make default '-misa=sm_30' explicit",
>>>>>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>>>>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>>>>>
>>>>>>> To the best of my knowledge, the first two patches do not change any
>>>>>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>>>>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>>>>>> likewise with the third patch, given implicit (default) or explicit
>>>>>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>>>>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>>>>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>>>>>> are used for explicit lower '-misa'.
>>>>>>>
>>>>>>> What do you think, OK to push to master branch?
>>>>>>>
>>>>>>>
>>>>>>> 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-Make-default-misa-sm_30-explicit.patch --]
[-- Type: text/x-diff, Size: 2757 bytes --]
From ae782b3d1db7a9b2dea744d2a718bec94ac57677 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 1/3] nvptx: Make default '-misa=sm_30' explicit
... primarily in preparation for later changes.
---
gcc/config.gcc | 16 ++++++++++++++++
gcc/config/nvptx/nvptx.cc | 4 ++++
gcc/config/nvptx/nvptx.h | 4 ++++
gcc/config/nvptx/nvptx.opt | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 16d304286d7..3b1bde78391 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4043,6 +4043,9 @@ if test x$with_arch = x ; then
mips*-*-vxworks)
with_arch=mips2
;;
+ nvptx-*)
+ with_arch=sm_30
+ ;;
esac
# Avoid overriding --with-arch-32 and --with-arch-64 values.
@@ -5436,6 +5439,19 @@ case "${target}" in
esac
;;
+ nvptx-*)
+ supported_defaults=arch
+ case $with_arch in
+ sm_30 )
+ # OK; default.
+ ;;
+ * )
+ echo "Unknown arch used in --with-arch=$with_arch" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+
powerpc*-*-* | rs6000-*-*)
supported_defaults="abi cpu cpu_32 cpu_64 float tune tune_32 tune_64 advance_toolchain"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index e4297e2d6c3..071759b9582 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -335,6 +335,10 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
+ /* Via nvptx 'OPTION_DEFAULT_SPECS', '-misa' always appears on the command
+ line. */
+ gcc_checking_assert (OPTION_SET_P (ptx_isa_option));
+
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index b184f1d0150..629d4a5d8bc 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -27,6 +27,10 @@
/* Run-time Target. */
+/* Use '--with-arch' for default '-misa'. */
+#define OPTION_DEFAULT_SPECS \
+ { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
+
/* Assembler supports '-v' option; handle similar to
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
#define ASM_SPEC "%{v}"
diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index c5a5668fce5..71d3b68510b 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -53,7 +53,7 @@ Target Mask(GOMP)
Generate code for OpenMP offloading: enables -msoft-stack and -muniform-simt.
misa=
-Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option)
Specify the PTX ISA target architecture to use.
march=
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-nvptx-Introduce-dummy-multilib-option-for-default-mi.patch --]
[-- Type: text/x-diff, Size: 1699 bytes --]
From 7889fb2d0ee1583a39ed1e2d4aadfd459edea9af Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 12:28:36 +0200
Subject: [PATCH 2/3] nvptx: Introduce dummy multilib option for default
'-misa=sm_30'
... primarily in preparation for later changes.
---
gcc/config.gcc | 1 +
gcc/config/nvptx/t-nvptx | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3b1bde78391..d492b7769fe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5441,6 +5441,7 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
+ TM_MULTILIB_CONFIG=$with_arch
case $with_arch in
sm_30 )
# OK; default.
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 2b68149ed7e..c797d57690f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -31,4 +31,22 @@ s-nvptx-gen-opt: $(srcdir)/config/nvptx/nvptx-sm.def \
tmp-nvptx-gen.opt $(srcdir)/config/nvptx/nvptx-gen.opt
$(STAMP) s-nvptx-gen-opt
-MULTILIB_OPTIONS = mgomp mptx=3.1
+
+# Multilib setup.
+
+MULTILIB_OPTIONS =
+MULTILIB_MATCHES =
+MULTILIB_EXCEPTIONS =
+
+MULTILIB_OPTIONS += mgomp
+
+multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
+multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
+# Add the default '-misa' as a multilib option:
+MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
+# ..., but don't handle it specially (remap to default):
+MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
+# ..., and don't actually build it:
+MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
+
+MULTILIB_OPTIONS += mptx=3.1
--
2.25.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-nvptx-Allow-with-arch-to-override-the-default-misa.patch --]
[-- Type: text/x-diff, Size: 6427 bytes --]
From 8343b7d0ed96cf5d45c12b36ea34a156229b8745 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 11 Jun 2022 19:37:10 +0200
Subject: [PATCH 3/3] nvptx: Allow '--with-arch' to override the default
'-misa'
---
gcc/config.gcc | 5 ++
gcc/config/nvptx/gen-multilib-matches.sh | 60 ++++++++++++++++++++++++
gcc/config/nvptx/t-nvptx | 21 +++++++--
gcc/doc/install.texi | 9 ++++
gcc/doc/invoke.texi | 4 +-
5 files changed, 93 insertions(+), 6 deletions(-)
create mode 100755 gcc/config/nvptx/gen-multilib-matches.sh
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d492b7769fe..8f51d333668 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5442,10 +5442,15 @@ case "${target}" in
nvptx-*)
supported_defaults=arch
TM_MULTILIB_CONFIG=$with_arch
+ #TODO 'sm_[...]' list per 'nvptx-sm.def'.
case $with_arch in
sm_30 )
# OK; default.
;;
+ sm_35 | sm_53 | sm_70 | sm_75 | sm_80 )
+ # OK, but we'd like 'sm_30', too.
+ TM_MULTILIB_CONFIG="$TM_MULTILIB_CONFIG sm_30"
+ ;;
* )
echo "Unknown arch used in --with-arch=$with_arch" 1>&2
exit 1
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
new file mode 100755
index 00000000000..9a5878e855b
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Print nvptx 'MULTILIB_MATCHES'
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+nvptx_sm_def="$1/nvptx-sm.def"
+multilib_options_isa_default=$2
+multilib_options_isa_list=$3
+
+sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
+
+# Every variant in 'sms' has to either be remapped to the default variant
+# ('.', which is always built), or does get built as non-default variant
+# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
+# variant that does get built.
+
+# The "lowest" variant has to be built.
+sm_next_lower=INVALID
+
+for sm in $sms; do
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
+ else
+ sm_map=$sm_next_lower
+ fi
+
+ if [ x"$sm_map" = x ]; then
+ sm_next_lower=$sm
+ else
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ echo ".=misa?sm_$sm"
+ else
+ echo "misa?sm_$sm_map=misa?sm_$sm"
+ fi
+
+ sm_next_lower=$sm_map
+ fi
+done
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index c797d57690f..9c5cbda0070 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -42,11 +42,22 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
-# Add the default '-misa' as a multilib option:
-MULTILIB_OPTIONS += misa=$(multilib_options_isa_default)
-# ..., but don't handle it specially (remap to default):
-MULTILIB_MATCHES += .=misa?$(multilib_options_isa_default)
-# ..., and don't actually build it:
+multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
+empty :=
+space := $(empty) $(empty)
+MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
+# ..., and remap '-misa' variants as appropriate:
+multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
+MULTILIB_MATCHES += $(multilib_matches)
+# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
MULTILIB_OPTIONS += mptx=3.1
+# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
+# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 %=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
+# ..., and special care has to be taken if '-mptx=3.1' is invalid for the
+# default variant:
+MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 45ef39da04e..7b4073bdafc 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4617,6 +4617,15 @@ the GCC sources.
Use the @option{--disable-sjlj-exceptions} and
@option{--enable-newlib-io-long-long} options when configuring.
+The @option{--with-arch} option may be specified to override the
+default value for the @option{-march} option, and to also build
+corresponding target libraries.
+The default is @option{--with-arch=sm_30}.
+
+For example, if @option{--with-arch=sm_70} is specified,
+@option{-march=sm_30} and @option{-march=sm_70} target libraries are
+built, and code generation defaults to @option{-march=sm_70}.
+
@html
<hr />
@end html
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e11b5bdb347..d96152b32a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -27549,7 +27549,9 @@ supported.
Generate code for the specified PTX ISA target architecture
(e.g.@: @samp{sm_35}). Valid architecture strings are @samp{sm_30},
@samp{sm_35}, @samp{sm_53}, @samp{sm_70}, @samp{sm_75} and
-@samp{sm_80}. The default target architecture is sm_30.
+@samp{sm_80}.
+The default depends on how the compiler has been configured, see
+@option{--with-arch}.
This option sets the value of the preprocessor macro
@code{__PTX_SM__}; for instance, for @samp{sm_35}, it has the value
--
2.25.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PING^5] nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)
2022-08-06 19:20 ` [PING^5] " Thomas Schwinge
2022-08-16 15:13 ` [PING^6] " Thomas Schwinge
@ 2022-09-18 8:53 ` Tom de Vries
1 sibling, 0 replies; 16+ messages in thread
From: Tom de Vries @ 2022-09-18 8:53 UTC (permalink / raw)
To: Thomas Schwinge, gcc-patches
On 8/6/22 21:20, Thomas Schwinge wrote:
> Hi Tom!
>
Hi Thomas,
thanks for doing this.
Series approved.
As I mentioned, I'm not completely happy with the multilib name, but I
don't think it makes sense to post-pone approval for this.
Thanks,
- Tom
> Ping.
>
>
> Grüße
> Thomas
>
>
> On 2022-07-27T17:48:58+0200, I wrote:
>> Hi Tom!
>>
>> Ping.
>>
>>
>> Grüße
>> Thomas
>>
>>
>> On 2022-07-20T14:46:03+0200, I wrote:
>>> Hi Tom!
>>>
>>> Ping.
>>>
>>>
>>> Grüße
>>> Thomas
>>>
>>>
>>> On 2022-07-13T10:42:44+0200, I wrote:
>>>> Hi Tom!
>>>>
>>>> Ping.
>>>>
>>>>
>>>> Grüße
>>>> Thomas
>>>>
>>>>
>>>> On 2022-07-05T16:59:23+0200, I wrote:
>>>>> Hi Tom!
>>>>>
>>>>> Ping.
>>>>>
>>>>>
>>>>> Grüße
>>>>> Thomas
>>>>>
>>>>>
>>>>> On 2022-06-15T23:18:10+0200, I wrote:
>>>>>> Hi Tom!
>>>>>>
>>>>>> On 2022-05-13T16:20:14+0200, I wrote:
>>>>>>> On 2022-02-04T13:09:29+0100, Tom de Vries via Gcc <gcc@gcc.gnu.org> wrote:
>>>>>>>> On 2/4/22 08:21, Thomas Schwinge wrote:
>>>>>>>>> On 2022-02-03T13:35:55+0000, "vries at gcc dot gnu.org via Gcc-bugs" <gcc-bugs@gcc.gnu.org> wrote:
>>>>>>>>>> I've tested this using (recommended) driver 470.94 on boards:
>>>>>>>
>>>>>>>>>> while iterating over dimensions { -mptx=3.1 , -mptx=6.3 } x { GOMP_NVPTX_JIT=-O0, <default> }.
>>>>>>>>>
>>>>>>>>> Do you use separate (nvptx-none offload target only?) builds for
>>>>>>>>> different '-mptx' variants (likewise: '-misa'), or have you hacked up the
>>>>>>>>> multilib configuration?
>>>>>>>>
>>>>>>>> Neither, I'm using --target_board=unix/foffload= for that.
>>>>>>>
>>>>>>> ACK, I see. So these flags then only affect GCC/nvptx code generation
>>>>>>> for the actual user code (here: GCC libgomp test cases), but for the
>>>>>>> GCC/nvptx target libraries (such as: libc, libm, libgfortran, libgomp --
>>>>>>> the latter especially relevant for OpenMP), it uses PTX code from one of
>>>>>>> the two "pre-compiled" GCC/nvptx multilibs: default or '-mptx=3.1'.
>>>>>>>
>>>>>>> Meaning, one can't just use such a flag for "completely building code"
>>>>>>> for a specific configuration. Random example,
>>>>>>> '-foffload-options=nvptx-none=-march=sm_75': as GCC/nvptx target
>>>>>>> libraries aren't being built for '-march=sm_75' multilib,
>>>>>>> '-foffload-options=nvptx-none=-march=sm_75' uses the default multilib,
>>>>>>> which isn't '-march=sm_75'.
>>>>>>>
>>>>>>>
>>>>>>>> ('gcc/config/nvptx/t-nvptx:MULTILIB_OPTIONS'
>>>>>>>>> etc., I suppose?) Should we add a few representative configurations to
>>>>>>>>> be built by default? And/or, should we have a way to 'configure' per
>>>>>>>>> user needs (I suppose: '--with-multilib-list=[...]', as supported for a
>>>>>>>>> few other targets?)? (I see there's also a new
>>>>>>>>> '--with-multilib-generator=[...]', haven't looked in detail.) No matter
>>>>>>>>> which way: again, combinatorial explosion is a problem, of course...
>>>>>>>>
>>>>>>>> As far as I know, the gcc build doesn't finish when switching default to
>>>>>>>> higher than sm_35, so there's little point to go to a multilib setup at
>>>>>>>> this point. But once we fix that, we could reconsider, otherwise,
>>>>>>>> things are likely to regress again.
>>>>>>>
>>>>>>> As far as I remember, several issues have been fixed. Still waiting for
>>>>>>> Roger's "middle-end: Support ABIs that pass FP values as wider integers"
>>>>>>> or something similar, but that PR104489 issue is being worked around by
>>>>>>> "Limit HFmode support to mexperimental", if I got that right.
>>>>>>>
>>>>>>> Now I'm not suggesting we should now enable all or any random GCC/nvptx
>>>>>>> multilibs, to get all these variants of GCC/nvptx target libraries built;
>>>>>>> especially also given that GCC/nvptx code generation currently doesn't
>>>>>>> make too much use of the new capabilities.
>>>>>>>
>>>>>>> However, we do have a specific request that a customer would like to be
>>>>>>> able to change at GCC 'configure' time the GCC/nvptx default multilib
>>>>>>> (including that being used for building corresponding GCC/nvptx target
>>>>>>> libraries).
>>>>>>>
>>>>>>> Per 'gcc/doc/install.texi', I do see that some GCC targets allow for
>>>>>>> GCC 'configure'-time '--with-multilib-list=[...]', or
>>>>>>> '--with-multilib-generator=[...]', and I suppose we could be doing
>>>>>>> something similar? But before starting implementing, I'd like your
>>>>>>> input, as you'll be the one to approve in the end. And/or, maybe you've
>>>>>>> already made up your own ideas about that?
>>>>>>
>>>>>> So, instead of "random GCC/nvptx multilib configuration" (last
>>>>>> paragraph), I've come up with a way to implement our customer's request
>>>>>> (second last paragraph): 'configure' GCC/nvptx '--with-arch=sm_70'.
>>>>>>
>>>>>> I think I've implemented this in a way so that "random GCC/nvptx multilib
>>>>>> configuration" may eventually be implemented on top of that. For easy
>>>>>> review/testing I've split my changes into three commits, see attached
>>>>>> "nvptx: Make default '-misa=sm_30' explicit",
>>>>>> "nvptx: Introduce dummy multilib option for default '-misa=sm_30'",
>>>>>> "nvptx: Allow '--with-arch' to override the default '-misa'".
>>>>>>
>>>>>> To the best of my knowledge, the first two patches do not change any
>>>>>> user-visible behavior (I generally 'diff'ed target libraries, and
>>>>>> compared a good number of 'gcc -print-multi-directory [flags]'), and
>>>>>> likewise with the third patch, given implicit (default) or explicit
>>>>>> '--with-arch=sm_30', and that with '--with-arch=sm_70', for example, the
>>>>>> '-misa=sm_70' multilib variants are used for implicit (default) or
>>>>>> explicit '-misa=sm_70' or higher, and the '-misa=sm_30' multilib variants
>>>>>> are used for explicit lower '-misa'.
>>>>>>
>>>>>> What do you think, OK to push to master branch?
>>>>>>
>>>>>>
>>>>>> 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] 16+ messages in thread
* 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))
2022-06-15 21:18 ` nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup) Thomas Schwinge
2022-07-05 14:59 ` [PING] " Thomas Schwinge
@ 2024-12-06 9:01 ` Thomas Schwinge
2024-12-06 9:32 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
2024-12-06 9:07 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main logic (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
2 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2024-12-06 9:01 UTC (permalink / raw)
To: gcc-patches; +Cc: Tom de Vries
[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]
Hi!
I recently learned that the exit status of the command invoked in a
'Makefile' via '$(shell [...])' effectively gets discarded (unless
explicitly checking the GNU Make 4.2+ '.SHELLSTATUS' variable or jumping
through other hoops). I was under the assumption that an error in a
'shell' function would cause 'make' to error out, similarly to how it
does in 'Makefile' rules...
I learned this The Hard Way here:
On 2022-06-15T23:18:10+0200, I wrote:
> --- a/gcc/config/nvptx/t-nvptx
> +++ b/gcc/config/nvptx/t-nvptx
> +multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
When recently working on changing nvptx multilib things, and for that
enhancing nvptx' 'gen-multilib-matches.sh', I made an error in there, and
then got confusing behavior in that I could still successfully 'make'
GCC, and my changes "mostly appeared to work as expected", but not quite.
This was due to garbage in 'MULTILIB_MATCHES', caused by a shell syntax
error in 'gen-multilib-matches.sh' -- which '$(shell [...])' swept under
the table.
Pushed to trunk branch commit 490443357668a87e3c322f218873a7649a2552df
"'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make'",
see attached.
Grüße
Thomas
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gcc-config-nvptx-t-nvptx-Don-t-use-the-shell-functio.patch --]
[-- Type: text/x-diff, Size: 3267 bytes --]
From 490443357668a87e3c322f218873a7649a2552df Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Mon, 2 Dec 2024 15:06:58 +0100
Subject: [PATCH] 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of
'make'
The exit status of the command invoked in a 'Makefile' via '$(shell [...])'
effectively gets discarded (unless explicitly checking the GNU Make 4.2+
'.SHELLSTATUS' variable or jumping through other hoops). In order to be able
to catch errors in what the 'shell' function invokes, let's make things
explicit: similar to how 'gcc/config/avr/t-avr' is doing with 't-multilib-avr',
for example.
gcc/
* config/nvptx/t-nvptx (multilib_matches): Don't use the 'shell'
function of 'make'.
* config/nvptx/gen-multilib-matches.sh: Adjust.
---
gcc/config/nvptx/gen-multilib-matches.sh | 9 +++++++--
gcc/config/nvptx/t-nvptx | 14 +++++++++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
index 44c758c3b1bf..a39baee5cd24 100755
--- a/gcc/config/nvptx/gen-multilib-matches.sh
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -33,6 +33,8 @@ sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
# variant that does get built.
+multilib_matches=
+
# The "lowest" variant has to be built.
sm_next_lower=INVALID
@@ -50,11 +52,14 @@ for sm in $sms; do
else
# Output format as required for 'MULTILIB_MATCHES'.
if [ x"$sm_map" = x. ]; then
- echo ".=misa?sm_$sm"
+ multilib_matches_sm=".=misa?sm_$sm"
else
- echo "misa?sm_$sm_map=misa?sm_$sm"
+ multilib_matches_sm="misa?sm_$sm_map=misa?sm_$sm"
fi
+ multilib_matches="$multilib_matches $multilib_matches_sm"
sm_next_lower=$sm_map
fi
done
+
+echo "multilib_matches := $multilib_matches"
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 9c5cbda00707..6c6a6329f0f8 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -43,12 +43,24 @@ MULTILIB_OPTIONS += mgomp
multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
+
+t-nvptx-gen-multilib-matches: $(srcdir)/config/nvptx/gen-multilib-matches.sh \
+ $(srcdir)/config/nvptx/t-nvptx \
+ Makefile \
+ $(srcdir)/config/nvptx/nvptx-sm.def
+ $(SHELL) $< \
+ $(dir $<) \
+ $(multilib_options_isa_default) \
+ '$(multilib_options_isa_list)' \
+ > $@
+
+include t-nvptx-gen-multilib-matches
+
# Add the requested '-misa' variants as a multilib option ('misa=VAR1/misa=VAR2/misa=VAR3' etc.):
empty :=
space := $(empty) $(empty)
MULTILIB_OPTIONS += $(subst $(space),/,$(multilib_options_misa_list))
# ..., and remap '-misa' variants as appropriate:
-multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
MULTILIB_MATCHES += $(multilib_matches)
# ..., and don't actually build what's the default '-misa':
MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
--
2.34.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* 'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main logic (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))
2022-06-15 21:18 ` nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup) Thomas Schwinge
2022-07-05 14:59 ` [PING] " Thomas Schwinge
2024-12-06 9:01 ` 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
@ 2024-12-06 9:07 ` Thomas Schwinge
2 siblings, 0 replies; 16+ messages in thread
From: Thomas Schwinge @ 2024-12-06 9:07 UTC (permalink / raw)
To: gcc-patches; +Cc: Tom de Vries
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]
Hi!
On 2022-06-15T23:18:10+0200, I wrote:
> --- /dev/null
> +++ b/gcc/config/nvptx/gen-multilib-matches.sh
> @@ -0,0 +1,60 @@
> +[...]
Pushed to trunk branch commit b352f89d81bb30dbeb406ff7e4d148e2fb640975
"'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main logic",
see attached.
Grüße
Thomas
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gcc-config-nvptx-gen-multilib-matches.sh-Encapsulate.patch --]
[-- Type: text/x-diff, Size: 3135 bytes --]
From b352f89d81bb30dbeb406ff7e4d148e2fb640975 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Mon, 2 Dec 2024 16:34:03 +0100
Subject: [PATCH] 'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main
logic
Refactoring for later extension. No change in behavior intended.
gcc/
* config/nvptx/gen-multilib-matches.sh: Encapsulate main logic.
---
gcc/config/nvptx/gen-multilib-matches.sh | 71 ++++++++++++++++--------
1 file changed, 47 insertions(+), 24 deletions(-)
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
index a39baee5cd24..e52d57130476 100755
--- a/gcc/config/nvptx/gen-multilib-matches.sh
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -23,8 +23,7 @@
set -e
nvptx_sm_def="$1/nvptx-sm.def"
-multilib_options_isa_default=$2
-multilib_options_isa_list=$3
+shift
sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
@@ -33,33 +32,57 @@ sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
# ('misa=sm_SM'; thus not remapped), or has to be remapped to the "next lower"
# variant that does get built.
-multilib_matches=
+print_multilib_matches() {
+ local sms
+ sms=${1?}
+ shift
+ local multilib_options_isa_default
+ multilib_options_isa_default=${1?}
+ shift
+ local multilib_options_isa_list
+ multilib_options_isa_list=${1?}
+ shift
+ [ $# = 0 ]
-# The "lowest" variant has to be built.
-sm_next_lower=INVALID
+ local multilib_matches
+ multilib_matches=
-for sm in $sms; do
- if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
- sm_map=.
- elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
- sm_map=
- else
- sm_map=$sm_next_lower
- fi
+ local sm_next_lower
+ unset sm_next_lower
- if [ x"$sm_map" = x ]; then
- sm_next_lower=$sm
- else
- # Output format as required for 'MULTILIB_MATCHES'.
- if [ x"$sm_map" = x. ]; then
- multilib_matches_sm=".=misa?sm_$sm"
+ local sm
+ for sm in $sms; do
+ local sm_map
+ unset sm_map
+ if [ x"sm_$sm" = x"$multilib_options_isa_default" ]; then
+ sm_map=.
+ elif expr " $multilib_options_isa_list " : ".* sm_$sm " > /dev/null; then
+ sm_map=
else
- multilib_matches_sm="misa?sm_$sm_map=misa?sm_$sm"
+ # Assert here that a "next lower" variant is available; the
+ # "lowest" variant always does get built.
+ sm_map=${sm_next_lower?}
fi
- multilib_matches="$multilib_matches $multilib_matches_sm"
- sm_next_lower=$sm_map
- fi
-done
+ if [ x"${sm_map?}" = x ]; then
+ sm_next_lower=$sm
+ else
+ local multilib_matches_sm
+ unset multilib_matches_sm
+ # Output format as required for 'MULTILIB_MATCHES'.
+ if [ x"$sm_map" = x. ]; then
+ multilib_matches_sm=".=misa?sm_$sm"
+ else
+ multilib_matches_sm="misa?sm_$sm_map=misa?sm_$sm"
+ fi
+ multilib_matches="$multilib_matches ${multilib_matches_sm?}"
+
+ sm_next_lower=$sm_map
+ fi
+ done
+
+ echo "$multilib_matches"
+}
+multilib_matches=$(print_multilib_matches "$sms" "$@")
echo "multilib_matches := $multilib_matches"
--
2.34.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)))
2024-12-06 9:01 ` 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
@ 2024-12-06 9:32 ` Thomas Schwinge
2024-12-06 9:34 ` Sam James
0 siblings, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2024-12-06 9:32 UTC (permalink / raw)
To: gcc-patches; +Cc: Tom de Vries
[-- Attachment #1: Type: text/plain, Size: 2770 bytes --]
Hi!
On 2024-12-06T10:01:22+0100, I wrote:
> I recently learned that the exit status of the command invoked in a
> 'Makefile' via '$(shell [...])' effectively gets discarded (unless
> explicitly checking the GNU Make 4.2+ '.SHELLSTATUS' variable or jumping
> through other hoops). I was under the assumption that an error in a
> 'shell' function would cause 'make' to error out, similarly to how it
> does in 'Makefile' rules...
>
> I learned this The Hard Way here:
>
> On 2022-06-15T23:18:10+0200, I wrote:
>> --- a/gcc/config/nvptx/t-nvptx
>> +++ b/gcc/config/nvptx/t-nvptx
>
>> +multilib_matches := $(shell $(srcdir)/config/nvptx/gen-multilib-matches.sh $(srcdir)/config/nvptx $(multilib_options_isa_default) "$(multilib_options_isa_list)")
>
> When recently working on changing nvptx multilib things, and for that
> enhancing nvptx' 'gen-multilib-matches.sh', I made an error in there, and
> then got confusing behavior in that I could still successfully 'make'
> GCC, and my changes "mostly appeared to work as expected", but not quite.
> This was due to garbage in 'MULTILIB_MATCHES', caused by a shell syntax
> error in 'gen-multilib-matches.sh' -- which '$(shell [...])' swept under
> the table.
>
> Pushed to trunk branch commit 490443357668a87e3c322f218873a7649a2552df
> "'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make'",
> see attached.
To further improve reliability of nvptx 'gen-multilib-matches.sh', in
<https://inbox.sourceware.org/875xornmp9.fsf@euler.schwinge.ddns.net>
"Re: [PATCH] v2: Run selftests for C++ as well as C", I recently
mentioned the idea of adding selftesting to this script and attaching a
new 's-selftest-nvptx_gen-multilib-matches' rule to the existing GCC
selftest framework rules. Instead, in a simpler way, let's just invoke
the 'gen-multilib-matches.sh --selftest' before actual use here:
> --- a/gcc/config/nvptx/t-nvptx
> +++ b/gcc/config/nvptx/t-nvptx
> @@ -43,12 +43,24 @@ MULTILIB_OPTIONS += mgomp
> multilib_options_isa_list := $(TM_MULTILIB_CONFIG)
> multilib_options_isa_default := $(word 1,$(multilib_options_isa_list))
> multilib_options_misa_list := $(addprefix misa=,$(multilib_options_isa_list))
> +
> +t-nvptx-gen-multilib-matches: $(srcdir)/config/nvptx/gen-multilib-matches.sh \
> + $(srcdir)/config/nvptx/t-nvptx \
> + Makefile \
> + $(srcdir)/config/nvptx/nvptx-sm.def
> + $(SHELL) $< \
> + $(dir $<) \
> + $(multilib_options_isa_default) \
> + '$(multilib_options_isa_list)' \
> + > $@
> +
> +include t-nvptx-gen-multilib-matches
Pushed to trunk branch commit ccd6ec23177f7a4ed69fabad8e79d5d4da419fb2
"'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest'", see
attached.
Grüße
Thomas
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gcc-config-nvptx-gen-multilib-matches.sh-Support-sel.patch --]
[-- Type: text/x-diff, Size: 5675 bytes --]
From ccd6ec23177f7a4ed69fabad8e79d5d4da419fb2 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Mon, 2 Dec 2024 16:50:16 +0100
Subject: [PATCH] 'gcc/config/nvptx/gen-multilib-matches.sh': Support
'--selftest'
..., and invoke that before actual use.
gcc/
* config/nvptx/gen-multilib-matches.sh: Support '--selftest'.
* config/nvptx/t-nvptx (t-nvptx-gen-multilib-matches:): Invoke it.
* config/nvptx/gen-multilib-matches-tests: New.
---
gcc/config/nvptx/gen-multilib-matches-tests | 77 +++++++++++++++++++
gcc/config/nvptx/gen-multilib-matches.sh | 82 ++++++++++++++++++++-
gcc/config/nvptx/t-nvptx | 2 +
3 files changed, 159 insertions(+), 2 deletions(-)
create mode 100644 gcc/config/nvptx/gen-multilib-matches-tests
diff --git a/gcc/config/nvptx/gen-multilib-matches-tests b/gcc/config/nvptx/gen-multilib-matches-tests
new file mode 100644
index 000000000000..c2775f268354
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches-tests
@@ -0,0 +1,77 @@
+# Test cases for 'gen-multilib-matches.sh'.
+
+# Blank lines and lines beginning with '#' are ignored.
+
+# 'BEGIN [name]': clear state, begin test [name].
+# 'SSMS 30 35 53': set 'sms' to '30 35 53'. Default: per 'nvptx-sm.def'.
+# 'SMOID sm_30': set 'multilib_options_isa_default' to 'sm_30'. Default: unset.
+# 'SMOIL sm_35 sm_30': set 'multilib_options_isa_list' to 'sm_35 sm_30'. Default: unset.
+# 'AEMM .=misa?sm_30': append '.=misa?sm_30' to expected "multilib matches". Default: unset.
+# 'CMMC': compute "multilib matches" per the current settings, and compare to the expected.
+
+
+BEGIN '--with-arch=sm_30'
+SMOID sm_30
+SMOIL sm_30
+AEMM .=misa?sm_30
+AEMM .=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_35'
+SMOID sm_35
+SMOIL sm_35 sm_30
+AEMM .=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_53'
+SMOID sm_53
+SMOIL sm_53 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_70'
+SMOID sm_70
+SMOIL sm_70 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_75'
+SMOID sm_75
+SMOIL sm_75 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM misa?sm_30=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_80'
+SMOID sm_80
+SMOIL sm_80 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM misa?sm_30=misa?sm_70
+AEMM misa?sm_30=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh b/gcc/config/nvptx/gen-multilib-matches.sh
index 09761a9e6907..f6f2ed079f68 100755
--- a/gcc/config/nvptx/gen-multilib-matches.sh
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -27,6 +27,7 @@ nvptx_dir=$(dirname "$0")
nvptx_sm_def="$nvptx_dir/nvptx-sm.def"
+gen_multilib_matches_tests="$nvptx_dir/gen-multilib-matches-tests"
sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
@@ -88,5 +89,82 @@ print_multilib_matches() {
echo "$multilib_matches"
}
-multilib_matches=$(print_multilib_matches "$sms" "$@")
-echo "multilib_matches := $multilib_matches"
+
+selftest() {
+ [ $# = 0 ]
+
+ local sms_default
+ sms_default=$sms
+
+ local name
+ unset name
+ local sms
+ unset sms
+ local multilib_options_isa_default
+ unset multilib_options_isa_default
+ local multilib_options_isa_list
+ unset multilib_options_isa_list
+ local multilib_matches_expected
+ unset multilib_matches_expected
+
+ local line
+ line=0
+ local f1 f2
+ unset f1 f2
+ while read -r f1 f2; do
+ line=$((line + 1))
+ case "$f1 $f2" in
+ ' ' | '#'* )
+ :
+ ;;
+ 'BEGIN '* )
+ name=$f2
+ sms=$sms_default
+ unset multilib_options_isa_default
+ unset multilib_options_isa_list
+ unset multilib_matches_expected
+ ;;
+ 'SSMS '* )
+ sms=$f2
+ ;;
+ 'SMOID '* )
+ multilib_options_isa_default=$f2
+ ;;
+ 'SMOIL '* )
+ multilib_options_isa_list=$f2
+ ;;
+ 'AEMM '* )
+ multilib_matches_expected="$multilib_matches_expected $f2"
+ ;;
+ 'CMMC ' )
+ local multilib_matches
+ multilib_matches=$(print_multilib_matches "${sms?}" "${multilib_options_isa_default?}" "${multilib_options_isa_list?}")
+ if [ "$multilib_matches" = "$multilib_matches_expected" ]; then
+ echo >&2 "$0": selftest PASS "${name?}" at "$gen_multilib_matches_tests:$line"
+ else
+ echo >&2 "$0": selftest FAIL "${name?}" at "$gen_multilib_matches_tests:$line"
+ echo >&2 expected:"$multilib_matches_expected"
+ echo >&2 actual:"$multilib_matches"
+ exit 1
+ fi
+ ;;
+ * )
+ echo >&2 "$0": selftest ERROR at "$gen_multilib_matches_tests:$line"
+ echo >&2 invalid directive: "$f1 $f2"
+ exit 1
+ ;;
+ esac
+ done < "$gen_multilib_matches_tests"
+}
+
+
+case "${1?}" in
+ --selftest )
+ shift
+ selftest "$@"
+ :;;
+ * )
+ multilib_matches=$(print_multilib_matches "$sms" "$@")
+ echo "multilib_matches := $multilib_matches"
+ ;;
+esac
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 00a7b15496e0..563c7b30dab2 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -48,6 +48,8 @@ t-nvptx-gen-multilib-matches: $(srcdir)/config/nvptx/gen-multilib-matches.sh \
$(srcdir)/config/nvptx/t-nvptx \
Makefile \
$(srcdir)/config/nvptx/nvptx-sm.def
+ $(SHELL) $< \
+ --selftest
$(SHELL) $< \
$(multilib_options_isa_default) \
'$(multilib_options_isa_list)' \
--
2.34.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)))
2024-12-06 9:32 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
@ 2024-12-06 9:34 ` Sam James
2024-12-06 9:52 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' Sam James
2024-12-06 10:02 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
0 siblings, 2 replies; 16+ messages in thread
From: Sam James @ 2024-12-06 9:34 UTC (permalink / raw)
To: tschwinge; +Cc: gcc-patches, tdevries
Hi!
The script has #!/bin/sh shebang (and hence must have POSIX shell
compatibility), but the patch introduces uses of the 'local' keyword
which isn't in POSIX.
While many shells do have the 'local' keyword, its behaviour isn't
portable across those either, which is why it's likely it'll never
be added to POSIX :(
thanks,
sam
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest'
2024-12-06 9:34 ` Sam James
@ 2024-12-06 9:52 ` Sam James
2024-12-06 10:02 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
1 sibling, 0 replies; 16+ messages in thread
From: Sam James @ 2024-12-06 9:52 UTC (permalink / raw)
To: tschwinge; +Cc: gcc-patches, tdevries
Sam James <sam@gentoo.org> writes:
> Hi!
>
> The script has #!/bin/sh shebang (and hence must have POSIX shell
> compatibility), but the patch introduces uses of the 'local' keyword
> which isn't in POSIX.
>
> While many shells do have the 'local' keyword, its behaviour isn't
> portable across those either, which is why it's likely it'll never
> be added to POSIX :(
BTW, shellcheck catches this, but unfortunately, checkbashisms does not.
>
> thanks,
> sam
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)))
2024-12-06 9:34 ` Sam James
2024-12-06 9:52 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' Sam James
@ 2024-12-06 10:02 ` Thomas Schwinge
2024-12-09 2:52 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' Sam James
1 sibling, 1 reply; 16+ messages in thread
From: Thomas Schwinge @ 2024-12-06 10:02 UTC (permalink / raw)
To: Sam James; +Cc: gcc-patches, tdevries
Hi Sam!
On 2024-12-06T09:34:32+0000, Sam James <sam@gentoo.org> wrote:
> The script has #!/bin/sh shebang (and hence must have POSIX shell
> compatibility), but the patch introduces uses of the 'local' keyword
> which isn't in POSIX.
>
> While many shells do have the 'local' keyword, its behaviour isn't
> portable across those either, which is why it's likely it'll never
> be added to POSIX :(
Right, but I intentionally picked the form that I thought was supported
by all reasonable '/bin/sh's: 'local [name]', without any further
adornement. For example, per <https://mywiki.wooledge.org/Bashism>:
| 'local' is mandated by the LSB and Debian policy specifications, though only the 'local varname' (not 'local var=value') syntax is specified.
Portable, reliable shell programming is a nice idea, but then, reality
check...
(Don't ask me how much time I already spent on this simple script, to get
it into its current form -- and I'd consider myself well-versed in shell
programming...)
I was inclined to just rewrite it in Python, what do you think? In my
opinion, a GCC-build-time Python dependency is not a problem for
'--target=nvptx-none', as that one's not in the bootstrapping chain?
Grüße
Thomas
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest'
2024-12-06 10:02 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
@ 2024-12-09 2:52 ` Sam James
0 siblings, 0 replies; 16+ messages in thread
From: Sam James @ 2024-12-09 2:52 UTC (permalink / raw)
To: Thomas Schwinge; +Cc: gcc-patches, tdevries
Thomas Schwinge <tschwinge@baylibre.com> writes:
> Hi Sam!
Hi!
>
> On 2024-12-06T09:34:32+0000, Sam James <sam@gentoo.org> wrote:
>> The script has #!/bin/sh shebang (and hence must have POSIX shell
>> compatibility), but the patch introduces uses of the 'local' keyword
>> which isn't in POSIX.
>>
>> While many shells do have the 'local' keyword, its behaviour isn't
>> portable across those either, which is why it's likely it'll never
>> be added to POSIX :(
>
> Right, but I intentionally picked the form that I thought was supported
> by all reasonable '/bin/sh's: 'local [name]', without any further
> adornement. For example, per <https://mywiki.wooledge.org/Bashism>:
>
> | 'local' is mandated by the LSB and Debian policy specifications, though only the 'local varname' (not 'local var=value') syntax is specified.
>
> Portable, reliable shell programming is a nice idea, but then, reality
> check...
Yeah, that's fair enough. (I just noticed by chance as I was looking at
my other issue; I didn't hit an actual problem with this at all.)
>
> (Don't ask me how much time I already spent on this simple script, to get
> it into its current form -- and I'd consider myself well-versed in shell
> programming...)
>
> I was inclined to just rewrite it in Python, what do you think? In my
> opinion, a GCC-build-time Python dependency is not a problem for
> '--target=nvptx-none', as that one's not in the bootstrapping chain?
I think that should be fine and far less error prone. Certainly not a
problem for us and I can't imagine it is for the others.
>
>
> Grüße
> Thomas
thanks,
sam
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-12-09 2:52 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-104364-4@http.gcc.gnu.org/bugzilla/>
[not found] ` <bug-104364-4-ILKfZXTaRC@http.gcc.gnu.org/bugzilla/>
[not found] ` <87r18jt7uu.fsf@euler.schwinge.homeip.net>
[not found] ` <cc77f4ed-fdb6-7536-a0ba-8802eb231bcc@suse.de>
[not found] ` <87o801see9.fsf@euler.schwinge.homeip.net>
2022-06-15 21:18 ` nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup) Thomas Schwinge
2022-07-05 14:59 ` [PING] " Thomas Schwinge
2022-07-13 8:42 ` [PING^2] " Thomas Schwinge
2022-07-20 12:46 ` [PING^3] " Thomas Schwinge
2022-07-27 15:48 ` [PING^4] " Thomas Schwinge
2022-08-06 19:20 ` [PING^5] " Thomas Schwinge
2022-08-16 15:13 ` [PING^6] " Thomas Schwinge
2022-08-30 13:44 ` [PING^7] " Thomas Schwinge
2022-09-18 8:53 ` [PING^5] " Tom de Vries
2024-12-06 9:01 ` 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) Thomas Schwinge
2024-12-06 9:32 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
2024-12-06 9:34 ` Sam James
2024-12-06 9:52 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' Sam James
2024-12-06 10:02 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' (was: 'gcc/config/nvptx/t-nvptx': Don't use the 'shell' function of 'make' (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup))) Thomas Schwinge
2024-12-09 2:52 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest' Sam James
2024-12-06 9:07 ` 'gcc/config/nvptx/gen-multilib-matches.sh': Encapsulate main logic (was: nvptx: Allow '--with-arch' to override the default '-misa' (was: nvptx multilib setup)) 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).