2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2022-01-13 13:03:40 +00:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2020-11-02 15:54:01 +01:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-09-24 10:18:32 +00:00
|
|
|
#include "shared/test/common/mocks/mock_host_ptr_manager.h"
|
2022-01-13 13:03:40 +00:00
|
|
|
#include "shared/test/common/test_macros/mock_method_macros.h"
|
2018-10-24 08:46:54 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "gmock/gmock.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-15 10:22:35 +01:00
|
|
|
template <class T>
|
|
|
|
|
class MemoryManagerCreate : public T {
|
|
|
|
|
public:
|
|
|
|
|
using T::T;
|
|
|
|
|
|
|
|
|
|
template <class... U>
|
2021-01-21 13:10:13 +01:00
|
|
|
MemoryManagerCreate(bool enable64kbPages, bool enableLocalMemory, U &&...args) : T(std::forward<U>(args)...) {
|
2020-02-12 08:29:26 +01:00
|
|
|
std::fill(this->enable64kbpages.begin(), this->enable64kbpages.end(), enable64kbPages);
|
|
|
|
|
std::fill(this->localMemorySupported.begin(), this->localMemorySupported.end(), enableLocalMemory);
|
2019-03-15 10:22:35 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
2017-12-21 00:45:38 +01:00
|
|
|
public:
|
2018-07-24 18:36:26 +02:00
|
|
|
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
|
2019-08-23 13:09:09 +02:00
|
|
|
using MemoryManager::allocateGraphicsMemoryWithAlignment;
|
2019-03-12 12:00:41 +01:00
|
|
|
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
2019-02-25 14:11:34 +01:00
|
|
|
using MemoryManager::createGraphicsAllocation;
|
2019-05-06 10:35:49 +02:00
|
|
|
using MemoryManager::createStorageInfoFromProperties;
|
2021-04-19 15:06:08 +00:00
|
|
|
using MemoryManager::defaultEngineIndex;
|
2021-07-22 06:36:45 +00:00
|
|
|
using MemoryManager::externalLocalMemoryUsageBankSelector;
|
2018-07-24 16:42:35 +02:00
|
|
|
using MemoryManager::getAllocationData;
|
2019-10-22 10:26:23 +02:00
|
|
|
using MemoryManager::gfxPartitions;
|
2021-07-22 06:36:45 +00:00
|
|
|
using MemoryManager::internalLocalMemoryUsageBankSelector;
|
2021-06-02 13:57:28 +00:00
|
|
|
using MemoryManager::isNonSvmBuffer;
|
2019-01-03 14:48:24 +01:00
|
|
|
using MemoryManager::multiContextResourceDestructor;
|
2020-01-15 17:02:47 +01:00
|
|
|
using MemoryManager::overrideAllocationData;
|
2019-07-04 12:17:42 +02:00
|
|
|
using MemoryManager::pageFaultManager;
|
2019-02-18 13:59:16 +01:00
|
|
|
using MemoryManager::registeredEngines;
|
2019-06-06 08:45:14 +02:00
|
|
|
using MemoryManager::supportsMultiStorageResources;
|
2019-12-18 17:16:49 +01:00
|
|
|
using MemoryManager::useNonSvmHostPtrAlloc;
|
2018-12-20 16:58:15 +01:00
|
|
|
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
|
2019-03-15 10:22:35 +01:00
|
|
|
using MemoryManagerCreate<OsAgnosticMemoryManager>::MemoryManagerCreate;
|
2021-02-25 09:38:48 +01:00
|
|
|
using MemoryManager::enable64kbpages;
|
2021-06-21 10:45:19 +00:00
|
|
|
using MemoryManager::isaInLocalMemory;
|
2021-03-09 23:02:59 +00:00
|
|
|
using MemoryManager::isAllocationTypeToCapture;
|
2020-01-13 09:40:03 +01:00
|
|
|
using MemoryManager::isCopyRequired;
|
2021-02-25 09:38:48 +01:00
|
|
|
using MemoryManager::localMemorySupported;
|
2019-08-27 15:26:30 +02:00
|
|
|
using MemoryManager::reservedMemory;
|
2018-12-20 16:58:15 +01:00
|
|
|
|
|
|
|
|
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, executionEnvironment) {}
|
|
|
|
|
|
2019-03-15 10:22:35 +01:00
|
|
|
MockMemoryManager(bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, enableLocalMemory, executionEnvironment) {
|
2018-10-24 08:46:54 +02:00
|
|
|
hostPtrManager.reset(new MockHostPtrManager);
|
|
|
|
|
};
|
2018-12-20 16:58:15 +01:00
|
|
|
|
2020-03-24 17:04:08 +01:00
|
|
|
MockMemoryManager() : MockMemoryManager(*(new MockExecutionEnvironment(defaultHwInfo.get()))) {
|
2020-02-25 16:38:47 +01:00
|
|
|
mockExecutionEnvironment.reset(static_cast<MockExecutionEnvironment *>(&executionEnvironment));
|
2021-09-20 14:29:22 +00:00
|
|
|
mockExecutionEnvironment->initGmm();
|
2018-10-01 16:10:54 +02:00
|
|
|
};
|
2020-03-24 17:04:08 +01:00
|
|
|
MockMemoryManager(bool enable64pages, bool enableLocalMemory) : MemoryManagerCreate(enable64pages, enableLocalMemory, *(new MockExecutionEnvironment(defaultHwInfo.get()))) {
|
2020-02-25 16:38:47 +01:00
|
|
|
mockExecutionEnvironment.reset(static_cast<MockExecutionEnvironment *>(&executionEnvironment));
|
2018-10-01 16:10:54 +02:00
|
|
|
}
|
2019-02-28 14:12:13 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
void setDeferredDeleter(DeferredDeleter *deleter);
|
|
|
|
|
void overrideAsyncDeleterFlag(bool newValue);
|
2019-01-22 12:40:17 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override;
|
2021-08-11 10:36:04 +00:00
|
|
|
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
int redundancyRatio = 1;
|
2018-07-24 16:42:35 +02:00
|
|
|
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2018-12-14 11:24:45 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override;
|
2021-02-25 09:38:48 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
|
2021-04-22 17:01:19 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
2018-12-14 11:24:45 +01:00
|
|
|
|
|
|
|
|
void *allocateSystemMemory(size_t size, size_t alignment) override;
|
2018-07-24 16:42:35 +02:00
|
|
|
|
2018-11-28 10:09:56 +00:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override {
|
|
|
|
|
freeGraphicsMemoryCalled++;
|
|
|
|
|
OsAgnosticMemoryManager::freeGraphicsMemoryImpl(gfxAllocation);
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-24 15:16:12 +01:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override {
|
|
|
|
|
lockResourceCalled++;
|
2021-02-01 14:27:48 +00:00
|
|
|
auto pLockedMemory = OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation);
|
|
|
|
|
lockResourcePointers.push_back(pLockedMemory);
|
|
|
|
|
return pLockedMemory;
|
2019-01-24 15:16:12 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-24 11:51:33 +01:00
|
|
|
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override {
|
2018-12-12 14:36:45 +01:00
|
|
|
unlockResourceCalled++;
|
2019-01-24 11:51:33 +01:00
|
|
|
OsAgnosticMemoryManager::unlockResourceImpl(gfxAllocation);
|
2018-12-12 14:36:45 +01:00
|
|
|
}
|
2019-03-04 14:50:26 +01:00
|
|
|
|
2021-01-18 15:09:44 +00:00
|
|
|
void waitForEnginesCompletion(GraphicsAllocation &graphicsAllocation) override {
|
|
|
|
|
waitForEnginesCompletionCalled++;
|
|
|
|
|
if (waitAllocations.get()) {
|
|
|
|
|
waitAllocations.get()->addAllocation(&graphicsAllocation);
|
|
|
|
|
}
|
|
|
|
|
MemoryManager::waitForEnginesCompletion(graphicsAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 14:50:26 +01:00
|
|
|
void handleFenceCompletion(GraphicsAllocation *graphicsAllocation) override {
|
|
|
|
|
handleFenceCompletionCalled++;
|
|
|
|
|
OsAgnosticMemoryManager::handleFenceCompletion(graphicsAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override {
|
2019-03-06 16:35:21 +01:00
|
|
|
if (failReserveAddress) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-01-07 07:42:40 +01:00
|
|
|
return OsAgnosticMemoryManager::reserveCpuAddressRange(size, rootDeviceIndex);
|
2019-03-06 16:35:21 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 09:38:48 +01:00
|
|
|
void *createMultiGraphicsAllocationInSystemMemoryPool(std::vector<uint32_t> &rootDeviceIndices,
|
|
|
|
|
AllocationProperties &properties,
|
|
|
|
|
MultiGraphicsAllocation &multiGraphicsAllocation) override {
|
|
|
|
|
if (isMockEventPoolCreateMemoryManager) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return OsAgnosticMemoryManager::createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphicsAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 09:59:18 +01:00
|
|
|
bool isCpuCopyRequired(const void *ptr) override { return cpuCopyRequired; }
|
|
|
|
|
|
2022-02-04 13:59:01 +00:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, AllocationType allocationType);
|
2020-07-01 14:03:46 +02:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override;
|
2018-12-12 14:36:45 +01:00
|
|
|
|
2021-05-06 14:15:19 +00:00
|
|
|
bool isLimitedGPU(uint32_t rootDeviceIndex) override {
|
|
|
|
|
return limitedGPU;
|
|
|
|
|
}
|
2020-01-29 17:48:36 +01:00
|
|
|
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size()); }
|
2019-08-23 13:09:09 +02:00
|
|
|
|
2021-10-11 09:27:26 +00:00
|
|
|
bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override {
|
2021-10-06 23:22:22 +00:00
|
|
|
memAdviseFlags = flags;
|
2021-10-11 09:27:26 +00:00
|
|
|
if (failSetMemAdvise) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return MemoryManager::setMemAdvise(gfxAllocation, flags, rootDeviceIndex);
|
2021-10-06 23:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-02 13:38:28 +00:00
|
|
|
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) override {
|
|
|
|
|
setMemPrefetchCalled = true;
|
|
|
|
|
return MemoryManager::setMemPrefetch(gfxAllocation, rootDeviceIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override {
|
|
|
|
|
if (DebugManager.flags.UseKmdMigration.get() != -1) {
|
|
|
|
|
return !!DebugManager.flags.UseKmdMigration.get();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:16:19 +00:00
|
|
|
struct CopyMemoryToAllocationBanksParams {
|
|
|
|
|
GraphicsAllocation *graphicsAllocation = nullptr;
|
|
|
|
|
size_t destinationOffset = 0u;
|
|
|
|
|
const void *memoryToCopy = nullptr;
|
|
|
|
|
size_t sizeToCopy = 0u;
|
|
|
|
|
DeviceBitfield handleMask = {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StackVec<CopyMemoryToAllocationBanksParams, 2> copyMemoryToAllocationBanksParamsPassed{};
|
|
|
|
|
bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) override;
|
|
|
|
|
|
2022-01-13 13:03:40 +00:00
|
|
|
MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override {
|
|
|
|
|
populateOsHandlesCalled++;
|
|
|
|
|
populateOsHandlesParamsPassed.push_back({handleStorage, rootDeviceIndex});
|
|
|
|
|
if (callBasePopulateOsHandles) {
|
|
|
|
|
populateOsHandlesResult = OsAgnosticMemoryManager::populateOsHandles(handleStorage, rootDeviceIndex);
|
|
|
|
|
}
|
|
|
|
|
return populateOsHandlesResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PopulateOsHandlesParams {
|
|
|
|
|
OsHandleStorage handleStorage{};
|
|
|
|
|
uint32_t rootDeviceIndex{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StackVec<PopulateOsHandlesParams, 1> populateOsHandlesParamsPassed{};
|
|
|
|
|
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override {
|
|
|
|
|
allocateGraphicsMemoryForNonSvmHostPtrCalled++;
|
|
|
|
|
if (callBaseAllocateGraphicsMemoryForNonSvmHostPtr) {
|
|
|
|
|
allocateGraphicsMemoryForNonSvmHostPtrResult = OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
|
|
|
|
}
|
|
|
|
|
return allocateGraphicsMemoryForNonSvmHostPtrResult;
|
|
|
|
|
}
|
2022-01-26 15:25:06 +00:00
|
|
|
bool allowIndirectAllocationsAsPack(uint32_t rootDeviceIndex) override {
|
|
|
|
|
if (overrideAllocateAsPackReturn != -1) {
|
|
|
|
|
return !!overrideAllocateAsPackReturn;
|
|
|
|
|
} else {
|
|
|
|
|
return MemoryManager::allowIndirectAllocationsAsPack(rootDeviceIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-13 13:03:40 +00:00
|
|
|
|
2021-10-21 11:16:19 +00:00
|
|
|
uint32_t copyMemoryToAllocationBanksCalled = 0u;
|
2022-01-13 13:03:40 +00:00
|
|
|
uint32_t populateOsHandlesCalled = 0u;
|
|
|
|
|
uint32_t allocateGraphicsMemoryForNonSvmHostPtrCalled = 0u;
|
2018-11-28 10:09:56 +00:00
|
|
|
uint32_t freeGraphicsMemoryCalled = 0u;
|
2018-12-12 14:36:45 +01:00
|
|
|
uint32_t unlockResourceCalled = 0u;
|
2019-01-24 15:16:12 +01:00
|
|
|
uint32_t lockResourceCalled = 0u;
|
2021-04-22 17:01:19 +00:00
|
|
|
uint32_t createGraphicsAllocationFromExistingStorageCalled = 0u;
|
2022-01-26 15:25:06 +00:00
|
|
|
int32_t overrideAllocateAsPackReturn = -1;
|
2021-04-22 17:01:19 +00:00
|
|
|
std::vector<GraphicsAllocation *> allocationsFromExistingStorage{};
|
2021-02-19 11:45:53 +00:00
|
|
|
AllocationData alignAllocationData;
|
2021-02-25 09:38:48 +01:00
|
|
|
uint32_t successAllocatedGraphicsMemoryIndex = 0u;
|
|
|
|
|
uint32_t maxSuccessAllocatedGraphicsMemoryIndex = std::numeric_limits<uint32_t>::max();
|
2021-02-01 14:27:48 +00:00
|
|
|
std::vector<void *> lockResourcePointers;
|
2019-03-04 14:50:26 +01:00
|
|
|
uint32_t handleFenceCompletionCalled = 0u;
|
2021-01-18 15:09:44 +00:00
|
|
|
uint32_t waitForEnginesCompletionCalled = 0u;
|
2021-02-25 09:38:48 +01:00
|
|
|
uint32_t allocateGraphicsMemoryWithPropertiesCount = 0;
|
2018-07-24 16:42:35 +02:00
|
|
|
bool allocationCreated = false;
|
|
|
|
|
bool allocation64kbPageCreated = false;
|
|
|
|
|
bool allocationInDevicePoolCreated = false;
|
|
|
|
|
bool failInDevicePool = false;
|
|
|
|
|
bool failInDevicePoolWithError = false;
|
2018-07-25 09:38:00 +02:00
|
|
|
bool failInAllocateWithSizeAndAlignment = false;
|
2021-12-03 13:52:16 +00:00
|
|
|
bool preferCompressedFlagPassed = false;
|
2019-01-22 12:40:17 +01:00
|
|
|
bool allocateForImageCalled = false;
|
2021-05-06 14:15:19 +00:00
|
|
|
bool allocate32BitGraphicsMemoryImplCalled = false;
|
2019-11-14 04:08:59 -05:00
|
|
|
bool allocateForShareableCalled = false;
|
2019-03-06 16:35:21 +01:00
|
|
|
bool failReserveAddress = false;
|
|
|
|
|
bool failAllocateSystemMemory = false;
|
2019-07-26 15:28:06 +02:00
|
|
|
bool failAllocate32Bit = false;
|
2021-10-11 09:27:26 +00:00
|
|
|
bool failSetMemAdvise = false;
|
2022-03-02 13:38:28 +00:00
|
|
|
bool setMemPrefetchCalled = false;
|
2020-02-28 09:59:18 +01:00
|
|
|
bool cpuCopyRequired = false;
|
2021-12-03 13:52:16 +00:00
|
|
|
bool forceCompressed = false;
|
2021-02-25 09:38:48 +01:00
|
|
|
bool forceFailureInPrimaryAllocation = false;
|
|
|
|
|
bool forceFailureInAllocationWithHostPointer = false;
|
|
|
|
|
bool isMockHostMemoryManager = false;
|
|
|
|
|
bool isMockEventPoolCreateMemoryManager = false;
|
2021-05-06 14:15:19 +00:00
|
|
|
bool limitedGPU = false;
|
2021-06-16 14:41:26 +00:00
|
|
|
bool returnFakeAllocation = false;
|
2022-01-13 13:03:40 +00:00
|
|
|
bool callBasePopulateOsHandles = true;
|
|
|
|
|
bool callBaseAllocateGraphicsMemoryForNonSvmHostPtr = true;
|
2020-02-25 16:38:47 +01:00
|
|
|
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
|
2020-04-16 17:24:38 +02:00
|
|
|
DeviceBitfield recentlyPassedDeviceBitfield{};
|
2021-01-18 15:09:44 +00:00
|
|
|
std::unique_ptr<MultiGraphicsAllocation> waitAllocations = nullptr;
|
2021-10-06 23:22:22 +00:00
|
|
|
MemAdviseFlags memAdviseFlags{};
|
2022-01-13 13:03:40 +00:00
|
|
|
MemoryManager::AllocationStatus populateOsHandlesResult = MemoryManager::AllocationStatus::Success;
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtrResult = nullptr;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2018-01-26 16:53:18 +01:00
|
|
|
|
|
|
|
|
class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager {
|
|
|
|
|
public:
|
2019-03-15 10:22:35 +01:00
|
|
|
MockAllocSysMemAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment) {
|
2018-01-26 16:53:18 +01:00
|
|
|
ptrRestrictions = nullptr;
|
|
|
|
|
testRestrictions.minAddress = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AlignedMallocRestrictions *getAlignedMallocRestrictions() override {
|
|
|
|
|
return ptrRestrictions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *allocateSystemMemory(size_t size, size_t alignment) override {
|
|
|
|
|
constexpr size_t minAlignment = 16;
|
|
|
|
|
alignment = std::max(alignment, minAlignment);
|
|
|
|
|
return alignedMalloc(size, alignment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AlignedMallocRestrictions testRestrictions;
|
|
|
|
|
AlignedMallocRestrictions *ptrRestrictions;
|
|
|
|
|
};
|
2018-10-19 13:41:42 +02:00
|
|
|
|
|
|
|
|
class FailMemoryManager : public MockMemoryManager {
|
|
|
|
|
public:
|
2019-03-12 12:00:41 +01:00
|
|
|
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
2018-10-19 13:41:42 +02:00
|
|
|
using MockMemoryManager::MockMemoryManager;
|
2019-03-28 15:42:23 +01:00
|
|
|
FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment);
|
2019-03-06 16:35:21 +01:00
|
|
|
FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment, bool localMemory);
|
2018-12-06 15:03:06 +01:00
|
|
|
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override {
|
2018-12-06 15:03:06 +01:00
|
|
|
if (failedAllocationsCount <= 0) {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2018-12-06 15:03:06 +01:00
|
|
|
failedAllocationsCount--;
|
|
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-02-28 14:12:13 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
2020-07-01 14:03:46 +02:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
2021-06-02 13:57:28 +00:00
|
|
|
|
2021-05-24 06:14:30 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
2022-02-04 13:59:01 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
2019-03-12 12:00:41 +01:00
|
|
|
}
|
2018-12-14 11:24:45 +01:00
|
|
|
|
2019-01-24 11:51:33 +01:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override { return nullptr; };
|
|
|
|
|
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override{};
|
2018-10-19 13:41:42 +02:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return AllocationStatus::Error;
|
|
|
|
|
};
|
2019-11-15 09:59:48 +01:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
|
2018-10-19 13:41:42 +02:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-25 14:11:34 +01:00
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
|
|
|
|
};
|
2019-01-22 12:40:17 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override {
|
2018-10-19 13:41:42 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2021-08-11 10:36:04 +00:00
|
|
|
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override {
|
2019-11-14 04:08:59 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2018-12-06 15:03:06 +01:00
|
|
|
int32_t failedAllocationsCount = 0;
|
2018-10-19 13:41:42 +02:00
|
|
|
};
|
2018-12-20 16:58:15 +01:00
|
|
|
|
2022-01-13 13:03:40 +00:00
|
|
|
class MockMemoryManagerFailFirstAllocation : public MockMemoryManager {
|
2018-12-20 16:58:15 +01:00
|
|
|
public:
|
2022-01-13 13:03:40 +00:00
|
|
|
MockMemoryManagerFailFirstAllocation(bool enableLocalMemory, const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(enableLocalMemory, const_cast<ExecutionEnvironment &>(executionEnvironment)){};
|
|
|
|
|
MockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : MockMemoryManagerFailFirstAllocation(false, executionEnvironment){};
|
|
|
|
|
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override {
|
|
|
|
|
allocateGraphicsMemoryInDevicePoolCalled++;
|
|
|
|
|
if (returnNullptr) {
|
|
|
|
|
returnNullptr = false;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (returnAllocateNonSystemGraphicsMemoryInDevicePool) {
|
|
|
|
|
returnAllocateNonSystemGraphicsMemoryInDevicePool = false;
|
|
|
|
|
return allocateNonSystemGraphicsMemoryInDevicePool(allocationData, status);
|
|
|
|
|
}
|
|
|
|
|
if (returnBaseAllocateGraphicsMemoryInDevicePool) {
|
|
|
|
|
return baseAllocateGraphicsMemoryInDevicePool(allocationData, status);
|
|
|
|
|
}
|
|
|
|
|
return allocateGraphicsMemoryInDevicePoolResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t allocateGraphicsMemoryInDevicePoolCalled = 0u;
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePoolResult = nullptr;
|
|
|
|
|
bool returnNullptr = false;
|
|
|
|
|
bool returnBaseAllocateGraphicsMemoryInDevicePool = false;
|
|
|
|
|
bool returnAllocateNonSystemGraphicsMemoryInDevicePool = false;
|
2018-12-20 16:58:15 +01:00
|
|
|
|
|
|
|
|
GraphicsAllocation *baseAllocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
|
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
|
|
|
|
|
}
|
|
|
|
|
GraphicsAllocation *allocateNonSystemGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
|
|
|
|
auto allocation = baseAllocateGraphicsMemoryInDevicePool(allocationData, status);
|
|
|
|
|
if (!allocation) {
|
|
|
|
|
allocation = allocateGraphicsMemory(allocationData);
|
|
|
|
|
}
|
|
|
|
|
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
|
|
|
|
|
return allocation;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-28 13:31:18 +00:00
|
|
|
class MockMemoryManagerOsAgnosticContext : public MockMemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
MockMemoryManagerOsAgnosticContext(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
|
|
|
|
|
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
|
|
|
|
|
const EngineDescriptor &engineDescriptor) override {
|
|
|
|
|
auto osContext = new OsContext(0, engineDescriptor);
|
|
|
|
|
osContext->incRefInternal();
|
|
|
|
|
registeredEngines.emplace_back(commandStreamReceiver, osContext);
|
|
|
|
|
return osContext;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|