2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-01-02 16:19:30 +00:00
|
|
|
* Copyright (C) 2018-2023 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"
|
2022-12-07 11:51:44 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2023-01-02 16:19:30 +00:00
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
2020-11-02 15:54:01 +01:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.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
|
|
|
|
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;
|
2022-08-02 16:08:54 +00:00
|
|
|
using MemoryManager::prefetchManager;
|
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) {}
|
|
|
|
|
|
2023-01-13 15:18:40 +00:00
|
|
|
MockMemoryManager(bool enableLocalMemory, ExecutionEnvironment &executionEnvironment);
|
|
|
|
|
MockMemoryManager();
|
|
|
|
|
MockMemoryManager(bool enable64pages, bool enableLocalMemory);
|
2022-11-15 14:34:44 +00:00
|
|
|
|
|
|
|
|
ADDMETHOD_NOBASE(registerSysMemAlloc, AllocationStatus, AllocationStatus::Success, (GraphicsAllocation * allocation));
|
|
|
|
|
ADDMETHOD_NOBASE(registerLocalMemAlloc, AllocationStatus, AllocationStatus::Success, (GraphicsAllocation * allocation, uint32_t rootDeviceIndex));
|
|
|
|
|
|
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;
|
2022-12-06 22:36:12 +00:00
|
|
|
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override;
|
|
|
|
|
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) 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;
|
2022-11-30 15:42:33 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override;
|
2022-06-15 11:07:49 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) 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++;
|
2023-01-09 12:18:49 +00:00
|
|
|
void *pLockedMemory = nullptr;
|
|
|
|
|
if (!failLockResource) {
|
|
|
|
|
pLockedMemory = OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation);
|
|
|
|
|
}
|
2021-02-01 14:27:48 +00:00
|
|
|
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
|
|
|
|
2023-01-03 18:39:11 +00:00
|
|
|
bool allocInUse(GraphicsAllocation &graphicsAllocation) override {
|
|
|
|
|
allocInUseCalled++;
|
|
|
|
|
if (deferAllocInUse) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 15:18:40 +00:00
|
|
|
void waitForEnginesCompletion(GraphicsAllocation &graphicsAllocation) override;
|
2021-01-18 15:09:44 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-04-07 13:09:40 +00:00
|
|
|
void *createMultiGraphicsAllocationInSystemMemoryPool(RootDeviceIndicesContainer &rootDeviceIndices,
|
2021-02-25 09:38:48 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2023-01-13 15:18:40 +00:00
|
|
|
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range);
|
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-11-30 00:48:56 +00:00
|
|
|
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override {
|
|
|
|
|
memPrefetchSubDeviceIds = subDeviceIds;
|
2022-03-02 13:38:28 +00:00
|
|
|
setMemPrefetchCalled = true;
|
2022-11-30 00:48:56 +00:00
|
|
|
return MemoryManager::setMemPrefetch(gfxAllocation, subDeviceIds, rootDeviceIndex);
|
2022-03-02 13:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-13 15:18:40 +00:00
|
|
|
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
|
2022-03-02 13:38:28 +00:00
|
|
|
|
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
|
|
|
|
2022-12-06 22:36:12 +00:00
|
|
|
bool mapPhysicalToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override {
|
|
|
|
|
if (failMapPhysicalToVirtualMemory) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return OsAgnosticMemoryManager::mapPhysicalToVirtualMemory(physicalAllocation, gpuRange, bufferSize);
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
2023-01-03 18:39:11 +00:00
|
|
|
uint32_t allocInUseCalled = 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;
|
2022-05-31 09:36:11 +00:00
|
|
|
osHandle capturedSharedHandle = 0u;
|
|
|
|
|
osHandle invalidSharedHandle = -1;
|
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;
|
2023-01-09 12:18:49 +00:00
|
|
|
bool failLockResource = 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;
|
2023-01-03 18:39:11 +00:00
|
|
|
bool singleFailureInPrimaryAllocation = false;
|
2021-02-25 09:38:48 +01:00
|
|
|
bool forceFailureInAllocationWithHostPointer = false;
|
|
|
|
|
bool isMockHostMemoryManager = false;
|
2023-01-03 18:39:11 +00:00
|
|
|
bool deferAllocInUse = false;
|
2021-02-25 09:38:48 +01:00
|
|
|
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;
|
2022-12-06 22:36:12 +00:00
|
|
|
bool failMapPhysicalToVirtualMemory = false;
|
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;
|
2022-11-30 00:48:56 +00:00
|
|
|
SubDeviceIdsVec memPrefetchSubDeviceIds;
|
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;
|
2022-11-21 11:03:05 +00:00
|
|
|
std::unique_ptr<AllocationProperties> lastAllocationProperties = 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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 15:18:40 +00:00
|
|
|
void *allocateSystemMemory(size_t size, size_t alignment) override;
|
2018-01-26 16:53:18 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-12-08 00:09:22 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override {
|
2022-01-31 23:29:01 +00:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 15:42:33 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) 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);
|
|
|
|
|
}
|
2023-01-13 15:18:40 +00:00
|
|
|
|
|
|
|
|
GraphicsAllocation *allocateNonSystemGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status);
|
2018-12-20 16:58:15 +01:00
|
|
|
};
|
|
|
|
|
|
2022-02-28 13:31:18 +00:00
|
|
|
class MockMemoryManagerOsAgnosticContext : public MockMemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
MockMemoryManagerOsAgnosticContext(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
|
|
|
|
|
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
|
2023-01-13 15:18:40 +00:00
|
|
|
const EngineDescriptor &engineDescriptor) override;
|
2022-09-19 13:34:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockMemoryManagerWithDebuggableOsContext : public MockMemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
MockMemoryManagerWithDebuggableOsContext(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
|
|
|
|
|
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
|
2023-01-13 15:18:40 +00:00
|
|
|
const EngineDescriptor &engineDescriptor) override;
|
2022-02-28 13:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
2022-04-14 15:23:52 +00:00
|
|
|
class MockMemoryManagerWithCapacity : public MockMemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
MockMemoryManagerWithCapacity(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
|
2022-10-11 13:16:40 +00:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override {
|
2022-04-14 15:23:52 +00:00
|
|
|
if (this->capacity >= properties.size) {
|
|
|
|
|
this->capacity -= properties.size;
|
2022-10-11 13:16:40 +00:00
|
|
|
return MockMemoryManager::allocateGraphicsMemoryWithProperties(properties, ptr);
|
2022-04-14 15:23:52 +00:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 13:16:40 +00:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
|
|
|
|
|
return this->allocateGraphicsMemoryWithProperties(properties, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 15:23:52 +00:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override {
|
|
|
|
|
this->capacity += gfxAllocation->getUnderlyingBufferSize();
|
|
|
|
|
MockMemoryManager::freeGraphicsMemoryImpl(gfxAllocation);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t capacity = 0u;
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-14 11:08:17 +00:00
|
|
|
class MemoryManagerMemHandleMock : public MockMemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) override {
|
|
|
|
|
return NTHandle;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool NTHandle = false;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|