[flang-commits] [flang] [flang][cuda] Allow PINNED argument to host dummy (PR #90651)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Apr 30 12:24:09 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/90651

Update the `AreCompatibleCUDADataAttrs` function to return true when one argument has the `PINNED` attribute and the other argument is just host data. 

>From 4fe4f2588151b703ed6140ef386d7657b28f7661 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 30 Apr 2024 12:22:06 -0700
Subject: [PATCH] [flang][cuda] Allow PINNED argument to host dummy

---
 flang/lib/Common/Fortran.cpp   |  3 +++
 flang/test/Semantics/cuf13.cuf | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 flang/test/Semantics/cuf13.cuf

diff --git a/flang/lib/Common/Fortran.cpp b/flang/lib/Common/Fortran.cpp
index 27ff31ef78da28..8ada8fe210a30f 100644
--- a/flang/lib/Common/Fortran.cpp
+++ b/flang/lib/Common/Fortran.cpp
@@ -103,6 +103,9 @@ bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr> x,
     return true;
   } else if (x && y && *x == *y) {
     return true;
+  } else if ((!x && y && *y == CUDADataAttr::Pinned) ||
+      (x && *x == CUDADataAttr::Pinned && !y)) {
+    return true;
   } else if (ignoreTKR.test(IgnoreTKR::Device) &&
       x.value_or(CUDADataAttr::Device) == CUDADataAttr::Device &&
       y.value_or(CUDADataAttr::Device) == CUDADataAttr::Device) {
diff --git a/flang/test/Semantics/cuf13.cuf b/flang/test/Semantics/cuf13.cuf
new file mode 100644
index 00000000000000..7c6673e21bf11b
--- /dev/null
+++ b/flang/test/Semantics/cuf13.cuf
@@ -0,0 +1,28 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+module matching
+  interface sub
+    module procedure sub_host
+    module procedure sub_device
+  end interface
+
+contains
+  subroutine sub_host(a)
+    integer :: a(:)
+  end
+
+  subroutine sub_device(a)
+    integer, device :: a(:)
+  end
+
+end module
+
+program m
+  use matching
+
+  integer, pinned, allocatable :: a(:)
+  logical :: plog
+  allocate(a(100), pinned = plog)
+
+  call sub(a)
+end



More information about the flang-commits mailing list