[llvm] [Offload]: Skip copying of unused kernel-mapped data (PR #124723)
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 6 15:35:35 PDT 2025
================
@@ -1197,6 +1197,97 @@ class PrivateArgumentManagerTy {
}
};
+/// Try to determine if kernel argument is unused. This method
+/// takes a conservative approach, i.e. it may return false
+/// negatives but it should never return a false positive.
+static bool isArgUnused(tgt_map_type ArgType) {
+ bool IsArgUnused = ArgType == OMP_TGT_MAPTYPE_NONE ||
+ ArgType == OMP_TGT_MAPTYPE_FROM ||
+ ArgType == OMP_TGT_MAPTYPE_TO ||
+ ArgType == (OMP_TGT_MAPTYPE_FROM | OMP_TGT_MAPTYPE_TO);
+ return IsArgUnused;
+}
+
+/// Try to find redundant mappings associated with a kernel launch,
+/// and provide a masked version of the kernel argument types that
+/// avoid redundant data transfers between the host and the 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);
+
+ bool AllArgsUnused = true;
+
+ for (int32_t I = 0; I < ArgNum; ++I) {
+ bool IsCustomMapped = ArgMappers && ArgMappers[I];
+
+ if (IsCustomMapped) {
+ ArgTypesOverride[I] = ArgTypes[I];
+ AllArgsUnused = false;
+ continue;
+ }
+
+ tgt_map_type ArgType = (tgt_map_type) ArgTypes[I];
----------------
jdoerfert wrote:
Clang format the commit. (sth like `git clang-format HEAD~` if the script is in your path)
https://github.com/llvm/llvm-project/pull/124723
More information about the llvm-commits
mailing list