diff mbox series

nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor sm_35 multilib variant is built (was: nvptx: Support '--with-multilib-list' (was: Raise nvptx code generation to default PTX ISA 7.3, sm_52, therefore CUDA 11.3 (released 2021-04)))

Message ID 87o7014udc.fsf@euler.schwinge.ddns.net
State New
Headers show
Series nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor sm_35 multilib variant is built (was: nvptx: Support '--with-multilib-list' (was: Raise nvptx code generation to default PTX ISA 7.3, sm_52, therefore CUDA 11.3 (released 2021-04))) | expand

Commit Message

Thomas Schwinge Jan. 20, 2025, 11:06 a.m. UTC
Hi!

On 2024-12-06T12:03:22+0100, I wrote:
> Pushed to trunk branch commit 86b3a7532d56f74fcd1c362f2da7f95e8cc4e4a6
> "nvptx: Support '--with-multilib-list'", [...]

Pushed to trunk branch commit 6c5937991bd744a4916e9cf65eb5d9c9b5706120
"nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor sm_35 multilib variant is built",
see attached.


Grüße
 Thomas
diff mbox series

Patch

From 6c5937991bd744a4916e9cf65eb5d9c9b5706120 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Fri, 17 Jan 2025 21:45:42 +0100
Subject: [PATCH] nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor
 sm_35 multilib variant is built

For example, for GCC/nvptx built with '--with-arch=sm_52' (current default)
and '--without-multilib-list', neither a sm_30 nor a sm_35 multilib variant
is built, and thus no '-mptx=3.1' sub-variant either.  Such a configuration
is possible as of commit 86b3a7532d56f74fcd1c362f2da7f95e8cc4e4a6
"nvptx: Support '--with-multilib-list'", but currently results in the
following bogus behavior:

    [...]/xgcc -print-multi-directory -mgomp -march=sm_52
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_35
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_30
    mgomp
    [...]/xgcc -print-multi-directory -mgomp -march=sm_35 -mptx=3.1
    .
    [...]/xgcc -print-multi-directory -mgomp -march=sm_30 -mptx=3.1
    .

The latter two '.' are unexpected; linking OpenMP/nvptx offloading code
like this fails with: 'unresolved symbol __nvptx_uni', for example.
Instead of '.', the latter two should print 'mgomp', too.  To achieve that,
we must not set up the '-mptx=3.1' multilib axis if no '-mptx=3.1'
sub-variant is built.

	gcc/
	* config/nvptx/t-nvptx (MULTILIB_OPTIONS): Don't add 'mptx=3.1' if
	neither sm_30 nor sm_35 multilib variant is built.
---
 gcc/config/nvptx/t-nvptx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 563c7b30dab..b77f63bde8f 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -66,11 +66,14 @@  MULTILIB_MATCHES += $(multilib_matches)
 # ..., and don't actually build what's the default '-misa':
 MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
 
+# Build '-mptx=3.1' sub-variants, if applicable.  Per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm':
+# only for sm_30, sm_35.
+ifneq ($(filter sm_30 sm_35,$(multilib_options_isa_list)),)
 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):
+# Filter out invalid '-misa'/'-mptx=3.1' combinations:
 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)
+endif
-- 
2.34.1