https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122233
Bug ID: 122233
Summary: [OpenMP] 'construct={target}' context selector should
evaluate to false on the host in 'declare target'
routines
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: openmp, wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: sandra at gcc dot gnu.org
Target Milestone: ---
Created attachment 62532
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62532&action=edit
Testcase - compile with -fopenmp
OpenMP specifies:
"For procedures that are determined to be 'target variants' by a 'declare
target directive', the 'target' trait is added to the beginning of the
construct trait set as c1 so the total size of the trait set is increased by
one."
Hereby,
"target variant - A version of a device procedure that can only be executed
as part of a target region."
In my reading:
#omp begin declare target
void foo() { }
#omp end declare target
void bar()
{
foo(); // Calls host version of 'foo', no 'target' trait
#pragma omp target
if (!omp_is_initial_device())
foo (); // Calls device version of 'foo', has a 'target' trait.
}
Currently, it seems as if 'foo' always has the target trait. See attached
testcase, 'metadirective.3.c' in the OpenMP example document also talk about
this, but it I am not sure it makes this clear.
NOTE: __builtin_omp_is_initial_device() is evaluated (late) at compile time,
i.e. generating a COND_EXPR with BUILT_IN_OMP_IS_INITIAL_DEVICE is compile-time
resolvable, albeit only rather late (when offloading is compiled in, otherwise,
much earlier).