[Openmp-commits] [openmp] 6780d56 - [LIBOMPTARGET]Fix order of mapper data for targetDataEnd function.

Alexey Bataev via Openmp-commits openmp-commits at lists.llvm.org
Wed Aug 5 10:49:11 PDT 2020


Author: Alexey Bataev
Date: 2020-08-05T13:42:24-04:00
New Revision: 6780d5675b7cd75279d8fc13ee1a1cc272087613

URL: https://github.com/llvm/llvm-project/commit/6780d5675b7cd75279d8fc13ee1a1cc272087613
DIFF: https://github.com/llvm/llvm-project/commit/6780d5675b7cd75279d8fc13ee1a1cc272087613.diff

LOG: [LIBOMPTARGET]Fix order of mapper data for targetDataEnd function.

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.

Differential Revision: https://reviews.llvm.org/D85216

Added: 
    

Modified: 
    openmp/libomptarget/src/omptarget.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 5f8a3a679e8a..4656ec0ed522 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -230,22 +230,26 @@ int targetDataMapper(DeviceTy &Device, void *arg_base, void *arg,
   // 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;
 }


        


More information about the Openmp-commits mailing list