Add retain handle and get allocation properties

Support function to retain allocation handle for memory mappings.
The get allocation properties function will return the current
allocation properties for existing memory mappings.

This is part of patch series for Virtual Memory API.

Change-Id: I0a53a11b6efc2b5bf9d463512a489a2abd812551
Этот коммит содержится в:
David Yat Sin
2022-12-19 00:09:08 +00:00
родитель b03c96c264
Коммит 687eb043d4
9 изменённых файлов: 124 добавлений и 0 удалений
+26
Просмотреть файл
@@ -2869,5 +2869,31 @@ hsa_status_t Runtime::VMemoryImportShareableHandle(int dmabuf_fd,
return HSA_STATUS_SUCCESS;
}
hsa_status_t Runtime::VMemoryRetainAllocHandle(hsa_amd_vmem_alloc_handle_t* mapped_handle,
void* va) {
auto mappedHandleIt = mapped_handle_map_.find(va);
if (mappedHandleIt == mapped_handle_map_.end()) return HSA_STATUS_ERROR_INVALID_ALLOCATION;
MemoryHandle* memoryHandle = mappedHandleIt->second.mem_handle;
memoryHandle->ref_count++;
*mapped_handle = MemoryHandle::Convert(memoryHandle->thunk_handle);
return HSA_STATUS_SUCCESS;
}
hsa_status_t Runtime::VMemoryGetAllocPropertiesFromHandle(hsa_amd_vmem_alloc_handle_t allocHandle,
const core::MemoryRegion** mem_region,
hsa_amd_memory_type_t* type) {
auto memoryHandleIt = memory_handle_map_.find(reinterpret_cast<void*>(allocHandle.handle));
if (memoryHandleIt == memory_handle_map_.end()) return HSA_STATUS_ERROR_INVALID_ALLOCATION;
*mem_region = memoryHandleIt->second.region;
*type = (memoryHandleIt->second.alloc_flag & core::MemoryRegion::AllocatePinned)
? MEMORY_TYPE_PINNED
: MEMORY_TYPE_NONE;
return HSA_STATUS_SUCCESS;
}
} // namespace core
} // namespace rocr