Skip to content

[Flang] Add semantics checks for cray pointer usage in DSA list #123171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

Thirumalai-Shaktivel
Copy link
Member

Fix failure caused by this PR: #121028

Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474

Problems:
- Cray pointee cannot be used in the DSA list
- Cray pointer has to be in DSA list when cray pointee is used
  in the default (none) region

Fix: Added required semantic checks along the tests
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-flang-openmp

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Changes

Fix failure caused by this PR: #121028

Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474


Full diff: https://github.com/llvm/llvm-project/pull/123171.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+4-6)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9cbc61391ba1fb..85159cb5ce0685 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2115,12 +2115,10 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
 static bool IsPrivatizable(const Symbol *sym) {
   auto *misc{sym->detailsIf<MiscDetails>()};
   return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
-      (!semantics::IsAssumedSizeArray(
-           *sym) || /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
-          (sym->test(Symbol::Flag::CrayPointee) &&
-              // If CrayPointer is among the DSA list then the
-              // CrayPointee is Privatizable
-              &semantics::GetCrayPointer(*sym))) &&
+      (!semantics::IsAssumedSizeArray(*sym) /* OpenMP 5.2, 5.1.1: Assumed-size
+          arrays are shared */ ||
+          sym->test(Symbol::Flag::CrayPointee) /* If CrayPointer is among the
+          DSA list then the CrayPointee is Privatizable */) &&
       !sym->owner().IsDerivedType() &&
       sym->owner().kind() != Scope::Kind::ImpliedDos &&
       !sym->detailsIf<semantics::AssocEntityDetails>() &&

@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-flang-semantics

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Changes

Fix failure caused by this PR: #121028

Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474


Full diff: https://github.com/llvm/llvm-project/pull/123171.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+4-6)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9cbc61391ba1fb..85159cb5ce0685 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2115,12 +2115,10 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
 static bool IsPrivatizable(const Symbol *sym) {
   auto *misc{sym->detailsIf<MiscDetails>()};
   return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
-      (!semantics::IsAssumedSizeArray(
-           *sym) || /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
-          (sym->test(Symbol::Flag::CrayPointee) &&
-              // If CrayPointer is among the DSA list then the
-              // CrayPointee is Privatizable
-              &semantics::GetCrayPointer(*sym))) &&
+      (!semantics::IsAssumedSizeArray(*sym) /* OpenMP 5.2, 5.1.1: Assumed-size
+          arrays are shared */ ||
+          sym->test(Symbol::Flag::CrayPointee) /* If CrayPointer is among the
+          DSA list then the CrayPointee is Privatizable */) &&
       !sym->owner().IsDerivedType() &&
       sym->owner().kind() != Scope::Kind::ImpliedDos &&
       !sym->detailsIf<semantics::AssocEntityDetails>() &&

@Thirumalai-Shaktivel
Copy link
Member Author

Thirumalai-Shaktivel commented Jan 16, 2025

I have a doubt,

Consider an example

program test
real :: pte(*)
! pointer(pte, ptr)
end program

For which, pte would be assumed rank array unless we use pointer(pte, ptr) to create CrayPointer and mark pte as CrayPointee. Is my understanding correct?

@jeanPerier @tblah @kiranchandramohan

!semantics::IsAssumedSizeArray(*sym) ||
// If CrayPointer is among the DSA list then the
// CrayPointee is Privatizable
sym->test(Symbol::Flag::CrayPointee)) &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, would checking only for CrayPointee be right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the compilation failure due to the use of & in &semantics::GetCrayPointer(*sym))?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It fails in flang-aarch64-libcxx and It says the following:

[...]
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/../clang/include -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o -MF tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o.d -o tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Semantics/resolve-directives.cpp
../llvm-project/flang/lib/Semantics/resolve-directives.cpp:2123:16: error: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true [-Werror,-Wundefined-bool-conversion]
 2120 |           (sym->test(Symbol::Flag::CrayPointee) &&
      |                                                 ~~
 2121 |               // If CrayPointer is among the DSA list then the
 2122 |               // CrayPointee is Privatizable
 2123 |               &semantics::GetCrayPointer(*sym))) &&
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../llvm-project/flang/include/flang/Semantics/tools.h:315:15: note: 'GetCrayPointer' returns a reference
  315 | const Symbol &GetCrayPointer(const Symbol &crayPointee);
      |               ^
1 error generated.

@kiranchandramohan
Copy link
Contributor

Can you revert the patch so that the bots pass?

@kiranchandramohan
Copy link
Contributor

I have a doubt,

Consider an example

program test
real :: pte(*)
! pointer(pte, ptr)
end program

For which, pte would be assumed rank array unless we use pointer(pte, ptr) to create CrayPointer and mark pte as CrayPointee. Is my understanding correct?

@jeanPerier @tblah @kiranchandramohan

I am not very familiar with Cray pointers. Would @DanielCChen or @kkwli know?

@kiranchandramohan
Copy link
Contributor

I have reverted the original patch (#123220) since we have not concluded. Hope it is OK.

@DanielCChen
Copy link
Contributor

I have a doubt,
Consider an example

program test
real :: pte(*)
! pointer(pte, ptr)
end program

For which, pte would be assumed rank array unless we use pointer(pte, ptr) to create CrayPointer and mark pte as CrayPointee. Is my understanding correct?
@jeanPerier @tblah @kiranchandramohan

I am not very familiar with Cray pointers. Would @DanielCChen or @kkwli know?

The example code is not standard conforming.
If I have to guess, real :: pte(*) is trying to declare a rank-1 assumed-size dummy argument, pte.
A CrayPointer is just a C pointer. It only represents address of its pointee.

I modified the code to make it executable and hopefully it will illustrate how CrayPointer works.

real :: arr(10)
arr = 10
call sub(arr)
contains
subroutine sub(pte)
  real :: pte(*)
  real :: local(10)
  pointer (ptr, local)
  ptr = loc(pte)
  print*, local
end
end

@Thirumalai-Shaktivel
Copy link
Member Author

Here is another example, that I was trying to compile and make it work
Godbolt: https://godbolt.org/z/MbYTx67KT

subroutine test_cray_pointer_usage
  implicit none
  real(8) :: var(*), pointee(2)
  pointer(ivar, var)

  pointee = 42.0
  ivar = loc(pointee)

  !$omp parallel num_threads(2) default(none)
    ! ERROR: The DEFAULT(NONE) clause requires that the Cray Pointer 'ivar' must be listed in a data-sharing attribute clause
    print *, var(1)
  !$omp end parallel

  ! ERROR: Cray Pointee 'var' may not appear in PRIVATE clause, use Cray Pointer 'ivar' instead
  !$omp parallel num_threads(2) default(none) private(var)
    print *, var(1)
  !$omp end parallel

  !$omp parallel num_threads(2) default(none) firstprivate(ivar)
    print *, var(1)
  !$omp end parallel

  !$omp parallel num_threads(2) default(private) shared(ivar)
    print *, var(1)
  !$omp end parallel
end subroutine test_cray_pointer_usage

@Thirumalai-Shaktivel
Copy link
Member Author

I have reverted the original patch (#123220) since we have not concluded. Hope it is OK.

Thank you, I will push changes here.

@Thirumalai-Shaktivel Thirumalai-Shaktivel changed the title [Flang] Remove redundant check for CrayPointer [Flang] Add semantics checks for cray pointer usage in DSA list Jan 17, 2025
@Thirumalai-Shaktivel
Copy link
Member Author

Ready for review.

@kkwli
Copy link
Collaborator

kkwli commented Jan 21, 2025

Do we need to have the same check for other DSA clauses (e.g. linear)?

@Thirumalai-Shaktivel
Copy link
Member Author

Thirumalai-Shaktivel commented Jan 22, 2025

Yes. I missed them, thanks for noticing.

Apart from Linear and LastPrivate, do you see anything else missing?
Reference: https://www.openmp.org/spec-html/5.0/openmpsu106.html#:~:text=DescriptionThe%20default(shared)%20clause,sharing%20attributes%20to%20be%20firstprivate.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM but I don't know enough about cray pointers to approve

@kkwli
Copy link
Collaborator

kkwli commented Jan 24, 2025

Apart from Linear and LastPrivate, do you see anything else missing?

I think linear and lastprivate are the ones missing for 5.0 support. The list of data-sharing attribute clause is extended to other clauses in 6.0 that we can leave it to another PR.

@Thirumalai-Shaktivel
Copy link
Member Author

@kkwli This PR is ready for review!

Copy link
Collaborator

@kkwli kkwli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks.

@Thirumalai-Shaktivel
Copy link
Member Author

Thanks for the reviews!

@Thirumalai-Shaktivel Thirumalai-Shaktivel merged commit ba789c6 into llvm:main Jan 28, 2025
8 checks passed
@Thirumalai-Shaktivel Thirumalai-Shaktivel deleted the llvm/cray_ptr_02 branch January 28, 2025 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants