Skip to content

Conversation

@clementval
Copy link
Contributor

  • Allow ieee_arithmetic on the device
  • Add ignore_tkr(d) to ieee_is_finite

@clementval clementval requested a review from wangzpgi March 18, 2025 22:34
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-flang-semantics

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

Changes
  • Allow ieee_arithmetic on the device
  • Add ignore_tkr(d) to ieee_is_finite

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

3 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+8)
  • (modified) flang/module/ieee_arithmetic.f90 (+1)
  • (modified) flang/test/Semantics/cuf09.cuf (+12)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index cb7a383284e63..dea170f7e099b 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -82,6 +82,14 @@ struct DeviceExprChecker
           }
         }
       }
+      const Symbol &ultimate{sym->GetUltimate()};
+      const Scope &scope{ultimate.owner()};
+      const Symbol *mod{scope.IsModule() ? scope.symbol() : nullptr};
+      // Allow ieee_arithmetic module functions to be called on the device.
+      // TODO: Check for unsupported ieee_arithmetic on the device.
+      if (mod && mod->name() == "ieee_arithmetic") {
+        return {};
+      }
     } else if (x.GetSpecificIntrinsic()) {
       // TODO(CUDA): Check for unsupported intrinsics here
       return {};
diff --git a/flang/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90
index 45016e84de7a3..4e938a2daaa91 100644
--- a/flang/module/ieee_arithmetic.f90
+++ b/flang/module/ieee_arithmetic.f90
@@ -339,6 +339,7 @@ end subroutine ieee_get_underflow_mode_l##GKIND;
 #define IEEE_IS_FINITE_R(XKIND) \
   elemental logical function ieee_is_finite_a##XKIND(x); \
     real(XKIND), intent(in) :: x; \
+    !dir$ ignore_tkr(d) x; \
   end function ieee_is_finite_a##XKIND;
   interface ieee_is_finite
     SPECIFICS_R(IEEE_IS_FINITE_R)
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index a8c62db65c6d5..b59d02192f618 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -209,3 +209,15 @@ subroutine host1()
     a(i) = a(i) + a(j) - 34.0
   end do
 end 
+
+subroutine ieee_test
+  use ieee_arithmetic
+
+  real(8), device :: y(100)
+  logical(4), managed :: ll(100)
+
+  !$cuf kernel do(1)<<<*,*>>>
+  do i = 1, 100
+    ll(i) = ieee_is_finite(y(i)) ! allow ieee_arithmetic functions on the device.
+  end do
+end subroutine

@clementval clementval merged commit 20feca4 into llvm:main Mar 19, 2025
14 checks passed
@clementval clementval deleted the cuf_ieee_arith branch March 19, 2025 14:20
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