Skip to content
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

[flang][cuda] Allow complex type in cuf kernel reduce #124185

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

clementval
Copy link
Contributor

Complex type is allowed in the reference compiler.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jan 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Complex type is allowed in the reference compiler.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+2-1)
  • (modified) flang/test/Semantics/reduce.cuf (+5-1)
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

@clementval clementval merged commit 4065d98 into llvm:main Jan 23, 2025
11 checks passed
@clementval clementval deleted the cuf_reduce_complex branch January 23, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants