[flang-commits] [flang] [flang][cuda] Allow complex type in cuf kernel reduce (PR #124185)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Jan 23 12:29:45 PST 2025


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

Complex type is allowed in the reference compiler. 

>From 17a8793c2c0a72fe8cbaa2fd618112375de475d6 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 23 Jan 2025 12:28:41 -0800
Subject: [PATCH] [flang][cuda] Allow complex type in cuf kernel reduce

---
 flang/lib/Semantics/check-cuda.cpp | 3 ++-
 flang/test/Semantics/reduce.cuf    | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index d8a5639227648f..f1bdb4f20a55cf 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -553,7 +553,8 @@ static void CheckReduce(
         case parser::ReductionOperator::Operator::Multiply:
         case parser::ReductionOperator::Operator::Max:
         case parser::ReductionOperator::Operator::Min:
-          isOk = cat == TypeCategory::Integer || cat == TypeCategory::Real;
+          isOk = cat == TypeCategory::Integer || cat == TypeCategory::Real ||
+              cat == TypeCategory::Complex;
           break;
         case parser::ReductionOperator::Operator::Iand:
         case parser::ReductionOperator::Operator::Ior:
diff --git a/flang/test/Semantics/reduce.cuf b/flang/test/Semantics/reduce.cuf
index 92d12ab149010d..0ee7fa097432c2 100644
--- a/flang/test/Semantics/reduce.cuf
+++ b/flang/test/Semantics/reduce.cuf
@@ -1,5 +1,5 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
-subroutine s(n,m,a,l)
+subroutine s(n,m,a,l,c)
   integer, intent(in) :: n
   integer, device, intent(in) :: m(n)
   real, device, intent(in) :: a(n)
@@ -7,6 +7,8 @@ subroutine s(n,m,a,l)
   integer j, mr
   real ar
   logical lr
+  complex :: cr
+  complex, device, intent(in) :: c(n)
 !$cuf kernel do <<<*,*>>> reduce (+:mr,ar)
   do j=1,n; mr = mr + m(j); ar = ar + a(j); end do
 !ERROR: !$CUF KERNEL DO REDUCE operation is not acceptable for a variable with type LOGICAL(4)
@@ -69,4 +71,6 @@ subroutine s(n,m,a,l)
 !ERROR: !$CUF KERNEL DO REDUCE operation is not acceptable for a variable with type REAL(4)
 !$cuf kernel do <<<*,*>>> reduce (.or.:mr,ar)
   do j=1,n; end do
+!$cuf kernel do <<<*,*>>> reduce (+:cr) ! ok complex type
+  do j=1,n; cr = cr + c(j); end do
 end



More information about the flang-commits mailing list