From 00632b266cfac53696bc630ea438548e77ddd394 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 [ROCm/hip commit: 5c7b7d1dd2bdcb5d5624e21d6f7f4ed7b42ac6a5] --- projects/hip/rocclr/hip_memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/hip/rocclr/hip_memory.cpp b/projects/hip/rocclr/hip_memory.cpp index da8bd5be78..b0e1d6abdd 100755 --- a/projects/hip/rocclr/hip_memory.cpp +++ b/projects/hip/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;