2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/deferred_deleter.h"
|
2018-06-21 17:36:47 +08:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/surface_formats.h"
|
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
void MockMemoryManager::setDeferredDeleter(DeferredDeleter *deleter) {
|
|
|
|
deferredDeleter.reset(deleter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockMemoryManager::overrideAsyncDeleterFlag(bool newValue) {
|
|
|
|
asyncDeleterEnabled = newValue;
|
|
|
|
if (asyncDeleterEnabled && deferredDeleter == nullptr) {
|
|
|
|
deferredDeleter = createDeferredDeleter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) {
|
|
|
|
imgInfo.size *= redundancyRatio;
|
|
|
|
auto *allocation = OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(imgInfo, gmm);
|
|
|
|
imgInfo.size /= redundancyRatio;
|
|
|
|
if (redundancyRatio != 1) {
|
|
|
|
memset((unsigned char *)allocation->getUnderlyingBuffer(), 0, imgInfo.size * redundancyRatio);
|
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MockMemoryManager::isAllocationListEmpty() {
|
2018-10-09 17:50:58 +08:00
|
|
|
return getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MockMemoryManager::peekAllocationListHead() {
|
2018-10-09 17:50:58 +08:00
|
|
|
return getCommandStreamReceiver(0)->getTemporaryAllocations().peekHead();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-24 15:06:33 +08:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) {
|
2018-07-24 22:42:35 +08:00
|
|
|
allocation64kbPageCreated = true;
|
|
|
|
preferRenderCompressedFlagPassed = preferRenderCompressed;
|
|
|
|
|
2018-07-24 15:06:33 +08:00
|
|
|
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemory64kb(size, alignment, forcePin, preferRenderCompressed);
|
|
|
|
if (allocation) {
|
2018-08-03 00:24:59 +08:00
|
|
|
allocation->gmm = new Gmm(allocation->getUnderlyingBuffer(), size, false, preferRenderCompressed, true);
|
2018-07-24 15:06:33 +08:00
|
|
|
allocation->gmm->isRenderCompressed = preferRenderCompressed;
|
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:42:35 +08:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
|
|
|
if (failInDevicePool) {
|
|
|
|
status = AllocationStatus::RetryInNonDevicePool;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (failInDevicePoolWithError) {
|
|
|
|
status = AllocationStatus::Error;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
|
|
|
|
if (allocation) {
|
|
|
|
allocationInDevicePoolCreated = true;
|
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) {
|
2018-07-25 15:38:00 +08:00
|
|
|
if (failInAllocateWithSizeAndAlignment) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-24 22:42:35 +08:00
|
|
|
allocationCreated = true;
|
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemory(size, alignment, forcePin, uncacheable);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|