[Openmp-commits] [openmp] 9d110f9 - [AMDGPU][Libomptarget] Move allow_access_to_all_gpu_agents to rtl.cpp

Pushpinder Singh via Openmp-commits openmp-commits at lists.llvm.org
Tue Jun 22 04:45:01 PDT 2021


Author: Pushpinder Singh
Date: 2021-06-22T11:44:52Z
New Revision: 9d110f915918fc6c2338837a15856c92a79f7b94

URL: https://github.com/llvm/llvm-project/commit/9d110f915918fc6c2338837a15856c92a79f7b94
DIFF: https://github.com/llvm/llvm-project/commit/9d110f915918fc6c2338837a15856c92a79f7b94.diff

LOG: [AMDGPU][Libomptarget] Move allow_access_to_all_gpu_agents to rtl.cpp

Moving this method helps eliminate a use of g_atl_machine.

Reviewed By: JonChesterfield

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

Added: 
    

Modified: 
    openmp/libomptarget/plugins/amdgpu/impl/data.cpp
    openmp/libomptarget/plugins/amdgpu/impl/internal.h
    openmp/libomptarget/plugins/amdgpu/impl/system.cpp
    openmp/libomptarget/plugins/amdgpu/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins/amdgpu/impl/data.cpp b/openmp/libomptarget/plugins/amdgpu/impl/data.cpp
index 070145a56d3a7..905d1615cec86 100644
--- a/openmp/libomptarget/plugins/amdgpu/impl/data.cpp
+++ b/openmp/libomptarget/plugins/amdgpu/impl/data.cpp
@@ -39,20 +39,16 @@ hsa_amd_memory_pool_t get_memory_pool_by_mem_place(int DeviceId,
 }
 } // namespace
 
-hsa_status_t register_allocation(void *ptr, size_t size,
-                                 atmi_devtype_t DeviceType) {
-  if (DeviceType == ATMI_DEVTYPE_CPU)
-    return allow_access_to_all_gpu_agents(ptr);
-  else
-    return HSA_STATUS_SUCCESS;
-}
-
 hsa_status_t Runtime::DeviceMalloc(void **ptr, size_t size, int DeviceId) {
   return Runtime::Malloc(ptr, size, DeviceId, ATMI_DEVTYPE_GPU);
 }
 
 hsa_status_t Runtime::HostMalloc(void **ptr, size_t size) {
-  return Runtime::Malloc(ptr, size, 0, ATMI_DEVTYPE_CPU);
+  hsa_status_t Err = Runtime::Malloc(ptr, size, 0, ATMI_DEVTYPE_CPU);
+  if (Err == HSA_STATUS_SUCCESS) {
+    Err = core::allow_access_to_all_gpu_agents(*ptr);
+  }
+  return Err;
 }
 
 hsa_status_t Runtime::Malloc(void **ptr, size_t size, int DeviceId,
@@ -62,11 +58,6 @@ hsa_status_t Runtime::Malloc(void **ptr, size_t size, int DeviceId,
   hsa_status_t err = hsa_amd_memory_pool_allocate(pool, size, 0, ptr);
   DEBUG_PRINT("Malloced [%s %d] %p\n",
               DeviceType == ATMI_DEVTYPE_CPU ? "CPU" : "GPU", DeviceId, *ptr);
-
-  if (err == HSA_STATUS_SUCCESS) {
-    err = register_allocation(*ptr, size, DeviceType);
-  }
-
   return (err == HSA_STATUS_SUCCESS) ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
 }
 

diff  --git a/openmp/libomptarget/plugins/amdgpu/impl/internal.h b/openmp/libomptarget/plugins/amdgpu/impl/internal.h
index 81a4f8f8cc6e2..25551f4a290c1 100644
--- a/openmp/libomptarget/plugins/amdgpu/impl/internal.h
+++ b/openmp/libomptarget/plugins/amdgpu/impl/internal.h
@@ -197,9 +197,6 @@ template <typename T> inline T *alignUp(T *value, size_t alignment) {
       alignDown((intptr_t)(value + alignment - 1), alignment));
 }
 
-hsa_status_t register_allocation(void *addr, size_t size,
-                                 atmi_devtype_t DeviceType);
-
 extern bool atl_is_atmi_initialized();
 
 bool handle_group_signal(hsa_signal_value_t value, void *arg);

diff  --git a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp
index bbe91ab93813c..e925c622213bc 100644
--- a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp
+++ b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp
@@ -144,16 +144,6 @@ ATLMachine g_atl_machine;
 
 namespace core {
 
-hsa_status_t allow_access_to_all_gpu_agents(void *ptr) {
-  std::vector<ATLGPUProcessor> &gpu_procs =
-      g_atl_machine.processors<ATLGPUProcessor>();
-  std::vector<hsa_agent_t> agents;
-  for (uint32_t i = 0; i < gpu_procs.size(); i++) {
-    agents.push_back(gpu_procs[i].agent());
-  }
-  return hsa_amd_agents_allow_access(agents.size(), &agents[0], NULL, ptr);
-}
-
 // Implement memory_pool iteration function
 static hsa_status_t get_memory_pool_info(hsa_amd_memory_pool_t memory_pool,
                                          void *data) {
@@ -937,11 +927,6 @@ populate_InfoTables(hsa_executable_symbol_t symbol,
 
     DEBUG_PRINT("Symbol %s = %p (%u bytes)\n", name, (void *)info.addr,
                 info.size);
-    err = register_allocation(reinterpret_cast<void *>(info.addr),
-                              (size_t)info.size, ATMI_DEVTYPE_GPU);
-    if (err != HSA_STATUS_SUCCESS) {
-      return err;
-    }
     SymbolInfoTable[std::string(name)] = info;
     free(name);
   } else {

diff  --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
index 51ff65c7098e6..8a4e12cff549f 100644
--- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -2118,3 +2118,11 @@ int32_t __tgt_rtl_synchronize(int32_t device_id, __tgt_async_info *AsyncInfo) {
   }
   return OFFLOAD_SUCCESS;
 }
+
+namespace core {
+hsa_status_t allow_access_to_all_gpu_agents(void *ptr) {
+  return hsa_amd_agents_allow_access(DeviceInfo.HSAAgents.size(),
+                                     &DeviceInfo.HSAAgents[0], NULL, ptr);
+}
+
+} // namespace core
\ No newline at end of file


        


More information about the Openmp-commits mailing list