diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h index 9ba67f34d3..4b7e489d94 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h @@ -822,7 +822,6 @@ class Runtime { std::map 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(reinterpret_cast(handle))}; return ret_handle; } + static __forceinline ThunkHandle Convert(hsa_amd_vmem_alloc_handle_t handle) { + return reinterpret_cast(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 memory_handle_map_; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index edba448c22..14b57254bb 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -54,9 +54,7 @@ #include #include #include -#include #include -#include #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 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 lock(&memory_lock_); - auto memoryHandleIt = memory_handle_map_.find(reinterpret_cast(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(va) + size > lowerMappedHandleIt->first) return HSA_STATUS_ERROR_INVALID_ARGUMENT; } - auto memoryHandleIt = memory_handle_map_.find(reinterpret_cast(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(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;