[Openmp-commits] [PATCH] D110513: [AMDGPU][OpenMP] Add memory pool size check to isValidMemoryPool

Pushpinder Singh via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Sep 27 02:53:00 PDT 2021


pdhaliwal updated this revision to Diff 375182.
pdhaliwal added a comment.

- rebase after rG9d0eb440ff40 <https://reviews.llvm.org/rG9d0eb440ff40a46a30c10a96a9ef86e50fd932a7>
- change return type of hsa_status_t


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110513/new/

https://reviews.llvm.org/D110513

Files:
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp


Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -304,8 +304,7 @@
   return header;
 }
 
-std::pair<hsa_status_t, bool>
-isValidMemoryPool(hsa_amd_memory_pool_t MemoryPool) {
+hsa_status_t isValidMemoryPool(hsa_amd_memory_pool_t MemoryPool) {
   bool AllocAllowed = false;
   hsa_status_t Err = hsa_amd_memory_pool_get_info(
       MemoryPool, HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED,
@@ -313,49 +312,38 @@
   if (Err != HSA_STATUS_SUCCESS) {
     DP("Alloc allowed in memory pool check failed: %s\n",
        get_error_string(Err));
-    return {Err, false};
+    return HSA_STATUS_ERROR;
+  }
+
+  size_t Size = 0;
+  Err = hsa_amd_memory_pool_get_info(MemoryPool, HSA_AMD_MEMORY_POOL_INFO_SIZE,
+                                     &Size);
+  if (Err != HSA_STATUS_SUCCESS) {
+    DP("Get memory pool size failed: %s\n", get_error_string(Err));
+    return HSA_STATUS_ERROR;
   }
 
-  return {HSA_STATUS_SUCCESS, AllocAllowed};
+  return AllocAllowed && Size > 0 ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
 }
 
 hsa_status_t addKernArgPool(hsa_amd_memory_pool_t MemoryPool, void *Data) {
   std::vector<hsa_amd_memory_pool_t> *Result =
       static_cast<std::vector<hsa_amd_memory_pool_t> *>(Data);
-  bool AllocAllowed = false;
-  hsa_status_t err = hsa_amd_memory_pool_get_info(
-      MemoryPool, HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED,
-      &AllocAllowed);
-  if (err != HSA_STATUS_SUCCESS) {
-    DP("Alloc allowed in memory pool check failed: %s\n",
-       get_error_string(err));
-    return err;
-  }
 
-  if (!AllocAllowed) {
-    // nothing needs to be done here.
-    return HSA_STATUS_SUCCESS;
+  if (isValidMemoryPool(MemoryPool) != HSA_STATUS_SUCCESS) {
+    return HSA_STATUS_ERROR;
   }
 
   uint32_t GlobalFlags = 0;
-  err = hsa_amd_memory_pool_get_info(
+  hsa_status_t err = hsa_amd_memory_pool_get_info(
       MemoryPool, HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, &GlobalFlags);
   if (err != HSA_STATUS_SUCCESS) {
     DP("Get memory pool info failed: %s\n", get_error_string(err));
     return err;
   }
 
-  size_t size = 0;
-  err = hsa_amd_memory_pool_get_info(MemoryPool, HSA_AMD_MEMORY_POOL_INFO_SIZE,
-                                     &size);
-  if (err != HSA_STATUS_SUCCESS) {
-    DP("Get memory pool size failed: %s\n", get_error_string(err));
-    return err;
-  }
-
   if ((GlobalFlags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED) &&
-      (GlobalFlags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT) &&
-      size > 0) {
+      (GlobalFlags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT)) {
     Result->push_back(MemoryPool);
   }
 
@@ -368,13 +356,7 @@
   for (int DeviceId = 0; DeviceId < Agents.size(); DeviceId++) {
     hsa_status_t Err = hsa::amd_agent_iterate_memory_pools(
         Agents[DeviceId], [&](hsa_amd_memory_pool_t MemoryPool) {
-          hsa_status_t Err;
-          bool Valid = false;
-          std::tie(Err, Valid) = isValidMemoryPool(MemoryPool);
-          if (Err != HSA_STATUS_SUCCESS) {
-            return Err;
-          }
-          if (Valid)
+          if (isValidMemoryPool(MemoryPool) == HSA_STATUS_SUCCESS)
             Func(MemoryPool, DeviceId);
           return HSA_STATUS_SUCCESS;
         });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110513.375182.patch
Type: text/x-patch
Size: 3381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210927/86ae8399/attachment-0001.bin>


More information about the Openmp-commits mailing list