From 9c2eea15fbab0b3ad56a5a560b3ff2a06dd59688 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Fri, 9 Oct 2020 18:25:29 -0400 Subject: [PATCH] Report managed memory capabilities Change-Id: I241a42e26ee49fb47dcb3ba87c4bd8fb691dffdf [ROCm/hip commit: d9f655f50e91ffa3623cab2235b869550c32d503] --- projects/hip/include/hip/hip_runtime_api.h | 19 +++++++++++++++++-- projects/hip/rocclr/hip_device.cpp | 7 +++++++ projects/hip/rocclr/hip_device_runtime.cpp | 17 ++++++++++++++++- projects/hip/rocclr/hip_memory.cpp | 12 ++++++++---- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/projects/hip/include/hip/hip_runtime_api.h b/projects/hip/include/hip/hip_runtime_api.h index 3a26fb74f4..7b79582807 100644 --- a/projects/hip/include/hip/hip_runtime_api.h +++ b/projects/hip/include/hip/hip_runtime_api.h @@ -139,7 +139,13 @@ typedef struct hipDeviceProp_t { int cooperativeMultiDeviceUnmatchedSharedMem; ///< HIP device supports cooperative launch on multiple ///devices with unmatched shared memories int isLargeBar; ///< 1: if it is a large PCI bar device, else 0 - int asicRevision; ///< Revision of the GPU in this device. + int asicRevision; ///< Revision of the GPU in this device + int managedMemory; ///< Device supports allocating managed memory on this system + int directManagedMemAccessFromHost; ///< Host can directly access managed memory on the device without migration + int concurrentManagedAccess; ///< Device can coherently access managed memory concurrently with the CPU + int pageableMemoryAccess; ///< Device supports coherently accessing pageable memory + ///< without calling hipHostRegister on it + int pageableMemoryAccessUsesHostPageTables; ///< Device accesses pageable memory via the host's page tables } hipDeviceProp_t; @@ -349,7 +355,16 @@ typedef enum hipDeviceAttribute_t { ///devices with unmatched block dimensions hipDeviceAttributeCooperativeMultiDeviceUnmatchedSharedMem, ///< Supports cooperative launch on multiple ///devices with unmatched shared memories - hipDeviceAttributeAsicRevision ///< Revision of the GPU in this device + hipDeviceAttributeAsicRevision, ///< Revision of the GPU in this device + hipDeviceAttributeManagedMemory, ///< Device supports allocating managed memory on this system + hipDeviceAttributeDirectManagedMemAccessFromHost, ///< Host can directly access managed memory on + /// the device without migration + hipDeviceAttributeConcurrentManagedAccess, ///< Device can coherently access managed memory + /// concurrently with the CPU + hipDeviceAttributePageableMemoryAccess, ///< Device supports coherently accessing pageable memory + /// without calling hipHostRegister on it + hipDeviceAttributePageableMemoryAccessUsesHostPageTables, ///< Device accesses pageable memory via + /// the host's page tables } hipDeviceAttribute_t; enum hipComputeMode { diff --git a/projects/hip/rocclr/hip_device.cpp b/projects/hip/rocclr/hip_device.cpp index 2c8c7f5c66..2c3996059b 100644 --- a/projects/hip/rocclr/hip_device.cpp +++ b/projects/hip/rocclr/hip_device.cpp @@ -226,6 +226,13 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) deviceProps.isLargeBar = info.largeBar_ ? 1 : 0; deviceProps.asicRevision = info.asicRevision_; + // HMM capabilities + deviceProps.managedMemory = info.hmmSupported_; + deviceProps.concurrentManagedAccess = info.hmmSupported_; + deviceProps.directManagedMemAccessFromHost = info.hmmDirectHostAccess_; + deviceProps.pageableMemoryAccess = info.hmmCpuMemoryAccessible_; + deviceProps.pageableMemoryAccessUsesHostPageTables = info.hostUnifiedMemory_; + *props = deviceProps; HIP_RETURN(hipSuccess); } diff --git a/projects/hip/rocclr/hip_device_runtime.cpp b/projects/hip/rocclr/hip_device_runtime.cpp index 350363b1b6..31231a4949 100755 --- a/projects/hip/rocclr/hip_device_runtime.cpp +++ b/projects/hip/rocclr/hip_device_runtime.cpp @@ -298,7 +298,22 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) break; case hipDeviceAttributeAsicRevision: *pi = prop.asicRevision; - break; + break; + case hipDeviceAttributeManagedMemory: + *pi = prop.managedMemory; + break; + case hipDeviceAttributeDirectManagedMemAccessFromHost: + *pi = prop.directManagedMemAccessFromHost; + break; + case hipDeviceAttributeConcurrentManagedAccess: + *pi = prop.concurrentManagedAccess; + break; + case hipDeviceAttributePageableMemoryAccess: + *pi = prop.pageableMemoryAccess; + break; + case hipDeviceAttributePageableMemoryAccessUsesHostPageTables: + *pi = prop.pageableMemoryAccessUsesHostPageTables; + break; default: HIP_RETURN(hipErrorInvalidValue); } diff --git a/projects/hip/rocclr/hip_memory.cpp b/projects/hip/rocclr/hip_memory.cpp index 02e973eaec..75f9fe3426 100755 --- a/projects/hip/rocclr/hip_memory.cpp +++ b/projects/hip/rocclr/hip_memory.cpp @@ -2031,6 +2031,7 @@ hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsi HIP_RETURN(hipSuccess); } +// ================================================================================================ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) { HIP_INIT_API(hipPointerGetAttributes, attributes, ptr); @@ -2043,12 +2044,15 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void memset(attributes, 0, sizeof(hipPointerAttribute_t)); if (memObj != nullptr) { - attributes->memoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) & memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice; + attributes->memoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) & + memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice; if (attributes->memoryType == hipMemoryTypeHost) { attributes->hostPointer = static_cast(memObj->getSvmPtr()) + offset; } attributes->devicePointer = static_cast(memObj->getSvmPtr()) + offset; - attributes->isManaged = 0; + constexpr uint32_t kManagedAlloc = (CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_ALLOC_HOST_PTR); + attributes->isManaged = + ((memObj->getMemFlags() & kManagedAlloc) == kManagedAlloc) ? true : false; attributes->allocationFlags = memObj->getMemFlags() >> 16; amd::Context* memObjCtx = &memObj->getContext(); @@ -2063,8 +2067,7 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void } ++device; } - DevLogPrintfError("Cannot find memory object context, memObjCtx: 0x%x \n", - memObjCtx); + DevLogPrintfError("Cannot find memory object context, memObjCtx: 0x%x \n", memObjCtx); HIP_RETURN(hipErrorInvalidDevice); } @@ -2072,6 +2075,7 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void HIP_RETURN(hipErrorInvalidValue); } +// ================================================================================================ hipError_t hipArrayDestroy(hipArray* array) { HIP_INIT_API(hipArrayDestroy, array);