From f45c2eb542e13660abb06dbfdd68bee499518b47 Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 7 Mar 2018 20:03:36 -0500 Subject: [PATCH] P4 to Git Change 1524135 by cpaquot@cpaquot-ocl-lc-lnx on 2018/03/07 19:52:00 SWDEV-145570 - [HIP] Hip Rearchitecture Implemented hipHostAlloc Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#5 edit [ROCm/clr commit: 336d1e589c4536972e1a7aaac9a2bdbea39796ea] --- projects/clr/hipamd/api/hip/hip_memory.cpp | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/api/hip/hip_memory.cpp b/projects/clr/hipamd/api/hip/hip_memory.cpp index 0911f61e4c..ddebc8623c 100644 --- a/projects/clr/hipamd/api/hip/hip_memory.cpp +++ b/projects/clr/hipamd/api/hip/hip_memory.cpp @@ -58,13 +58,32 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) { HIP_INIT_API(ptr, sizeBytes, flags); - assert(0 && "Unimplemented"); + if (sizeBytes == 0) { + *ptr = nullptr; + return hipSuccess; + } + else if (!ptr) { + return hipErrorInvalidValue; + } - return hipErrorUnknown; + if (g_context->devices()[0]->info().maxMemAllocSize_ < sizeBytes) { + return hipErrorOutOfMemory; + } + + *ptr = amd::SvmBuffer::malloc(*g_context, 0, sizeBytes, g_context->devices()[0]->info().memBaseAddrAlign_); + if (!*ptr) { + return hipErrorOutOfMemory; + } + + return hipSuccess; } hipError_t hipFree(void* ptr) { + if (amd::SvmBuffer::malloced(ptr)) { + amd::SvmBuffer::free(*g_context, ptr); + return hipSuccess; + } if (!is_valid(reinterpret_cast(ptr))) { return hipErrorInvalidValue; }