> -----Original Message----- > From: Thomas Schwinge <tschwi...@baylibre.com> > Sent: Friday, August 9, 2024 12:55 AM > To: Prathamesh Kulkarni <prathame...@nvidia.com> > Cc: Andrew Pinski <pins...@gmail.com>; Richard Biener > <rguent...@suse.de>; gcc-patches@gcc.gnu.org; Jakub Jelinek > <ja...@redhat.com> > Subject: Re: [nvptx] Pass -m32/-m64 to host_compiler if it has > multilib support > > External email: Use caution opening links or attachments > > > Hi Prathamesh! Hi Thomas, > > On 2024-08-08T06:46:25-0700, Andrew Pinski <pins...@gmail.com> wrote: > > On Thu, Aug 8, 2024 at 6:11 AM Prathamesh Kulkarni > > <prathame...@nvidia.com> wrote: > >> After differing NUM_POLY_INT_COEFFS fix for AArch64/nvptx > offloading, the following minimal test: > > 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! :-) > > Please CC me for GCC/nvptx issues for (at least potentially...) faster > response times. Thanks, will do 😊 > > >> compiled with -fopenmp -foffload=nvptx-none now fails with: > >> gcc: error: unrecognized command-line option '-m64' > >> nvptx mkoffload: fatal error: ../install/bin/gcc returned 1 exit > status compilation terminated. > > Heh. Yeah... > > >> 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. > >> > >> Based on your suggestion in: > >> https://gcc.gnu.org/pipermail/gcc/2024-July/244470.html, > >> The attached patch generates new macro HOST_MULTILIB derived from > >> $enable_as_accelerator_for, and in mkoffload.cc it gates passing > >> -m32/-m64 to host_compiler on HOST_MULTILIB. I verified that the > macro is set to 0 for aarch64 host (and thus avoids above unrecognized > command line option error), and is set to 1 for x86_64 host. > >> > >> Does the patch look OK ? > > > > Note I think the usage of the name MULTILIB here is wrong because > > aarch64 (and riscv) could have MUTLILIB support just the options are > > different. > > I also think the proposed patch is not quite the right hammer for the > issue at hand. > > > For aarch64, it would be -mabi=ilp32/-mabi=lp64 (riscv it is more > > complex). > > > > This most likely should be something more complex due to the above. > > Right. > > > Maybe call it HOST_64_32 but even that seems wrong due to Aarch64 > > having ILP32 support and such. > > Right. > > > What about HOST_64ABI_OPTS="-mabi=lp64"/HOST_32ABI_OPTS="- > mabi=ilp32" > > but I am not sure if that would be enough to support RISCV which > > requires two options. > > So, my idea is: instead of the current strategy that the host > 'TARGET_OFFLOAD_OPTIONS' synthesizes '-foffload-abi=lp64' 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=-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? > > And use something like '-foffload-abi=disable' to replace the current: > > /* PR libgomp/65099: Currently, we only support offloading in 64- > bit > configurations. */ > if (offload_abi == OFFLOAD_ABI_LP64) > { > > (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_abi == OFFLOAD_ABI_LP64, which is synthesized from -foffload-abi=lp64. If we change -foffload-abi to instead specify host-specific ABI opts, I guess mkoffload will still need to somehow figure out which ABI is used, so it can disable offloading for 32-bit ? I suppose we could adjust TARGET_OFFLOAD_OPTIONS for each host to pass -foffload-abi=disable if TARGET_ILP32 is set and offload target is nvptx, but not sure if that'd be correct ?
In the attached patch, 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 mkoffload can use to enable/disable offloading (as before). Does that look OK ? Signed-off-by: Prathamesh Kulkarni <prathame...@nvidia.com> Thanks, Prathamesh > > > Grüße > 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 <prathame...@nvidia.com> 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) +foffload-abi-host-opts= +Common Driver Joined MissingArgError(option or option=abi missing after %qs) +-foffload-abi-host-opts=<options>=<abi> 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=ilp32"); + return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-mabi=ilp32"); else - return xstrdup ("-foffload-abi=lp64"); + return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-mabi=lp64"); } static struct machine_function * diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.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=lp64"); - return xstrdup ("-foffload-abi=ilp32"); + return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-m64"); + return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-m32"); } /* 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; enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; +const char *host_abi_opts = NULL; /* Delete tempfiles. */ @@ -607,17 +608,9 @@ compile_native (const char *infile, const char *outfile, 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=")) + host_abi_opts = argv[i] + strlen ("-foffload-abi-host-opts="); else if (strcmp (argv[i], "-fopenmp") == 0) fopenmp = true; else if (strcmp (argv[i], "-fopenacc") == 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=lp64"); + return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-m64"); else - return xstrdup ("-foffload-abi=ilp32"); + return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-m32"); } 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<cl_decoded_option> 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; case OPT_foffload_abi_: + case OPT_foffload_abi_host_opts_: #ifdef ACCEL_COMPILER /* Handled in the 'mkoffload's. */ #else