From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 07968385828F; Mon, 26 Sep 2022 14:21:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07968385828F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664202069; bh=6QfqhFdkUBAW657+JtQ63z30vL1m+o5G8WZRD74bYmA=; h=From:To:Subject:Date:From; b=Xx7OapPiE9jYnIV3tvW+DQpK/d6AZ0s/3wfQlMt78aqQqvQCESmy29171u+2DnXjx CzMtQrLGUGEkTMKhUqP8Oftl4jsy+NR3Xf/zu0tbM5wjAr1u2zyoEY4GKwfD9fgfkp YJNsh3ccrrFQ7w3luosCInKo9jHXFv6KflBREw5Q= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] nvptx: Allow '--with-arch' to override the default '-misa' X-Act-Checkin: gcc X-Git-Author: Thomas Schwinge X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 74ddd1ec9d8d7b91790962faed0a5e23b5d1bbcb X-Git-Newrev: 8cf4c2316cb6a4082bf24fcc3003124e4b0a05c3 Message-Id: <20220926142109.07968385828F@sourceware.org> Date: Mon, 26 Sep 2022 14:21:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8cf4c2316cb6a4082bf24fcc3003124e4b0a05c3 commit 8cf4c2316cb6a4082bf24fcc3003124e4b0a05c3 Author: Thomas Schwinge Date: Sat Jun 11 19:37:10 2022 +0200 nvptx: Allow '--with-arch' to override the default '-misa' gcc/ * config.gcc (with_arch) [nvptx]: Allow '--with-arch' to override the default. * config/nvptx/gen-multilib-matches.sh: New. * config/nvptx/t-nvptx (MULTILIB_OPTIONS, MULTILIB_MATCHES) (MULTILIB_EXCEPTIONS): Handle this. * doc/install.texi (Specific) : Document this. * doc/invoke.texi (Nvidia PTX Options): Likewise. (cherry picked from commit e9019085e17554c209ca8531022f116b2d7f94fe) Diff: --- gcc/ChangeLog.omp | 13 +++++++ 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 ++- 6 files changed, 106 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 43fa05159b6..ed2073297e7 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,16 @@ +2022-09-26 Thomas Schwinge + + Backported from master: + 2022-09-26 Thomas Schwinge + + * config.gcc (with_arch) [nvptx]: Allow '--with-arch' to override + the default. + * config/nvptx/gen-multilib-matches.sh: New. + * config/nvptx/t-nvptx (MULTILIB_OPTIONS, MULTILIB_MATCHES) + (MULTILIB_EXCEPTIONS): Handle this. + * doc/install.texi (Specific) : Document this. + * doc/invoke.texi (Nvidia PTX Options): Likewise. + 2022-09-26 Thomas Schwinge Backported from master: 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 +# . + +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 ed0d1d882c3..13310d6b981 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -4632,6 +4632,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
@end html diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1b290e153d0..3477d4426a0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -27606,7 +27606,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