This is an archive of the discontinued LLVM Phabricator instance.

[libomptarget] Update device pointer only if needed
ClosedPublic

Authored by grokos on Jul 12 2021, 6:34 AM.

Details

Summary

Currently, libomptarget will always perform a host-to-device memory transfer in order to update the device pointer of a PTR_AND_OBJ entry. This is not always necessary because the device pointer may have been set to the correct pointee address already, so we can eliminate the redundant memory transfer.

The attached test is C code emulating what happens when mapping Fortran dope vectors.

Diff Detail

Event Timeline

grokos requested review of this revision.Jul 12 2021, 6:34 AM
grokos created this revision.
tianshilei1992 accepted this revision.Jul 12 2021, 5:03 PM

LGTM. Thanks. Please fix clang-format issues before commit.

This revision is now accepted and ready to land.Jul 12 2021, 5:03 PM
jdenny added inline comments.Jul 12 2021, 5:56 PM
openmp/libomptarget/test/mapping/device_ptr_update.c
20

Assume we insert s1.p = B here. Without this patch, the target directive below then changes s1.p on the device, but it doesn't with this patch, right?

However, I don't think OpenMP permits that line to be inserted in the case of C/C++:

A pointer that has a corresponding attached pointer must not be modified for the duration of the lifetime of the list item to which the corresponding pointer is attached in the device data environment.

This patch can then be considered as purely an optimization, right?

grokos marked an inline comment as done.Jul 13 2021, 4:19 AM
grokos added inline comments.
openmp/libomptarget/test/mapping/device_ptr_update.c
20

Right. Since the pointer on the host is not allowed to be reassigned to another object while the PTR_AND_OBJ pair is mapped on the device, we can take advantage of this restriction and optimize away all redundant device pointer updates.

grokos closed this revision.Jul 13 2021, 4:35 AM
grokos marked an inline comment as done.

Closed by commit rGbb0166dc7279: [libomptarget] Update device pointer only if needed (authored by grokos).

jdenny added inline comments.Jul 13 2021, 6:37 AM
openmp/libomptarget/test/mapping/device_ptr_update.c
20

Thanks.