Check for max allocation size while allocating USM.

Change-Id: I870ffd5d8716dc50ac064666b54f5fa92d8beca3
Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2019-11-18 13:59:27 +01:00
committed by sys_ocldev
parent 16f7b9af16
commit 6646bd81a7
2 changed files with 37 additions and 3 deletions

View File

@@ -3412,6 +3412,11 @@ void *clHostMemAllocINTEL(
return nullptr;
}
if (size > neoContext->getDevice(0u)->getDeviceInfo().maxMemAllocSize) {
err.set(CL_INVALID_BUFFER_SIZE);
return nullptr;
}
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY);
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
err.set(CL_INVALID_VALUE);
@@ -3429,23 +3434,29 @@ void *clDeviceMemAllocINTEL(
cl_uint alignment,
cl_int *errcodeRet) {
Context *neoContext = nullptr;
Device *neoDevice = nullptr;
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
auto retVal = validateObjects(WithCastToInternal(context, &neoContext), WithCastToInternal(device, &neoDevice));
if (retVal != CL_SUCCESS) {
err.set(retVal);
return nullptr;
}
if (size > neoDevice->getDeviceInfo().maxMemAllocSize) {
err.set(CL_INVALID_BUFFER_SIZE);
return nullptr;
}
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY);
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
err.set(CL_INVALID_VALUE);
return nullptr;
}
return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(neoContext->getDevice(0)->getRootDeviceIndex(), size, unifiedMemoryProperties);
return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(neoDevice->getRootDeviceIndex(), size, unifiedMemoryProperties);
}
void *clSharedMemAllocINTEL(
@@ -3456,16 +3467,22 @@ void *clSharedMemAllocINTEL(
cl_uint alignment,
cl_int *errcodeRet) {
Context *neoContext = nullptr;
Device *neoDevice = nullptr;
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
auto retVal = validateObjects(WithCastToInternal(context, &neoContext), WithCastToInternal(device, &neoDevice));
if (retVal != CL_SUCCESS) {
err.set(retVal);
return nullptr;
}
if (size > neoDevice->getDeviceInfo().maxMemAllocSize) {
err.set(CL_INVALID_BUFFER_SIZE);
return nullptr;
}
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY);
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
err.set(CL_INVALID_VALUE);