[flang-commits] [flang] [flang][cuda] Do not generate section checks in device context (PR #146170)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri Jun 27 15:13:01 PDT 2025
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/146170
This check is only useful on the host side. Also the function is bot built for the device.
>From 47d457f8268cb50db5e4144afdf1ab3ad5004b91 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 27 Jun 2025 15:11:59 -0700
Subject: [PATCH] [flang][cuda] Do not generate section checks in device
context
---
flang/lib/Lower/ConvertCall.cpp | 4 ++-
flang/test/Lower/CUDA/cuda-runtime-check.cuf | 38 +++++++++++++-------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index 864499e6c3431..6ed15df0de754 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -20,6 +20,7 @@
#include "flang/Lower/StatementContext.h"
#include "flang/Lower/SymbolMap.h"
#include "flang/Optimizer/Builder/BoxValue.h"
+#include "flang/Optimizer/Builder/CUFCommon.h"
#include "flang/Optimizer/Builder/Character.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/HLFIRTools.h"
@@ -545,7 +546,8 @@ Fortran::lower::genCallOpAndResult(
caller.getProcedureAttrs(builder.getContext());
if (converter.getLoweringOptions().getCUDARuntimeCheck()) {
- if (caller.getCallDescription().chevrons().empty()) {
+ if (caller.getCallDescription().chevrons().empty() &&
+ !cuf::isCUDADeviceContext(builder.getRegion())) {
for (auto [oper, arg] :
llvm::zip(operands, caller.getPassedArguments())) {
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(oper.getType())) {
diff --git a/flang/test/Lower/CUDA/cuda-runtime-check.cuf b/flang/test/Lower/CUDA/cuda-runtime-check.cuf
index f26d372769cab..1aa95ec0ff405 100644
--- a/flang/test/Lower/CUDA/cuda-runtime-check.cuf
+++ b/flang/test/Lower/CUDA/cuda-runtime-check.cuf
@@ -1,22 +1,36 @@
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
-! Check insertion of runtime checks
+! Check insertion of runtime checks in host side only
+
+module section_test
+
+contains
-interface
subroutine foo(a)
real, device, dimension(:,:) :: a
end subroutine
-end interface
- real, device, allocatable, dimension(:,:) :: a
- allocate(a(10,10))
- call foo(a(1:10,1:10:2))
-end
+ subroutine test_host()
+ real, device, allocatable, dimension(:,:) :: a
+ allocate(a(10,10))
+ call foo(a(1:10,1:10:2))
+ end subroutine
+
+ attributes(device) subroutine zoo(a)
+ real, device, dimension(:,:) :: a
+ end subroutine
-subroutine foo(a)
- real, device, dimension(:,:) :: a
-end subroutine
+ attributes(global) subroutine test_device()
+ real, device, allocatable, dimension(:,:) :: a
+ allocate(a(10,10))
+ call zoo(a(1:10,1:10:2))
+ end subroutine
+end module
-! CHECK-LABEL: func.func @_QQmain()
+! CHECK-LABEL: func.func @_QMsection_testPtest_host()
! CHECK: fir.call @_FortranACUFDescriptorCheckSection
-! CHECK: fir.call @_QPfoo
+! CHECK: fir.call @_QMsection_testPfoo
+
+! CHECK-LABEL: func.func @_QMsection_testPtest_device()
+! CHECK-NOT: fir.call @_FortranACUFDescriptorCheckSection
+! CHECK: fir.call @_QMsection_testPzoo
More information about the flang-commits
mailing list