[patch] OpenMP (C/C++): Keep pointer value of unmapped ptr with default mapping [PR110270]

Tobias Burnus tobias@codesourcery.com
Fri Jun 16 16:17:18 GMT 2023


This fixes an issue related to OpenMP C/C++'s default mapping of pointer variables.
(That's 'defaultmap(default:pointer)' – which is possibly surprisingly *not* the
same as 'defaultmap(firstprivate:pointer)').

Namely, OpenMP supports the following:

int *ptr = malloc(sizeof(int)*5);
#pragma omp target enter data map(ptr[:5])

#pragma omp target
   p[2] = 5;

which matches 'firstprivate(p)' + attaching the device address of 'p[:0]' (a zero-sized array),
the latter making it possible to use 'p' automatically without the need to add any map clauses
at least as long as *p has been mapped before.

However, for

  int *ptr = omp_target_alloc (sizeof(int)*5, dev_num);
  #pragma omp target
    p[2] = 5;
or for
   #pragma omp requires unified_shared_memory
   int pa = &A[0];
   #pragma omp target
     pa[0] = 6;

it failed before because neither 'ptr' nor 'pa' were mapped. Solution as a user was
either to add a (default)map clause (with map type than 'default'), a firstprivate
or an is_device_ptr clause.
The problem was that with default mapping, p and pa had the value NULL in the example
above on the device. (As required by OpenMP 5.0/5.1). With the commit, they retain
the original value avoiding surprises for the code above.
(See PR for the reference to the relevant sections of the OpenMP 5.{0,1,2} specifications.)


I would love if someone would give a review it;  albeit the actual code change in
libgomp/target.c is just a changing a single enum value.

If there are no comments, I intent to push it next week ...

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
-------------- next part --------------
A non-text attachment was scrubbed...
Name: omp-ptr-priv.diff
Type: text/x-patch
Size: 20020 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20230616/7e30a7ae/attachment-0001.bin>


More information about the Gcc-patches mailing list