From c10cebcf6f3f50a32ccaa9d670e15df7023b64af Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 4 Jun 2019 10:24:11 -0400 Subject: [PATCH] P4 to Git Change 1791519 by vsytchen@vsytchen-remote-ocl-win10 on 2019/06/04 10:06:43 SWDEV-189383 - [HIP CQE][HIPonPAL][WIN] hipDeviceMalloc, hip_test_ldg, hipHostRegister, hipModule, hipStreamSync2 tests failed on VEGA10. 1. For pinned memory allocations add the host pointer and all of its respective device pointers to the memory object map. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#57 edit [ROCm/clr commit: 9a301adffe4d49368c0a99ed82f2ee64c9735d01] --- projects/clr/hipamd/api/hip/hip_memory.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/projects/clr/hipamd/api/hip/hip_memory.cpp b/projects/clr/hipamd/api/hip/hip_memory.cpp index f34b9e99c0..18097e725a 100644 --- a/projects/clr/hipamd/api/hip/hip_memory.cpp +++ b/projects/clr/hipamd/api/hip/hip_memory.cpp @@ -560,6 +560,22 @@ hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) mem->release(); HIP_RETURN(hipErrorMemoryAllocation); } + + std::vector devPtrs; + for (const auto& device: hip::getCurrentContext()->devices()) { + 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(hostPtr, mem); HIP_RETURN(hipSuccess); } else { @@ -582,6 +598,10 @@ hipError_t hipHostUnregister(void* hostPtr) { if(mem) { hip::syncStreams(); hip::getNullStream()->finish(); + for (const auto& device: hip::getCurrentContext()->devices()) { + const device::Memory* devMem = mem->getDeviceMemory(*device); + amd::MemObjMap::RemoveMemObj(reinterpret_cast(devMem->virtualAddress())); + } amd::MemObjMap::RemoveMemObj(hostPtr); mem->release(); HIP_RETURN(hipSuccess);