Skip to content

Commit 7d80a3f

Browse files
committed
Fixing the location attribute added to mapInfoOp
Named location attribute added tgt_info shall be used by runtime calls like ompx_dump_mapping_tables to print the information of variables that are mapped to the device. Before this change, ompx_dump_mapping_tables was printing the wrong location information.
1 parent b4a0fd4 commit 7d80a3f

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,13 @@ bool ClauseProcessor::processMap(
903903
// Explicit map captures are captured ByRef by default,
904904
// optimisation passes may alter this to ByCopy or other capture
905905
// types to optimise
906+
auto context = converter.getFirOpBuilder().getContext();
907+
auto location = mlir::NameLoc::get(
908+
mlir::StringAttr::get(context, asFortran.str()),
909+
symAddr.getLoc());
906910
mlir::Value mapOp = createMapInfoOp(
907-
firOpBuilder, clauseLocation, symAddr, mlir::Value{},
908-
asFortran.str(), bounds, {},
911+
firOpBuilder, location, symAddr, mlir::Value{}, asFortran.str(),
912+
bounds, {},
909913
static_cast<
910914
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
911915
mapTypeBits),

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,11 +1644,14 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
16441644
} else if (!fir::isa_builtin_cptr_type(eleType)) {
16451645
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
16461646
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1647-
}
1648-
1647+
};
1648+
auto context = converter.getFirOpBuilder().getContext();
1649+
auto location = mlir::NameLoc::get(
1650+
mlir::StringAttr::get(context, sym.name().ToString()),
1651+
baseOp.getLoc());
16491652
mlir::Value mapOp = createMapInfoOp(
1650-
firOpBuilder, baseOp.getLoc(), baseOp, mlir::Value{}, name.str(),
1651-
bounds, {},
1653+
firOpBuilder, location, baseOp, mlir::Value{}, name.str(), bounds,
1654+
{},
16521655
static_cast<
16531656
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
16541657
mapFlag),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
! Offloading test with a target region mapping a declare target
2+
! Fortran array writing some values to it and checking the host
3+
! correctly receives the updates made on the device.
4+
! REQUIRES: flang
5+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
6+
! UNSUPPORTED: aarch64-unknown-linux-gnu
7+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
8+
! UNSUPPORTED: x86_64-pc-linux-gnu
9+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
10+
11+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
12+
13+
program map_dump_example
14+
INTERFACE
15+
SUBROUTINE ompx_dump_mapping_tables() BIND(C)
16+
END SUBROUTINE ompx_dump_mapping_tables
17+
END INTERFACE
18+
19+
integer i,j,k,N
20+
integer async_q(4)
21+
real :: A(5000000),B(5000000),C(5000000)
22+
N=5000000
23+
do i=1, N
24+
A(i)=0
25+
enddo
26+
! clang-format off
27+
! CHECK: omptarget device 0 info: OpenMP Host-Device pointer mappings after block
28+
! CHECK-NEXT: omptarget device 0 info: Host Ptr Target Ptr Size (B) DynRefCount HoldRefCount Declaration
29+
! CHECK-NEXT: omptarget device 0 info: {{(0x[0-9a-f]{16})}} {{(0x[0-9a-f]{16})}} 20000000 1 0 {{.*}} at a(:n):21:11
30+
! clang-format on
31+
!$omp target enter data map(to:A(:N))
32+
call ompx_dump_mapping_tables()
33+
!$omp target parallel do
34+
do i=1, N
35+
A(i)=B(i)*C(i)
36+
enddo
37+
!$omp target exit data map(from:A)
38+
end program

0 commit comments

Comments
 (0)