Tracking the internal allocation when creating a buffer

This fix prevents the creation of a buffer from the pointer
obtained from clEnqueueMapBuffer

Change-Id: I203f2d5263eeb02fe0d73bc9db159438af3cf1fc
This commit is contained in:
Koska, Andrzej
2018-05-08 10:00:23 +02:00
committed by sys_ocldev
parent c46f716d6c
commit fe56c57318
16 changed files with 233 additions and 11 deletions

View File

@@ -124,6 +124,9 @@ Buffer *Buffer::create(Context *context,
}
if (allocateMemory) {
memory = memoryManager->createGraphicsAllocationWithRequiredBitness(size, nullptr, true);
if (memory) {
memoryManager->addAllocationToHostPtrManager(memory);
}
if (context->isProvidingPerformanceHints()) {
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_BUFFER_NEEDS_ALLOCATE_MEMORY);
}
@@ -166,6 +169,7 @@ Buffer *Buffer::create(Context *context,
isHostPtrSVM,
false);
if (!pBuffer && allocateMemory) {
memoryManager->removeAllocationFromHostPtrManager(memory);
memoryManager->freeGraphicsMemory(memory);
memory = nullptr;
}
@@ -208,6 +212,11 @@ void Buffer::checkMemory(cl_mem_flags flags,
if (flags & CL_MEM_USE_HOST_PTR) {
if (hostPtr) {
auto fragment = memMngr->hostPtrManager.getFragment(hostPtr);
if (fragment && fragment->driverAllocation) {
errcodeRet = CL_INVALID_HOST_PTR;
return;
}
if (alignUp(hostPtr, MemoryConstants::cacheLineSize) != hostPtr ||
alignUp(size, MemoryConstants::cacheLineSize) != size ||
minAddress > reinterpret_cast<uintptr_t>(hostPtr) ||