From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 6348B3858C52 for ; Tue, 13 Aug 2024 15:47:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6348B3858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6348B3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723564058; cv=none; b=GhBm6y0bNzRbNA7m+LlqKxBNk8+zbBFhWS93C9WWp3Xa/U7MQvIAARz33VhqcFZch7mpqlftN1lGUoeRWlGoaR08vNeb7SVhGnpMw/J7aOelzFgmj6Ieowm4/w43Hdsvr6Tmq75aLXS37n1NEM6t9aZ4ak9Y4UVNN9uDqykJF6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723564058; c=relaxed/simple; bh=62xSmjF8DspJ0CMCUzygcyplPUlOCv0s8eyHLPC9hMQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JTOs2AGUMRhYy4v73dIYefU/dSF8+qPI2bDbB/a0akz5lnAMQP72kSc+wT57A/TB4VDuaIXgS01OTHacek5xs7w/PDefw+I5gvhhS6ioeQbFYq0DsRMiW3VyaftE+8t2mG8fEFc8B6OgHRLFh/HmOJke94sU/PlrfgxHA8mpZc0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52f01b8738dso4949981e87.1 for ; Tue, 13 Aug 2024 08:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1723564054; x=1724168854; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uhhJ2RzQr/fXWr9rbg8mTsDrGRHCABlOP/pqm0D6UUg=; b=WamYlpEhuGteTnLM1hmYFkElfAnttCDzWT1TCURoYhMfhZPZSVdzep8psdO1TbLGBX qwbGSTfwgsOHxOJhF5M8vkGGhXiy+WFa+8DCu1UCaXIMqJgjj9PUUhm11WpvNlWp4XSs jhQ32oZJ/I03yakIxXikqHUHSM2ikGBzdM8esDbWJgRQIzP/R9mM60q/u2BvmkJst9lF pRTHVCP0/+TweNSVa4YPRIrRmNdL4VIMaRz/3pVLNo0mdqGvLL76i5jvjx2UzFP82khq xey3SrcsrUaYx9f2vF99+oLna9QSdDNW4PsgCdkXGpiP6tbX7Ys+X1ruZg2B3liG1aNT bvAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723564054; x=1724168854; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uhhJ2RzQr/fXWr9rbg8mTsDrGRHCABlOP/pqm0D6UUg=; b=tug9S+JIzTkEH3eBqXm5e20RZycm0F2Cnujl4XoPn1b0IgVE64WCxJhyMMW+xGyzT5 Rb23ZlkKsLBkS0xuiRIQ7AXxBBL1QdjBBJgbad4ZGDtNnh1JYxqKJFfYRAkByQmoVI+h 12wA/Ii6jY4pTxZ9R9oxshDc4fJLQTFXCkhVDSqkRj1rUCheo4WZGFys+13F+SDnLmoB NY0Z9noj3/WLPCiwpZ96XjimLlJOcL2rVqr3NqySeZWOEVkysoHxNZuaCXP6Ovz6FMeE 7wS1XNaTYXDvbWvqa8N7ZEH8HxtnyTFdJc/yrUSEwh4hJvhgUuBCFKBI4AMeqEc5dRrm C1ag== X-Forwarded-Encrypted: i=1; AJvYcCUQT3ppxVNKRi1VOecYDqWA9L2qgxCSQ8LTM5ZeFNwS/UGaPUVGKZveWm5eAu6SFGgjhM6xVo4bVubcuuLzOWI45KY3VXB+/g== X-Gm-Message-State: AOJu0YyWO1SgqoKojaQyZE8Y5g/57IWt+U/BIOHnC/xwtuh+3BBaj0WK nHzeAFfM5zt05H4WA1HY7SsGPA5lBFnHd2MNfKZCW+nnA5r9ujlYD+wA0GU3mKQ= X-Google-Smtp-Source: AGHT+IHLQskLL/nCiskxzvlwbTcQPOKTy2j0Fb7Xy2ald28FaJjdA3Jwxc2BqtLjlVoutZCcoTpUvw== X-Received: by 2002:a05:6512:e92:b0:52e:7125:c70a with SMTP id 2adb3069b0e04-532136841b4mr1979262e87.47.1723564053444; Tue, 13 Aug 2024 08:47:33 -0700 (PDT) Received: from euler.schwinge.ddns.net (p200300c8b733b9005e8fc6f38b6af531.dip0.t-ipconnect.de. [2003:c8:b733:b900:5e8f:c6f3:8b6a:f531]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429c75044a8sm145247295e9.9.2024.08.13.08.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 08:47:33 -0700 (PDT) From: Thomas Schwinge To: Prathamesh Kulkarni Cc: Andrew Pinski , Richard Biener , gcc-patches@gcc.gnu.org, Jakub Jelinek Subject: RE: [nvptx] Pass -m32/-m64 to host_compiler if it has multilib support In-Reply-To: References: <87zfpmg6ml.fsf@euler.schwinge.ddns.net> User-Agent: Notmuch/0.30+8~g47a4bad (https://notmuchmail.org) Emacs/29.4 (x86_64-pc-linux-gnu) Date: Tue, 13 Aug 2024 17:47:30 +0200 Message-ID: <874j7ojugd.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Prathamesh! On 2024-08-12T07:50:07+0000, Prathamesh Kulkarni w= rote: >> From: Thomas Schwinge >> Sent: Friday, August 9, 2024 12:55 AM >> On 2024-08-08T06:46:25-0700, Andrew Pinski wrote: >> > On Thu, Aug 8, 2024 at 6:11=E2=80=AFAM Prathamesh Kulkarni >> > wrote: >> >> After differing NUM_POLY_INT_COEFFS fix for AArch64/nvptx >> offloading, the following minimal test: >>=20 >> First, thanks for your work on enabling this! I will say that I had >> the plan to re-engage with Nvidia to hire us (as initial implementors >> of GCC/nvptx offloading) to make AArch64/nvptx offloading work, but >> now that Nvidia has its own GCC team, that's great that you're able to >> work on this yourself! :-) >>=20 >> Please CC me for GCC/nvptx issues for (at least potentially...) faster >> response times. > Thanks, will do =F0=9F=98=8A Heh, so much for "potentially": I'm not able to spend a lot of time on this right now, as I shall soon be out of office. Quickly: >> >> compiled with -fopenmp -foffload=3Dnvptx-none now fails with: >> >> gcc: error: unrecognized command-line option '-m64' >> >> nvptx mkoffload: fatal error: ../install/bin/gcc returned 1 exit >> status compilation terminated. >>=20 >> Heh. Yeah... >>=20 >> >> As mentioned in RFC email, this happens because >> >> nvptx/mkoffload.cc:compile_native passes -m64/-m32 to host compiler >> depending on whether offload_abi is OFFLOAD_ABI_LP64 or >> OFFLOAD_ABI_ILP32, and aarch64 backend doesn't recognize these >> options. >> So, my idea is: instead of the current strategy that the host >> 'TARGET_OFFLOAD_OPTIONS' synthesizes '-foffload-abi=3Dlp64' etc., which >> the 'mkoffload's then interpret and re-synthesize '-m64' etc. -- how >> about we instead directly tell the 'mkoffload's the relevant ABI >> options? That is, 'TARGET_OFFLOAD_OPTIONS' instead synthesizes '- >> foffload-abi=3D-m64' >> etc., which the 'mkoffload's can then readily use. Could you please >> give that a try, and/or does anyone see any issues with that approach? >>=20 >> And use something like '-foffload-abi=3Ddisable' to replace the current: >>=20 >> /* PR libgomp/65099: Currently, we only support offloading in 64- >> bit >> configurations. */ >> if (offload_abi =3D=3D OFFLOAD_ABI_LP64) >> { >>=20 >> (As discussed before, this should be done differently altogether, but >> that's for another day.) > Sorry, I don't quite follow. Currently we enable offloading if offload_ab= i =3D=3D OFFLOAD_ABI_LP64, > which is synthesized from -foffload-abi=3Dlp64. If we change -foffload-ab= i to instead specify > host-specific ABI opts, I guess mkoffload will still need to somehow figu= re out which ABI is used, > so it can disable offloading for 32-bit ? I suppose we could adjust TARGE= T_OFFLOAD_OPTIONS for each > host to pass -foffload-abi=3Ddisable if TARGET_ILP32 is set and offload t= arget is nvptx, but not sure > if that'd be correct ? Basically, yes. My idea was that all 'TARGET_OFFLOAD_OPTIONS' implementations return either the correct host flags to be used by the 'mkoffload's (the case that offloading is supported for the current host flags/ABI configuration), or otherwise return '-foffload-abi=3Ddisable'. For example (untested): > char * > ix86_offload_options (void) > { > if (TARGET_LP64) > - return xstrdup ("-foffload-abi=3Dlp64"); > + return xstrdup ("-foffload-abi=3D-m64"); > - return xstrdup ("-foffload-abi=3Dilp32"); > + return xstrdup ("-foffload-abi=3Ddisable"); > } That is, only for 'TARGET_LP64' offloading is supported, and via '-foffload-abi=3D-m64' the 'mkoffload's know that they need to specify '-m64'. For other host flags/ABI configuration, the 'mkoffload's see '-foffload-abi=3Ddisable' and thus disable offload code generation (replacing the current 'if (offload_abi =3D=3D OFFLOAD_ABI_LP64)' in 'mkoffload'). > In the attached patch Yes, that's going in the right direction, thanks! > I added another option -foffload-abi-host-opts to specify host abi > opts, and leave -foffload-abi to specify if ABI is 32/64 bit which mkoffl= oad can use to > enable/disable offloading (as before). I'm not sure however, if this additional option is really necessary? In case we're not happy to re-purpose the flag name '-foffload-abi=3D[...]', we could also rename that one to '-foffload-abi-host-opts=3D[...]'; the former is not user-exposed, so we may change it as necessary. (Or, in other words, go with your proposed '-foffload-abi-host-opts=3D[...]', but also remove '-foffload-abi=3D[...]' = at the same time.) I'll be able to spend more time on this in two weeks. Gr=C3=BC=C3=9Fe Thomas > [nvptx] Pass host specific ABI opts from mkoffload. > > The patch adds an option -foffload-abi-host-opts, which > is set by host in TARGET_OFFLOAD_OPTIONS, and mkoffload then passes it's = value > to host_compiler. > > gcc/ChangeLog: > * common.opt (foffload-abi-host-opts): New option. > * config/aarch64/aarch64.cc (aarch64_offload_options): Set > -foffload-abi-host-opts. > * config/i386/i386-opts.cc (ix86_offload_options): Likewise. > * config/rs6000/rs6000.cc (rs6000_offload_options): Likewise. > * config/nvptx/mkoffload.cc (host_abi_opts): Define. > (compile_native): Append host_abi_opts to argv_obstack. > (main): Handle option -foffload-abi-host-opts. > * lto-wrapper.cc (append_compiler_options): Handle > -foffload-abi-host-opts. > * opts.cc (common_handle_option): Likewise. > > Signed-off-by: Prathamesh Kulkarni > > diff --git a/gcc/common.opt b/gcc/common.opt > index ea39f87ae71..d1a9efb9513 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -2361,6 +2361,10 @@ Enum(offload_abi) String(ilp32) Value(OFFLOAD_ABI_= ILP32) > EnumValue > Enum(offload_abi) String(lp64) Value(OFFLOAD_ABI_LP64) >=20=20 > +foffload-abi-host-opts=3D > +Common Driver Joined MissingArgError(option or option=3Dabi missing afte= r %qs) > +-foffload-abi-host-opts=3D=3D Specify host abi options. > + > fomit-frame-pointer > Common Var(flag_omit_frame_pointer) Optimization > When possible do not generate stack frames. > diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc > index 2ac5a22c848..7418cb1fb69 100644 > --- a/gcc/config/aarch64/aarch64.cc > +++ b/gcc/config/aarch64/aarch64.cc > @@ -18999,9 +18999,9 @@ static char * > aarch64_offload_options (void) > { > if (TARGET_ILP32) > - return xstrdup ("-foffload-abi=3Dilp32"); > + return xstrdup ("-foffload-abi=3Dilp32 -foffload-abi-host-opts=3D-ma= bi=3Dilp32"); > else > - return xstrdup ("-foffload-abi=3Dlp64"); > + return xstrdup ("-foffload-abi=3Dlp64 -foffload-abi-host-opts=3D-mab= i=3Dlp64"); > } >=20=20 > static struct machine_function * > diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-optio= ns.cc > index 1c8f7835af2..bd960674e5d 100644 > --- a/gcc/config/i386/i386-options.cc > +++ b/gcc/config/i386/i386-options.cc > @@ -3669,8 +3669,8 @@ char * > ix86_offload_options (void) > { > if (TARGET_LP64) > - return xstrdup ("-foffload-abi=3Dlp64"); > - return xstrdup ("-foffload-abi=3Dilp32"); > + return xstrdup ("-foffload-abi=3Dlp64 -foffload-abi-host-opts=3D-m64= "); > + return xstrdup ("-foffload-abi=3Dilp32 -foffload-abi-host-opts=3D-m32"= ); > } >=20=20 > /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall", > diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc > index 503b1abcefd..d5ca2386641 100644 > --- a/gcc/config/nvptx/mkoffload.cc > +++ b/gcc/config/nvptx/mkoffload.cc > @@ -61,6 +61,7 @@ static const char *omp_requires_file; > static const char *ptx_dumpbase; >=20=20 > enum offload_abi offload_abi =3D OFFLOAD_ABI_UNSET; > +const char *host_abi_opts =3D NULL; >=20=20 > /* Delete tempfiles. */ >=20=20 > @@ -607,17 +608,9 @@ compile_native (const char *infile, const char *outf= ile, const char *compiler, > obstack_ptr_grow (&argv_obstack, ptx_dumpbase); > obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); > obstack_ptr_grow (&argv_obstack, ".c"); > - switch (offload_abi) > - { > - case OFFLOAD_ABI_LP64: > - obstack_ptr_grow (&argv_obstack, "-m64"); > - break; > - case OFFLOAD_ABI_ILP32: > - obstack_ptr_grow (&argv_obstack, "-m32"); > - break; > - default: > - gcc_unreachable (); > - } > + if (!host_abi_opts) > + fatal_error (input_location, "-foffload-abi-host-opts not specified.= "); > + obstack_ptr_grow (&argv_obstack, host_abi_opts); > obstack_ptr_grow (&argv_obstack, infile); > obstack_ptr_grow (&argv_obstack, "-c"); > obstack_ptr_grow (&argv_obstack, "-o"); > @@ -721,6 +714,8 @@ main (int argc, char **argv) > "unrecognizable argument of option " STR); > } > #undef STR > + else if (startswith (argv[i], "-foffload-abi-host-opts=3D")) > + host_abi_opts =3D argv[i] + strlen ("-foffload-abi-host-opts=3D"); > else if (strcmp (argv[i], "-fopenmp") =3D=3D 0) > fopenmp =3D true; > else if (strcmp (argv[i], "-fopenacc") =3D=3D 0) > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 0bcc6a2d0ab..decdf49a1f5 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -17333,9 +17333,9 @@ static char * > rs6000_offload_options (void) > { > if (TARGET_64BIT) > - return xstrdup ("-foffload-abi=3Dlp64"); > + return xstrdup ("-foffload-abi=3Dlp64 -foffload-abi-host-opts=3D-m64= "); > else > - return xstrdup ("-foffload-abi=3Dilp32"); > + return xstrdup ("-foffload-abi=3Dilp32 -foffload-abi-host-opts=3D-m3= 2"); > } >=20=20 > > diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc > index 6bfc96590a5..1ecc4997e5a 100644 > --- a/gcc/lto-wrapper.cc > +++ b/gcc/lto-wrapper.cc > @@ -745,6 +745,7 @@ append_compiler_options (obstack *argv_obstack, vec opts) > case OPT_fopenacc: > case OPT_fopenacc_dim_: > case OPT_foffload_abi_: > + case OPT_foffload_abi_host_opts_: > case OPT_fcf_protection_: > case OPT_fasynchronous_unwind_tables: > case OPT_funwind_tables: > diff --git a/gcc/opts.cc b/gcc/opts.cc > index 0b7b137c376..79118237ce4 100644 > --- a/gcc/opts.cc > +++ b/gcc/opts.cc > @@ -3069,6 +3069,7 @@ common_handle_option (struct gcc_options *opts, > break; >=20=20 > case OPT_foffload_abi_: > + case OPT_foffload_abi_host_opts_: > #ifdef ACCEL_COMPILER > /* Handled in the 'mkoffload's. */ > #else