[flang-commits] [flang] [flang][cuda] Implicitly set bind(c) called kernel as global (PR #191050)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Apr 8 14:42:47 PDT 2026
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/191050 at github.com>
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/191050
>From e3b9d129ea245b94e3b859637bbc710d8052f5b4 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 8 Apr 2026 13:46:08 -0700
Subject: [PATCH 1/2] [flang][cuda] Implicitly set bind(c) called kernel as
global
---
flang/lib/Semantics/expression.cpp | 6 ++++++
flang/test/Lower/CUDA/cuda-device-proc.cuf | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
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>}
>From 0c262f22cee9a4c59eabe8a4d5f09ec691be1d9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?=
=?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?=
=?UTF-8?q?=E3=83=B3=29?= <clementval at gmail.com>
Date: Wed, 8 Apr 2026 14:42:37 -0700
Subject: [PATCH 2/2] Apply suggestion from @clementval
---
flang/test/Lower/CUDA/cuda-device-proc.cuf | 2 --
1 file changed, 2 deletions(-)
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index 95be49157b907..61662e4822177 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -2,8 +2,6 @@
! Test CUDA Fortran procedures available in cudadevice module
-
-
attributes(global) subroutine devsub()
implicit none
integer :: ret
More information about the flang-commits
mailing list