From 74cdf8f9e3e8f0691a233ab93e51585efc2f3938 Mon Sep 17 00:00:00 2001 From: Sarbojit Sarkar Date: Tue, 1 Sep 2020 05:49:23 -0400 Subject: [PATCH] Fix for hipPointerGetAttributes [github#2137] Change-Id: I5295575638ecc4d3b7129552a9c26c6f6a7195fc --- hipamd/rocclr/hip_memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hipamd/rocclr/hip_memory.cpp b/hipamd/rocclr/hip_memory.cpp index da8bd5be78..b0e1d6abdd 100755 --- a/hipamd/rocclr/hip_memory.cpp +++ b/hipamd/rocclr/hip_memory.cpp @@ -2029,14 +2029,20 @@ hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsi hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) { HIP_INIT_API(hipPointerGetAttributes, attributes, ptr); + if (attributes == nullptr || ptr == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } size_t offset = 0; amd::Memory* memObj = getMemoryObject(ptr, offset); int device = 0; + memset(attributes, 0, sizeof(hipPointerAttribute_t)); if (memObj != nullptr) { attributes->memoryType = (CL_MEM_SVM_FINE_GRAIN_BUFFER & memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice; - attributes->hostPointer = memObj->getSvmPtr(); - attributes->devicePointer = memObj->getSvmPtr(); + if (attributes->memoryType == hipMemoryTypeHost) { + attributes->hostPointer = static_cast(memObj->getSvmPtr()) + offset; + } + attributes->devicePointer = static_cast(memObj->getSvmPtr()) + offset; attributes->isManaged = 0; attributes->allocationFlags = memObj->getMemFlags() >> 16;