[Openmp-commits] [PATCH] D155629: [OpenMP][libomptarget] Retrieve multiple resources from resource managers

Kevin Sala via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Jul 18 12:15:44 PDT 2023


kevinsala created this revision.
kevinsala added reviewers: jdoerfert, jhuber6, tianshilei1992.
kevinsala added a project: OpenMP.
Herald added subscribers: sunshaoce, kerbowa, guansong, yaxunl, jvesely.
Herald added a project: All.
kevinsala requested review of this revision.
Herald added subscribers: openmp-commits, jplehr, sstefan1.

This patch extends the plugin resource managers to return more than one resource
per call. The return function is not extended since we do not return more than
one resource anywhere.

Depends on D155621 <https://reviews.llvm.org/D155621>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155629

Files:
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h


Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -1161,8 +1161,8 @@
     return Plugin::success();
   }
 
-  /// Get resource from the pool or create new resources. If the function
-  /// succeeeds, the handle to the resource is saved in \p Handle.
+  /// Get a resource from the pool or create new ones. If the function succeeds,
+  /// the handle to the resource is saved in \p Handle.
   Error getResource(ResourceHandleTy &Handle) {
     const std::lock_guard<std::mutex> Lock(Mutex);
 
@@ -1180,6 +1180,32 @@
     return Plugin::success();
   }
 
+  /// Get multiple resources from the pool or create new ones. If the function
+  /// succeeeds, the handles to the resources are saved in \p Handles.
+  Error getResources(uint32_t Num,
+                     llvm::SmallVectorImpl<ResourceHandleTy> &Handles) {
+    Handles.resize(Num);
+
+    const std::lock_guard<std::mutex> Lock(Mutex);
+
+    assert(NextAvailable <= ResourcePool.size() &&
+           "Resource pool is corrupted");
+
+    if (NextAvailable + Num > ResourcePool.size())
+      // Double the resource pool or resize it to provide the requested ones.
+      if (auto Err = ResourcePoolTy::resizeResourcePool(
+              std::max(NextAvailable * 2, NextAvailable + Num)))
+        return Err;
+
+    // Save the handles in the output array parameter.
+    for (uint32_t r = 0; r < Num; ++r)
+      Handles[r] = ResourcePool[NextAvailable + r];
+
+    NextAvailable += Num;
+
+    return Plugin::success();
+  }
+
   /// Return resource to the pool.
   Error returnResource(ResourceHandleTy Handle) {
     const std::lock_guard<std::mutex> Lock(Mutex);
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -1142,13 +1142,9 @@
   Error pushMemoryCopyD2HAsync(void *Dst, const void *Src, void *Inter,
                                uint64_t CopySize,
                                AMDGPUMemoryManagerTy &MemoryManager) {
-    // TODO: Managers should define a function to retrieve multiple resources
-    // in a single call.
     // Retrieve available signals for the operation's outputs.
-    AMDGPUSignalTy *OutputSignals[2] = {nullptr};
-    if (auto Err = SignalManager.getResource(OutputSignals[0]))
-      return Err;
-    if (auto Err = SignalManager.getResource(OutputSignals[1]))
+    llvm::SmallVector<AMDGPUSignalTy *, 2> OutputSignals;
+    if (auto Err = SignalManager.getResources(2, OutputSignals))
       return Err;
     OutputSignals[0]->reset();
     OutputSignals[1]->reset();
@@ -1215,10 +1211,8 @@
                                uint64_t CopySize,
                                AMDGPUMemoryManagerTy &MemoryManager) {
     // Retrieve available signals for the operation's outputs.
-    AMDGPUSignalTy *OutputSignals[2] = {nullptr};
-    if (auto Err = SignalManager.getResource(OutputSignals[0]))
-      return Err;
-    if (auto Err = SignalManager.getResource(OutputSignals[1]))
+    llvm::SmallVector<AMDGPUSignalTy *, 2> OutputSignals;
+    if (auto Err = SignalManager.getResources(2, OutputSignals))
       return Err;
     OutputSignals[0]->reset();
     OutputSignals[1]->reset();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155629.541667.patch
Type: text/x-patch
Size: 3558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230718/0e1c02e3/attachment.bin>


More information about the Openmp-commits mailing list