For libgomp OpenACC entry points, redefine the "device" argument to "flags"

... so that we're then able to use this for other flags in addition to
"GOACC_FLAG_HOST_FALLBACK".

	gcc/
	* omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
	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".

From-SVN: r267448
This commit is contained in:
Thomas Schwinge 2018-12-28 12:34:14 +01:00 committed by Thomas Schwinge
parent 5a12987e79
commit 59d5960cdb
7 changed files with 137 additions and 62 deletions

View File

@ -1,3 +1,8 @@
2018-12-28 Thomas Schwinge <thomas@codesourcery.com>
* omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
code paths. Update for libgomp OpenACC entry points change.
2018-12-28 Thomas Schwinge <thomas@codesourcery.com> 2018-12-28 Thomas Schwinge <thomas@codesourcery.com>
Julian Brown <julian@codesourcery.com> Julian Brown <julian@codesourcery.com>

View File

@ -7496,9 +7496,8 @@ expand_omp_target (struct omp_region *region)
/* Emit a library call to launch the offloading region, or do data /* Emit a library call to launch the offloading region, or do data
transfers. */ 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; enum built_in_function start_ix;
location_t clause_loc;
unsigned int flags_i = 0; unsigned int flags_i = 0;
switch (gimple_omp_target_kind (entry_stmt)) switch (gimple_omp_target_kind (entry_stmt))
@ -7542,49 +7541,63 @@ expand_omp_target (struct omp_region *region)
clauses = gimple_omp_target_clauses (entry_stmt); clauses = gimple_omp_target_clauses (entry_stmt);
/* By default, the value of DEVICE is GOMP_DEVICE_ICV (let runtime tree device = NULL_TREE;
library choose) and there is no conditional. */ location_t device_loc = UNKNOWN_LOCATION;
cond = NULL_TREE; tree goacc_flags = NULL_TREE;
device = build_int_cst (integer_type_node, GOMP_DEVICE_ICV); if (is_gimple_omp_oacc (entry_stmt))
{
c = omp_find_clause (clauses, OMP_CLAUSE_IF); /* By default, no GOACC_FLAGs are set. */
if (c) goacc_flags = integer_zero_node;
cond = OMP_CLAUSE_IF_EXPR (c); }
else
{
c = omp_find_clause (clauses, OMP_CLAUSE_DEVICE); c = omp_find_clause (clauses, OMP_CLAUSE_DEVICE);
if (c) 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 == BUILT_IN_GOMP_TARGET
|| start_ix == BUILT_IN_GOMP_TARGET_DATA
|| start_ix == BUILT_IN_GOMP_TARGET_UPDATE
|| start_ix == BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA);
device = OMP_CLAUSE_DEVICE_ID (c); device = OMP_CLAUSE_DEVICE_ID (c);
clause_loc = OMP_CLAUSE_LOCATION (c); device_loc = OMP_CLAUSE_LOCATION (c);
} }
else else
clause_loc = gimple_location (entry_stmt); {
/* By default, the value of DEVICE is GOMP_DEVICE_ICV (let runtime
library choose). */
device = build_int_cst (integer_type_node, GOMP_DEVICE_ICV);
device_loc = gimple_location (entry_stmt);
}
c = omp_find_clause (clauses, OMP_CLAUSE_NOWAIT); c = omp_find_clause (clauses, OMP_CLAUSE_NOWAIT);
if (c) if (c)
flags_i |= GOMP_TARGET_FLAG_NOWAIT; flags_i |= GOMP_TARGET_FLAG_NOWAIT;
}
/* Ensure 'device' is of the correct type. */ /* By default, there is no conditional. */
device = fold_convert_loc (clause_loc, integer_type_node, device); tree cond = NULL_TREE;
c = omp_find_clause (clauses, OMP_CLAUSE_IF);
/* If we found the clause 'if (cond)', build if (c)
(cond ? device : GOMP_DEVICE_HOST_FALLBACK). */ cond = OMP_CLAUSE_IF_EXPR (c);
/* If we found the clause 'if (cond)', build:
OpenACC: goacc_flags = (cond ? goacc_flags : flags | GOACC_FLAG_HOST_FALLBACK)
OpenMP: device = (cond ? device : GOMP_DEVICE_HOST_FALLBACK) */
if (cond) if (cond)
{ {
tree *tp;
if (is_gimple_omp_oacc (entry_stmt))
tp = &goacc_flags;
else
{
/* Ensure 'device' is of the correct type. */
device = fold_convert_loc (device_loc, integer_type_node, device);
tp = &device;
}
cond = gimple_boolify (cond); cond = gimple_boolify (cond);
basic_block cond_bb, then_bb, else_bb; basic_block cond_bb, then_bb, else_bb;
edge e; edge e;
tree tmp_var; tree tmp_var;
tmp_var = create_tmp_var (TREE_TYPE (device)); tmp_var = create_tmp_var (TREE_TYPE (*tp));
if (offloaded) if (offloaded)
e = split_block_after_labels (new_bb); e = split_block_after_labels (new_bb);
else else
@ -7607,10 +7620,17 @@ expand_omp_target (struct omp_region *region)
gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
gsi = gsi_start_bb (then_bb); gsi = gsi_start_bb (then_bb);
stmt = gimple_build_assign (tmp_var, device); stmt = gimple_build_assign (tmp_var, *tp);
gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
gsi = gsi_start_bb (else_bb); gsi = gsi_start_bb (else_bb);
if (is_gimple_omp_oacc (entry_stmt))
stmt = gimple_build_assign (tmp_var,
BIT_IOR_EXPR,
*tp,
build_int_cst (integer_type_node,
GOACC_FLAG_HOST_FALLBACK));
else
stmt = gimple_build_assign (tmp_var, stmt = gimple_build_assign (tmp_var,
build_int_cst (integer_type_node, build_int_cst (integer_type_node,
GOMP_DEVICE_HOST_FALLBACK)); GOMP_DEVICE_HOST_FALLBACK));
@ -7623,12 +7643,15 @@ expand_omp_target (struct omp_region *region)
make_edge (then_bb, new_bb, EDGE_FALLTHRU); make_edge (then_bb, new_bb, EDGE_FALLTHRU);
make_edge (else_bb, new_bb, EDGE_FALLTHRU); make_edge (else_bb, new_bb, EDGE_FALLTHRU);
device = tmp_var; *tp = tmp_var;
gsi = gsi_last_nondebug_bb (new_bb); gsi = gsi_last_nondebug_bb (new_bb);
} }
else else
{ {
gsi = gsi_last_nondebug_bb (new_bb); gsi = gsi_last_nondebug_bb (new_bb);
if (device != NULL_TREE)
device = force_gimple_operand_gsi (&gsi, device, true, NULL_TREE, device = force_gimple_operand_gsi (&gsi, device, true, NULL_TREE,
true, GSI_SAME_STMT); true, GSI_SAME_STMT);
} }
@ -7654,6 +7677,16 @@ expand_omp_target (struct omp_region *region)
bool tagging = false; bool tagging = false;
/* The maximum number used by any start_ix, without varargs. */ /* The maximum number used by any start_ix, without varargs. */
auto_vec<tree, 11> args; auto_vec<tree, 11> args;
if (is_gimple_omp_oacc (entry_stmt))
{
tree goacc_flags_m = fold_build1 (GOACC_FLAGS_MARSHAL_OP,
TREE_TYPE (goacc_flags), goacc_flags);
goacc_flags_m = force_gimple_operand_gsi (&gsi, goacc_flags_m, true,
NULL_TREE, true,
GSI_SAME_STMT);
args.quick_push (goacc_flags_m);
}
else
args.quick_push (device); args.quick_push (device);
if (offloaded) if (offloaded)
args.quick_push (build_fold_addr_expr (child_fn)); args.quick_push (build_fold_addr_expr (child_fn));

View File

@ -4697,7 +4697,7 @@ find_func_aliases_for_builtin_call (struct function *fn, gcall *t)
argpos = 1; argpos = 1;
break; break;
case BUILT_IN_GOACC_PARALLEL: case BUILT_IN_GOACC_PARALLEL:
/* __builtin_GOACC_parallel (device, fn, mapnum, hostaddrs, /* __builtin_GOACC_parallel (flags_m, fn, mapnum, hostaddrs,
sizes, kinds, ...). */ sizes, kinds, ...). */
fnpos = 1; fnpos = 1;
argpos = 3; argpos = 3;
@ -5255,7 +5255,7 @@ find_func_clobbers (struct function *fn, gimple *origt)
argpos = 1; argpos = 1;
break; break;
case BUILT_IN_GOACC_PARALLEL: case BUILT_IN_GOACC_PARALLEL:
/* __builtin_GOACC_parallel (device, fn, mapnum, hostaddrs, /* __builtin_GOACC_parallel (flags_m, fn, mapnum, hostaddrs,
sizes, kinds, ...). */ sizes, kinds, ...). */
fnpos = 1; fnpos = 1;
argpos = 3; argpos = 3;

View File

@ -1,3 +1,8 @@
2018-12-28 Thomas Schwinge <thomas@codesourcery.com>
* gomp-constants.h (GOACC_FLAG_HOST_FALLBACK)
(GOACC_FLAGS_MARSHAL_OP, GOACC_FLAGS_UNMARSHAL): Define.
2018-12-22 Jason Merrill <jason@redhat.com> 2018-12-22 Jason Merrill <jason@redhat.com>
* demangle.h: Remove support for ancient GNU (pre-3.0), Lucid, * demangle.h: Remove support for ancient GNU (pre-3.0), Lucid,

View File

@ -197,6 +197,18 @@ enum gomp_map_kind
/* Internal to libgomp. */ /* Internal to libgomp. */
#define GOMP_TARGET_FLAG_UPDATE (1U << 31) #define GOMP_TARGET_FLAG_UPDATE (1U << 31)
/* 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 inverted
bitmask. */
#define GOACC_FLAGS_MARSHAL_OP BIT_NOT_EXPR
#define GOACC_FLAGS_UNMARSHAL(X) (~(X))
/* Versions of libgomp and device-specific plugins. GOMP_VERSION /* Versions of libgomp and device-specific plugins. GOMP_VERSION
should be incremented whenever an ABI-incompatible change is introduced should be incremented whenever an ABI-incompatible change is introduced
to the plugin interface defined in libgomp/libgomp.h. */ to the plugin interface defined in libgomp/libgomp.h. */

View File

@ -1,3 +1,9 @@
2018-12-28 Thomas Schwinge <thomas@codesourcery.com>
* 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 <thomas@codesourcery.com> 2018-12-28 Thomas Schwinge <thomas@codesourcery.com>
Cesar Philippidis <cesar@codesourcery.com> Cesar Philippidis <cesar@codesourcery.com>

View File

@ -38,6 +38,16 @@
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
/* 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) == 0,
"legacy GOMP_DEVICE_ICV broken");
_Static_assert (GOACC_FLAGS_UNMARSHAL (GOMP_DEVICE_HOST_FALLBACK)
== GOACC_FLAG_HOST_FALLBACK,
"legacy GOMP_DEVICE_HOST_FALLBACK broken");
/* Returns the number of mappings associated with the pointer or pset. PSET /* Returns the number of mappings associated with the pointer or pset. PSET
have three mappings, whereas pointer have two. */ have three mappings, whereas pointer have two. */
@ -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); static void goacc_wait (int async, int num_waits, va_list *ap);
/* 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 address. MAPNUM, HOSTADDRS, SIZES & KINDS describe the memory
blocks to be copied to/from the device. Varadic arguments are blocks to be copied to/from the device. Varadic arguments are
keyed optional parameters terminated with a zero. */ keyed optional parameters terminated with a zero. */
void 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, size_t mapnum, void **hostaddrs, size_t *sizes,
unsigned short *kinds, ...) unsigned short *kinds, ...)
{ {
bool host_fallback = device == GOMP_DEVICE_HOST_FALLBACK; int flags = GOACC_FLAGS_UNMARSHAL (flags_m);
va_list ap; va_list ap;
struct goacc_thread *thr; struct goacc_thread *thr;
struct gomp_device_descr *acc_dev; struct gomp_device_descr *acc_dev;
@ -145,7 +156,7 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
/* Host fallback if "if" clause is false or if the current device is set to /* Host fallback if "if" clause is false or if the current device is set to
the host. */ the host. */
if (host_fallback) if (flags & GOACC_FLAG_HOST_FALLBACK)
{ {
goacc_save_and_set_bind (acc_device_host); goacc_save_and_set_bind (acc_device_host);
fn (hostaddrs); fn (hostaddrs);
@ -269,7 +280,7 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
/* Legacy entry point, only provide host execution. */ /* Legacy entry point, only provide host execution. */
void void
GOACC_parallel (int device, void (*fn) (void *), GOACC_parallel (int flags_m, void (*fn) (void *),
size_t mapnum, void **hostaddrs, size_t *sizes, size_t mapnum, void **hostaddrs, size_t *sizes,
unsigned short *kinds, unsigned short *kinds,
int num_gangs, int num_workers, int vector_length, int num_gangs, int num_workers, int vector_length,
@ -281,10 +292,11 @@ GOACC_parallel (int device, void (*fn) (void *),
} }
void 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) void **hostaddrs, size_t *sizes, unsigned short *kinds)
{ {
bool host_fallback = device == GOMP_DEVICE_HOST_FALLBACK; int flags = GOACC_FLAGS_UNMARSHAL (flags_m);
struct target_mem_desc *tgt; struct target_mem_desc *tgt;
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
@ -302,7 +314,7 @@ GOACC_data_start (int device, size_t mapnum,
/* Host fallback or 'do nothing'. */ /* Host fallback or 'do nothing'. */
if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
|| host_fallback) || (flags & GOACC_FLAG_HOST_FALLBACK))
{ {
tgt = gomp_map_vars (NULL, 0, NULL, NULL, NULL, NULL, true, tgt = gomp_map_vars (NULL, 0, NULL, NULL, NULL, NULL, true,
GOMP_MAP_VARS_OPENACC); GOMP_MAP_VARS_OPENACC);
@ -333,13 +345,14 @@ GOACC_data_end (void)
} }
void 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, void **hostaddrs, size_t *sizes, unsigned short *kinds,
int async, int num_waits, ...) int async, int num_waits, ...)
{ {
int flags = GOACC_FLAGS_UNMARSHAL (flags_m);
struct goacc_thread *thr; struct goacc_thread *thr;
struct gomp_device_descr *acc_dev; struct gomp_device_descr *acc_dev;
bool host_fallback = device == GOMP_DEVICE_HOST_FALLBACK;
bool data_enter = false; bool data_enter = false;
size_t i; size_t i;
@ -349,7 +362,7 @@ GOACC_enter_exit_data (int device, size_t mapnum,
acc_dev = thr->dev; acc_dev = thr->dev;
if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
|| host_fallback) || (flags & GOACC_FLAG_HOST_FALLBACK))
return; return;
if (num_waits) if (num_waits)
@ -523,11 +536,12 @@ goacc_wait (int async, int num_waits, va_list *ap)
} }
void void
GOACC_update (int device, size_t mapnum, GOACC_update (int flags_m, size_t mapnum,
void **hostaddrs, size_t *sizes, unsigned short *kinds, void **hostaddrs, size_t *sizes, unsigned short *kinds,
int async, int num_waits, ...) int async, int num_waits, ...)
{ {
bool host_fallback = device == GOMP_DEVICE_HOST_FALLBACK; int flags = GOACC_FLAGS_UNMARSHAL (flags_m);
size_t i; size_t i;
goacc_lazy_initialize (); goacc_lazy_initialize ();
@ -536,7 +550,7 @@ GOACC_update (int device, size_t mapnum,
struct gomp_device_descr *acc_dev = thr->dev; struct gomp_device_descr *acc_dev = thr->dev;
if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
|| host_fallback) || (flags & GOACC_FLAG_HOST_FALLBACK))
return; return;
if (num_waits) if (num_waits)
@ -643,7 +657,7 @@ GOACC_get_thread_num (void)
} }
void void
GOACC_declare (int device, size_t mapnum, GOACC_declare (int flags_m, size_t mapnum,
void **hostaddrs, size_t *sizes, unsigned short *kinds) void **hostaddrs, size_t *sizes, unsigned short *kinds)
{ {
int i; int i;
@ -663,7 +677,7 @@ GOACC_declare (int device, size_t mapnum,
case GOMP_MAP_POINTER: case GOMP_MAP_POINTER:
case GOMP_MAP_RELEASE: case GOMP_MAP_RELEASE:
case GOMP_MAP_DELETE: 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); &kinds[i], GOMP_ASYNC_SYNC, 0);
break; break;
@ -672,18 +686,18 @@ GOACC_declare (int device, size_t mapnum,
case GOMP_MAP_ALLOC: case GOMP_MAP_ALLOC:
if (!acc_is_present (hostaddrs[i], sizes[i])) 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); &kinds[i], GOMP_ASYNC_SYNC, 0);
break; break;
case GOMP_MAP_TO: 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); &kinds[i], GOMP_ASYNC_SYNC, 0);
break; break;
case GOMP_MAP_FROM: 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); &kinds[i], GOMP_ASYNC_SYNC, 0);
break; break;