Skip to content

Commit 570b952

Browse files
authored
[flang][cuda] Do not generate section checks in device context (#146170)
This check is only useful on the host side. Also the function is bot built for the device.
1 parent 6d81781 commit 570b952

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

flang/lib/Lower/ConvertCall.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "flang/Lower/StatementContext.h"
2121
#include "flang/Lower/SymbolMap.h"
2222
#include "flang/Optimizer/Builder/BoxValue.h"
23+
#include "flang/Optimizer/Builder/CUFCommon.h"
2324
#include "flang/Optimizer/Builder/Character.h"
2425
#include "flang/Optimizer/Builder/FIRBuilder.h"
2526
#include "flang/Optimizer/Builder/HLFIRTools.h"
@@ -545,7 +546,8 @@ Fortran::lower::genCallOpAndResult(
545546
caller.getProcedureAttrs(builder.getContext());
546547

547548
if (converter.getLoweringOptions().getCUDARuntimeCheck()) {
548-
if (caller.getCallDescription().chevrons().empty()) {
549+
if (caller.getCallDescription().chevrons().empty() &&
550+
!cuf::isCUDADeviceContext(builder.getRegion())) {
549551
for (auto [oper, arg] :
550552
llvm::zip(operands, caller.getPassedArguments())) {
551553
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(oper.getType())) {
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
22

3-
! Check insertion of runtime checks
3+
! Check insertion of runtime checks in host side only
4+
5+
module section_test
6+
7+
contains
48

5-
interface
69
subroutine foo(a)
710
real, device, dimension(:,:) :: a
811
end subroutine
9-
end interface
1012

11-
real, device, allocatable, dimension(:,:) :: a
12-
allocate(a(10,10))
13-
call foo(a(1:10,1:10:2))
14-
end
13+
subroutine test_host()
14+
real, device, allocatable, dimension(:,:) :: a
15+
allocate(a(10,10))
16+
call foo(a(1:10,1:10:2))
17+
end subroutine
18+
19+
attributes(device) subroutine zoo(a)
20+
real, device, dimension(:,:) :: a
21+
end subroutine
1522

16-
subroutine foo(a)
17-
real, device, dimension(:,:) :: a
18-
end subroutine
23+
attributes(global) subroutine test_device()
24+
real, device, allocatable, dimension(:,:) :: a
25+
allocate(a(10,10))
26+
call zoo(a(1:10,1:10:2))
27+
end subroutine
28+
end module
1929

20-
! CHECK-LABEL: func.func @_QQmain()
30+
! CHECK-LABEL: func.func @_QMsection_testPtest_host()
2131
! CHECK: fir.call @_FortranACUFDescriptorCheckSection
22-
! CHECK: fir.call @_QPfoo
32+
! CHECK: fir.call @_QMsection_testPfoo
33+
34+
! CHECK-LABEL: func.func @_QMsection_testPtest_device()
35+
! CHECK-NOT: fir.call @_FortranACUFDescriptorCheckSection
36+
! CHECK: fir.call @_QMsection_testPzoo

0 commit comments

Comments
 (0)