/* Scan CLAUSES for launch dimensions and attach them to the oacc
function attribute. Push any that are non-constant onto the ARGS
- list, along with an appropriate GOMP_LAUNCH_DIM tag. */
+ list, along with an appropriate GOMP_LAUNCH_DIM tag. IS_KERNEL is
+ true, if these are for a kernels region offload function. */
void
-set_oacc_fn_attrib (tree fn, tree clauses, vec<tree> *args)
+set_oacc_fn_attrib (tree fn, tree clauses, bool is_kernel, vec<tree> *args)
{
/* Must match GOMP_DIM ordering. */
static const omp_clause_code ids[]
non_const |= GOMP_DIM_MASK (ix);
}
attr = tree_cons (NULL_TREE, dim, attr);
+ /* Note kernelness with TREE_PUBLIC. */
+ if (is_kernel)
+ TREE_PUBLIC (attr) = 1;
}
replace_oacc_fn_attrib (fn, attr);
return lookup_attribute (OACC_FN_ATTRIB, DECL_ATTRIBUTES (fn));
}
+/* Return true if this oacc fn attrib is for a kernels offload
+ region. We use the TREE_PUBLIC flag of each dimension -- only
+ need to check the first one. */
+
+bool
+oacc_fn_attrib_kernels_p (tree attr)
+{
+ return TREE_PUBLIC (TREE_VALUE (attr));
+}
+
+/* Return level at which oacc routine may spawn a partitioned loop, or
+ -1 if it is not a routine (i.e. is an offload fn). */
+
+static int
+oacc_fn_attrib_level (tree attr)
+{
+ tree pos = TREE_VALUE (attr);
+
+ if (!TREE_PURPOSE (pos))
+ return -1;
+
+ int ix = 0;
+ for (ix = 0; ix != GOMP_DIM_MAX;
+ ix++, pos = TREE_CHAIN (pos))
+ if (!integer_zerop (TREE_PURPOSE (pos)))
+ break;
+
+ return ix;
+}
+
/* Extract an oacc execution dimension from FN. FN must be an
offloaded function or routine that has already had its execution
dimensions lowered to the target-specific values. */
enum built_in_function start_ix;
location_t clause_loc;
unsigned int flags_i = 0;
+ bool oacc_kernels_p = false;
switch (gimple_omp_target_kind (entry_stmt))
{
start_ix = BUILT_IN_GOMP_TARGET_ENTER_EXIT_DATA;
flags_i |= GOMP_TARGET_FLAG_EXIT_DATA;
break;
- case GF_OMP_TARGET_KIND_OACC_PARALLEL:
case GF_OMP_TARGET_KIND_OACC_KERNELS:
+ oacc_kernels_p = true;
+ /* FALLTHROUGH */
+ case GF_OMP_TARGET_KIND_OACC_PARALLEL:
start_ix = BUILT_IN_GOACC_PARALLEL;
break;
case GF_OMP_TARGET_KIND_OACC_DATA:
break;
case BUILT_IN_GOACC_PARALLEL:
{
- set_oacc_fn_attrib (child_fn, clauses, &args);
+ set_oacc_fn_attrib (child_fn, clauses, oacc_kernels_p, &args);
tagging = true;
}
/* FALLTHRU */
}
/* Validate and update the dimensions for offloaded FN. ATTRS is the
- raw attribute. DIMS is an array of dimensions, which is returned.
- Returns the function level dimensionality -- the level at which an
- offload routine wishes to partition a loop. */
+ raw attribute. DIMS is an array of dimensions, which is filled in.
+ LEVEL is the partitioning level of a routine, or -1 for an offload
+ region itself. */
-static int
-oacc_validate_dims (tree fn, tree attrs, int *dims)
+static void
+oacc_validate_dims (tree fn, tree attrs, int *dims, int level)
{
tree purpose[GOMP_DIM_MAX];
unsigned ix;
tree pos = TREE_VALUE (attrs);
- int fn_level = -1;
+ bool is_kernel = oacc_fn_attrib_kernels_p (attrs);
/* Make sure the attribute creator attached the dimension
information. */
for (ix = 0; ix != GOMP_DIM_MAX; ix++)
{
purpose[ix] = TREE_PURPOSE (pos);
-
- if (purpose[ix])
- {
- if (integer_zerop (purpose[ix]))
- fn_level = ix + 1;
- else if (fn_level < 0)
- fn_level = ix;
- }
-
tree val = TREE_VALUE (pos);
dims[ix] = val ? TREE_INT_CST_LOW (val) : -1;
pos = TREE_CHAIN (pos);
}
- bool changed = targetm.goacc.validate_dims (fn, dims, fn_level);
+ bool changed = targetm.goacc.validate_dims (fn, dims, level);
/* Default anything left to 1. */
for (ix = 0; ix != GOMP_DIM_MAX; ix++)
/* Replace the attribute with new values. */
pos = NULL_TREE;
for (ix = GOMP_DIM_MAX; ix--;)
- pos = tree_cons (purpose[ix],
- build_int_cst (integer_type_node, dims[ix]),
- pos);
+ {
+ pos = tree_cons (purpose[ix],
+ build_int_cst (integer_type_node, dims[ix]),
+ pos);
+ if (is_kernel)
+ TREE_PUBLIC (pos) = 1;
+ }
replace_oacc_fn_attrib (fn, pos);
}
-
- return fn_level;
}
/* Create an empty OpenACC loop structure at LOC. */
new_oacc_loop_routine (oacc_loop *parent, gcall *call, tree decl, tree attrs)
{
oacc_loop *loop = new_oacc_loop_raw (parent, gimple_location (call));
- int dims[GOMP_DIM_MAX];
- int level = oacc_validate_dims (decl, attrs, dims);
+ int level = oacc_fn_attrib_level (attrs);
gcc_assert (level >= 0);
execute_oacc_device_lower ()
{
tree attrs = get_oacc_fn_attrib (current_function_decl);
- int dims[GOMP_DIM_MAX];
if (!attrs)
/* Not an offloaded function. */
return 0;
- int fn_level = oacc_validate_dims (current_function_decl, attrs, dims);
-
/* Discover, partition and process the loops. */
oacc_loop *loops = oacc_loop_discovery ();
+ int fn_level = oacc_fn_attrib_level (attrs);
+
+ if (dump_file)
+ fprintf (dump_file, oacc_fn_attrib_kernels_p (attrs)
+ ? "Function is kernels offload\n"
+ : fn_level < 0 ? "Function is parallel offload\n"
+ : "Function is routine level %d\n", fn_level);
+
unsigned outer_mask = fn_level >= 0 ? GOMP_DIM_MASK (fn_level) - 1 : 0;
oacc_loop_partition (loops, outer_mask);
+
+ int dims[GOMP_DIM_MAX];
+ oacc_validate_dims (current_function_decl, attrs, dims, fn_level);
+
+ if (dump_file)
+ {
+ const char *comma = "Compute dimensions [";
+ for (int ix = 0; ix != GOMP_DIM_MAX; ix++, comma = ", ")
+ fprintf (dump_file, "%s%d", comma, dims[ix]);
+ fprintf (dump_file, "]\n");
+ }
+
oacc_loop_process (loops);
if (dump_file)
{