Skip to content

Commit 794bf30

Browse files
committed
[flang][OpenMP][Offloading][AMDGPU] Add offloading test for target update
Adds a new test for offloading `target update` directive to AMD GPUs.
1 parent 5c458ed commit 794bf30

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ void mlir::configureOpenMPToLLVMConversionLegality(
239239
target.addDynamicallyLegalOp<
240240
mlir::omp::AtomicReadOp, mlir::omp::AtomicWriteOp, mlir::omp::FlushOp,
241241
mlir::omp::ThreadprivateOp, mlir::omp::YieldOp, mlir::omp::EnterDataOp,
242-
mlir::omp::ExitDataOp, mlir::omp::DataBoundsOp, mlir::omp::MapInfoOp>(
243-
[&](Operation *op) {
244-
return typeConverter.isLegal(op->getOperandTypes()) &&
245-
typeConverter.isLegal(op->getResultTypes());
246-
});
242+
mlir::omp::ExitDataOp, mlir::omp::UpdateDataOp, mlir::omp::DataBoundsOp,
243+
mlir::omp::MapInfoOp>([&](Operation *op) {
244+
return typeConverter.isLegal(op->getOperandTypes()) &&
245+
typeConverter.isLegal(op->getResultTypes());
246+
});
247247
target.addDynamicallyLegalOp<mlir::omp::ReductionOp>([&](Operation *op) {
248248
return typeConverter.isLegal(op->getOperandTypes());
249249
});
@@ -282,6 +282,7 @@ void mlir::populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter,
282282
RegionLessOpConversion<omp::YieldOp>,
283283
RegionLessOpConversion<omp::EnterDataOp>,
284284
RegionLessOpConversion<omp::ExitDataOp>,
285+
RegionLessOpConversion<omp::UpdateDataOp>,
285286
RegionLessOpWithVarOperandsConversion<omp::DataBoundsOp>>(converter);
286287
}
287288

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
! Offloading test for the `target update` directive.
2+
3+
! REQUIRES: flang, amdgcn-amd-amdhsa
4+
5+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
6+
program target_update
7+
implicit none
8+
integer :: x(1)
9+
integer :: host_id
10+
integer :: device_id(1)
11+
12+
INTERFACE
13+
FUNCTION omp_get_device_num() BIND(C)
14+
USE, INTRINSIC :: iso_c_binding, ONLY: C_INT
15+
integer :: omp_get_device_num
16+
END FUNCTION omp_get_device_num
17+
END INTERFACE
18+
19+
x(1) = 5
20+
host_id = omp_get_device_num()
21+
22+
!$omp target enter data map(to:x, device_id)
23+
!$omp target
24+
x(1) = 42
25+
!$omp end target
26+
27+
! Test that without a `target update` directive, the target update to x is
28+
! not yet seen by the host.
29+
! CHECK: After first target regions and before target update: x = 5
30+
print *, "After first target regions and before target update: x =", x(1)
31+
32+
!$omp target
33+
x(1) = 84
34+
device_id(1) = omp_get_device_num()
35+
!$omp end target
36+
!$omp target update from(x, device_id)
37+
38+
! Test that after the `target update`, the host can see the new x value.
39+
! CHECK: After second target regions and target update: x = 84
40+
print *, "After second target regions and target update: x =", x(1)
41+
42+
! Make sure that offloading to the device actually happened. This way we
43+
! verify that we didn't take the fallback host execution path.
44+
! CHECK: Offloading succeeded!
45+
if (host_id /= device_id(1)) then
46+
print *, "Offloading succeeded!"
47+
else
48+
print *, "Offloading failed!"
49+
end if
50+
end program target_update

0 commit comments

Comments
 (0)