From patchwork Tue Aug 18 16:17:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 508390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3D6CD1402B5 for ; Wed, 19 Aug 2015 02:18:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eDjGG3Ap; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=AWCcZ900XnvPzprR sMHlssDqPPLumuES4uH1xeIQ0FBA1ZJ38dvC34dAujbhkWgt09fKpV8nU7EaCyP6 DA5dKJrI9JSLuTa+FVPUySgpDsdcmN7VHJ4I2HvAz1tpQuxT84dgafVtVTbUCaJ3 mxjX0juAOMHRdJe5EmDbn9nhPVU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=E9CsTtJkPz0o356uZ+x8Vu CqrR0=; b=eDjGG3ApfyRwPIG2YPmRABDnOBnSxw2yH0UdTl0badQ+5uP7WeNyYa gmEWZvd0pjfThAzLSM93kIKCoq7oE8j0TqFR7SJQfmHTwKa6EfstH7ekrQQRKjWR LyOcqrpExte3087ipaiIURWO8QR2VKaoYPX3dehhDIz/m+RaZ2wHc= Received: (qmail 16032 invoked by alias); 18 Aug 2015 16:18:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 15934 invoked by uid 89); 18 Aug 2015 16:18:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: Yes, score=5.1 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS, UNSUBSCRIBE_BODY, ZIP_ATTACHED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Aug 2015 16:18:37 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZRjjX-0004k3-Fi from Thomas_Schwinge@mentor.com for gcc-patches@gcc.gnu.org; Tue, 18 Aug 2015 09:27:32 -0700 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Tue, 18 Aug 2015 17:17:56 +0100 From: Thomas Schwinge To: Joseph Myers CC: GCC Patches , Nathan Sidwell Subject: Re: Forwarding -foffload=[...] from the driver (compile-time) to libgomp (run-time) In-Reply-To: References: <20141020111935.GA9362@msticlxl57.ims.intel.com> <20141024141601.GA62562@msticlxl57.ims.intel.com> <20141024142028.GD10376@tucnak.redhat.com> <20141028193047.GA17865@msticlxl57.ims.intel.com> <20141103092447.GO5026@tucnak.redhat.com> <20141105124655.GA42356@msticlxl57.ims.intel.com> <87egjopgh0.fsf@kepler.schwinge.homeip.net> <20150731142007.GA64740@msticlxl57.ims.intel.com> <20150805150904.GA3211@msticlxl57.ims.intel.com> <87bneatd5q.fsf@schwinge.name> <87lhddsfs4.fsf@schwinge.name> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Tue, 18 Aug 2015 18:17:47 +0200 Message-ID: <87oai4r2ok.fsf@schwinge.name> MIME-Version: 1.0 Hi! On Fri, 14 Aug 2015 22:56:30 +0000, Joseph Myers wrote: > On Fri, 14 Aug 2015, Thomas Schwinge wrote: > > > Can you suggest off-hand where you'd expect this option filtering to > > happen? Should this be during specs parsing in the driver; something > > like adding a lang_mask to gcc/gcc.c:struct switchstr, and then in > > gcc/gcc.c:give_switch ignore any switches that don't match the expected > > CL_*? I seem to have difficulties to properly populate/deduce that > > lang_mask at the call sites of gcc/gcc.c:save_switch. (I figured that out.) > > Alternatively, what about changing gcc/opts-global.c:complain_wrong_lang > > to silently ignore options that don't apply instead of emitting a »is > > valid for [...] but not for [...]« diagnostic, if a (new) flag > > (-f[something]?) has been set, which would be active only during the > > add-omp-infile compilation? > > That would be a possibility, yes. ..., and that even looked like a sensible thing to do, also given that I found where you added the internal -lang-asm flag five years ago, gcc/c-family/c-opts.c:accept_all_c_family_options »Whether options from all C-family languages should be accepted quietly«, which does a rather similar thing. Unfortunately, going that route turned out to not work correctly: consider the Fortran -ffixed-form option, and likewise the -ffixed-line-length-[...] options. If not compiling for Fortran, these will be passed to C-family front ends, and be recognized there by means of the Common option -ffixed-[...], resulting in »cc1: warning: unknown register name: form«, for example. (Yay!) ;-) So, back to modifying the driver; here is my current messy WIP patch with still a lot of TODOs in it -- but it appears to work at last. :-) Maybe somebody else is able to continue with that task while I'm out of office. This has been developed on top of gomp-4_0-branch r226832. I'm also attaching a tarball of the even more messy indivdual patches, foffload.tar.bz2, in case there's anything to salvage in there, or if that helps to understand the development options/history. Earlier messages in this thread should give enough context what this is about, . gcc/doc/invoke.texi | 4 + gcc/gcc.c | 200 ++++++++++++++++++--- libgomp/config.h.in | 8 +- libgomp/configure | 33 +++- libgomp/env.c | 6 +- libgomp/libgomp.h | 1 + libgomp/libgomp.map | 7 +- libgomp/libgomp_g.h | 1 + libgomp/oacc-init.c | 18 +- libgomp/plugin/configfrag.ac | 10 +- libgomp/target.c | 172 ++++++++++++++---- libgomp/testsuite/lib/libgomp.exp | 75 ++------ libgomp/testsuite/libgomp.c++/c++.exp | 13 -- libgomp/testsuite/libgomp.c/c.exp | 2 - libgomp/testsuite/libgomp.fortran/fortran.exp | 5 - libgomp/testsuite/libgomp.graphite/graphite.exp | 2 - libgomp/testsuite/libgomp.oacc-c++/c++.exp | 33 ++-- libgomp/testsuite/libgomp.oacc-c/c.exp | 17 +- libgomp/testsuite/libgomp.oacc-fortran/fortran.exp | 23 +-- 19 files changed, 408 insertions(+), 222 deletions(-) Grüße, Thomas diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi index 8c96ca5..80bc639 100644 --- gcc/doc/invoke.texi +++ gcc/doc/invoke.texi @@ -24036,6 +24036,10 @@ macro in the machine description macro file. This flag does not have a negative form, because it specifies a three-way choice. +Note that this flag may conflict with the @option{-ffixed-form} as +well as @option{-ffixed-line-length-none} and +@option{-ffixed-line-length-} options of the Fortran front end. + @item -fcall-used-@var{reg} @opindex fcall-used Treat the register named @var{reg} as an allocable register that is diff --git gcc/gcc.c gcc/gcc.c index 0642be1..5c7c462 100644 --- gcc/gcc.c +++ gcc/gcc.c @@ -1,3 +1,5 @@ +#define FPRINTF if (getenv("DEBUG")) fprintf + /* Compiler driver program that can handle many languages. Copyright (C) 1987-2015 Free Software Foundation, Inc. @@ -158,7 +160,7 @@ static const char *const spec_version = DEFAULT_TARGET_VERSION; static const char *spec_machine = DEFAULT_TARGET_MACHINE; static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE; -/* List of offload targets. */ +/* List of offload targets. Empty string for -foffload=disable. */ static char *offload_targets = NULL; @@ -275,6 +277,8 @@ static const char *compare_debug_auxbase_opt_spec_function (int, const char **); static const char *pass_through_libs_spec_func (int, const char **); static const char *replace_extension_spec_func (int, const char **); static const char *greater_than_spec_func (int, const char **); +static const char *add_omp_infile_spec_func (int, const char **); + static char *convert_white_space (char *); /* The Specs Language @@ -1061,6 +1065,14 @@ static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; static const char *const driver_self_specs[] = { "%{fdump-final-insns:-fdump-final-insns=.} %arg; + FPRINTF(stderr, "%s: %s\n", __FUNCTION__, opt); if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-' && !(decoded->errors & CL_ERR_NEGATIVE)) { @@ -3404,7 +3431,8 @@ driver_unknown_option_callback (const struct cl_decoded_option *decoded) diagnosed only if there are warnings. */ save_switch (decoded->canonical_option[0], decoded->canonical_option_num_elements - 1, - &decoded->canonical_option[1], false, true); + &decoded->canonical_option[1], false, true, + /* TODO */ cl_options[decoded->opt_index].flags); return false; } if (decoded->opt_index == OPT_SPECIAL_unknown) @@ -3412,7 +3440,8 @@ driver_unknown_option_callback (const struct cl_decoded_option *decoded) /* Give it a chance to define it a spec file. */ save_switch (decoded->canonical_option[0], decoded->canonical_option_num_elements - 1, - &decoded->canonical_option[1], false, false); + &decoded->canonical_option[1], false, false, + /* TODO */ cl_options[decoded->opt_index].flags); return false; } else @@ -3433,13 +3462,20 @@ driver_wrong_lang_callback (const struct cl_decoded_option *decoded, options. */ const struct cl_option *option = &cl_options[decoded->opt_index]; + FPRINTF(stderr, "%s: %s\n", __FUNCTION__, decoded->orig_option_with_args_text); + FPRINTF(stderr, " D->opt_index: %d\n", decoded->opt_index); + FPRINTF(stderr, " O->back_chain: %d\n", option->back_chain); + if (option->back_chain != N_OPTS) + FPRINTF(stderr, " %s\n", cl_options[option->back_chain].opt_text); + FPRINTF(stderr, " O->flags: 0x%x\n", option->flags); if (option->cl_reject_driver) error ("unrecognized command line option %qs", decoded->orig_option_with_args_text); else save_switch (decoded->canonical_option[0], decoded->canonical_option_num_elements - 1, - &decoded->canonical_option[1], false, true); + &decoded->canonical_option[1], false, true, + /* TODO */ /* lang_mask */ option->flags); } static const char *spec_lang = 0; @@ -3450,6 +3486,8 @@ static int last_language_n_infiles; static void handle_foffload_option (const char *arg) { + FPRINTF(stderr, "%s (\"%s\")\n", __FUNCTION__, arg); + const char *c, *cur, *n, *next, *end; char *target; @@ -3689,7 +3727,8 @@ driver_handle_option (struct gcc_options *opts, compare_debug_opt = NULL; else compare_debug_opt = arg; - save_switch (compare_debug_replacement_opt, 0, NULL, validated, true); + save_switch (compare_debug_replacement_opt, 0, NULL, validated, true, + /* TODO */ /* lang_mask */ cl_options[opt_index].flags); return true; case OPT_fdiagnostics_color_: @@ -3783,12 +3822,14 @@ driver_handle_option (struct gcc_options *opts, case OPT_L: /* Similarly, canonicalize -L for linkers that may not accept separate arguments. */ - save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true); + save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true, + /* TODO */ /* lang_mask */ cl_options[opt_index].flags); return true; case OPT_F: /* Likewise -F. */ - save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true); + save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true, + /* TODO */ /* lang_mask */ cl_options[opt_index].flags); return true; case OPT_save_temps: @@ -3911,7 +3952,8 @@ driver_handle_option (struct gcc_options *opts, save_temps_prefix = xstrdup (arg); /* On some systems, ld cannot handle "-o" without a space. So split the option from its argument. */ - save_switch ("-o", 1, &arg, validated, true); + save_switch ("-o", 1, &arg, validated, true, + /* TODO */ /* lang_mask */ cl_options[opt_index].flags); return true; #ifdef ENABLE_DEFAULT_PIE @@ -3945,9 +3987,13 @@ driver_handle_option (struct gcc_options *opts, } if (do_save) + { + FPRINTF(stderr, "%s: %s\n", __FUNCTION__, decoded->orig_option_with_args_text); save_switch (decoded->canonical_option[0], decoded->canonical_option_num_elements - 1, - &decoded->canonical_option[1], validated, true); + &decoded->canonical_option[1], validated, true, + /* TODO */ /* lang_mask */ cl_options[opt_index].flags); + } return true; } @@ -4386,7 +4432,8 @@ process_command (unsigned int decoded_options_count, if (compare_debug == 2 || compare_debug == 3) { const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL); - save_switch (opt, 0, NULL, false, true); + save_switch (opt, 0, NULL, false, true, + /* TODO */ cl_options[OPT_fcompare_debug_].flags); compare_debug = 1; } @@ -4779,7 +4826,8 @@ do_self_spec (const char *spec) save_switch (decoded_options[j].canonical_option[0], (decoded_options[j].canonical_option_num_elements - 1), - &decoded_options[j].canonical_option[1], false, true); + &decoded_options[j].canonical_option[1], false, true, + /* TODO */ cl_options[decoded_options[j].opt_index].flags); break; default: @@ -6010,6 +6058,7 @@ mark_matching_switches (const char *atom, const char *end_atom, int starred) static inline void process_marked_switches (void) { + //FPRINTF(stderr, "%s\n", __FUNCTION__); int i; for (i = 0; i < n_switches; i++) @@ -6204,6 +6253,7 @@ static const char * process_brace_body (const char *p, const char *atom, const char *end_atom, int starred, int matched) { + //FPRINTF(stderr, "%s(\"%s\")\n", __FUNCTION__, p); const char *body, *end_body; unsigned int nesting_level; bool have_subst = false; @@ -6269,6 +6319,7 @@ process_brace_body (const char *p, const char *atom, const char *end_atom, } } } + //FPRINTF(stderr, "%s\n", __FUNCTION__); return p; @@ -6368,6 +6419,35 @@ check_live_switch (int switchnum, int prefix_length) static void give_switch (int switchnum, int omit_first_word) { + FPRINTF(stderr, "%s (%d, %d)\n", __FUNCTION__, switchnum, omit_first_word); + int lang_mask = switches[switchnum].lang_mask & ((1U << cl_lang_count) - 1); + FPRINTF(stderr, " -%s 0x%x (0x%x)\n", + switches[switchnum].part1, switches[switchnum].lang_mask, lang_mask); + unsigned int lang_mask_accept = (1U << cl_lang_count) - 1; + //gcc_assert (input_file_compiler); + /* TODO: It seems to work, but I'm not concinved that looking at + infiles[input_file_number] here is actually correct; that it will always + be correctly set up here, that is, will always point to the infile we're + currently evaluating specs for. So we need to have some way of knowing + what our current "specs processing context" is. */ + /* TODO: hard-coding "cpp-output-with-lang-complain-none" and CL_C here is + ugly. We should instead have a new field in struct infile, or something + like that. */ + if (infiles[input_file_number].language + && strcmp (infiles[input_file_number].language, + "cpp-output-with-lang-complain-none") == 0) + lang_mask_accept = CL_C; + FPRINTF(stderr, " %s: lang_mask_accept=0x%x\n", infiles[input_file_number].language, lang_mask_accept); + /* TODO: now we know whether a switch is not specific to a language (keep), + specific to languages but including the one we're interested in (keep), or + not (drop). */ + if (lang_mask != 0 + && !(lang_mask & lang_mask_accept)) + { + FPRINTF(stderr, " dropped\n"); + return; + } + if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0) return; @@ -7162,6 +7242,8 @@ driver::build_multilib_strings () const void driver::set_up_specs () const { + FPRINTF(stderr, "%s\n", __FUNCTION__); + const char *spec_machine_suffix; char *specs_file; size_t i; @@ -7448,22 +7530,16 @@ driver::maybe_putenv_COLLECT_LTO_WRAPPER () const void driver::maybe_putenv_OFFLOAD_TARGETS () const { - const char *targets = offload_targets; + FPRINTF(stderr, "OFFLOAD_TARGETS = %s\n", offload_targets); - /* If no targets specified by -foffload, use all available targets. */ - if (!targets) - targets = OFFLOAD_TARGETS; - - if (strlen (targets) > 0) + if (offload_targets && offload_targets[0] != '\0') { obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=", sizeof ("OFFLOAD_TARGET_NAMES=") - 1); - obstack_grow (&collect_obstack, targets, - strlen (targets) + 1); + obstack_grow (&collect_obstack, offload_targets, + strlen (offload_targets) + 1); xputenv (XOBFINISH (&collect_obstack, char *)); } - - free (offload_targets); } /* Reject switches that no pass was interested in. */ @@ -7767,6 +7843,8 @@ driver::do_spec_on_infiles () const debug_check_temp_file[1] = NULL; } + FPRINTF(stderr, "%s: %s\n", __FUNCTION__, gcc_input_filename); + FPRINTF(stderr, " %s\n", input_file_compiler->spec); value = do_spec (input_file_compiler->spec); infiles[i].compiled = true; if (value < 0) @@ -9507,6 +9585,78 @@ greater_than_spec_func (int argc, const char **argv) return NULL; } +/* If applicable, generate a C source file containing a constructor call to + GOMP_set_offload_targets, to inform libgomp which offload targets have + actually been requested (-foffload=[...]), and adds that as an infile. */ + +static const char * +add_omp_infile_spec_func (int argc, const char **) +{ + gcc_assert (argc == 0); + gcc_assert (offload_targets != NULL); + + /* Nothing to do if we're not actually linking. */ + if (have_c) + return NULL; + + int err; + const char *tmp_filename; + tmp_filename = make_temp_file (".c"); + FPRINTF(stderr, "%s: %s\n", __FUNCTION__, tmp_filename); + record_temp_file (tmp_filename, !save_temps_flag, !save_temps_flag); + FILE *f = fopen (tmp_filename, "w"); + if (f == NULL) + fatal_error (input_location, + "could not open temporary file %s", tmp_filename); + /* As libgomp uses constructors internally, and this code is only added when + linking against libgomp, it is fine to use a constructor here. */ + err = fprintf (f, + "extern void GOMP_set_offload_targets (const char *);\n" + "static __attribute__ ((constructor)) void\n" + "init (void)\n" + "{\n" + " GOMP_set_offload_targets (\"%s\");\n" + "}\n", + offload_targets); + if (err < 0) + fatal_error (input_location, + "could not write to temporary file %s", tmp_filename); + err = fclose (f); + if (err == EOF) + fatal_error (input_location, + "could not close temporary file %s", tmp_filename); + + //TODO: correct thing to do? +#if 1 + add_infile (tmp_filename, "cpp-output-with-lang-complain-none"); + return NULL; +#elif 0 + return tmp_filename; +#elif 0 + store_arg ("-x", 0, 0); + store_arg ("cpp-output", 0, 0); + store_arg (tmp_filename, 0, 0); + return NULL; +#else + //add_infile (tmp_filename, /* TODO */ "cpp-output"); + //int i = n_infiles - 1; + //input_file_number = i; + set_input (tmp_filename); + //outfiles[i] = gcc_input_filename; + input_file_compiler + = lookup_compiler (gcc_input_filename, input_filename_length, + "cpp-output"); + err = do_spec (input_file_compiler->spec); + //infiles[i].compiled = true; + if (err < 0) + { + delete_failure_queue (); + errorcount++; + } + clear_failure_queue (); +#endif +} + /* Insert backslash before spaces in ORIG (usually a file path), to avoid being broken by spec parser. diff --git libgomp/config.h.in libgomp/config.h.in index 8533f03..d9d5914 100644 --- libgomp/config.h.in +++ libgomp/config.h.in @@ -24,6 +24,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the `fnmatch' function. */ +#undef HAVE_FNMATCH + +/* Define to 1 if you have the header file. */ +#undef HAVE_FNMATCH_H + /* Define to 1 if you have the `getloadavg' function. */ #undef HAVE_GETLOADAVG @@ -95,7 +101,7 @@ */ #undef LT_OBJDIR -/* Define to hold the list of target names suitable for offloading. */ +/* Define to hold the list of offload targets, separated by colons. */ #undef OFFLOAD_TARGETS /* Name of package */ diff --git libgomp/configure libgomp/configure index c93e877..3d990bb 100755 --- libgomp/configure +++ libgomp/configure @@ -15119,6 +15119,33 @@ esac offload_targets= plugin_support=yes +for ac_header in fnmatch.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "fnmatch.h" "ac_cv_header_fnmatch_h" "$ac_includes_default" +if test "x$ac_cv_header_fnmatch_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_FNMATCH_H 1 +_ACEOF + +else + plugin_support=no +fi + +done + +for ac_func in fnmatch +do : + ac_fn_c_check_func "$LINENO" "fnmatch" "ac_cv_func_fnmatch" +if test "x$ac_cv_func_fnmatch" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_FNMATCH 1 +_ACEOF + +else + plugin_support=no +fi +done + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlsym in -ldl" >&5 $as_echo_n "checking for dlsym in -ldl... " >&6; } if test "${ac_cv_lib_dl_dlsym+set}" = set; then : @@ -15236,10 +15263,8 @@ if test x"$enable_offload_targets" != x; then tgt=`echo $tgt | sed 's/=.*//'` case $tgt in *-intelmic-* | *-intelmicemul-*) - tgt_name=intelmic ;; nvptx*) - tgt_name=nvptx PLUGIN_NVPTX=$tgt PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS @@ -15282,9 +15307,9 @@ rm -f core conftest.err conftest.$ac_objext \ ;; esac if test x"$offload_targets" = x; then - offload_targets=$tgt_name + offload_targets=$tgt else - offload_targets=$offload_targets,$tgt_name + offload_targets=$offload_targets:$tgt fi if test x"$tgt_dir" != x; then offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin" diff --git libgomp/env.c libgomp/env.c index 1811bf5..6b5e963 100644 --- libgomp/env.c +++ libgomp/env.c @@ -1175,11 +1175,7 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy) } -/* TODO. See testsuite/lib/libgomp.exp:libgomp_init. */ -#if 0 -static -#endif -void __attribute__((constructor)) +static void __attribute__((constructor)) initialize_env (void) { unsigned long thread_limit_var, stacksize; diff --git libgomp/libgomp.h libgomp/libgomp.h index 420a525..1f95906 100644 --- libgomp/libgomp.h +++ libgomp/libgomp.h @@ -785,6 +785,7 @@ extern void gomp_unmap_vars (struct target_mem_desc *, bool); extern void gomp_init_device (struct gomp_device_descr *); extern void gomp_fini_device (struct gomp_device_descr *); extern void gomp_unload_device (struct gomp_device_descr *); +extern bool gomp_offload_target_available_p (int); /* work.c */ diff --git libgomp/libgomp.map libgomp/libgomp.map index 36932d3..05e75fb0 100644 --- libgomp/libgomp.map +++ libgomp/libgomp.map @@ -339,6 +339,7 @@ GOACC_2.0.GOMP_4_BRANCH { GOACC_get_ganglocal_ptr; GOACC_parallel_keyed; GOACC_register_static; + GOMP_set_offload_targets; } GOACC_2.0; GOMP_PLUGIN_1.0 { @@ -352,9 +353,3 @@ GOMP_PLUGIN_1.0 { GOMP_PLUGIN_async_unmap_vars; GOMP_PLUGIN_acc_thread; }; - -# TODO. See testsuite/lib/libgomp.exp:libgomp_init. -INTERNAL { - global: - initialize_env; -}; diff --git libgomp/libgomp_g.h libgomp/libgomp_g.h index e65b888..e67fc86 100644 --- libgomp/libgomp_g.h +++ libgomp/libgomp_g.h @@ -206,6 +206,7 @@ extern void GOMP_single_copy_end (void *); /* target.c */ +extern void GOMP_set_offload_targets (const char *); extern void GOMP_target (int, void (*) (void *), const void *, size_t, void **, size_t *, unsigned char *); extern void GOMP_target_data (int, const void *, diff --git libgomp/oacc-init.c libgomp/oacc-init.c index 8dfe4a7..78f130c 100644 --- libgomp/oacc-init.c +++ libgomp/oacc-init.c @@ -122,7 +122,9 @@ resolve_device (acc_device_t d, bool fail_is_error) { if (goacc_device_type) { - /* Lookup the named device. */ + /* Lookup the device that has been explicitly named, so do not pay + attention to gomp_offload_target_available_p. (That is, hard + error if not actually available.) */ while (++d != _ACC_device_hwm) if (dispatchers[d] && !strcasecmp (goacc_device_type, @@ -148,8 +150,14 @@ resolve_device (acc_device_t d, bool fail_is_error) case acc_device_not_host: /* Find the first available device after acc_device_not_host. */ while (++d != _ACC_device_hwm) - if (dispatchers[d] && dispatchers[d]->get_num_devices_func () > 0) + if (dispatchers[d] + && dispatchers[d]->get_num_devices_func () > 0 + /* No device has been explicitly named, so pay attention to + gomp_offload_target_available_p, to not decide on an offload + target that we don't have offload data available for. */ + && gomp_offload_target_available_p (dispatchers[d]->type)) goto found; + /* No non-host device found. */ if (d_arg == acc_device_default) { d = acc_device_host; @@ -164,9 +172,6 @@ resolve_device (acc_device_t d, bool fail_is_error) return NULL; break; - case acc_device_host: - break; - default: if (d > _ACC_device_hwm) { @@ -181,7 +186,8 @@ resolve_device (acc_device_t d, bool fail_is_error) assert (d != acc_device_none && d != acc_device_default - && d != acc_device_not_host); + && d != acc_device_not_host + && d < _ACC_device_hwm); if (dispatchers[d] == NULL && fail_is_error) { diff --git libgomp/plugin/configfrag.ac libgomp/plugin/configfrag.ac index 8c2a420..e2392e1 100644 --- libgomp/plugin/configfrag.ac +++ libgomp/plugin/configfrag.ac @@ -29,6 +29,8 @@ offload_targets= AC_SUBST(offload_targets) plugin_support=yes +AC_CHECK_HEADERS([fnmatch.h], , [plugin_support=no]) +AC_CHECK_FUNCS([fnmatch], , [plugin_support=no]) AC_CHECK_LIB(dl, dlsym, , [plugin_support=no]) if test x"$plugin_support" = xyes; then AC_DEFINE(PLUGIN_SUPPORT, 1, @@ -92,10 +94,8 @@ if test x"$enable_offload_targets" != x; then tgt=`echo $tgt | sed 's/=.*//'` case $tgt in *-intelmic-* | *-intelmicemul-*) - tgt_name=intelmic ;; nvptx*) - tgt_name=nvptx PLUGIN_NVPTX=$tgt PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS @@ -127,9 +127,9 @@ if test x"$enable_offload_targets" != x; then ;; esac if test x"$offload_targets" = x; then - offload_targets=$tgt_name + offload_targets=$tgt else - offload_targets=$offload_targets,$tgt_name + offload_targets=$offload_targets:$tgt fi if test x"$tgt_dir" != x; then offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin" @@ -141,7 +141,7 @@ if test x"$enable_offload_targets" != x; then done fi AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets", - [Define to hold the list of target names suitable for offloading.]) + [Define to hold the list of offload targets, separated by colons.]) AM_CONDITIONAL([PLUGIN_NVPTX], [test $PLUGIN_NVPTX = 1]) AC_DEFINE_UNQUOTED([PLUGIN_NVPTX], [$PLUGIN_NVPTX], [Define to 1 if the NVIDIA plugin is built, 0 if not.]) diff --git libgomp/target.c libgomp/target.c index 6426254..9cf5251 100644 --- libgomp/target.c +++ libgomp/target.c @@ -41,6 +41,7 @@ #ifdef PLUGIN_SUPPORT #include +#include #include "plugin-suffix.h" #endif @@ -122,17 +123,26 @@ gomp_get_num_devices (void) } static struct gomp_device_descr * -resolve_device (int device_id) +resolve_device (int device) { - if (device_id == GOMP_DEVICE_ICV) + int device_id; + if (device == GOMP_DEVICE_ICV) { struct gomp_task_icv *icv = gomp_icv (false); device_id = icv->default_device_var; } + else + device_id = device; if (device_id < 0 || device_id >= gomp_get_num_devices ()) return NULL; + /* If the device-var ICV does not actually have offload data available, don't + try use it (which will fail), and use host fallback instead. */ + if (device == GOMP_DEVICE_ICV + && !gomp_offload_target_available_p (devices[device_id].type)) + return NULL; + return &devices[device_id]; } @@ -947,6 +957,49 @@ gomp_fini_device (struct gomp_device_descr *devicep) devicep->is_initialized = false; } +/* Do we have offload data available for the given offload target type? + Instead of verifying that *all* offload data is available that could + possibly be required, we instead just look for *any*. If we later find any + offload data missing, that's user error. */ + +attribute_hidden bool +gomp_offload_target_available_p (int type) +{ + bool available = false; + + /* Has the offload target already been initialized? */ + for (int i = 0; !available && i < num_devices; i++) + { + struct gomp_device_descr *devicep = &devices[i]; + gomp_mutex_lock (&devicep->lock); + if (devicep->type == type && devicep->is_initialized) + available = true; + gomp_mutex_unlock (&devicep->lock); + } + + if (!available) + { + // TODO: locking correct? + gomp_mutex_lock (®ister_lock); + + /* If there is no offload data available at all, we cannot later fail to + find any of it for a specific offload target. This is the case where + there are no offloaded code regions in user code, but there can still + be executable directives used, or runtime library calls made. */ + if (num_offload_images == 0) + available = true; + + /* Can the offload target be initialized? */ + for (int i = 0; !available && i < num_offload_images; i++) + if (offload_images[i].type == type) + available = true; + + gomp_mutex_unlock (®ister_lock); + } + + return available; +} + /* Called when encountering a target directive. If DEVICE is GOMP_DEVICE_ICV, it means use device-var ICV. If it is GOMP_DEVICE_HOST_FALLBACK (or any value @@ -1116,6 +1169,8 @@ static bool gomp_load_plugin_for_device (struct gomp_device_descr *device, const char *plugin_name) { + gomp_debug (0, "%s (\"%s\")\n", __FUNCTION__, plugin_name); + const char *err = NULL, *last_missing = NULL; void *plugin_handle = dlopen (plugin_name, RTLD_LAZY); @@ -1212,6 +1267,38 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device, return 0; } +/* Helper, to translate from an offload target to the corresponding plugin name. */ + +static const char * +offload_target_to_plugin_name (const char *offload_target) +{ + if (fnmatch ("*-intelmic*", offload_target, 0) == 0) + return "intelmic"; + if (fnmatch ("nvptx*", offload_target, 0) == 0) + return "nvptx"; + gomp_fatal ("Unknown offload target: %s", offload_target); +} + +/* List of offload targets, separated by colon. Defaults to the list + determined when configuring libgomp. */ +static const char *gomp_offload_targets = OFFLOAD_TARGETS; + +/* Override the list of offload targets. This must be called early, and only + once. */ + +void +GOMP_set_offload_targets (const char *offload_targets) +{ + gomp_debug (0, "%s (\"%s\")\n", __FUNCTION__, offload_targets); + + //TODO: any locking? + /* Make sure this gets called early. */ + assert (gomp_is_initialized == PTHREAD_ONCE_INIT); + ///* Make sure this only gets called once. */ + //assert (gomp_offload_targets == OFFLOAD_TARGETS); + gomp_offload_targets = offload_targets; +} + /* This function initializes the runtime needed for offloading. It parses the list of offload targets and tries to load the plugins for these targets. On return, the variables NUM_DEVICES and NUM_DEVICES_OPENMP @@ -1219,11 +1306,12 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device, corresponding devices, first the GOMP_OFFLOAD_CAP_OPENMP_400 ones, follows by the others. */ +static const char *gomp_plugin_prefix ="libgomp-plugin-"; +static const char *gomp_plugin_suffix = SONAME_SUFFIX (1); + static void gomp_target_init (void) { - const char *prefix ="libgomp-plugin-"; - const char *suffix = SONAME_SUFFIX (1); const char *cur, *next; char *plugin_name; int i, new_num_devices; @@ -1231,48 +1319,60 @@ gomp_target_init (void) num_devices = 0; devices = NULL; - cur = OFFLOAD_TARGETS; + cur = gomp_offload_targets; if (*cur) do { + next = strchr (cur, ':'); + /* If no other offload target following... */ + if (next == NULL) + /* ..., point to the terminating NUL character. */ + next = cur + strlen (cur); + + size_t gomp_plugin_prefix_len = strlen (gomp_plugin_prefix); + size_t cur_len = next - cur; + size_t gomp_plugin_suffix_len = strlen (gomp_plugin_suffix); + plugin_name = gomp_malloc (gomp_plugin_prefix_len + + cur_len + + gomp_plugin_suffix_len + + 1); + memcpy (plugin_name, gomp_plugin_prefix, gomp_plugin_prefix_len); + memcpy (plugin_name + gomp_plugin_prefix_len, cur, cur_len); + /* NUL-terminate the string here... */ + plugin_name[gomp_plugin_prefix_len + cur_len] = '\0'; + /* ..., so that we can then use it to translate the offload target to + the plugin name... */ + const char *cur_plugin_name + = offload_target_to_plugin_name (plugin_name + + gomp_plugin_prefix_len); + size_t cur_plugin_name_len = strlen (cur_plugin_name); + assert (cur_plugin_name_len <= cur_len); + /* ..., and then rewrite it. */ + memcpy (plugin_name + gomp_plugin_prefix_len, + cur_plugin_name, cur_plugin_name_len); + memcpy (plugin_name + gomp_plugin_prefix_len + cur_plugin_name_len, + gomp_plugin_suffix, gomp_plugin_suffix_len); + plugin_name[gomp_plugin_prefix_len + + cur_plugin_name_len + + gomp_plugin_suffix_len] = '\0'; + struct gomp_device_descr current_device; - - next = strchr (cur, ','); - - plugin_name = (char *) malloc (1 + (next ? next - cur : strlen (cur)) - + strlen (prefix) + strlen (suffix)); - if (!plugin_name) - { - num_devices = 0; - break; - } - - strcpy (plugin_name, prefix); - strncat (plugin_name, cur, next ? next - cur : strlen (cur)); - strcat (plugin_name, suffix); - if (gomp_load_plugin_for_device (¤t_device, plugin_name)) { new_num_devices = current_device.get_num_devices_func (); if (new_num_devices >= 1) { - /* Augment DEVICES and NUM_DEVICES. */ - - devices = realloc (devices, (num_devices + new_num_devices) - * sizeof (struct gomp_device_descr)); - if (!devices) - { - num_devices = 0; - free (plugin_name); - break; - } - current_device.name = current_device.get_name_func (); /* current_device.capabilities has already been set. */ current_device.type = current_device.get_type_func (); current_device.mem_map.root = NULL; current_device.is_initialized = false; current_device.openacc.data_environ = NULL; + + /* Augment DEVICES and NUM_DEVICES. */ + devices = gomp_realloc (devices, + ((num_devices + new_num_devices) + * sizeof (struct gomp_device_descr))); for (i = 0; i < new_num_devices; i++) { current_device.target_id = i; @@ -1286,18 +1386,12 @@ gomp_target_init (void) free (plugin_name); cur = next + 1; } - while (next); + while (*next); /* In DEVICES, sort the GOMP_OFFLOAD_CAP_OPENMP_400 ones first, and set NUM_DEVICES_OPENMP. */ struct gomp_device_descr *devices_s - = malloc (num_devices * sizeof (struct gomp_device_descr)); - if (!devices_s) - { - num_devices = 0; - free (devices); - devices = NULL; - } + = gomp_malloc (num_devices * sizeof (struct gomp_device_descr)); num_devices_openmp = 0; for (i = 0; i < num_devices; i++) if (devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp index 33d1a54..898dfc3 100644 --- libgomp/testsuite/lib/libgomp.exp +++ libgomp/testsuite/lib/libgomp.exp @@ -36,24 +36,21 @@ load_gcc_lib fortran-modules.exp load_file libgomp-test-support.exp # Populate offload_targets_s (offloading targets separated by a space), and -# offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells -# some of them a little differently). -set offload_targets_s [split $offload_targets ","] +# offload_targets_s_openacc (those suitable for OpenACC). +set offload_targets_s [split $offload_targets ":"] set offload_targets_s_openacc {} foreach offload_target_openacc $offload_targets_s { - switch $offload_target_openacc { - intelmic { + switch -glob $offload_target_openacc { + *-intelmic* { # TODO. Skip; will all FAIL because of missing # GOMP_OFFLOAD_CAP_OPENACC_200. continue } - nvptx { - set offload_target_openacc "nvidia" - } } lappend offload_targets_s_openacc "$offload_target_openacc" } -lappend offload_targets_s_openacc "host" +# Host fallback. +lappend offload_targets_s_openacc "disable" set dg-do-what-default run @@ -134,7 +131,7 @@ proc libgomp_init { args } { # Add liboffloadmic build directory in LD_LIBRARY_PATH to support # non-fallback testing for Intel MIC targets global offload_targets - if { [string match "*,intelmic,*" ",$offload_targets,"] } { + if { [string match "*:*-intelmic*:*" ":$offload_targets:"] } { append always_ld_library_path ":${blddir}/../liboffloadmic/.libs" append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs" # libstdc++ is required by liboffloadmic @@ -235,56 +232,6 @@ proc libgomp_init { args } { if { $offload_additional_options != "" } { lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}" } - - # TODO. Evil hack. DejaGnu doesn't have a mechanism for setting - # environment variables on remote boards. Thus, we have to fake it, using - # GCC's constructor attributes to create object files that install the - # desired environment variables. - set e_list [list \ - [list defaults DUMMY=dummy ] \ - [list ACC_DEVICE_TYPE-host ACC_DEVICE_TYPE=host ] \ - [list ACC_DEVICE_TYPE-nvidia ACC_DEVICE_TYPE=nvidia ] ] - foreach e $e_list { - set v [lindex $e 0] - set s [lindex $e 1] - verbose "creating constructor-setenv: $v: $s" - set src constructor-setenv-$v.c - set obj constructor-setenv-$v.o - set f_src [open $src "w"] - puts $f_src "static void __attribute__((constructor(1000)))" - puts $f_src "init_env(void) {" - puts $f_src " int putenv(char *);" - puts $f_src " putenv(\"$s\");" - puts $f_src "}" - if { $v == "defaults" } { - # TODO. We want libgomp to initialize after the putenv calls. - # But: shared libraries' constructors (and thus - # env.c:initialize_env) will be called before the executable's - # (init_env functions created above), so it will already have been - # initialized (and has to be, in case we're not linking in this - # gunk). Assuming no execution of other libgomp functionality in - # between (which we're not doing during initialization), - # initialize_env's effects are idempotent when calling it again, so - # we'll do that now, after the putenv calls have been executed. - puts $f_src "static void __attribute__((constructor(1001)))" - puts $f_src "init_libgomp(void) {" - # Some test cases specify -fno-openmp, so libgomp isn't linked in. - puts $f_src " void initialize_env(void) __attribute__((weak));" - puts $f_src " if (initialize_env)" - puts $f_src " initialize_env();" - puts $f_src "}" - } - close $f_src - # TODO. Using whichever compiler is currently configured... At least - # switch it into C mode. - set lines [libgomp_target_compile $src $obj object "additional_flags=-xc"] - # TODO. Error checking. - file delete $src - } - # When adding constructor-setenv-*.o files, make sure to cancel any -x flag - # that may have been set before. - lappend ALWAYS_CFLAGS "ldflags=-x none" - lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-defaults.o" } # @@ -296,6 +243,7 @@ proc libgomp_target_compile { source dest type options } { global libgomp_compile_options global gluefile wrap_flags global ALWAYS_CFLAGS + global GCC_UNDER_TEST global lang_test_file global lang_library_path global lang_link_flags @@ -323,6 +271,7 @@ proc libgomp_target_compile { source dest type options } { lappend options "additional_flags=[libio_include_flags]" lappend options "timeout=[timeout_value]" + lappend options "compiler=$GCC_UNDER_TEST" set options [concat $libgomp_compile_options $options] @@ -370,7 +319,7 @@ proc check_effective_target_offload_device { } { proc check_effective_target_openacc_nvidia_accel_supported { } { global offload_targets_s_openacc - set res [lsearch $offload_targets_s_openacc "nvidia" ] + set res [lsearch -glob $offload_targets_s_openacc "nvptx*" ] if { $res != -1 } { return 1; } @@ -396,7 +345,7 @@ proc check_effective_target_openacc_nvidia_accel_selected { } { return 0; } global offload_target_openacc - if { $offload_target_openacc == "nvidia" } { + if { [string match "nvptx*" $offload_target_openacc] } { return 1; } return 0; @@ -406,7 +355,7 @@ proc check_effective_target_openacc_nvidia_accel_selected { } { proc check_effective_target_openacc_host_selected { } { global offload_target_openacc - if { $offload_target_openacc == "host" } { + if { $offload_target_openacc == "disable" } { return 1; } return 0; diff --git libgomp/testsuite/libgomp.c++/c++.exp libgomp/testsuite/libgomp.c++/c++.exp index d6d525a..0454f95 100644 --- libgomp/testsuite/libgomp.c++/c++.exp +++ libgomp/testsuite/libgomp.c++/c++.exp @@ -4,7 +4,6 @@ load_gcc_lib gcc-dg.exp global shlib_ext set shlib_ext [get_shlib_extension] -#TODO set lang_link_flags "-lstdc++" set lang_test_file_found 0 set lang_library_path "../libstdc++-v3/src/.libs" @@ -47,13 +46,6 @@ if { $blddir != "" } { } if { $lang_test_file_found } { - if ![info exists GXX_UNDER_TEST] then { - # TODO. See libgomp.oacc-c++/c++.exp. - set HAVE_SET_GXX_UNDER_TEST "" - set GXX_UNDER_TEST "$GCC_UNDER_TEST" - } - lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [find $srcdir/$subdir *.C]] @@ -76,10 +68,5 @@ if { $lang_test_file_found } { dg-runtest $tests "" "$libstdcxx_includes $DEFAULT_CFLAGS" } -# TODO. See above. -if { [info exists HAVE_SET_GXX_UNDER_TEST] } { - unset GXX_UNDER_TEST -} - # All done. dg-finish diff --git libgomp/testsuite/libgomp.c/c.exp libgomp/testsuite/libgomp.c/c.exp index 25f347b..300b921 100644 --- libgomp/testsuite/libgomp.c/c.exp +++ libgomp/testsuite/libgomp.c/c.exp @@ -23,8 +23,6 @@ dg-init # Turn on OpenMP. lappend ALWAYS_CFLAGS "additional_flags=-fopenmp" -lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [find $srcdir/$subdir *.c]] diff --git libgomp/testsuite/libgomp.fortran/fortran.exp libgomp/testsuite/libgomp.fortran/fortran.exp index 883c416..f684abc 100644 --- libgomp/testsuite/libgomp.fortran/fortran.exp +++ libgomp/testsuite/libgomp.fortran/fortran.exp @@ -47,11 +47,6 @@ if { $blddir != "" } { } if { $lang_test_file_found } { - if ![info exists GFORTRAN_UNDER_TEST] then { - set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST - } - lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]] diff --git libgomp/testsuite/libgomp.graphite/graphite.exp libgomp/testsuite/libgomp.graphite/graphite.exp index 716cdc3..d737c85 100644 --- libgomp/testsuite/libgomp.graphite/graphite.exp +++ libgomp/testsuite/libgomp.graphite/graphite.exp @@ -48,8 +48,6 @@ dg-init # Turn on OpenMP. lappend ALWAYS_CFLAGS "additional_flags=-fopenmp" -lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [find $srcdir/$subdir *.c]] diff --git libgomp/testsuite/libgomp.oacc-c++/c++.exp libgomp/testsuite/libgomp.oacc-c++/c++.exp index e5c875c..f513d87 100644 --- libgomp/testsuite/libgomp.oacc-c++/c++.exp +++ libgomp/testsuite/libgomp.oacc-c++/c++.exp @@ -13,7 +13,6 @@ load_gcc_lib gcc-dg.exp global shlib_ext set shlib_ext [get_shlib_extension] -#TODO set lang_link_flags "-lstdc++" set lang_test_file_found 0 set lang_library_path "../libstdc++-v3/src/.libs" @@ -32,6 +31,11 @@ dg-init # Turn on OpenACC. lappend ALWAYS_CFLAGS "additional_flags=-fopenacc" +# Switch into C++ mode. Otherwise, the libgomp.oacc-c-c++-common/*.c +# files would be compiled as C files. +set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST" +set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++" + set blddir [lookfor_file [get_multilibs] libgomp] @@ -56,14 +60,6 @@ if { $blddir != "" } { } if { $lang_test_file_found } { - if ![info exists GXX_UNDER_TEST] then { - # Use GCC_UNDER_TEST, but switch into C++ mode, as otherwise the - # libgomp.oacc-c-c++-common/*.c files would be compiled as C files. - set HAVE_SET_GXX_UNDER_TEST "" - set GXX_UNDER_TEST "$GCC_UNDER_TEST -x c++" - } - lappend libgomp_compile_options "compiler=$GXX_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [concat \ [find $srcdir/$subdir *.C] \ @@ -104,17 +100,14 @@ if { $lang_test_file_found } { set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS" foreach offload_target_openacc $offload_targets_s_openacc { set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS" - set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1" - # Set $ACC_DEVICE_TYPE. See the comments in - # ../lib/libgomp.exp:libgomp_init. - lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o" # Todo: Determine shared memory or not using run-time test. - switch $offload_target_openacc { - host { + switch -glob $offload_target_openacc { + disable { set acc_mem_shared 1 + set tagopt "-DACC_DEVICE_TYPE_host=1" } - nvidia { + nvptx* { if { ![check_effective_target_openacc_nvidia_accel_present] } { # Don't bother; execution testing is going to FAIL. untested "$subdir $offload_target_openacc offloading" @@ -128,12 +121,14 @@ if { $lang_test_file_found } { lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common" set acc_mem_shared 0 + set tagopt "-DACC_DEVICE_TYPE_nvidia=1" } default { set acc_mem_shared 0 + #TODO error } } - set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared" + set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared -foffload=$offload_target_openacc" dg-runtest $tests "$tagopt" "$libstdcxx_includes $DEFAULT_CFLAGS" gcc-dg-runtest $ttests "$tagopt" "$libstdcxx_includes" @@ -141,9 +136,7 @@ if { $lang_test_file_found } { } # See above. -if { [info exists HAVE_SET_GXX_UNDER_TEST] } { - unset GXX_UNDER_TEST -} +set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST" unset TORTURE_OPTIONS diff --git libgomp/testsuite/libgomp.oacc-c/c.exp libgomp/testsuite/libgomp.oacc-c/c.exp index c91a41b..03fe3a4 100644 --- libgomp/testsuite/libgomp.oacc-c/c.exp +++ libgomp/testsuite/libgomp.oacc-c/c.exp @@ -32,8 +32,6 @@ dg-init # Turn on OpenACC. lappend ALWAYS_CFLAGS "additional_flags=-fopenacc" -lappend libgomp_compile_options "compiler=$GCC_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [concat \ [find $srcdir/$subdir *.c] \ @@ -62,17 +60,14 @@ set_ld_library_path_env_vars set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS" foreach offload_target_openacc $offload_targets_s_openacc { set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS" - set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1" - # Set $ACC_DEVICE_TYPE. See the comments in - # ../lib/libgomp.exp:libgomp_init. - lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o" # Todo: Determine shared memory or not using run-time test. - switch $offload_target_openacc { - host { + switch -glob $offload_target_openacc { + disable { set acc_mem_shared 1 + set tagopt "-DACC_DEVICE_TYPE_host=1" } - nvidia { + nvptx* { if { ![check_effective_target_openacc_nvidia_accel_present] } { # Don't bother; execution testing is going to FAIL. untested "$subdir $offload_target_openacc offloading" @@ -86,12 +81,14 @@ foreach offload_target_openacc $offload_targets_s_openacc { lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common" set acc_mem_shared 0 + set tagopt "-DACC_DEVICE_TYPE_nvidia=1" } default { set acc_mem_shared 0 + #TODO error } } - set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared" + set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared -foffload=$offload_target_openacc" dg-runtest $tests "$tagopt" $DEFAULT_CFLAGS gcc-dg-runtest $ttests "$tagopt" "" diff --git libgomp/testsuite/libgomp.oacc-fortran/fortran.exp libgomp/testsuite/libgomp.oacc-fortran/fortran.exp index df46004..b9ad6dc 100644 --- libgomp/testsuite/libgomp.oacc-fortran/fortran.exp +++ libgomp/testsuite/libgomp.oacc-fortran/fortran.exp @@ -49,11 +49,6 @@ if { $blddir != "" } { } if { $lang_test_file_found } { - if ![info exists GFORTRAN_UNDER_TEST] then { - set GFORTRAN_UNDER_TEST $GCC_UNDER_TEST - } - lappend libgomp_compile_options "compiler=$GFORTRAN_UNDER_TEST" - # Gather a list of all tests. set tests [lsort [find $srcdir/$subdir *.\[fF\]{,90,95,03,08}]] @@ -74,20 +69,14 @@ if { $lang_test_file_found } { set_ld_library_path_env_vars # Test OpenACC with available accelerators. - set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS" foreach offload_target_openacc $offload_targets_s_openacc { - set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS" - set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1" - # Set $ACC_DEVICE_TYPE. See the comments in - # ../lib/libgomp.exp:libgomp_init. - lappend ALWAYS_CFLAGS "ldflags=constructor-setenv-ACC_DEVICE_TYPE-$offload_target_openacc.o" - # Todo: Determine shared memory or not using run-time test. - switch $offload_target_openacc { - host { + switch -glob $offload_target_openacc { + disable { set acc_mem_shared 1 + set tagopt "-DACC_DEVICE_TYPE_host=1" } - nvidia { + nvptx* { if { ![check_effective_target_openacc_nvidia_accel_present] } { # Don't bother; execution testing is going to FAIL. untested "$subdir $offload_target_openacc offloading" @@ -95,12 +84,14 @@ if { $lang_test_file_found } { } set acc_mem_shared 0 + set tagopt "-DACC_DEVICE_TYPE_nvidia=1" } default { set acc_mem_shared 0 + #TODO error } } - set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared" + set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared -foffload=$offload_target_openacc" # For Fortran we're doing torture testing, as Fortran has far more tests # with arrays etc. that testing just -O0 or -O2 is insufficient, that is