Revert "Add flag for external memory allocations"

This reverts commit 59685f4492.

Change-Id: I32a92672553c4c38ffae53a085f83c0403c160ae
Этот коммит содержится в:
David Yat Sin
2023-02-23 16:29:16 +00:00
родитель 37b5b421b3
Коммит 7ed6d73b6d
5 изменённых файлов: 17 добавлений и 28 удалений
+5 -13
Просмотреть файл
@@ -177,13 +177,11 @@ class Runtime {
/// @param [in] size Allocation size in bytes.
/// @param [in] alloc_flags Modifiers to pass to MemoryRegion allocator.
/// @param [out] address Pointer to store the allocation result.
/// @param [in] user_request Set to true if this is an external allocation, i.e this address
/// is directly visible to the user of this library
///
/// @retval ::HSA_STATUS_SUCCESS If allocation is successful.
hsa_status_t AllocateMemory(const MemoryRegion* region, size_t size,
MemoryRegion::AllocateFlags alloc_flags, void** address,
bool user_request = false);
MemoryRegion::AllocateFlags alloc_flags,
void** address);
/// @brief Free memory previously allocated with AllocateMemory.
///
@@ -320,7 +318,7 @@ class Runtime {
hsa_status_t PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, void* (*alloc)(size_t),
uint32_t* num_agents_accessible, hsa_agent_t** accessible,
PtrInfoBlockData* block_info = nullptr, bool user_request = false);
PtrInfoBlockData* block_info = nullptr);
hsa_status_t SetPtrInfoData(const void* ptr, void* userptr);
@@ -406,13 +404,8 @@ class Runtime {
struct AllocationRegion {
AllocationRegion() : region(NULL), size(0), size_requested(0), user_ptr(nullptr) {}
AllocationRegion(const MemoryRegion* region_arg, size_t size_arg, size_t size_requested,
bool user_request = false)
: region(region_arg),
size(size_arg),
size_requested(size_requested),
user_ptr(nullptr),
user_request(user_request) {}
AllocationRegion(const MemoryRegion* region_arg, size_t size_arg, size_t size_requested)
: region(region_arg), size(size_arg), size_requested(size_requested), user_ptr(nullptr) {}
struct notifier_t {
void* ptr;
@@ -425,7 +418,6 @@ class Runtime {
size_t size_requested; /* size requested by user */
void* user_ptr;
std::unique_ptr<std::vector<notifier_t>> notifiers;
bool user_request;
};
struct AsyncEventsControl {
+2 -2
Просмотреть файл
@@ -546,8 +546,8 @@ hsa_status_t MemoryRegion::AllowAccess(uint32_t num_agents,
ScopedAcquire<KernelMutex> lock(&access_lock_);
if (core::Runtime::runtime_singleton_->PtrInfo(const_cast<void*>(ptr), &info, malloc,
&agent_count, &accessible, &blockInfo,
true) == HSA_STATUS_SUCCESS) {
&agent_count, &accessible,
&blockInfo) == HSA_STATUS_SUCCESS) {
/* Thunk may return type = HSA_EXT_POINTER_TYPE_UNKNOWN for userptrs */
if (info.type != HSA_EXT_POINTER_TYPE_UNKNOWN &&
(blockInfo.length != size || info.sizeInBytes != size)) {
+1 -1
Просмотреть файл
@@ -1092,7 +1092,7 @@ hsa_status_t
IS_VALID(mem_region);
return core::Runtime::runtime_singleton_->AllocateMemory(
mem_region, size, core::MemoryRegion::AllocateNoFlags, ptr, true);
mem_region, size, core::MemoryRegion::AllocateNoFlags, ptr);
CATCH;
}
+2 -3
Просмотреть файл
@@ -756,7 +756,7 @@ hsa_status_t hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool, siz
if (flags == HSA_AMD_MEMORY_POOL_PCIE_FLAG) alloc_flag |= core::MemoryRegion::AllocatePCIeRW;
return core::Runtime::runtime_singleton_->AllocateMemory(mem_region, size, alloc_flag, ptr, true);
return core::Runtime::runtime_singleton_->AllocateMemory(mem_region, size, alloc_flag, ptr);
CATCH;
}
@@ -907,8 +907,7 @@ hsa_status_t hsa_amd_pointer_info(const void* ptr, hsa_amd_pointer_info_t* info,
IS_OPEN();
IS_BAD_PTR(ptr);
IS_BAD_PTR(info);
return core::Runtime::runtime_singleton_->PtrInfo(ptr, info, alloc, num_accessible, accessible,
NULL, true);
return core::Runtime::runtime_singleton_->PtrInfo(ptr, info, alloc, num_accessible, accessible);
CATCH;
}
+7 -9
Просмотреть файл
@@ -284,14 +284,14 @@ hsa_status_t Runtime::IterateAgent(hsa_status_t (*callback)(hsa_agent_t agent,
}
hsa_status_t Runtime::AllocateMemory(const MemoryRegion* region, size_t size,
MemoryRegion::AllocateFlags alloc_flags, void** address,
bool user_request) {
MemoryRegion::AllocateFlags alloc_flags,
void** address) {
size_t size_requested = size; // region->Allocate(...) may align-up size to granularity
hsa_status_t status = region->Allocate(size, alloc_flags, address);
// Track the allocation result so that it could be freed properly.
if (status == HSA_STATUS_SUCCESS) {
ScopedAcquire<KernelSharedMutex> lock(&memory_lock_);
allocation_map_[*address] = AllocationRegion(region, size, size_requested, user_request);
allocation_map_[*address] = AllocationRegion(region, size, size_requested);
}
return status;
@@ -788,7 +788,7 @@ hsa_status_t Runtime::InteropUnmap(void* ptr) {
hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, void* (*alloc)(size_t),
uint32_t* num_agents_accessible, hsa_agent_t** accessible,
PtrInfoBlockData* block_info, bool user_request) {
PtrInfoBlockData* block_info) {
static_assert(static_cast<int>(HSA_POINTER_UNKNOWN) == static_cast<int>(HSA_EXT_POINTER_TYPE_UNKNOWN),
"Thunk pointer info mismatch");
static_assert(static_cast<int>(HSA_POINTER_ALLOCATED) == static_cast<int>(HSA_EXT_POINTER_TYPE_HSA),
@@ -859,13 +859,11 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi
auto fragment = allocation_map_.upper_bound(ptr);
if (fragment != allocation_map_.begin()) {
fragment--;
if ((fragment->first <= ptr) && (user_request && fragment->second.user_request) &&
(ptr <
reinterpret_cast<const uint8_t*>(fragment->first) + fragment->second.size_requested)) {
if ((fragment->first <= ptr) &&
(ptr < reinterpret_cast<const uint8_t*>(fragment->first) + fragment->second.size_requested)) {
// agent and host address must match here. Only lock memory is allowed to have differing
// addresses but lock memory has type HSA_EXT_POINTER_TYPE_LOCKED and cannot be
// suballocated.
retInfo.agentBaseAddress = const_cast<void*>(fragment->first);
retInfo.hostBaseAddress = retInfo.agentBaseAddress;
retInfo.sizeInBytes = fragment->second.size_requested;
@@ -960,7 +958,7 @@ hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* han
PtrInfoBlockData block;
hsa_amd_pointer_info_t info;
info.size = sizeof(info);
if (PtrInfo(ptr, &info, nullptr, nullptr, nullptr, &block, true) != HSA_STATUS_SUCCESS)
if (PtrInfo(ptr, &info, nullptr, nullptr, nullptr, &block) != HSA_STATUS_SUCCESS)
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
// Temporary: Previous versions of HIP will call hsa_amd_ipc_memory_create with the len aligned to