Skip to content

Commit

Permalink
[AMDGPU][Libomptarget] Delete g_atl_machine global
Browse files Browse the repository at this point in the history
With uses of g_atl_machine gone, a significant portion of dead
code has been removed.

This patch depends on D104691 and D104695.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D104696
  • Loading branch information
pdhaliwal-amd committed Aug 24, 2021
1 parent 1f8602e commit 9b8b7c1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 430 deletions.
1 change: 0 additions & 1 deletion openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
Expand Up @@ -66,7 +66,6 @@ add_library(omptarget.rtl.amdgpu SHARED
impl/atmi_interop_hsa.cpp
impl/data.cpp
impl/get_elf_mach_gfx_name.cpp
impl/machine.cpp
impl/system.cpp
impl/utils.cpp
impl/msgpack.cpp
Expand Down
10 changes: 6 additions & 4 deletions openmp/libomptarget/plugins/amdgpu/impl/atmi.cpp
Expand Up @@ -50,7 +50,8 @@ struct atmiFreePtrDeletor {

hsa_status_t atmi_memcpy_h2d(hsa_signal_t signal, void *deviceDest,
const void *hostSrc, size_t size,
hsa_agent_t agent) {
hsa_agent_t agent,
hsa_amd_memory_pool_t MemoryPool) {
hsa_status_t rc = hsa_memory_copy(deviceDest, hostSrc, size);

// hsa_memory_copy sometimes fails in situations where
Expand All @@ -61,7 +62,7 @@ hsa_status_t atmi_memcpy_h2d(hsa_signal_t signal, void *deviceDest,
}

void *tempHostPtr;
hsa_status_t ret = core::Runtime::HostMalloc(&tempHostPtr, size);
hsa_status_t ret = core::Runtime::HostMalloc(&tempHostPtr, size, MemoryPool);
if (ret != HSA_STATUS_SUCCESS) {
DEBUG_PRINT("HostMalloc: Unable to alloc %zu bytes for temp scratch\n",
size);
Expand All @@ -79,7 +80,8 @@ hsa_status_t atmi_memcpy_h2d(hsa_signal_t signal, void *deviceDest,

hsa_status_t atmi_memcpy_d2h(hsa_signal_t signal, void *dest,
const void *deviceSrc, size_t size,
hsa_agent_t agent) {
hsa_agent_t agent,
hsa_amd_memory_pool_t MemoryPool) {
hsa_status_t rc = hsa_memory_copy(dest, deviceSrc, size);

// hsa_memory_copy sometimes fails in situations where
Expand All @@ -90,7 +92,7 @@ hsa_status_t atmi_memcpy_d2h(hsa_signal_t signal, void *dest,
}

void *tempHostPtr;
hsa_status_t ret = core::Runtime::HostMalloc(&tempHostPtr, size);
hsa_status_t ret = core::Runtime::HostMalloc(&tempHostPtr, size, MemoryPool);
if (ret != HSA_STATUS_SUCCESS) {
DEBUG_PRINT("HostMalloc: Unable to alloc %zu bytes for temp scratch\n",
size);
Expand Down
5 changes: 0 additions & 5 deletions openmp/libomptarget/plugins/amdgpu/impl/atmi_interop_hsa.cpp
Expand Up @@ -7,11 +7,6 @@
//===----------------------------------------------------------------------===//
#include "atmi_interop_hsa.h"
#include "internal.h"
#include "machine.h"

// TODO: need to get rid of this as well

extern ATLMachine g_atl_machine;

hsa_status_t atmi_interop_hsa_get_symbol_info(
const std::map<std::string, atl_symbol_info_t> &SymbolInfoTable,
Expand Down
6 changes: 4 additions & 2 deletions openmp/libomptarget/plugins/amdgpu/impl/atmi_runtime.h
Expand Up @@ -55,11 +55,13 @@ hsa_status_t atmi_module_register_from_memory_to_place(

hsa_status_t atmi_memcpy_h2d(hsa_signal_t signal, void *deviceDest,
const void *hostSrc, size_t size,
hsa_agent_t agent);
hsa_agent_t agent,
hsa_amd_memory_pool_t MemoryPool);

hsa_status_t atmi_memcpy_d2h(hsa_signal_t sig, void *hostDest,
const void *deviceSrc, size_t size,
hsa_agent_t agent);
hsa_agent_t agent,
hsa_amd_memory_pool_t MemoryPool);

/** @} */

Expand Down
43 changes: 6 additions & 37 deletions openmp/libomptarget/plugins/amdgpu/impl/data.cpp
Expand Up @@ -8,55 +8,24 @@
#include "atmi_runtime.h"
#include "hsa_api.h"
#include "internal.h"
#include "machine.h"
#include "rt.h"
#include <cassert>
#include <stdio.h>
#include <string.h>
#include <vector>

using core::TaskImpl;
extern ATLMachine g_atl_machine;

namespace core {

namespace {
ATLProcessor &get_processor_by_mem_place(int DeviceId,
atmi_devtype_t DeviceType) {
switch (DeviceType) {
case ATMI_DEVTYPE_CPU:
return g_atl_machine.processors<ATLCPUProcessor>()[DeviceId];
case ATMI_DEVTYPE_GPU:
return g_atl_machine.processors<ATLGPUProcessor>()[DeviceId];
}
}

hsa_amd_memory_pool_t get_memory_pool_by_mem_place(int DeviceId,
atmi_devtype_t DeviceType) {
ATLProcessor &proc = get_processor_by_mem_place(DeviceId, DeviceType);
return get_memory_pool(proc, 0 /*Memory Type (always zero) */);
}
} // namespace
hsa_status_t Runtime::HostMalloc(void **ptr, size_t size,
hsa_amd_memory_pool_t MemoryPool) {
hsa_status_t err = hsa_amd_memory_pool_allocate(MemoryPool, size, 0, ptr);
DEBUG_PRINT("Malloced [CPU %d] %p\n", DeviceId, *ptr);

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) {
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);
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,
atmi_devtype_t DeviceType) {
hsa_amd_memory_pool_t pool =
get_memory_pool_by_mem_place(DeviceId, DeviceType);
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);
return (err == HSA_STATUS_SUCCESS) ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
}

Expand Down
56 changes: 0 additions & 56 deletions openmp/libomptarget/plugins/amdgpu/impl/machine.cpp

This file was deleted.

79 changes: 0 additions & 79 deletions openmp/libomptarget/plugins/amdgpu/impl/machine.h

This file was deleted.

8 changes: 2 additions & 6 deletions openmp/libomptarget/plugins/amdgpu/impl/rt.h
Expand Up @@ -60,16 +60,12 @@ class Runtime final {
// data
static hsa_status_t Memcpy(hsa_signal_t, void *, const void *, size_t);
static hsa_status_t Memfree(void *);
static hsa_status_t HostMalloc(void **ptr, size_t size);
static hsa_status_t DeviceMalloc(void **ptr, size_t size, int DeviceId);
static hsa_status_t HostMalloc(void **ptr, size_t size,
hsa_amd_memory_pool_t MemoryPool);

int getMaxQueueSize() const { return env_.getMaxQueueSize(); }
int getDebugMode() const { return env_.getDebugMode(); }

private:
static hsa_status_t Malloc(void **ptr, size_t size, int DeviceId,
atmi_devtype_t DeviceType);

protected:
Runtime() = default;
~Runtime() = default;
Expand Down

0 comments on commit 9b8b7c1

Please sign in to comment.