OpenMP-Validation-and-Verification / OpenMP_VV

OpenMP Offloading Validation & Verification Suite; Official repository. We have migrated from bitbucket!! For documentation, results, publication and presentations, please check out our website ->
https://crpl.cis.udel.edu/ompvvsollve/
Other
54 stars 19 forks source link

test_target_has_device_addr.F90: Wrong testcase violating restrictions #756

Closed tob2 closed 11 months ago

tob2 commented 1 year ago

https://github.com/SOLLVE/sollve_vv/blob/master/tests/5.1/target/test_target_has_device_addr.F90 → Was added in Pull Request #717

The code does:

    INTEGER, POINTER :: first_scalar_device_addr
...
    !$omp target map(from: first_scalar_device_addr, first_arr_device_addr) map(to: x, arr)
      first_scalar_device_addr => x
...
    !$omp end target

There are multiple problems with this:

  1. "The association status of a list item that is a pointer must not be undefined unless it is a structure component and it results from a predefined default mapper." (TR11 [160:15–16], "5.8.3 map Clause" under "Restrictions to the map clause")

While only added in TR11, it is a bug fix to the specification and not a new feature. The background for that change is (TR11 wording but feature is old):

  • If a list item in a map clause is an associated pointer that is not attach-ineligible and the pointer is not the base pointer of another list item in a map clause on the same construct, then it is treated as if its pointer target is implicitly mapped in the same clause.

The problem is that a compiler cannot distinguish an undefined pointer from an associated pointer.

Solution: you need to nullify() / null() the pointer before mapping.

  1. The following feature – here, the second bullet applies (at least after nullifying):
  • If the association status of a list item with the POINTER attribute that appears in a map clause on the construct is associated upon entry to the target region, the list item must be associated with the same pointer target upon exit from the region.
  • If the association status of a list item with the POINTER attribute that appears in a map clause on the construct is disassociated upon entry to the target region, the list item must be disassociated upon exit from the region.

(OpenMP 5.2 [287:29-31, 288:1-3], "Restrictions to the target construct" in "13.8 target Construct")

While only in OpenMP 5.2, the issue is generic — and also the main reason that the testcase has problems. Namely, the following applies:

For the reasons mentioned above, the restriction was added in 5.2 and in TR11 — while the restrictions are new, the issue itself also applied to 5.1 and earlier.

  1. What means "has_device_addr"

Namely: Does it apply to the array descriptor / pointer itself — or to the address it points to. It was clarified in TR11 that it applies to the address it points to. Upon entering a target region, those are taken from the host (by copying in/firstprivatizing the array descriptor; the pointer attribute inside of it is then the device one):

  1. Fortran's "associated" intrinsic

For completeness, I want to point out that the Fortran "associated" intrinsic for arrays not only check the pointer address but also that the array bounds match. That's not a problem here, but I want to point out that that's the case.

@seyonglee @fel-cab @spophale

spophale commented 11 months ago

Fix hs been merged. Thanks @tob2 !