[Openmp-commits] [PATCH] D85216: [LIBOMPTARGET]Fix order of mapper data for targetDataEnd function.

Alexey Bataev via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Aug 4 09:06:17 PDT 2020


ABataev created this revision.
ABataev added reviewers: jdoerfert, grokos, lildmh.
Herald added a project: OpenMP.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.

targetDataMapper function fills arrays with the mapping data in the
direct order. When this function is called by targetDataBegin or
tgt_target_update functions, it works as expected. But targetDataEnd
function processes mapped data in reverse order. In this case, the base
pointer might be deleted before the associated data is deleted. Need to
reverse data, mapped by mapper, too, since it always adds data that must
be deleted at the end of the buffer.
Fixes the test declare_mapper_target_update.cpp.
Also, reduces the memry fragmentation by preallocation the memory
buffers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85216

Files:
  openmp/libomptarget/src/omptarget.cpp


Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ openmp/libomptarget/src/omptarget.cpp
@@ -230,22 +230,26 @@
   // Construct new arrays for args_base, args, arg_sizes and arg_types
   // using the information in MapperComponents and call the corresponding
   // target_data_* function using these new arrays.
-  std::vector<void *> mapper_args_base;
-  std::vector<void *> mapper_args;
-  std::vector<int64_t> mapper_arg_sizes;
-  std::vector<int64_t> mapper_arg_types;
-
-  for (auto& C : MapperComponents.Components) {
-    mapper_args_base.push_back(C.Base);
-    mapper_args.push_back(C.Begin);
-    mapper_arg_sizes.push_back(C.Size);
-    mapper_arg_types.push_back(C.Type);
+  std::vector<void *> MapperArgsBase(MapperComponents.Components.size());
+  std::vector<void *> MapperArgs(MapperComponents.Components.size());
+  std::vector<int64_t> MapperArgSizes(MapperComponents.Components.size());
+  std::vector<int64_t> MapperArgTypes(MapperComponents.Components.size());
+
+  for (unsigned I = 0, E = MapperComponents.Components.size(); I < E; ++I) {
+    auto &C =
+        MapperComponents
+            .Components[target_data_function == targetDataEnd ? I : E - I - 1];
+    MapperArgsBase[I] = C.Base;
+    MapperArgs[I] = C.Begin;
+    MapperArgSizes[I] = C.Size;
+    MapperArgTypes[I] = C.Type;
   }
 
   int rc = target_data_function(Device, MapperComponents.Components.size(),
-      mapper_args_base.data(), mapper_args.data(), mapper_arg_sizes.data(),
-      mapper_arg_types.data(), /*arg_mappers*/ nullptr,
-      /*__tgt_async_info*/ nullptr);
+                                MapperArgsBase.data(), MapperArgs.data(),
+                                MapperArgSizes.data(), MapperArgTypes.data(),
+                                /*arg_mappers*/ nullptr,
+                                /*__tgt_async_info*/ nullptr);
 
   return rc;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85216.282938.patch
Type: text/x-patch
Size: 1971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200804/d5f13dcc/attachment.bin>


More information about the Openmp-commits mailing list