Skip to content

Commit 1a2a0c0

Browse files
authored
Fixing the location attribute added to mapInfoOp (#90764)
Named location attribute added to `tgt_offload_entry` shall be used by runtime calls like `ompx_dump_mapping_tables` to print the information of variables that are mapped to the device. `ompx_dump_mapping_tables` was printing the wrong location information and this change fixes it. A sample execution of example before the change: ``` omptarget device 0 info: OpenMP Host-Device pointer mappings after block at libomptarget:0:0: omptarget device 0 info: Host Ptr Target Ptr Size (B) DynRefCount HoldRefCount Declaration omptarget device 0 info: 0x0000000000206df0 0x00007f02cdc00000 20000000 1 0 <program-file-loc> at unknown:18:35 ``` The change replaces unknown to the mapped symbol and location to the declaration location.
1 parent 4c48b3c commit 1a2a0c0

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,11 @@ bool ClauseProcessor::processMap(
882882
// Explicit map captures are captured ByRef by default,
883883
// optimisation passes may alter this to ByCopy or other capture
884884
// types to optimise
885+
auto location = mlir::NameLoc::get(
886+
mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()),
887+
symAddr.getLoc());
885888
mlir::omp::MapInfoOp mapOp = createMapInfoOp(
886-
firOpBuilder, clauseLocation, symAddr,
889+
firOpBuilder, location, symAddr,
887890
/*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
888891
/*members=*/{}, /*membersIndex=*/mlir::DenseIntElementsAttr{},
889892
static_cast<

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,9 +1604,12 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
16041604
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
16051605
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
16061606
}
1607-
1607+
auto location =
1608+
mlir::NameLoc::get(mlir::StringAttr::get(firOpBuilder.getContext(),
1609+
sym.name().ToString()),
1610+
baseOp.getLoc());
16081611
mlir::Value mapOp = createMapInfoOp(
1609-
firOpBuilder, baseOp.getLoc(), baseOp, /*varPtrPtr=*/mlir::Value{},
1612+
firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{},
16101613
name.str(), bounds, /*members=*/{},
16111614
/*membersIndex=*/mlir::DenseIntElementsAttr{},
16121615
static_cast<
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
! Offloading test with runtine call to ompx_dump_mapping_tables
2+
! Fortran array writing some values and printing the variable mapped to device
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)
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)=A(i)*2
36+
enddo
37+
!$omp target exit data map(from:A)
38+
end program

0 commit comments

Comments
 (0)