This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP]Fix PR46824: Global declare target pointer cannot be accessed in target region.
ClosedPublic

Authored by ABataev on Jul 28 2020, 10:11 AM.

Details

Summary

Need to map the base pointer for all directives, not only target
data-based ones.
The base pointer is mapped for array sections, array subscript, array
shaping and other array-like constructs with the base pointer. Also,
codegen for use_device_ptr clause was modified to correctly handle
mapping combination of array like constructs + use_device_ptr clause.
The data for use_device_ptr clause is emitted as the last records in the
data mapping array.

Diff Detail

Event Timeline

ABataev created this revision.Jul 28 2020, 10:11 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 28 2020, 10:11 AM
ABataev requested review of this revision.Jul 28 2020, 10:11 AM
ye-luo requested changes to this revision.Jul 28 2020, 12:42 PM

Please check the reproducer in https://bugs.llvm.org/show_bug.cgi?id=46868 with LIBOMPTARGET_DEBUG=1.
The reference counting on the base pointer variable has side effects. It was not cleaned up when these variables leave its scope.

This revision now requires changes to proceed.Jul 28 2020, 12:42 PM
ABataev updated this revision to Diff 281369.Jul 28 2020, 2:42 PM

Fixed ref count for base pointer + extra test.

This patch
GPU activities: 96.99% 350.05ms 10 35.005ms 1.5680us 350.00ms [CUDA memcpy HtoD]
before the July21 change
GPU activities: 95.33% 20.317ms 4 5.0793ms 1.6000us 20.305ms [CUDA memcpy HtoD]
Still more transfer than it should.

ye-luo added a comment.EditedJul 28 2020, 4:13 PM

This patch
GPU activities: 96.99% 350.05ms 10 35.005ms 1.5680us 350.00ms [CUDA memcpy HtoD]
before the July21 change
GPU activities: 95.33% 20.317ms 4 5.0793ms 1.6000us 20.305ms [CUDA memcpy HtoD]
Still more transfer than it should.

@ABataev could you have a look? My July 21 compiler was built before "[OPENMP]Fix PR46012: declare target pointer cannot be accessed in target region." gets in.

This patch
GPU activities: 96.99% 350.05ms 10 35.005ms 1.5680us 350.00ms [CUDA memcpy HtoD]
before the July21 change
GPU activities: 95.33% 20.317ms 4 5.0793ms 1.6000us 20.305ms [CUDA memcpy HtoD]
Still more transfer than it should.

@ABataev could you have a look? My July 21 compiler was built before "[OPENMP]Fix PR46012: declare target pointer cannot be accessed in target region." gets in.

Are you talking about the number of calls value? The total number of calls will increase after the patch anyway, PTR_AND_OBJ adds 1 extra mem transfer for transferring translated pointer address.

ABataev updated this revision to Diff 281665.Jul 29 2020, 10:41 AM

Rebase + apply to global pointers only.

grokos added inline comments.Jul 29 2020, 11:27 AM
clang/test/OpenMP/target_data_codegen.cpp
659–661

MEMBER_OF_7=0x9000000000000 --> MEMBER_OF_7=0x7000000000000

ABataev updated this revision to Diff 281690.Jul 29 2020, 11:36 AM

Fixed comment in test

ye-luo accepted this revision.Jul 29 2020, 2:09 PM

LGTM. My applications run as expected now. PR46824, PR46012, PR46868 all work fine.

This revision is now accepted and ready to land.Jul 29 2020, 2:09 PM
This revision was landed with ongoing or failed builds.Jul 30 2020, 6:41 AM
This revision was automatically updated to reflect the committed changes.