2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-22 12:40:17 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
|
|
|
|
2018-10-09 11:50:58 +02:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2018-06-21 11:36:47 +02:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/helpers/surface_formats.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/memory_manager/deferred_deleter.h"
|
2018-12-21 10:16:27 +01:00
|
|
|
#include "unit_tests/mocks/mock_allocation_properties.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
void MockMemoryManager::setDeferredDeleter(DeferredDeleter *deleter) {
|
|
|
|
deferredDeleter.reset(deleter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockMemoryManager::overrideAsyncDeleterFlag(bool newValue) {
|
|
|
|
asyncDeleterEnabled = newValue;
|
|
|
|
if (asyncDeleterEnabled && deferredDeleter == nullptr) {
|
|
|
|
deferredDeleter = createDeferredDeleter();
|
|
|
|
}
|
|
|
|
}
|
2018-12-14 11:24:45 +01:00
|
|
|
|
|
|
|
void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
|
2019-03-06 16:35:21 +01:00
|
|
|
if (failAllocateSystemMemory) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-12-14 11:24:45 +01:00
|
|
|
return OsAgnosticMemoryManager::allocateSystemMemory(redundancyRatio * size, alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
|
2018-12-20 07:43:57 +00:00
|
|
|
AllocationProperties adjustedProperties(properties);
|
|
|
|
adjustedProperties.size = redundancyRatio * properties.size;
|
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties(adjustedProperties);
|
2018-12-14 11:24:45 +01:00
|
|
|
}
|
|
|
|
|
2019-01-22 12:40:17 +01:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(const AllocationData &allocationData) {
|
|
|
|
allocateForImageCalled = true;
|
|
|
|
auto *allocation = MemoryManager::allocateGraphicsMemoryForImage(allocationData);
|
2017-12-21 00:45:38 +01:00
|
|
|
if (redundancyRatio != 1) {
|
2019-01-22 12:40:17 +01:00
|
|
|
memset((unsigned char *)allocation->getUnderlyingBuffer(), 0, allocationData.imgInfo->size * redundancyRatio);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
2019-02-28 14:12:13 +01:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) {
|
2018-07-24 16:42:35 +02:00
|
|
|
allocation64kbPageCreated = true;
|
2018-12-06 15:03:06 +01:00
|
|
|
preferRenderCompressedFlagPassed = allocationData.flags.preferRenderCompressed;
|
2018-07-24 16:42:35 +02:00
|
|
|
|
2018-12-06 15:03:06 +01:00
|
|
|
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemory64kb(allocationData);
|
2018-07-24 09:06:33 +02:00
|
|
|
if (allocation) {
|
2019-03-12 13:24:58 +01:00
|
|
|
allocation->setDefaultGmm(new Gmm(allocation->getUnderlyingBuffer(), allocationData.size, false, preferRenderCompressedFlagPassed, true, {}));
|
|
|
|
allocation->getDefaultGmm()->isRenderCompressed = preferRenderCompressedFlagPassed;
|
2018-07-24 09:06:33 +02:00
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:42:35 +02: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;
|
2019-04-16 15:42:23 +02:00
|
|
|
if (localMemorySupported) {
|
|
|
|
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::LocalMemory);
|
|
|
|
}
|
2018-07-24 16:42:35 +02:00
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
|
2018-07-25 09:38:00 +02:00
|
|
|
if (failInAllocateWithSizeAndAlignment) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-24 16:42:35 +02:00
|
|
|
allocationCreated = true;
|
2018-11-30 11:01:33 +01:00
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
2018-07-24 16:42:35 +02:00
|
|
|
}
|
2019-02-21 16:29:05 +01:00
|
|
|
|
|
|
|
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) {
|
2018-12-21 10:16:27 +01:00
|
|
|
bool allocateMemory = ptr == nullptr;
|
|
|
|
AllocationData allocationData;
|
2019-05-10 11:30:07 +02:00
|
|
|
MockAllocationProperties properties(allocateMemory, size, allocationType);
|
|
|
|
getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties));
|
2018-12-21 10:16:27 +01:00
|
|
|
return allocate32BitGraphicsMemoryImpl(allocationData);
|
|
|
|
}
|
2018-07-24 16:42:35 +02:00
|
|
|
|
2019-07-26 15:28:06 +02:00
|
|
|
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) {
|
|
|
|
if (failAllocate32Bit) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(allocationData);
|
|
|
|
}
|
|
|
|
|
2019-03-28 15:42:23 +01:00
|
|
|
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {
|
2018-12-06 15:03:06 +01:00
|
|
|
this->failedAllocationsCount = failedAllocationsCount;
|
2018-10-19 13:41:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-06 16:35:21 +01:00
|
|
|
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment, bool enableLocalMemory)
|
|
|
|
: MockMemoryManager(enableLocalMemory, executionEnvironment) {
|
|
|
|
this->failedAllocationsCount = failedAllocationsCount;
|
|
|
|
}
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|