-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Offload]: Skip copying of unused kernel-mapped data #124723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pradt2
wants to merge
9
commits into
llvm:main
Choose a base branch
from
pradt2:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6e42d52
[Offload]: Skip copying of unused kernel-mapped data
pradt2 12561c4
[Offload]: Skip copying of unused kernel-mapped data
pradt2 10860d1
Merge branch 'main' into main
pradt2 02f78ec
[Offload]: Skip copying of unused kernel-mapped data
pradt2 153b3f9
[Offload]: Skip copying of unused kernel-mapped data
pradt2 de77e4b
[Offload]: Skip copying of unused kernel-mapped data
pradt2 050c5e3
[Offload]: Skip copying of unused kernel-mapped data
pradt2 99bd34b
[Offload]: Skip copying of unused kernel-mapped data
pradt2 a9f28dd
Merge branch 'main' of https://github.com/llvm/llvm-project
pradt2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1197,6 +1197,71 @@ class PrivateArgumentManagerTy { | |
| } | ||
| }; | ||
|
|
||
| /// Try to find redundant mappings associated with a kernel launch, | ||
| /// and provide a masked version of the kernel argument types that | ||
| /// avoid redundant to data transfers between the host and device. | ||
| static std::unique_ptr<int64_t[]> maskRedundantTransfers(DeviceTy &Device, int32_t ArgNum, | ||
| int64_t *ArgTypes, int64_t *ArgSizes, | ||
| map_var_info_t *ArgNames, void **ArgPtrs, | ||
| void **ArgMappers) { | ||
| std::unique_ptr<int64_t[]> ArgTypesOverride = std::make_unique<int64_t[]>(ArgNum); | ||
|
|
||
| MappingInfoTy &MappingInfo = Device.getMappingInfo(); | ||
| MappingInfoTy::HDTTMapAccessorTy HDTTMap = MappingInfo | ||
| .HostDataToTargetMap.getExclusiveAccessor(); | ||
|
|
||
| int64_t UnusedArgs = 0; | ||
|
|
||
| for (int32_t I = 0; I < ArgNum; ++I) { | ||
| tgt_map_type ArgType = (tgt_map_type) ArgTypes[I]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang format the commit. (sth like |
||
|
|
||
| // Check for unused implicit mappings | ||
| bool IsArgUnused = ArgType == OMP_TGT_MAPTYPE_NONE; | ||
|
|
||
| // Check for unused `map(buf[0:size])` mappings | ||
| IsArgUnused |= ArgType == OMP_TGT_MAPTYPE_FROM | ||
| || ArgType == OMP_TGT_MAPTYPE_TO | ||
| || ArgType == (OMP_TGT_MAPTYPE_FROM | OMP_TGT_MAPTYPE_TO); | ||
|
|
||
| // Check for unused `map(wrapper.buf[0:size])` mappings | ||
| IsArgUnused |= UnusedArgs == ArgNum - 1 && ArgType & OMP_TGT_MAPTYPE_MEMBER_OF | ||
| && ((ArgType & ~OMP_TGT_MAPTYPE_MEMBER_OF) == OMP_TGT_MAPTYPE_PTR_AND_OBJ | ||
| || (ArgType & ~OMP_TGT_MAPTYPE_MEMBER_OF) == (OMP_TGT_MAPTYPE_PTR_AND_OBJ | OMP_TGT_MAPTYPE_TO) | ||
| || (ArgType & ~OMP_TGT_MAPTYPE_MEMBER_OF) == (OMP_TGT_MAPTYPE_PTR_AND_OBJ | OMP_TGT_MAPTYPE_FROM | OMP_TGT_MAPTYPE_TO)); | ||
|
|
||
| bool IsExistingMapping = !MappingInfo.lookupMapping(HDTTMap, ArgPtrs[I], ArgSizes[I]).isEmpty(); | ||
|
|
||
| bool IsCustomMapped = ArgMappers && ArgMappers[I]; | ||
|
|
||
| if (IsExistingMapping | IsCustomMapped | !IsArgUnused) { | ||
| ArgTypesOverride[I] = ArgTypes[I]; | ||
| continue; | ||
| } | ||
|
|
||
| const std::string Name = ArgNames && ArgNames[I] ? | ||
| getNameFromMapping(ArgNames[I]) : std::string("unknown"); | ||
|
|
||
| bool IsArgFrom = ArgType & OMP_TGT_MAPTYPE_FROM; | ||
| bool IsArgTo = ArgType & OMP_TGT_MAPTYPE_TO; | ||
|
|
||
| const char *Type = IsArgFrom && IsArgTo ? "tofrom" | ||
| : IsArgFrom ? "from" | ||
| : IsArgTo ? "to" | ||
| : "unknown"; | ||
|
|
||
| // Optimisation: | ||
| // A new mapping is not used by the kernel. | ||
| // Change the type such that no data is transferred to and/or from the device. | ||
| INFO(OMP_INFOTYPE_REDUNDANT_TRANSFER, Device.DeviceID, "%s(%s)[%" PRId64 "] %s\n", Type, | ||
| Name.c_str(), ArgSizes[I], "is not used and will not be copied"); | ||
|
|
||
| ArgTypesOverride[I] = ArgTypes[I] & ~(OMP_TGT_MAPTYPE_TO | OMP_TGT_MAPTYPE_FROM); | ||
| UnusedArgs++; | ||
| } | ||
|
|
||
| return ArgTypesOverride; | ||
| } | ||
|
|
||
| /// Process data before launching the kernel, including calling targetDataBegin | ||
| /// to map and transfer data to target device, transferring (first-)private | ||
| /// variables. | ||
|
|
@@ -1417,11 +1482,16 @@ int target(ident_t *Loc, DeviceTy &Device, void *HostPtr, | |
|
|
||
| int NumClangLaunchArgs = KernelArgs.NumArgs; | ||
| int Ret = OFFLOAD_SUCCESS; | ||
|
|
||
| std::unique_ptr<int64_t[]> ArgTypesOverride = | ||
| maskRedundantTransfers(Device, NumClangLaunchArgs, KernelArgs.ArgTypes, | ||
| KernelArgs.ArgSizes, KernelArgs.ArgNames, KernelArgs.ArgPtrs, KernelArgs.ArgMappers); | ||
|
|
||
| if (NumClangLaunchArgs) { | ||
| // Process data, such as data mapping, before launching the kernel | ||
| Ret = processDataBefore(Loc, DeviceId, HostPtr, NumClangLaunchArgs, | ||
| KernelArgs.ArgBasePtrs, KernelArgs.ArgPtrs, | ||
| KernelArgs.ArgSizes, KernelArgs.ArgTypes, | ||
| KernelArgs.ArgSizes, ArgTypesOverride.get(), | ||
| KernelArgs.ArgNames, KernelArgs.ArgMappers, TgtArgs, | ||
| TgtOffsets, PrivateArgumentManager, AsyncInfo); | ||
| if (Ret != OFFLOAD_SUCCESS) { | ||
|
|
@@ -1473,7 +1543,7 @@ int target(ident_t *Loc, DeviceTy &Device, void *HostPtr, | |
| // variables | ||
| Ret = processDataAfter(Loc, DeviceId, HostPtr, NumClangLaunchArgs, | ||
| KernelArgs.ArgBasePtrs, KernelArgs.ArgPtrs, | ||
| KernelArgs.ArgSizes, KernelArgs.ArgTypes, | ||
| KernelArgs.ArgSizes, ArgTypesOverride.get(), | ||
| KernelArgs.ArgNames, KernelArgs.ArgMappers, | ||
| PrivateArgumentManager, AsyncInfo); | ||
| if (Ret != OFFLOAD_SUCCESS) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // clang-format off | ||
| // RUN: %libomptarget-compilexx-generic | ||
| // RUN: env LIBOMPTARGET_INFO=128 %libomptarget-run-generic 2>&1 \ | ||
| // RUN: | %fcheck-generic | ||
|
|
||
| // REQUIRES: gpu | ||
| // clang-format on | ||
|
|
||
| int main() { | ||
| float DataStack = 0; | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: from(unknown)[4] is not used and will not be copied | ||
| #pragma omp target map(from: DataStack) | ||
| { | ||
| DataStack = 1; | ||
| } | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: to(unknown)[4] is not used and will not be copied | ||
| #pragma omp target map(always to: DataStack) | ||
| ; | ||
|
|
||
| // CHECK: omptarget device 0 info: tofrom(unknown)[4] is not used and will not be copied | ||
| #pragma omp target map(tofrom: DataStack) | ||
| ; | ||
|
|
||
| int Size = 16; | ||
| double *Data = new double[Size]; | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: tofrom(unknown)[8] is not used and will not be copied | ||
| #pragma omp target map(tofrom: Data[0:1]) | ||
| { | ||
| Data[0] = 1; | ||
| } | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: tofrom(unknown)[16] is not used and will not be copied | ||
| #pragma omp target map(always tofrom: Data[0:2]) | ||
| ; | ||
|
|
||
| // CHECK: omptarget device 0 info: from(unknown)[24] is not used and will not be copied | ||
| #pragma omp target map(from: Data[0:3]) | ||
| ; | ||
|
|
||
| // CHECK: omptarget device 0 info: to(unknown)[24] is not used and will not be copied | ||
| #pragma omp target map(to: Data[0:3]) | ||
| ; | ||
|
|
||
| // CHECK: omptarget device 0 info: tofrom(unknown)[32] is not used and will not be copied | ||
| #pragma omp target map(tofrom: Data[0:4]) | ||
| ; | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: to(unknown)[40] is not used and will not be copied | ||
| #pragma omp target map(to: Data[0:5]) | ||
| { | ||
| #pragma omp teams | ||
| Data[0] = 1; | ||
| } | ||
|
|
||
| struct { | ||
| double *Data; | ||
| } Wrapper { .Data = Data }; | ||
|
|
||
| // CHECK-NOT: omptarget device 0 info: tofrom(unknown)[48] is not used and will not be copied | ||
| #pragma omp target map(tofrom: Wrapper.Data[0:6]) | ||
| { | ||
| Wrapper.Data[0] = 1; | ||
| } | ||
|
|
||
| // CHECK: omptarget device 0 info: unknown(unknown)[8] is not used and will not be copied | ||
| // CHECK: omptarget device 0 info: tofrom(unknown)[56] is not used and will not be copied | ||
| #pragma omp target map(tofrom: Wrapper.Data[0:7]) | ||
| ; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.