From d6ef90f64c48b2bfb3406e9d96a61ae69d311b85 Mon Sep 17 00:00:00 2001 From: Raghu Maddhipatla Date: Thu, 13 Apr 2023 11:33:21 -0500 Subject: [PATCH] [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_PTR clause on OMP TARGET DATA directive. Initial support for USE_DEVICE_PTR clause on OMP TARGET DATA directive. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D148254 --- flang/docs/OpenMP-semantics.md | 17 +++++++++++++++++ flang/include/flang/Semantics/symbol.h | 1 + flang/lib/Parser/openmp-parsers.cpp | 2 +- flang/lib/Semantics/check-omp-structure.cpp | 11 ++++++----- flang/lib/Semantics/resolve-directives.cpp | 7 ++++++- flang/lib/Semantics/resolve-names.cpp | 1 - flang/test/Semantics/OpenMP/use_device_ptr.f90 | 21 +++++++++++++++++++++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 3 +-- 8 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 flang/test/Semantics/OpenMP/use_device_ptr.f90 diff --git a/flang/docs/OpenMP-semantics.md b/flang/docs/OpenMP-semantics.md index 46dc189..579c406 100644 --- a/flang/docs/OpenMP-semantics.md +++ b/flang/docs/OpenMP-semantics.md @@ -318,6 +318,7 @@ w/ For the following OpenMP regions: * `target` regions +* `target data` regions * `teams` regions * `parallel` regions * `simd` regions @@ -407,6 +408,16 @@ More details are listed in the following table: OmpLastPrivate + + use_device_ptr + + Yes + + New Symbol + + OmpUseDevicePtr + + To determine the right data-sharing attribute, @@ -519,6 +530,12 @@ will be determined and represented as `Flag` in the `Symbol` object of the variable. No `Symbol` or `Scope` will be created. +However, there are some exceptions for this, Pointers that appear in a +use_device_ptr clause are privatized and the device pointers to the +corresponding list items in the device data environment are assigned into the +private versions so it is best to follow the representation for privatised +variables i.e represent them with a new Symbol and `OmpUseDevicePtr` flag. + The basic steps to determine the data-mapping attribute are: 1. If _map_ clause is present, diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h index ddeb73f..41a03a2 100644 --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -560,6 +560,7 @@ public: OmpShared, OmpPrivate, OmpLinear, OmpFirstPrivate, OmpLastPrivate, // OpenMP data-mapping attribute OmpMapTo, OmpMapFrom, OmpMapAlloc, OmpMapRelease, OmpMapDelete, + OmpUseDevicePtr, // OpenMP data-copying attribute OmpCopyIn, OmpCopyPrivate, // OpenMP miscellaneous flags diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e7d628d..cec08e1 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -309,7 +309,7 @@ TYPE_PARSER( "TO" >> construct(construct( parenthesized(Parser{}))) || "USE_DEVICE_PTR" >> construct(construct( - parenthesized(nonemptyList(name)))) || + parenthesized(Parser{}))) || "UNIFIED_ADDRESS" >> construct(construct()) || "UNIFIED_SHARED_MEMORY" >> diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 9794424..c7bc019 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -2766,11 +2766,12 @@ const parser::OmpObjectList *OmpStructureChecker::GetOmpObjectList( const parser::OmpClause &clause) { // Clauses with OmpObjectList as its data member - using MemberObjectListClauses = std::tuple; + using MemberObjectListClauses = + std::tuple; // Clauses with OmpObjectList in the tuple using TupleObjectListClauses = std::tuple(x.t)}; const auto &beginDir{std::get(beginBlockDir.t)}; switch (beginDir.v) { - case llvm::omp::Directive::OMPD_target_data: case llvm::omp::Directive::OMPD_master: case llvm::omp::Directive::OMPD_ordered: case llvm::omp::Directive::OMPD_taskgroup: diff --git a/flang/test/Semantics/OpenMP/use_device_ptr.f90 b/flang/test/Semantics/OpenMP/use_device_ptr.f90 new file mode 100644 index 0000000..738904b --- /dev/null +++ b/flang/test/Semantics/OpenMP/use_device_ptr.f90 @@ -0,0 +1,21 @@ +! RUN: %flang -fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s +! OpenMP Version 5.0 +! 2.10.1 use_device_ptr clause +! List items that appear in a use_device_ptr clause are converted into device +! pointers to the corresponding list item in the device data environment. + +subroutine omp_target_data + use iso_c_binding + integer :: a(1024) + !CHECK: b size=8 offset=4096: ObjectEntity type: TYPE(c_ptr) + type(C_PTR) :: b + integer, pointer :: arrayB + a = 1 + !$omp target data map(tofrom: a, arrayB) use_device_ptr(b) + !CHECK: b (OmpUseDevicePtr) + allocate(arrayB) + call c_f_pointer(b, arrayB) + a = arrayB + !$omp end target data +end subroutine omp_target_data + diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td index fe5af4c..6e94302f 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -295,8 +295,7 @@ def OMPC_From : Clause<"from"> { } def OMPC_UseDevicePtr : Clause<"use_device_ptr"> { let clangClass = "OMPUseDevicePtrClause"; - let flangClass = "Name"; - let isValueList = true; + let flangClass = "OmpObjectList"; } def OMPC_IsDevicePtr : Clause<"is_device_ptr"> { let clangClass = "OMPIsDevicePtrClause"; -- 2.7.4