From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111343 invoked by alias); 28 Dec 2018 11:44:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 111325 invoked by uid 89); 28 Dec 2018 11:44:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=whenever, julian, whereas, clause 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; Fri, 28 Dec 2018 11:44:42 +0000 Received: from svr-orw-mbx-06.mgc.mentorg.com ([147.34.90.206]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gcqZF-0000ak-7B from Thomas_Schwinge@mentor.com ; Fri, 28 Dec 2018 03:44:41 -0800 Received: from svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) by SVR-ORW-MBX-06.mgc.mentorg.com (147.34.90.206) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 28 Dec 2018 03:44:38 -0800 Received: from tftp-cs (147.34.91.1) by svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) with Microsoft SMTP Server id 15.0.1320.4 via Frontend Transport; Fri, 28 Dec 2018 03:44:38 -0800 Received: by tftp-cs (Postfix, from userid 49978) id 53B83C220A; Fri, 28 Dec 2018 03:44:38 -0800 (PST) From: Thomas Schwinge To: CC: Jakub Jelinek , , =?utf-8?Q?Gerg?= =?utf-8?Q?=C3=B6?= Barany Subject: Re: For libgomp OpenACC entry points, redefine the "device" argument to "flags" In-Reply-To: References: <0fe4cc25-8ed3-831f-337f-c61fd54eb7f0@mentor.com> <6a1ccffb-b139-3bde-6e3d-198464051cbf@mentor.com> <20181219133838.GA23305@tucnak> <20181219140342.GB23305@tucnak> <20181219141812.GC23305@tucnak> User-Agent: Notmuch/0.9-125-g4686d11 (http://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Fri, 28 Dec 2018 14:04:00 -0000 Message-ID: <87r2e1q3j4.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-12/txt/msg01727.txt.bz2 Hi! On Wed, 19 Dec 2018 22:56:05 +0100, I wrote: > On Wed, 19 Dec 2018 15:18:12 +0100, Jakub Jelinek wrot= e: > > On Wed, Dec 19, 2018 at 03:03:42PM +0100, Jakub Jelinek wrote: > > > On Wed, Dec 19, 2018 at 02:59:54PM +0100, Thomas Schwinge wrote: > > > > Right. For OpenACC, there's no "device" clause, so we only ever pa= ssed > > > > in "GOMP_DEVICE_ICV" (default), or "GOMP_DEVICE_HOST_FALLBACK" ("if > > > > (false)" clause). Therefore, the libgomp "resolve_legacy_flags" fu= nction > > > > added to make sure that these two values (as used by old executable= s) > > > > continue to work as before (with new libgomp). (And, we have to ma= ke > > > > sure that no (new) "GOACC_FLAG_*" combination ever results in these > > > > values; will document that.) >=20 > > > LGTM then in principle. > Is the attached OK for trunk? No further comments received; committed the following to trunk in r267448: commit 813421cdb9712da2a4f3804c35b4a7328e81f88e Author: tschwinge Date: Fri Dec 28 11:34:14 2018 +0000 For libgomp OpenACC entry points, redefine the "device" argument to "fl= ags" =20=20=20=20 ... so that we're then able to use this for other flags in addition to "GOACC_FLAG_HOST_FALLBACK". =20=20=20=20 gcc/ * omp-expand.c (expand_omp_target): Restructure OpenACC vs. Ope= nMP code paths. Update for libgomp OpenACC entry points change. include/ * gomp-constants.h (GOACC_FLAG_HOST_FALLBACK) (GOACC_FLAGS_MARSHAL_OP, GOACC_FLAGS_UNMARSHAL): Define. libgomp/ * oacc-parallel.c (GOACC_parallel_keyed, GOACC_parallel) (GOACC_data_start, GOACC_enter_exit_data, GOACC_update) (GOACC_declare): Redefine the "device" argument to "flags". =20=20=20=20 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267448 138bc75d-0d04-04= 10-961f-82ee72b054a4 --- gcc/ChangeLog | 5 ++ gcc/omp-expand.c | 115 +++++++++++++++++++++++++++++------------= ---- gcc/tree-ssa-structalias.c | 4 +- include/ChangeLog | 5 ++ include/gomp-constants.h | 12 +++++ libgomp/ChangeLog | 6 +++ libgomp/oacc-parallel.c | 52 ++++++++++++-------- 7 files changed, 137 insertions(+), 62 deletions(-) diff --git gcc/ChangeLog gcc/ChangeLog index feaa4251815a..741c02d6cdae 100644 --- gcc/ChangeLog +++ gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-12-28 Thomas Schwinge + + * omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP + code paths. Update for libgomp OpenACC entry points change. + 2018-12-28 Thomas Schwinge Julian Brown =20 diff --git gcc/omp-expand.c gcc/omp-expand.c index b5cb4241508e..79bc9acb7711 100644 --- gcc/omp-expand.c +++ gcc/omp-expand.c @@ -7496,9 +7496,8 @@ expand_omp_target (struct omp_region *region) =20 /* Emit a library call to launch the offloading region, or do data transfers. */ - tree t1, t2, t3, t4, device, cond, depend, c, clauses; + tree t1, t2, t3, t4, depend, c, clauses; enum built_in_function start_ix; - location_t clause_loc; unsigned int flags_i =3D 0; =20 switch (gimple_omp_target_kind (entry_stmt)) @@ -7542,49 +7541,63 @@ expand_omp_target (struct omp_region *region) =20 clauses =3D gimple_omp_target_clauses (entry_stmt); =20 - /* By default, the value of DEVICE is GOMP_DEVICE_ICV (let runtime - library choose) and there is no conditional. */ - cond =3D NULL_TREE; - device =3D build_int_cst (integer_type_node, GOMP_DEVICE_ICV); + tree device =3D NULL_TREE; + location_t device_loc =3D UNKNOWN_LOCATION; + tree goacc_flags =3D NULL_TREE; + if (is_gimple_omp_oacc (entry_stmt)) + { + /* By default, no GOACC_FLAGs are set. */ + goacc_flags =3D integer_zero_node; + } + else + { + c =3D omp_find_clause (clauses, OMP_CLAUSE_DEVICE); + if (c) + { + device =3D OMP_CLAUSE_DEVICE_ID (c); + device_loc =3D OMP_CLAUSE_LOCATION (c); + } + else + { + /* By default, the value of DEVICE is GOMP_DEVICE_ICV (let runtime + library choose). */ + device =3D build_int_cst (integer_type_node, GOMP_DEVICE_ICV); + device_loc =3D gimple_location (entry_stmt); + } =20 + c =3D omp_find_clause (clauses, OMP_CLAUSE_NOWAIT); + if (c) + flags_i |=3D GOMP_TARGET_FLAG_NOWAIT; + } + + /* By default, there is no conditional. */ + tree cond =3D NULL_TREE; c =3D omp_find_clause (clauses, OMP_CLAUSE_IF); if (c) cond =3D OMP_CLAUSE_IF_EXPR (c); - - c =3D omp_find_clause (clauses, OMP_CLAUSE_DEVICE); - if (c) - { - /* Even if we pass it to all library function calls, it is currently= only - defined/used for the OpenMP target ones. */ - gcc_checking_assert (start_ix =3D=3D BUILT_IN_GOMP_TARGET - || start_ix =3D=3D BUILT_IN_GOMP_TARGET_DATA - || start_ix =3D=3D BUILT_IN_GOMP_TARGET_UPDATE - || start_ix =3D=3D BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA); - - device =3D OMP_CLAUSE_DEVICE_ID (c); - clause_loc =3D OMP_CLAUSE_LOCATION (c); - } - else - clause_loc =3D gimple_location (entry_stmt); - - c =3D omp_find_clause (clauses, OMP_CLAUSE_NOWAIT); - if (c) - flags_i |=3D GOMP_TARGET_FLAG_NOWAIT; - - /* Ensure 'device' is of the correct type. */ - device =3D fold_convert_loc (clause_loc, integer_type_node, device); - - /* If we found the clause 'if (cond)', build - (cond ? device : GOMP_DEVICE_HOST_FALLBACK). */ + /* If we found the clause 'if (cond)', build: + OpenACC: goacc_flags =3D (cond ? goacc_flags : flags | GOACC_FLAG_HOS= T_FALLBACK) + OpenMP: device =3D (cond ? device : GOMP_DEVICE_HOST_FALLBACK) */ if (cond) { + tree *tp; + if (is_gimple_omp_oacc (entry_stmt)) + tp =3D &goacc_flags; + else + { + /* Ensure 'device' is of the correct type. */ + device =3D fold_convert_loc (device_loc, integer_type_node, device); + + tp =3D &device; + } + cond =3D gimple_boolify (cond); =20 basic_block cond_bb, then_bb, else_bb; edge e; tree tmp_var; =20 - tmp_var =3D create_tmp_var (TREE_TYPE (device)); + tmp_var =3D create_tmp_var (TREE_TYPE (*tp)); if (offloaded) e =3D split_block_after_labels (new_bb); else @@ -7607,13 +7620,20 @@ expand_omp_target (struct omp_region *region) gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); =20 gsi =3D gsi_start_bb (then_bb); - stmt =3D gimple_build_assign (tmp_var, device); + stmt =3D gimple_build_assign (tmp_var, *tp); gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); =20 gsi =3D gsi_start_bb (else_bb); - stmt =3D gimple_build_assign (tmp_var, - build_int_cst (integer_type_node, - GOMP_DEVICE_HOST_FALLBACK)); + if (is_gimple_omp_oacc (entry_stmt)) + stmt =3D gimple_build_assign (tmp_var, + BIT_IOR_EXPR, + *tp, + build_int_cst (integer_type_node, + GOACC_FLAG_HOST_FALLBACK)); + else + stmt =3D gimple_build_assign (tmp_var, + build_int_cst (integer_type_node, + GOMP_DEVICE_HOST_FALLBACK)); gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); =20 make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE); @@ -7623,14 +7643,17 @@ expand_omp_target (struct omp_region *region) make_edge (then_bb, new_bb, EDGE_FALLTHRU); make_edge (else_bb, new_bb, EDGE_FALLTHRU); =20 - device =3D tmp_var; + *tp =3D tmp_var; + gsi =3D gsi_last_nondebug_bb (new_bb); } else { gsi =3D gsi_last_nondebug_bb (new_bb); - device =3D force_gimple_operand_gsi (&gsi, device, true, NULL_TREE, - true, GSI_SAME_STMT); + + if (device !=3D NULL_TREE) + device =3D force_gimple_operand_gsi (&gsi, device, true, NULL_TREE, + true, GSI_SAME_STMT); } =20 t =3D gimple_omp_target_data_arg (entry_stmt); @@ -7654,7 +7677,17 @@ expand_omp_target (struct omp_region *region) bool tagging =3D false; /* The maximum number used by any start_ix, without varargs. */ auto_vec args; - args.quick_push (device); + if (is_gimple_omp_oacc (entry_stmt)) + { + tree goacc_flags_m =3D fold_build1 (GOACC_FLAGS_MARSHAL_OP, + TREE_TYPE (goacc_flags), goacc_flags); + goacc_flags_m =3D force_gimple_operand_gsi (&gsi, goacc_flags_m, tru= e, + NULL_TREE, true, + GSI_SAME_STMT); + args.quick_push (goacc_flags_m); + } + else + args.quick_push (device); if (offloaded) args.quick_push (build_fold_addr_expr (child_fn)); args.quick_push (t1); diff --git gcc/tree-ssa-structalias.c gcc/tree-ssa-structalias.c index fc85e9ded5e8..cfdfb50854f0 100644 --- gcc/tree-ssa-structalias.c +++ gcc/tree-ssa-structalias.c @@ -4697,7 +4697,7 @@ find_func_aliases_for_builtin_call (struct function *= fn, gcall *t) argpos =3D 1; break; case BUILT_IN_GOACC_PARALLEL: - /* __builtin_GOACC_parallel (device, fn, mapnum, hostaddrs, + /* __builtin_GOACC_parallel (flags_m, fn, mapnum, hostaddrs, sizes, kinds, ...). */ fnpos =3D 1; argpos =3D 3; @@ -5255,7 +5255,7 @@ find_func_clobbers (struct function *fn, gimple *orig= t) argpos =3D 1; break; case BUILT_IN_GOACC_PARALLEL: - /* __builtin_GOACC_parallel (device, fn, mapnum, hostaddrs, + /* __builtin_GOACC_parallel (flags_m, fn, mapnum, hostaddrs, sizes, kinds, ...). */ fnpos =3D 1; argpos =3D 3; diff --git include/ChangeLog include/ChangeLog index 74b5a1f1dd45..886e9a6ca35c 100644 --- include/ChangeLog +++ include/ChangeLog @@ -1,3 +1,8 @@ +2018-12-28 Thomas Schwinge + + * gomp-constants.h (GOACC_FLAG_HOST_FALLBACK) + (GOACC_FLAGS_MARSHAL_OP, GOACC_FLAGS_UNMARSHAL): Define. + 2018-12-22 Jason Merrill =20 * demangle.h: Remove support for ancient GNU (pre-3.0), Lucid, diff --git include/gomp-constants.h include/gomp-constants.h index d3e64d4e352a..b6b6733bd875 100644 --- include/gomp-constants.h +++ include/gomp-constants.h @@ -197,6 +197,18 @@ enum gomp_map_kind /* Internal to libgomp. */ #define GOMP_TARGET_FLAG_UPDATE (1U << 31) =20 + +/* OpenACC construct flags. */ + +/* Force host fallback execution. */ +#define GOACC_FLAG_HOST_FALLBACK (1 << 0) + +/* For legacy reasons, in the ABI, the GOACC_FLAGs are encoded as an inver= ted + bitmask. */ +#define GOACC_FLAGS_MARSHAL_OP BIT_NOT_EXPR +#define GOACC_FLAGS_UNMARSHAL(X) (~(X)) + + /* Versions of libgomp and device-specific plugins. GOMP_VERSION should be incremented whenever an ABI-incompatible change is introduced to the plugin interface defined in libgomp/libgomp.h. */ diff --git libgomp/ChangeLog libgomp/ChangeLog index 5b014b032beb..aa69f42d3ca0 100644 --- libgomp/ChangeLog +++ libgomp/ChangeLog @@ -1,3 +1,9 @@ +2018-12-28 Thomas Schwinge + + * oacc-parallel.c (GOACC_parallel_keyed, GOACC_parallel) + (GOACC_data_start, GOACC_enter_exit_data, GOACC_update) + (GOACC_declare): Redefine the "device" argument to "flags". + 2018-12-28 Thomas Schwinge Cesar Philippidis =20 diff --git libgomp/oacc-parallel.c libgomp/oacc-parallel.c index e2405d73d5a9..57bd484ba8a1 100644 --- libgomp/oacc-parallel.c +++ libgomp/oacc-parallel.c @@ -38,6 +38,16 @@ #include #include =20 + +/* In the ABI, the GOACC_FLAGs are encoded as an inverted bitmask, so that= we + continue to support the following two legacy values. */ +_Static_assert (GOACC_FLAGS_UNMARSHAL (GOMP_DEVICE_ICV) =3D=3D 0, + "legacy GOMP_DEVICE_ICV broken"); +_Static_assert (GOACC_FLAGS_UNMARSHAL (GOMP_DEVICE_HOST_FALLBACK) + =3D=3D GOACC_FLAG_HOST_FALLBACK, + "legacy GOMP_DEVICE_HOST_FALLBACK broken"); + + /* Returns the number of mappings associated with the pointer or pset. PSET have three mappings, whereas pointer have two. */ =20 @@ -105,17 +115,18 @@ handle_ftn_pointers (size_t mapnum, void **hostaddrs,= size_t *sizes, static void goacc_wait (int async, int num_waits, va_list *ap); =20 =20 -/* Launch a possibly offloaded function on DEVICE. FN is the host fn +/* Launch a possibly offloaded function with FLAGS. FN is the host fn address. MAPNUM, HOSTADDRS, SIZES & KINDS describe the memory blocks to be copied to/from the device. Varadic arguments are keyed optional parameters terminated with a zero. */ =20 void -GOACC_parallel_keyed (int device, void (*fn) (void *), +GOACC_parallel_keyed (int flags_m, void (*fn) (void *), size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds, ...) { - bool host_fallback =3D device =3D=3D GOMP_DEVICE_HOST_FALLBACK; + int flags =3D GOACC_FLAGS_UNMARSHAL (flags_m); + va_list ap; struct goacc_thread *thr; struct gomp_device_descr *acc_dev; @@ -145,7 +156,7 @@ GOACC_parallel_keyed (int device, void (*fn) (void *), =20 /* Host fallback if "if" clause is false or if the current device is set= to the host. */ - if (host_fallback) + if (flags & GOACC_FLAG_HOST_FALLBACK) { goacc_save_and_set_bind (acc_device_host); fn (hostaddrs); @@ -269,7 +280,7 @@ GOACC_parallel_keyed (int device, void (*fn) (void *), /* Legacy entry point, only provide host execution. */ =20 void -GOACC_parallel (int device, void (*fn) (void *), +GOACC_parallel (int flags_m, void (*fn) (void *), size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds, int num_gangs, int num_workers, int vector_length, @@ -281,10 +292,11 @@ GOACC_parallel (int device, void (*fn) (void *), } =20 void -GOACC_data_start (int device, size_t mapnum, +GOACC_data_start (int flags_m, size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds) { - bool host_fallback =3D device =3D=3D GOMP_DEVICE_HOST_FALLBACK; + int flags =3D GOACC_FLAGS_UNMARSHAL (flags_m); + struct target_mem_desc *tgt; =20 #ifdef HAVE_INTTYPES_H @@ -302,7 +314,7 @@ GOACC_data_start (int device, size_t mapnum, =20 /* Host fallback or 'do nothing'. */ if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) - || host_fallback) + || (flags & GOACC_FLAG_HOST_FALLBACK)) { tgt =3D gomp_map_vars (NULL, 0, NULL, NULL, NULL, NULL, true, GOMP_MAP_VARS_OPENACC); @@ -333,13 +345,14 @@ GOACC_data_end (void) } =20 void -GOACC_enter_exit_data (int device, size_t mapnum, +GOACC_enter_exit_data (int flags_m, size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds, int async, int num_waits, ...) { + int flags =3D GOACC_FLAGS_UNMARSHAL (flags_m); + struct goacc_thread *thr; struct gomp_device_descr *acc_dev; - bool host_fallback =3D device =3D=3D GOMP_DEVICE_HOST_FALLBACK; bool data_enter =3D false; size_t i; =20 @@ -349,7 +362,7 @@ GOACC_enter_exit_data (int device, size_t mapnum, acc_dev =3D thr->dev; =20 if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) - || host_fallback) + || (flags & GOACC_FLAG_HOST_FALLBACK)) return; =20 if (num_waits) @@ -523,11 +536,12 @@ goacc_wait (int async, int num_waits, va_list *ap) } =20 void -GOACC_update (int device, size_t mapnum, +GOACC_update (int flags_m, size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds, int async, int num_waits, ...) { - bool host_fallback =3D device =3D=3D GOMP_DEVICE_HOST_FALLBACK; + int flags =3D GOACC_FLAGS_UNMARSHAL (flags_m); + size_t i; =20 goacc_lazy_initialize (); @@ -536,7 +550,7 @@ GOACC_update (int device, size_t mapnum, struct gomp_device_descr *acc_dev =3D thr->dev; =20 if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) - || host_fallback) + || (flags & GOACC_FLAG_HOST_FALLBACK)) return; =20 if (num_waits) @@ -643,7 +657,7 @@ GOACC_get_thread_num (void) } =20 void -GOACC_declare (int device, size_t mapnum, +GOACC_declare (int flags_m, size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds) { int i; @@ -663,7 +677,7 @@ GOACC_declare (int device, size_t mapnum, case GOMP_MAP_POINTER: case GOMP_MAP_RELEASE: case GOMP_MAP_DELETE: - GOACC_enter_exit_data (device, 1, &hostaddrs[i], &sizes[i], + GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i], &kinds[i], GOMP_ASYNC_SYNC, 0); break; =20 @@ -672,18 +686,18 @@ GOACC_declare (int device, size_t mapnum, =20 case GOMP_MAP_ALLOC: if (!acc_is_present (hostaddrs[i], sizes[i])) - GOACC_enter_exit_data (device, 1, &hostaddrs[i], &sizes[i], + GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i], &kinds[i], GOMP_ASYNC_SYNC, 0); break; =20 case GOMP_MAP_TO: - GOACC_enter_exit_data (device, 1, &hostaddrs[i], &sizes[i], + GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i], &kinds[i], GOMP_ASYNC_SYNC, 0); =20 break; =20 case GOMP_MAP_FROM: - GOACC_enter_exit_data (device, 1, &hostaddrs[i], &sizes[i], + GOACC_enter_exit_data (flags_m, 1, &hostaddrs[i], &sizes[i], &kinds[i], GOMP_ASYNC_SYNC, 0); break; =20 Gr=C3=BC=C3=9Fe Thomas