[flang-commits] [flang] [flang][cuda][NFC] Add tests for device functions in cuf kernels (PR #125882)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 5 08:55:57 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

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

<details>
<summary>Changes</summary>

Using device function in cuf kernel is allowed but requires an explicit use of the cudadevice module. The two added tests make sur it works when the cudadevice module is used and failed when it is not.

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


2 Files Affected:

- (modified) flang/test/Lower/CUDA/cuda-device-proc.cuf (+14) 
- (modified) flang/test/Semantics/cuf09.cuf (+13) 


``````````diff
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index 7ef391c7d308ba..5805dd5010a842 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -87,3 +87,17 @@ end
 ! CHECK: func.func private @llvm.nvvm.barrier0.and(i32) -> i32
 ! CHECK: func.func private @llvm.nvvm.barrier0.popc(i32) -> i32
 ! CHECK: func.func private @llvm.nvvm.barrier0.or(i32) -> i32
+
+subroutine host1()
+  integer, device :: a(32)
+  integer :: i, j
+
+block; use cudadevice
+  !$cuf kernel do(1) <<<*,32>>>
+  do i = 1, 32
+    a(i) = a(i) * 2.0
+    call syncthreads()
+    a(i) = a(i) + a(j) - 34.0
+  end do
+end block
+end 
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index fda8938b8ffc0d..7d32e0d70ba36c 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -192,3 +192,16 @@ program main
      enddo
   enddo
 end
+
+subroutine host1()
+  integer, device :: a(32)
+  integer :: i, j
+
+  !$cuf kernel do(1) <<<*,32>>>
+  do i = 1, 32
+    a(i) = a(i) * 2.0
+    !ERROR: 'syncthreads' may not be called in device code
+    call syncthreads() ! missing explicit use cudadevice
+    a(i) = a(i) + a(j) - 34.0
+  end do
+end 

``````````

</details>


https://github.com/llvm/llvm-project/pull/125882


More information about the flang-commits mailing list