From 3bc17113301ba33ade33836bded5d6dbc301fd22 Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 6 Jun 2019 11:51:22 -0400 Subject: [PATCH] P4 to Git Change 1792745 by vsytchen@vsytchen-remote-ocl-win10 on 2019/06/06 11:18:13 SWDEV-145570 - Simplify pinned memory allocation logic ReviewBoardURL = http://ocltc.amd.com/reviews/r/17467/diff/ Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#58 edit [ROCm/clr commit: 5683d9d218175de1e423773f63c8951d2892768e] --- projects/clr/hipamd/api/hip/hip_memory.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/projects/clr/hipamd/api/hip/hip_memory.cpp b/projects/clr/hipamd/api/hip/hip_memory.cpp index 18097e725a..d932c88705 100644 --- a/projects/clr/hipamd/api/hip/hip_memory.cpp +++ b/projects/clr/hipamd/api/hip/hip_memory.cpp @@ -556,26 +556,21 @@ hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) if(hostPtr != nullptr) { amd::Memory* mem = new (*hip::host_context) amd::Buffer(*hip::host_context, CL_MEM_USE_HOST_PTR, sizeBytes); - if (!mem->create(hostPtr)) { + constexpr bool sysMemAlloc = false; + constexpr bool skipAlloc = false; + constexpr bool forceAlloc = true; + if (!mem->create(hostPtr, sysMemAlloc, skipAlloc, forceAlloc)) { mem->release(); HIP_RETURN(hipErrorMemoryAllocation); } - std::vector devPtrs; for (const auto& device: hip::getCurrentContext()->devices()) { + // Since the amd::Memory object is shared between all devices + // it's fine to have multiple addresses mapped to it const device::Memory* devMem = mem->getDeviceMemory(*device); - if (devMem != nullptr) { - devPtrs.emplace_back(reinterpret_cast(devMem->virtualAddress())); - } else { - mem->release(); - HIP_RETURN(hipErrorMemoryAllocation); - } - } - // Since the amd::Memory object is shared between all devices - // it's fine to have multiple addresses mapped to it - for (const auto& devPtr: devPtrs) { - amd::MemObjMap::AddMemObj(devPtr, mem); + amd::MemObjMap::AddMemObj(reinterpret_cast(devMem->virtualAddress()), mem); } + amd::MemObjMap::AddMemObj(hostPtr, mem); HIP_RETURN(hipSuccess); } else {