[flang-commits] [flang] 996efea - [flang][cuda] Implicitly set bind(c) called kernel as global (#191050)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 8 14:53:38 PDT 2026


Author: Valentin Clement (バレンタイン クレメン)
Date: 2026-04-08T14:53:34-07:00
New Revision: 996efeaaa20247ac6bcdf5de9bf533c94c8a360f

URL: https://github.com/llvm/llvm-project/commit/996efeaaa20247ac6bcdf5de9bf533c94c8a360f
DIFF: https://github.com/llvm/llvm-project/commit/996efeaaa20247ac6bcdf5de9bf533c94c8a360f.diff

LOG: [flang][cuda] Implicitly set bind(c) called kernel as global (#191050)

Added: 
    

Modified: 
    flang/lib/Semantics/expression.cpp
    flang/test/Lower/CUDA/cuda-device-proc.cuf

Removed: 
    


################################################################################
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..61662e4822177 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -766,3 +766,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>}


        


More information about the flang-commits mailing list