rocr: Adding conversion function from hsa_amd_vmem_alloc_handle_t to ThunkHandle
[ROCm/ROCR-Runtime commit: b7cd5cc7f1]
This commit is contained in:
committed by
Yat Sin, David
parent
54933a3db2
commit
9fd770ac78
@@ -822,7 +822,6 @@ class Runtime {
|
||||
std::map<const void*, AddressHandle> reserved_address_map_; // Indexed by VA
|
||||
|
||||
struct MemoryHandle {
|
||||
MemoryHandle() : region(NULL), size(0), ref_count(0), thunk_handle(NULL), alloc_flag(0) {}
|
||||
MemoryHandle(const MemoryRegion* region, size_t size, uint64_t flags_unused,
|
||||
ThunkHandle thunk_handle, MemoryRegion::AllocateFlags alloc_flag)
|
||||
: region(region),
|
||||
@@ -832,19 +831,23 @@ class Runtime {
|
||||
thunk_handle(thunk_handle),
|
||||
alloc_flag(alloc_flag) {}
|
||||
|
||||
static __forceinline hsa_amd_vmem_alloc_handle_t Convert(void* handle) {
|
||||
static __forceinline hsa_amd_vmem_alloc_handle_t Convert(ThunkHandle handle) {
|
||||
hsa_amd_vmem_alloc_handle_t ret_handle = {
|
||||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(handle))};
|
||||
return ret_handle;
|
||||
}
|
||||
|
||||
static __forceinline ThunkHandle Convert(hsa_amd_vmem_alloc_handle_t handle) {
|
||||
return reinterpret_cast<void*>(handle.handle);
|
||||
}
|
||||
|
||||
__forceinline core::Agent* agentOwner() const { return region->owner(); }
|
||||
|
||||
const MemoryRegion* region;
|
||||
size_t size;
|
||||
int ref_count;
|
||||
int use_count;
|
||||
ThunkHandle thunk_handle; // handle returned by hsaKmtAllocMemory(NoAddress = 1)
|
||||
ThunkHandle thunk_handle; // handle returned by Driver::Allocate(NoAddress = 1)
|
||||
MemoryRegion::AllocateFlags alloc_flag;
|
||||
};
|
||||
std::map<ThunkHandle, MemoryHandle> memory_handle_map_;
|
||||
|
||||
@@ -54,9 +54,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "core/inc/runtime.h"
|
||||
#include "core/inc/hsa_table_interface.h"
|
||||
@@ -3219,7 +3217,7 @@ hsa_status_t Runtime::VMemoryHandleCreate(const MemoryRegion* region, size_t siz
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
ScopedAcquire<KernelSharedMutex> lock(&memory_lock_);
|
||||
void *user_mode_driver_handle;
|
||||
ThunkHandle user_mode_driver_handle;
|
||||
hsa_status_t status =
|
||||
region->Allocate(size, alloc_flags, &user_mode_driver_handle, 0);
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
@@ -3236,7 +3234,7 @@ hsa_status_t Runtime::VMemoryHandleCreate(const MemoryRegion* region, size_t siz
|
||||
|
||||
hsa_status_t Runtime::VMemoryHandleRelease(hsa_amd_vmem_alloc_handle_t memoryOnlyHandle) {
|
||||
ScopedAcquire<KernelSharedMutex> lock(&memory_lock_);
|
||||
auto memoryHandleIt = memory_handle_map_.find(reinterpret_cast<void*>(memoryOnlyHandle.handle));
|
||||
auto memoryHandleIt = memory_handle_map_.find(MemoryHandle::Convert(memoryOnlyHandle));
|
||||
|
||||
if (memoryHandleIt == memory_handle_map_.end()) {
|
||||
debug_warning(false && "Can't find memory handle");
|
||||
@@ -3291,7 +3289,7 @@ hsa_status_t Runtime::VMemoryHandleMap(void* va, size_t size, size_t in_offset,
|
||||
if (reinterpret_cast<uint8_t*>(va) + size > lowerMappedHandleIt->first) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
auto memoryHandleIt = memory_handle_map_.find(reinterpret_cast<void*>(memoryOnlyHandle.handle));
|
||||
auto memoryHandleIt = memory_handle_map_.find(MemoryHandle::Convert(memoryOnlyHandle));
|
||||
if (memoryHandleIt == memory_handle_map_.end()) {
|
||||
debug_warning(false && "Can't find memory handle");
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
@@ -3654,7 +3652,7 @@ hsa_status_t Runtime::VMemoryExportShareableHandle(int* dmabuf_fd,
|
||||
hsa_amd_vmem_alloc_handle_t handle,
|
||||
uint64_t flags) {
|
||||
*dmabuf_fd = -1;
|
||||
auto memoryHandle = memory_handle_map_.find((void*)handle.handle);
|
||||
auto memoryHandle = memory_handle_map_.find(MemoryHandle::Convert(handle));
|
||||
if (memoryHandle == memory_handle_map_.end()) {
|
||||
debug_warning(false && "Can't find memory handle");
|
||||
return HSA_STATUS_ERROR_INVALID_ALLOCATION;
|
||||
@@ -3750,7 +3748,7 @@ hsa_status_t Runtime::VMemoryRetainAllocHandle(hsa_amd_vmem_alloc_handle_t* mapp
|
||||
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));
|
||||
auto memoryHandleIt = memory_handle_map_.find(MemoryHandle::Convert(allocHandle));
|
||||
if (memoryHandleIt == memory_handle_map_.end()) return HSA_STATUS_ERROR_INVALID_ALLOCATION;
|
||||
|
||||
*mem_region = memoryHandleIt->second.region;
|
||||
|
||||
Reference in New Issue
Block a user