[flang-commits] [flang] [flang][cuda][NFC] Add tests for device functions in cuf kernels (PR #125882)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Feb 5 08:55:24 PST 2025
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/125882
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.
>From 40342f5bb8ed4b0eb6acda01a80e96de6b6286a3 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 4 Feb 2025 15:53:24 -0800
Subject: [PATCH] [flang][cuda][NFC] Add tests for device functions in cuf
kernels
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.
---
flang/test/Lower/CUDA/cuda-device-proc.cuf | 14 ++++++++++++++
flang/test/Semantics/cuf09.cuf | 13 +++++++++++++
2 files changed, 27 insertions(+)
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
More information about the flang-commits
mailing list