From 3e5101424d7749133d5fd64b6e0c1f54fca7833e Mon Sep 17 00:00:00 2001 From: Igor Venevtsev Date: Fri, 24 Mar 2023 12:37:05 +0000 Subject: [PATCH] Optimize small buffers allocator - Do not wait for GPU completion on pool exhaust if allocs are in use, allocate new pool instead - Free small buffer address range if allocs are not in use and buffer pool is exhausted Resolves: NEO-7769, NEO-7836 Signed-off-by: Igor Venevtsev --- opencl/source/context/context.cpp | 171 +++++++--- opencl/source/context/context.h | 41 ++- opencl/source/mem_obj/mem_obj.cpp | 2 - .../mem_obj/buffer_pool_alloc_tests.cpp | 293 ++++++++++-------- opencl/test/unit_test/mocks/mock_context.h | 4 +- 5 files changed, 336 insertions(+), 175 deletions(-) diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index c4f22de2ec..179fcae71f 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -51,9 +51,11 @@ Context::Context( Context::~Context() { gtpinNotifyContextDestroy((cl_context)this); + if (multiRootDeviceTimestampPacketAllocator.get() != nullptr) { multiRootDeviceTimestampPacketAllocator.reset(); } + if (smallBufferPoolAllocator.isAggregatedSmallBuffersEnabled(this)) { smallBufferPoolAllocator.releaseSmallBufferPool(); } @@ -502,26 +504,103 @@ bool Context::BufferPoolAllocator::isAggregatedSmallBuffersEnabled(Context *cont (isSupportedForSingleDeviceContexts && context->isSingleDeviceContext()); } -void Context::BufferPoolAllocator::initAggregatedSmallBuffers(Context *context) { +Context::BufferPoolAllocator::BufferPool::BufferPool(Context *context) : memoryManager(context->memoryManager) { static constexpr cl_mem_flags flags{}; [[maybe_unused]] cl_int errcodeRet{}; Buffer::AdditionalBufferCreateArgs bufferCreateArgs{}; bufferCreateArgs.doNotProvidePerformanceHints = true; bufferCreateArgs.makeAllocationLockable = true; - this->mainStorage = Buffer::create(context, - flags, - BufferPoolAllocator::aggregatedSmallBuffersPoolSize, - nullptr, - bufferCreateArgs, - errcodeRet); - if (this->mainStorage) { - this->chunkAllocator.reset(new HeapAllocator(BufferPoolAllocator::startingOffset, - BufferPoolAllocator::aggregatedSmallBuffersPoolSize, - BufferPoolAllocator::chunkAlignment)); + mainStorage.reset(Buffer::create(context, + flags, + BufferPoolAllocator::aggregatedSmallBuffersPoolSize, + nullptr, + bufferCreateArgs, + errcodeRet)); + if (mainStorage) { + chunkAllocator.reset(new HeapAllocator(BufferPoolAllocator::startingOffset, + BufferPoolAllocator::aggregatedSmallBuffersPoolSize, + BufferPoolAllocator::chunkAlignment)); context->decRefInternal(); } } +Context::BufferPoolAllocator::BufferPool::BufferPool(BufferPool &&bufferPool) : memoryManager(bufferPool.memoryManager), + mainStorage(std::move(bufferPool.mainStorage)), + chunkAllocator(std::move(bufferPool.chunkAllocator)) {} + +Buffer *Context::BufferPoolAllocator::BufferPool::allocate(const MemoryProperties &memoryProperties, + cl_mem_flags flags, + cl_mem_flags_intel flagsIntel, + size_t requestedSize, + void *hostPtr, + cl_int &errcodeRet) { + cl_buffer_region bufferRegion{}; + size_t actualSize = requestedSize; + bufferRegion.origin = static_cast(chunkAllocator->allocate(actualSize)); + if (bufferRegion.origin == 0) { + return nullptr; + } + bufferRegion.origin -= BufferPoolAllocator::startingOffset; + bufferRegion.size = requestedSize; + auto bufferFromPool = mainStorage->createSubBuffer(flags, flagsIntel, &bufferRegion, errcodeRet); + bufferFromPool->createFunction = mainStorage->createFunction; + bufferFromPool->setSizeInPoolAllocator(actualSize); + return bufferFromPool; +} + +bool Context::BufferPoolAllocator::BufferPool::isPoolBuffer(const MemObj *buffer) const { + return mainStorage.get() == buffer; +} + +void Context::BufferPoolAllocator::BufferPool::drain() { + for (auto allocation : mainStorage->getMultiGraphicsAllocation().getGraphicsAllocations()) { + if (memoryManager->allocInUse(*allocation)) { + return; + } + } + + for (auto &chunk : chunksToFree) { + chunkAllocator->free(chunk.first, chunk.second); + } + + chunksToFree.clear(); +} + +void Context::BufferPoolAllocator::BufferPool::tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size) { + if (this->isPoolBuffer(possiblePoolBuffer)) { + chunksToFree.push_back({offset + BufferPoolAllocator::startingOffset, size}); + } +} + +void Context::BufferPoolAllocator::addNewBufferPool() { + Context::BufferPoolAllocator::BufferPool bufferPool(context); + if (bufferPool.mainStorage) { + bufferPools.push_back(std::move(bufferPool)); + } +} + +void Context::BufferPoolAllocator::initAggregatedSmallBuffers(Context *context) { + this->context = context; + addNewBufferPool(); +} + +bool Context::BufferPoolAllocator::isPoolBuffer(const MemObj *buffer) const { + for (auto &bufferPool : bufferPools) { + if (bufferPool.isPoolBuffer(buffer)) { + return true; + } + } + + return false; +} + +void Context::BufferPoolAllocator::tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size) { + auto lock = std::unique_lock(this->mutex); + for (auto &bufferPool : bufferPools) { + bufferPool.tryFreeFromPoolBuffer(possiblePoolBuffer, offset, size); + } +} + Buffer *Context::BufferPoolAllocator::allocateBufferFromPool(const MemoryProperties &memoryProperties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel, @@ -529,45 +608,55 @@ Buffer *Context::BufferPoolAllocator::allocateBufferFromPool(const MemoryPropert void *hostPtr, cl_int &errcodeRet) { errcodeRet = CL_MEM_OBJECT_ALLOCATION_FAILURE; - if (this->mainStorage && - this->isSizeWithinThreshold(requestedSize) && - this->flagsAllowBufferFromPool(flags, flagsIntel)) { - auto lock = std::unique_lock(this->mutex); - cl_buffer_region bufferRegion{}; - size_t actualSize = requestedSize; - bufferRegion.origin = static_cast(this->chunkAllocator->allocate(actualSize)); - if (bufferRegion.origin == 0) { - return nullptr; - } - bufferRegion.origin -= BufferPoolAllocator::startingOffset; - bufferRegion.size = requestedSize; - auto bufferFromPool = this->mainStorage->createSubBuffer(flags, flagsIntel, &bufferRegion, errcodeRet); - bufferFromPool->createFunction = this->mainStorage->createFunction; - bufferFromPool->setSizeInPoolAllocator(actualSize); + if (bufferPools.empty() || + !isSizeWithinThreshold(requestedSize) || + !flagsAllowBufferFromPool(flags, flagsIntel)) { + return nullptr; + } + + auto lock = std::unique_lock(mutex); + auto bufferFromPool = allocateFromPools(memoryProperties, flags, flagsIntel, requestedSize, hostPtr, errcodeRet); + if (bufferFromPool != nullptr) { return bufferFromPool; } - return nullptr; -} -bool Context::BufferPoolAllocator::isPoolBuffer(const MemObj *buffer) const { - return buffer != nullptr && this->mainStorage == buffer; -} + drain(); -void Context::BufferPoolAllocator::tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size) { - if (this->isPoolBuffer(possiblePoolBuffer)) { - auto lock = std::unique_lock(this->mutex); - DEBUG_BREAK_IF(!this->mainStorage); - DEBUG_BREAK_IF(size == 0); - auto internalBufferAddress = offset + BufferPoolAllocator::startingOffset; - this->chunkAllocator->free(internalBufferAddress, size); + bufferFromPool = allocateFromPools(memoryProperties, flags, flagsIntel, requestedSize, hostPtr, errcodeRet); + if (bufferFromPool != nullptr) { + return bufferFromPool; } + + addNewBufferPool(); + return allocateFromPools(memoryProperties, flags, flagsIntel, requestedSize, hostPtr, errcodeRet); } void Context::BufferPoolAllocator::releaseSmallBufferPool() { - DEBUG_BREAK_IF(!this->mainStorage); - delete this->mainStorage; - this->mainStorage = nullptr; + bufferPools.clear(); } + +void Context::BufferPoolAllocator::drain() { + for (auto &bufferPool : bufferPools) { + bufferPool.drain(); + } +} + +Buffer *Context::BufferPoolAllocator::allocateFromPools(const MemoryProperties &memoryProperties, + cl_mem_flags flags, + cl_mem_flags_intel flagsIntel, + size_t requestedSize, + void *hostPtr, + cl_int &errcodeRet) { + for (auto &bufferPool : bufferPools) { + auto bufferFromPool = bufferPool.allocate(memoryProperties, flags, flagsIntel, requestedSize, hostPtr, errcodeRet); + if (bufferFromPool != nullptr) { + return bufferFromPool; + } + } + + return nullptr; +} + TagAllocatorBase *Context::getMultiRootDeviceTimestampPacketAllocator() { return multiRootDeviceTimestampPacketAllocator.get(); } diff --git a/opencl/source/context/context.h b/opencl/source/context/context.h index 512df2fdcc..7493e209db 100644 --- a/opencl/source/context/context.h +++ b/opencl/source/context/context.h @@ -60,24 +60,49 @@ class Context : public BaseObject<_cl_context> { size_t size, void *hostPtr, cl_int &errcodeRet); - void tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size); + void releaseSmallBufferPool(); - bool isAggregatedSmallBuffersEnabled(Context *context) const; - void initAggregatedSmallBuffers(Context *context); - bool isPoolBuffer(const MemObj *buffer) const; - bool flagsAllowBufferFromPool(const cl_mem_flags &flags, const cl_mem_flags_intel &flagsIntel) const; + void tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size); protected: + Buffer *allocateFromPools(const MemoryProperties &memoryProperties, + cl_mem_flags flags, + cl_mem_flags_intel flagsIntel, + size_t size, + void *hostPtr, + cl_int &errcodeRet); + inline bool isSizeWithinThreshold(size_t size) const { return BufferPoolAllocator::smallBufferThreshold >= size; } - Buffer *mainStorage{nullptr}; - std::unique_ptr chunkAllocator; + + void drain(); + void addNewBufferPool(); + + struct BufferPool { + BufferPool(Context *context); + BufferPool(BufferPool &&bufferPool); + bool isPoolBuffer(const MemObj *buffer) const; + void tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size); + Buffer *allocate(const MemoryProperties &memoryProperties, + cl_mem_flags flags, + cl_mem_flags_intel flagsIntel, + size_t size, + void *hostPtr, + cl_int &errcodeRet); + void drain(); + MemoryManager *memoryManager{nullptr}; + std::unique_ptr mainStorage; + std::unique_ptr chunkAllocator; + std::vector> chunksToFree; + }; + Context *context{nullptr}; std::mutex mutex; + std::vector bufferPools; }; static const cl_ulong objectMagic = 0xA4234321DC002130LL; @@ -221,7 +246,7 @@ class Context : public BaseObject<_cl_context> { static Platform *getPlatformFromProperties(const cl_context_properties *properties, cl_int &errcode); BufferPoolAllocator &getBufferPoolAllocator() { - return this->smallBufferPoolAllocator; + return smallBufferPoolAllocator; } TagAllocatorBase *getMultiRootDeviceTimestampPacketAllocator(); std::unique_lock obtainOwnershipForMultiRootDeviceAllocator(); diff --git a/opencl/source/mem_obj/mem_obj.cpp b/opencl/source/mem_obj/mem_obj.cpp index 3cc97729ff..3c90ee1049 100644 --- a/opencl/source/mem_obj/mem_obj.cpp +++ b/opencl/source/mem_obj/mem_obj.cpp @@ -90,8 +90,6 @@ MemObj::~MemObj() { } destroyGraphicsAllocation(graphicsAllocation, doAsyncDestructions); graphicsAllocation = nullptr; - } else if (graphicsAllocation && context->getBufferPoolAllocator().isPoolBuffer(associatedMemObject)) { - memoryManager->waitForEnginesCompletion(*graphicsAllocation); } if (!associatedMemObject) { releaseMapAllocation(rootDeviceIndex, doAsyncDestructions); diff --git a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp index 81c4366674..420cf3e0b0 100644 --- a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp @@ -30,12 +30,6 @@ class AggregatedSmallBuffersTestTemplate : public ::testing::Test { } } - void TearDown() override { - if (this->context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())) { - this->context->getBufferPoolAllocator().releaseSmallBufferPool(); - } - } - void setAllocationToFail(bool shouldFail) { this->mockMemoryManager->failInDevicePoolWithError = shouldFail; } @@ -62,7 +56,7 @@ class AggregatedSmallBuffersTestTemplate : public ::testing::Test { this->setAllocationToFail(failMainStorageAllocation); cl_device_id devices[] = {device}; this->context.reset(Context::create(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal)); - ASSERT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(retVal, CL_SUCCESS); this->setAllocationToFail(false); this->poolAllocator = static_cast(&context->smallBufferPoolAllocator); } @@ -83,8 +77,8 @@ class AggregatedSmallBuffersKernelTest : public AggregatedSmallBuffersTestTempla retVal = CL_INVALID_VALUE; pMultiDeviceKernel.reset(MultiDeviceKernel::create(pProgram.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, device->getRootDeviceIndex()), retVal)); pKernel = static_cast(pMultiDeviceKernel->getKernel(device->getRootDeviceIndex())); - ASSERT_NE(pKernel, nullptr); - ASSERT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(pKernel, nullptr); + EXPECT_EQ(retVal, CL_SUCCESS); pKernel->setCrossThreadData(pCrossThreadData, sizeof(pCrossThreadData)); pKernelArg = (void **)(pKernel->getCrossThreadData() + pKernelInfo->argAsPtr(0).stateless); @@ -143,87 +137,167 @@ HWTEST_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOrM using AggregatedSmallBuffersDisabledTest = AggregatedSmallBuffersTestTemplate<0>; TEST_F(AggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWhenBufferCreateCalledThenDoNotUsePool) { - ASSERT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_EQ(poolAllocator->mainStorage, nullptr); + EXPECT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(0u, poolAllocator->bufferPools.size()); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - EXPECT_NE(buffer, nullptr); - EXPECT_EQ(retVal, CL_SUCCESS); - - EXPECT_EQ(poolAllocator->mainStorage, nullptr); + EXPECT_NE(nullptr, buffer); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(0u, poolAllocator->bufferPools.size()); } using AggregatedSmallBuffersEnabledTest = AggregatedSmallBuffersTestTemplate<1>; TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenAllocatingMainStorageThenMakeDeviceBufferLockable) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); - ASSERT_NE(mockMemoryManager->lastAllocationProperties, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + EXPECT_NE(nullptr, mockMemoryManager->lastAllocationProperties); EXPECT_TRUE(mockMemoryManager->lastAllocationProperties->makeDeviceBufferLockable); } TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLargerThanThresholdWhenBufferCreateCalledThenDoNotUsePool) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); size = PoolAllocator::smallBufferThreshold + 1; std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - EXPECT_NE(buffer, nullptr); - EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(nullptr, buffer); + EXPECT_EQ(CL_SUCCESS, retVal); } -TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLowerThenChunkAlignmentWhenBufferCreatedAndDestroyedThenSizeIsAsRequestedAndCorrectSizeIsFreed) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); - ASSERT_EQ(poolAllocator->chunkAllocator->getUsedSize(), 0u); +TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLowerThenChunkAlignmentWhenBufferCreatedAndDestroyedThenSizeIsAsRequestedAndCorrectSizeIsNotFreed) { + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + EXPECT_EQ(0u, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); size = PoolAllocator::chunkAlignment / 2; std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); EXPECT_NE(buffer, nullptr); - EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_EQ(buffer->getSize(), size); - EXPECT_EQ(poolAllocator->chunkAllocator->getUsedSize(), PoolAllocator::chunkAlignment); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(size, buffer->getSize()); + EXPECT_EQ(PoolAllocator::chunkAlignment, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); auto mockBuffer = static_cast(buffer.get()); - EXPECT_EQ(mockBuffer->sizeInPoolAllocator, PoolAllocator::chunkAlignment); + EXPECT_EQ(PoolAllocator::chunkAlignment, mockBuffer->sizeInPoolAllocator); buffer.reset(nullptr); - EXPECT_EQ(poolAllocator->chunkAllocator->getUsedSize(), 0u); + EXPECT_EQ(PoolAllocator::chunkAlignment, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); } TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledThenUsePool) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); EXPECT_NE(buffer, nullptr); EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); auto mockBuffer = static_cast(buffer.get()); EXPECT_GE(mockBuffer->getSize(), size); EXPECT_GE(mockBuffer->getOffset(), 0u); EXPECT_LE(mockBuffer->getOffset(), PoolAllocator::aggregatedSmallBuffersPoolSize - size); EXPECT_TRUE(mockBuffer->isSubBuffer()); - EXPECT_EQ(poolAllocator->mainStorage, mockBuffer->associatedMemObject); + EXPECT_EQ(mockBuffer->associatedMemObject, poolAllocator->bufferPools[0].mainStorage.get()); retVal = clReleaseMemObject(buffer.release()); EXPECT_EQ(retVal, CL_SUCCESS); } -TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenClReleaseMemObjectCalledThenWaitForEnginesCompletionCalled) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); +TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenClReleaseMemObjectCalledThenWaitForEnginesCompletionNotCalledAndMemoryRegionIsNotFreed) { + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + EXPECT_EQ(0u, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - ASSERT_NE(buffer, nullptr); - ASSERT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(buffer, nullptr); + EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); auto mockBuffer = static_cast(buffer.get()); - ASSERT_TRUE(mockBuffer->isSubBuffer()); - ASSERT_EQ(poolAllocator->mainStorage, mockBuffer->associatedMemObject); + EXPECT_TRUE(mockBuffer->isSubBuffer()); + EXPECT_EQ(mockBuffer->associatedMemObject, poolAllocator->bufferPools[0].mainStorage.get()); - ASSERT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 0u); + EXPECT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 0u); retVal = clReleaseMemObject(buffer.release()); - ASSERT_EQ(retVal, CL_SUCCESS); - EXPECT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 1u); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 0u); + EXPECT_EQ(size, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); +} + +TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndBufferPoolIsExhaustedAndAllocationsAreNotInUseAndBufferWasFreedThenPoolIsReused) { + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + + constexpr auto buffersToCreate = PoolAllocator::aggregatedSmallBuffersPoolSize / PoolAllocator::smallBufferThreshold; + std::vector> buffers(buffersToCreate); + for (auto i = 0u; i < buffersToCreate; i++) { + buffers[i].reset(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + } + + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); + EXPECT_EQ(0u, mockMemoryManager->allocInUseCalled); + mockMemoryManager->deferAllocInUse = false; + + buffers[0] = nullptr; + + std::unique_ptr bufferAfterFreeMustSucceed(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_EQ(poolAllocator->bufferPools[0].mainStorage->getMultiGraphicsAllocation().getGraphicsAllocations().size(), mockMemoryManager->allocInUseCalled); + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); +} + +TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndBufferPoolIsExhaustedAndAllocationsAreNotInUseAndNoBuffersFreedThenNewPoolIsCreated) { + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + + constexpr auto buffersToCreate = PoolAllocator::aggregatedSmallBuffersPoolSize / PoolAllocator::smallBufferThreshold; + std::vector> buffers(buffersToCreate); + for (auto i = 0u; i < buffersToCreate; i++) { + buffers[i].reset(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + } + + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); + EXPECT_EQ(0u, mockMemoryManager->allocInUseCalled); + mockMemoryManager->deferAllocInUse = false; + + std::unique_ptr bufferAfterExhaustMustSucceed(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(2u, poolAllocator->bufferPools.size()); + EXPECT_EQ(poolAllocator->bufferPools[0].mainStorage->getMultiGraphicsAllocation().getGraphicsAllocations().size(), mockMemoryManager->allocInUseCalled); + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); + EXPECT_EQ(size, poolAllocator->bufferPools[1].chunkAllocator->getUsedSize()); +} + +TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndBufferPoolIsExhaustedAndAllocationsAreInUseThenNewPoolIsCreated) { + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); + + constexpr auto buffersToCreate = PoolAllocator::aggregatedSmallBuffersPoolSize / PoolAllocator::smallBufferThreshold; + std::vector> buffers(buffersToCreate); + for (auto i = 0u; i < buffersToCreate; i++) { + buffers[i].reset(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + } + + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); + EXPECT_EQ(0u, mockMemoryManager->allocInUseCalled); + mockMemoryManager->deferAllocInUse = true; + + std::unique_ptr bufferAfterExhaustMustSucceed(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(2u, poolAllocator->bufferPools.size()); + EXPECT_EQ(poolAllocator->bufferPools[0].mainStorage->getMultiGraphicsAllocation().getGraphicsAllocations().size(), mockMemoryManager->allocInUseCalled); + EXPECT_EQ(size * buffersToCreate, poolAllocator->bufferPools[0].chunkAllocator->getUsedSize()); + EXPECT_EQ(size, poolAllocator->bufferPools[1].chunkAllocator->getUsedSize()); } TEST_F(AggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBufferButCopyFailedThenDoNotUsePool) { @@ -249,14 +323,15 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBuffer unsigned char dataToCopy[PoolAllocator::smallBufferThreshold]; hostPtr = dataToCopy; - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); if (commandQueue->writeBufferCounter == 0) { GTEST_SKIP(); } EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); auto mockBuffer = static_cast(buffer.get()); EXPECT_FALSE(mockBuffer->isSubBuffer()); @@ -265,8 +340,9 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBuffer } TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledMultipleTimesThenUsePool) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_EQ(1u, poolAllocator->bufferPools.size()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); constexpr auto buffersToCreate = PoolAllocator::aggregatedSmallBuffersPoolSize / PoolAllocator::smallBufferThreshold; std::vector> buffers(buffersToCreate); @@ -274,11 +350,8 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS buffers[i].reset(Buffer::create(context.get(), flags, size, hostPtr, retVal)); EXPECT_EQ(retVal, CL_SUCCESS); } - EXPECT_NE(poolAllocator->mainStorage, nullptr); - std::unique_ptr bufferAfterPoolIsFull(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_NE(bufferAfterPoolIsFull, nullptr); - EXPECT_FALSE(bufferAfterPoolIsFull->isSubBuffer()); + + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); using Bounds = struct { size_t left; @@ -292,7 +365,8 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS EXPECT_NE(buffers[i], nullptr); EXPECT_TRUE(buffers[i]->isSubBuffer()); auto mockBuffer = static_cast(buffers[i].get()); - EXPECT_EQ(poolAllocator->mainStorage, mockBuffer->associatedMemObject); + EXPECT_EQ(mockBuffer->associatedMemObject, poolAllocator->bufferPools[0].mainStorage.get()); + EXPECT_NE(nullptr, poolAllocator->bufferPools[0].mainStorage.get()); EXPECT_GE(mockBuffer->getSize(), size); EXPECT_GE(mockBuffer->getOffset(), 0u); EXPECT_LE(mockBuffer->getOffset(), PoolAllocator::aggregatedSmallBuffersPoolSize - size); @@ -307,42 +381,24 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS subBuffersBounds[j].right <= subBuffersBounds[i].left); } } - - // freeing subbuffer frees space in pool - ASSERT_LT(poolAllocator->chunkAllocator->getLeftSize(), size); - clReleaseMemObject(buffers[0].release()); - EXPECT_GE(poolAllocator->chunkAllocator->getLeftSize(), size); - std::unique_ptr bufferAfterPoolHasSpaceAgain(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(bufferAfterPoolHasSpaceAgain, nullptr); - EXPECT_TRUE(bufferAfterPoolHasSpaceAgain->isSubBuffer()); - - // subbuffer after free does not overlap - subBuffersBounds[0] = Bounds{bufferAfterPoolHasSpaceAgain->getOffset(), bufferAfterPoolHasSpaceAgain->getOffset() + bufferAfterPoolHasSpaceAgain->getSize()}; - for (auto i = 0u; i < buffersToCreate; i++) { - for (auto j = i + 1; j < buffersToCreate; j++) { - EXPECT_TRUE(subBuffersBounds[i].right <= subBuffersBounds[j].left || - subBuffersBounds[j].right <= subBuffersBounds[i].left); - } - } } TEST_F(AggregatedSmallBuffersKernelTest, givenBufferFromPoolWhenOffsetSubbufferIsPassedToSetKernelArgThenCorrectGpuVAIsPatched) { std::unique_ptr unusedBuffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); - ASSERT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); - ASSERT_GT(buffer->getOffset(), 0u); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(buffer, nullptr); + EXPECT_GT(buffer->getOffset(), 0u); cl_buffer_region region; region.origin = 0xc0; region.size = 32; cl_int error = 0; std::unique_ptr subBuffer(buffer->createSubBuffer(buffer->getFlags(), buffer->getFlagsIntel(), ®ion, error)); - ASSERT_NE(subBuffer, nullptr); + EXPECT_NE(subBuffer, nullptr); EXPECT_EQ(ptrOffset(buffer->getCpuAddress(), region.origin), subBuffer->getCpuAddress()); const auto graphicsAllocation = subBuffer->getGraphicsAllocation(device->getRootDeviceIndex()); - ASSERT_NE(graphicsAllocation, nullptr); + EXPECT_NE(graphicsAllocation, nullptr); const auto gpuAddress = graphicsAllocation->getGpuAddress(); EXPECT_EQ(ptrOffset(gpuAddress, buffer->getOffset() + region.origin), subBuffer->getBufferAddress(device->getRootDeviceIndex())); @@ -353,13 +409,13 @@ TEST_F(AggregatedSmallBuffersKernelTest, givenBufferFromPoolWhenOffsetSubbufferI using AggregatedSmallBuffersEnabledTestFailPoolInit = AggregatedSmallBuffersTestTemplate<1, true>; TEST_F(AggregatedSmallBuffersEnabledTestFailPoolInit, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledButPoolCreateFailedThenDoNotUsePool) { - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_EQ(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_TRUE(poolAllocator->bufferPools.empty()); std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); EXPECT_EQ(retVal, CL_SUCCESS); EXPECT_NE(buffer.get(), nullptr); - EXPECT_EQ(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->bufferPools.empty()); } using AggregatedSmallBuffersEnabledTestDoNotRunSetup = AggregatedSmallBuffersTestTemplate<1, false, false>; @@ -368,9 +424,9 @@ TEST_F(AggregatedSmallBuffersEnabledTestDoNotRunSetup, givenAggregatedSmallBuffe testing::internal::CaptureStdout(); DebugManager.flags.PrintDriverDiagnostics.set(1); setUpImpl(); - ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); - ASSERT_NE(poolAllocator->mainStorage, nullptr); - ASSERT_NE(context->driverDiagnostics, nullptr); + EXPECT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get())); + EXPECT_FALSE(poolAllocator->bufferPools.empty()); + EXPECT_NE(context->driverDiagnostics, nullptr); std::string output = testing::internal::GetCapturedStdout(); EXPECT_EQ(0u, output.size()); } @@ -383,7 +439,7 @@ class AggregatedSmallBuffersApiTestTemplate : public ::testing::Test { auto device = deviceFactory->rootDevices[0]; cl_device_id devices[] = {device}; clContext = clCreateContext(nullptr, 1, devices, nullptr, nullptr, &retVal); - ASSERT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(retVal, CL_SUCCESS); context = castToObject(clContext); poolAllocator = static_cast(&context->getBufferPoolAllocator()); } @@ -416,7 +472,7 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenNotSmallBufferWhenCreatingBuff size = PoolAllocator::smallBufferThreshold + 1; cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); MockBuffer *asBuffer = static_cast(buffer); EXPECT_FALSE(asBuffer->isSubBuffer()); @@ -431,14 +487,13 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSmallBufferWhenCreatingBufferT auto contextRefCountBefore = context->getRefInternalCount(); cl_mem smallBuffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(smallBuffer, nullptr); + EXPECT_NE(smallBuffer, nullptr); MockBuffer *asBuffer = static_cast(smallBuffer); EXPECT_TRUE(asBuffer->isSubBuffer()); Buffer *parentBuffer = static_cast(asBuffer->associatedMemObject); EXPECT_EQ(2, parentBuffer->getRefInternalCount()); - MockBufferPoolAllocator *mockBufferPoolAllocator = static_cast(&context->getBufferPoolAllocator()); - EXPECT_EQ(parentBuffer, mockBufferPoolAllocator->mainStorage); + EXPECT_EQ(parentBuffer, poolAllocator->bufferPools[0].mainStorage.get()); retVal = clReleaseMemObject(smallBuffer); EXPECT_EQ(retVal, CL_SUCCESS); @@ -448,24 +503,20 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSmallBufferWhenCreatingBufferT EXPECT_EQ(clReleaseContext(context), CL_SUCCESS); } -TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSmallBufferWhenCreatingBufferWithNullPropertiesThenUsePool) { - auto contextRefCountBefore = context->getRefInternalCount(); - cl_mem smallBuffer = clCreateBufferWithProperties(clContext, nullptr, flags, size, hostPtr, &retVal); +TEST_F(AggregatedSmallBuffersEnabledApiTest, givenUseHostPointerWhenCreatingBufferThenDoNotUsePool) { + flags |= CL_MEM_USE_HOST_PTR; + unsigned char hostData[PoolAllocator::smallBufferThreshold]; + hostPtr = hostData; + cl_mem smallBuffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(smallBuffer, nullptr); + EXPECT_NE(smallBuffer, nullptr); MockBuffer *asBuffer = static_cast(smallBuffer); - EXPECT_TRUE(asBuffer->isSubBuffer()); - Buffer *parentBuffer = static_cast(asBuffer->associatedMemObject); - EXPECT_EQ(2, parentBuffer->getRefInternalCount()); - MockBufferPoolAllocator *mockBufferPoolAllocator = static_cast(&context->getBufferPoolAllocator()); - EXPECT_EQ(parentBuffer, mockBufferPoolAllocator->mainStorage); + EXPECT_FALSE(asBuffer->isSubBuffer()); retVal = clReleaseMemObject(smallBuffer); EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_EQ(context->getRefInternalCount(), contextRefCountBefore); - EXPECT_EQ(clReleaseContext(context), CL_SUCCESS); } @@ -474,14 +525,13 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSmallBufferWhenCreatingBufferW cl_mem_properties memProperties{}; cl_mem smallBuffer = clCreateBufferWithProperties(clContext, &memProperties, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(smallBuffer, nullptr); + EXPECT_NE(smallBuffer, nullptr); MockBuffer *asBuffer = static_cast(smallBuffer); EXPECT_TRUE(asBuffer->isSubBuffer()); Buffer *parentBuffer = static_cast(asBuffer->associatedMemObject); EXPECT_EQ(2, parentBuffer->getRefInternalCount()); - MockBufferPoolAllocator *mockBufferPoolAllocator = static_cast(&context->getBufferPoolAllocator()); - EXPECT_EQ(parentBuffer, mockBufferPoolAllocator->mainStorage); + EXPECT_EQ(parentBuffer, poolAllocator->bufferPools[0].mainStorage.get()); retVal = clReleaseMemObject(smallBuffer); EXPECT_EQ(retVal, CL_SUCCESS); @@ -494,7 +544,7 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSmallBufferWhenCreatingBufferW TEST_F(AggregatedSmallBuffersEnabledApiTest, givenBufferFromPoolWhenGetMemObjInfoCalledThenReturnValuesLikeForNormalBuffer) { cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); MockBuffer *asBuffer = static_cast(buffer); EXPECT_TRUE(asBuffer->isSubBuffer()); @@ -521,14 +571,14 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenSubBufferNotFromPoolAndAggrega size_t size = PoolAllocator::smallBufferThreshold + 1; cl_mem largeBuffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); - ASSERT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(largeBuffer, nullptr); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(largeBuffer, nullptr); cl_buffer_region region{}; region.size = 1; cl_mem subBuffer = clCreateSubBuffer(largeBuffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &retVal); - ASSERT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(subBuffer, nullptr); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(subBuffer, nullptr); DebugManager.flags.ExperimentalSmallBufferPoolAllocator.set(1); retVal = clReleaseMemObject(subBuffer); @@ -549,14 +599,13 @@ TEST_F(AggregatedSmallBuffersEnabledApiTest, givenCopyHostPointerWhenCreatingBuf cl_mem smallBuffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(context->getRefInternalCount(), contextRefCountBefore + 1); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(smallBuffer, nullptr); + EXPECT_NE(smallBuffer, nullptr); MockBuffer *asBuffer = static_cast(smallBuffer); EXPECT_TRUE(asBuffer->isSubBuffer()); Buffer *parentBuffer = static_cast(asBuffer->associatedMemObject); EXPECT_EQ(2, parentBuffer->getRefInternalCount()); - MockBufferPoolAllocator *mockBufferPoolAllocator = static_cast(&context->getBufferPoolAllocator()); - EXPECT_EQ(parentBuffer, mockBufferPoolAllocator->mainStorage); + EXPECT_EQ(parentBuffer, poolAllocator->bufferPools[0].mainStorage.get()); // check that data has been copied auto address = asBuffer->getCpuAddress(); @@ -579,17 +628,17 @@ TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenBufferFromPoolWhenCreateSubB cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); MockBuffer *mockBuffer = static_cast(buffer); EXPECT_GT(mockBuffer->offset, 0u); - EXPECT_EQ(ptrOffset(poolAllocator->mainStorage->getCpuAddress(), mockBuffer->getOffset()), mockBuffer->getCpuAddress()); + EXPECT_EQ(ptrOffset(poolAllocator->bufferPools[0].mainStorage->getCpuAddress(), mockBuffer->getOffset()), mockBuffer->getCpuAddress()); cl_buffer_region region{}; region.size = 1; region.origin = size / 2; cl_mem subBuffer = clCreateSubBuffer(buffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(subBuffer, nullptr); + EXPECT_NE(subBuffer, nullptr); MockBuffer *mockSubBuffer = static_cast(subBuffer); EXPECT_EQ(mockSubBuffer->associatedMemObject, buffer); EXPECT_EQ(ptrOffset(mockBuffer->getCpuAddress(), region.origin), mockSubBuffer->getCpuAddress()); @@ -609,16 +658,16 @@ TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenBufferFromPoolWhenCreateSubB TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenSubBufferFromBufferPoolWhenGetMemObjInfoCalledThenReturnValuesLikeForNormalSubBuffer) { cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); MockBuffer *mockBuffer = static_cast(buffer); - ASSERT_TRUE(context->getBufferPoolAllocator().isPoolBuffer(mockBuffer->associatedMemObject)); + EXPECT_TRUE(context->getBufferPoolAllocator().isPoolBuffer(mockBuffer->associatedMemObject)); cl_buffer_region region{}; region.size = 1; region.origin = size / 2; cl_mem subBuffer = clCreateSubBuffer(buffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(subBuffer, nullptr); + EXPECT_NE(subBuffer, nullptr); cl_mem associatedMemObj = nullptr; retVal = clGetMemObjectInfo(subBuffer, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof(cl_mem), &associatedMemObj, nullptr); @@ -642,7 +691,7 @@ TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenSubBufferFromBufferPoolWhenG TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenBufferFromPoolWhenCreateSubBufferCalledWithRegionOutsideBufferThenItFails) { cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); cl_buffer_region region{}; region.size = size + 1; @@ -666,14 +715,14 @@ TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenBufferFromPoolWhenCreateSubB TEST_F(AggregatedSmallBuffersSubBufferApiTest, givenSubBufferFromBufferFromPoolWhenCreateSubBufferCalledThenItFails) { cl_mem buffer = clCreateBuffer(clContext, flags, size, hostPtr, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(buffer, nullptr); + EXPECT_NE(buffer, nullptr); cl_buffer_region region{}; region.size = 1; region.origin = size / 2; cl_mem subBuffer = clCreateSubBuffer(buffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &retVal); EXPECT_EQ(retVal, CL_SUCCESS); - ASSERT_NE(subBuffer, nullptr); + EXPECT_NE(subBuffer, nullptr); region.origin = 0; cl_mem subSubBuffer = clCreateSubBuffer(subBuffer, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &retVal); diff --git a/opencl/test/unit_test/mocks/mock_context.h b/opencl/test/unit_test/mocks/mock_context.h index 5cd570eeb6..28112d28e2 100644 --- a/opencl/test/unit_test/mocks/mock_context.h +++ b/opencl/test/unit_test/mocks/mock_context.h @@ -55,9 +55,9 @@ class MockContext : public Context { class MockBufferPoolAllocator : public BufferPoolAllocator { public: - using BufferPoolAllocator::chunkAllocator; + using BufferPoolAllocator::BufferPool; + using BufferPoolAllocator::bufferPools; using BufferPoolAllocator::isAggregatedSmallBuffersEnabled; - using BufferPoolAllocator::mainStorage; }; private: