Skip to content

Commit

Permalink
[AMDGPU][Libomptarget] Move allow_access_to_all_gpu_agents to rtl.cpp
Browse files Browse the repository at this point in the history
Moving this method helps eliminate a use of g_atl_machine.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D104691
  • Loading branch information
pdhaliwal-amd committed Jun 22, 2021
1 parent c462048 commit 9d110f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
19 changes: 5 additions & 14 deletions openmp/libomptarget/plugins/amdgpu/impl/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
3 changes: 0 additions & 3 deletions openmp/libomptarget/plugins/amdgpu/impl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions openmp/libomptarget/plugins/amdgpu/impl/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9d110f9

Please sign in to comment.