From 61635b585f44604b02429777eee54029f72f236b Mon Sep 17 00:00:00 2001 From: pensun Date: Tue, 8 Nov 2016 01:01:26 -0600 Subject: [PATCH] Add option to alloc fingrained system memory Change-Id: Ia13c8e058cb988b5857e75a590a4d67411362ae1 [ROCm/clr commit: 23de0e1b50c3739973712b3381d73d3968432c99] --- projects/clr/hipamd/src/hip_memory.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 85b22d86d0..e59e6c261d 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -154,6 +154,16 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) if(ctx){ // am_alloc requires writeable __acc, perhaps could be refactored? auto device = ctx->getWriteableDevice(); + // If HIP_COHERENT_HOST_ALLOC is defined, we always alloc coherent host system memroy + #ifdef HIP_COHERENT_HOST_ALLOC + *ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned); + if(sizeBytes < 1 && (*ptr == NULL)){ + hip_status = hipErrorMemoryAllocation; + } else { + hc::am_memtracker_update(*ptr, device->_deviceId, amHostCoherent); + } + tprintf(DB_MEM, " %s: pinned ptr=%p\n", __func__, *ptr); + #else if((flags == hipHostMallocDefault)|| (flags == hipHostMallocPortable)){ *ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned); if (sizeBytes < 1 && (*ptr == NULL)) { @@ -179,6 +189,7 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) tprintf(DB_MEM, "allocated pinned host ptr=%p on dev=%d, allow access to %d peer(s)\n", *ptr, device->_deviceId, peerCnt); } } + #endif //HIP_COHERENT_HOST_ALLOC } return ihipLogStatus(hip_status); }