[flang-commits] [flang] [flang][cuda] Implicitly set bind(c) called kernel as global (PR #191050)
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 8 14:03:09 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/191050.diff
2 Files Affected:
- (modified) flang/lib/Semantics/expression.cpp (+6)
- (modified) flang/test/Lower/CUDA/cuda-device-proc.cuf (+16)
``````````diff
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index bd4e2a44df8ae..756bfd551a90a 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -3551,6 +3551,12 @@ void ExpressionAnalyzer::Analyze(const parser::CallStmt &callStmt) {
isKernel = *attrs == common::CUDASubprogramAttrs::Global ||
*attrs == common::CUDASubprogramAttrs::Grid_Global;
}
+ // Implicitly set the CUDA subprogram attributes to GLOBAL for bind(c)
+ // subprograms that are not marked as kernel.
+ if (!isKernel && isBindC && !chevrons->empty()) {
+ const_cast<semantics::SubprogramDetails *>(subpDetails)
+ ->set_cudaSubprogramAttrs(common::CUDASubprogramAttrs::Global);
+ }
} else if (const auto *procDetails{
ultimate.detailsIf<semantics::ProcEntityDetails>()}) {
isKernel = procDetails->isCUDAKernel();
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index f5ea2c5d414ea..95be49157b907 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -2,6 +2,8 @@
! Test CUDA Fortran procedures available in cudadevice module
+
+
attributes(global) subroutine devsub()
implicit none
integer :: ret
@@ -766,3 +768,17 @@ end subroutine
! CHECK: nvvm.cp.async.bulk.global.shared.cta %{{.*}}, %{{.*}}, %{{.*}} : <1>, <3>
! CHECK: nvvm.inline_ptx "cp.async.bulk.commit_group;"
! CHECK: nvvm.cp.async.bulk.wait_group 0
+
+
+subroutine call_c_kernel()
+ interface
+ subroutine c_kernel() bind(c,name='c_kernel')
+ end subroutine
+ end interface
+
+ call c_kernel<<<1,1>>>()
+end subroutine
+
+! CHECK-LABEL: func.func @_QPcall_c_kernel()
+! CHECK: cuf.kernel_launch @c_kernel<<<{{.*}}>>>()
+! CHECK: func.func private @c_kernel() attributes {cuf.proc_attr = #cuf.cuda_proc<global>, fir.bindc_name = "c_kernel", fir.proc_attrs = #fir.proc_attrs<bind_c>}
``````````
</details>
https://github.com/llvm/llvm-project/pull/191050
More information about the flang-commits
mailing list