Skip to content

[flang][cuda][NFC] Add tests for device functions in cuf kernels #125882

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

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

clementval
Copy link
Contributor

@clementval clementval commented Feb 5, 2025

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

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.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Feb 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 5, 2025

@llvm/pr-subscribers-flang-semantics

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

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

Changes

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 --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 

@clementval clementval merged commit d3e2459 into llvm:main Feb 5, 2025
10 of 11 checks passed
@clementval clementval deleted the cuf_intrinsic_in_cuf_kernel branch February 5, 2025 17:53
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir 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