mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 08:07:19 +08:00
move mock_memory_manager to shared
Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
9d69c70424
commit
9bea74a780
@@ -8,8 +8,6 @@
|
||||
#pragma once
|
||||
#include "aub_mem_dump.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class AubStreamProvider {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "shared/test/common/fixtures/device_fixture.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -69,6 +69,7 @@ set(igdrcl_libult_common_SRCS_LIB_ULT
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/libult/source_level_debugger_library.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/libult/source_level_debugger_library.h
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/libult/source_level_debugger_ult.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_memory_manager.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/test_macros/test_excludes.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/test_macros/test_excludes.h
|
||||
${NEO_SHARED_TEST_DIRECTORY}/unit_test/base_ult_config_listener.cpp
|
||||
|
||||
@@ -49,6 +49,7 @@ set(NEO_CORE_tests_mocks
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_host_ptr_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_hw_info_config.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_io_functions.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_operations_handler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_migration_sync_data.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_multi_graphics_allocation.h
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "shared/source/os_interface/linux/allocator_helper.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_host_ptr_manager.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
#include "shared/source/command_stream/preemption.h"
|
||||
#include "shared/source/os_interface/os_context.h"
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/ult_device_factory.h"
|
||||
#include "shared/test/unit_test/tests_configuration.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_ostime.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
170
shared/test/common/mocks/mock_memory_manager.cpp
Normal file
170
shared/test/common/mocks/mock_memory_manager.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/gmm_helper/gmm.h"
|
||||
#include "shared/source/memory_manager/deferred_deleter.h"
|
||||
|
||||
#include "opencl/source/helpers/surface_formats.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
void MockMemoryManager::setDeferredDeleter(DeferredDeleter *deleter) {
|
||||
deferredDeleter.reset(deleter);
|
||||
}
|
||||
|
||||
void MockMemoryManager::overrideAsyncDeleterFlag(bool newValue) {
|
||||
asyncDeleterEnabled = newValue;
|
||||
if (asyncDeleterEnabled && deferredDeleter == nullptr) {
|
||||
deferredDeleter = createDeferredDeleter();
|
||||
}
|
||||
}
|
||||
|
||||
void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
|
||||
if (failAllocateSystemMemory) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fakeBigAllocations && size > bigAllocation) {
|
||||
size = MemoryConstants::pageSize64k;
|
||||
}
|
||||
|
||||
return OsAgnosticMemoryManager::allocateSystemMemory(redundancyRatio * size, alignment);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
|
||||
if (isMockHostMemoryManager) {
|
||||
allocateGraphicsMemoryWithPropertiesCount++;
|
||||
if (forceFailureInPrimaryAllocation) {
|
||||
return nullptr;
|
||||
}
|
||||
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
|
||||
}
|
||||
|
||||
recentlyPassedDeviceBitfield = properties.subDevicesBitfield;
|
||||
AllocationProperties adjustedProperties(properties);
|
||||
adjustedProperties.size = redundancyRatio * properties.size;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties(adjustedProperties);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) {
|
||||
if (returnFakeAllocation) {
|
||||
return new GraphicsAllocation(properties.rootDeviceIndex, properties.allocationType, reinterpret_cast<void *>(dummyAddress), reinterpret_cast<uint64_t>(ptr), properties.size, 0, MemoryPool::System4KBPages, maxOsContextCount);
|
||||
}
|
||||
if (isMockHostMemoryManager) {
|
||||
allocateGraphicsMemoryWithPropertiesCount++;
|
||||
if (forceFailureInAllocationWithHostPointer) {
|
||||
return nullptr;
|
||||
}
|
||||
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties, ptr);
|
||||
}
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties(properties, ptr);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(const AllocationData &allocationData) {
|
||||
allocateForImageCalled = true;
|
||||
auto *allocation = MemoryManager::allocateGraphicsMemoryForImage(allocationData);
|
||||
if (redundancyRatio != 1) {
|
||||
memset((unsigned char *)allocation->getUnderlyingBuffer(), 0, allocationData.imgInfo->size * redundancyRatio);
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
|
||||
allocateForShareableCalled = true;
|
||||
return OsAgnosticMemoryManager::allocateMemoryByKMD(allocationData);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) {
|
||||
allocation64kbPageCreated = true;
|
||||
preferRenderCompressedFlagPassed = forceRenderCompressed ? true : allocationData.flags.preferRenderCompressed;
|
||||
|
||||
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemory64kb(allocationData);
|
||||
if (allocation) {
|
||||
allocation->getDefaultGmm()->isCompressionEnabled = preferRenderCompressedFlagPassed;
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
||||
if (failInDevicePool) {
|
||||
status = AllocationStatus::RetryInNonDevicePool;
|
||||
return nullptr;
|
||||
}
|
||||
if (failInDevicePoolWithError) {
|
||||
status = AllocationStatus::Error;
|
||||
return nullptr;
|
||||
}
|
||||
if (successAllocatedGraphicsMemoryIndex >= maxSuccessAllocatedGraphicsMemoryIndex) {
|
||||
return nullptr;
|
||||
|
||||
} else {
|
||||
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
|
||||
if (allocation) {
|
||||
allocationInDevicePoolCreated = true;
|
||||
if (localMemorySupported[allocation->getRootDeviceIndex()]) {
|
||||
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::LocalMemory);
|
||||
}
|
||||
}
|
||||
successAllocatedGraphicsMemoryIndex++;
|
||||
return allocation;
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
|
||||
if (failInAllocateWithSizeAndAlignment) {
|
||||
return nullptr;
|
||||
}
|
||||
allocationCreated = true;
|
||||
alignAllocationData = allocationData;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) {
|
||||
bool allocateMemory = ptr == nullptr;
|
||||
AllocationData allocationData{};
|
||||
MockAllocationProperties properties(rootDeviceIndex, allocateMemory, size, allocationType);
|
||||
getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties));
|
||||
bool useLocalMemory = !allocationData.flags.useSystemMemory && this->localMemorySupported[rootDeviceIndex];
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData, useLocalMemory);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) {
|
||||
allocateGraphicsMemoryForNonSvmHostPtrCalled = true;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
|
||||
allocate32BitGraphicsMemoryImplCalled = true;
|
||||
if (failAllocate32Bit) {
|
||||
return nullptr;
|
||||
}
|
||||
return OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(allocationData, useLocalMemory);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) {
|
||||
auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromExistingStorage(properties, ptr, multiGraphicsAllocation);
|
||||
createGraphicsAllocationFromExistingStorageCalled++;
|
||||
allocationsFromExistingStorage.push_back(allocation);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {
|
||||
this->failedAllocationsCount = failedAllocationsCount;
|
||||
}
|
||||
|
||||
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment, bool enableLocalMemory)
|
||||
: MockMemoryManager(enableLocalMemory, executionEnvironment) {
|
||||
this->failedAllocationsCount = failedAllocationsCount;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
290
shared/test/common/mocks/mock_memory_manager.h
Normal file
290
shared/test/common/mocks/mock_memory_manager.h
Normal file
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "shared/test/common/helpers/default_hw_info.h"
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
#include "shared/test/common/mocks/mock_host_ptr_manager.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <class T>
|
||||
class MemoryManagerCreate : public T {
|
||||
public:
|
||||
using T::T;
|
||||
|
||||
template <class... U>
|
||||
MemoryManagerCreate(bool enable64kbPages, bool enableLocalMemory, U &&...args) : T(std::forward<U>(args)...) {
|
||||
std::fill(this->enable64kbpages.begin(), this->enable64kbpages.end(), enable64kbPages);
|
||||
std::fill(this->localMemorySupported.begin(), this->localMemorySupported.end(), enableLocalMemory);
|
||||
}
|
||||
};
|
||||
|
||||
class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
public:
|
||||
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
|
||||
using MemoryManager::allocateGraphicsMemoryWithAlignment;
|
||||
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
||||
using MemoryManager::createGraphicsAllocation;
|
||||
using MemoryManager::createStorageInfoFromProperties;
|
||||
using MemoryManager::defaultEngineIndex;
|
||||
using MemoryManager::externalLocalMemoryUsageBankSelector;
|
||||
using MemoryManager::getAllocationData;
|
||||
using MemoryManager::gfxPartitions;
|
||||
using MemoryManager::internalLocalMemoryUsageBankSelector;
|
||||
using MemoryManager::isNonSvmBuffer;
|
||||
using MemoryManager::multiContextResourceDestructor;
|
||||
using MemoryManager::overrideAllocationData;
|
||||
using MemoryManager::pageFaultManager;
|
||||
using MemoryManager::registeredEngines;
|
||||
using MemoryManager::supportsMultiStorageResources;
|
||||
using MemoryManager::useNonSvmHostPtrAlloc;
|
||||
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
|
||||
using MemoryManagerCreate<OsAgnosticMemoryManager>::MemoryManagerCreate;
|
||||
using MemoryManager::enable64kbpages;
|
||||
using MemoryManager::isaInLocalMemory;
|
||||
using MemoryManager::isAllocationTypeToCapture;
|
||||
using MemoryManager::isCopyRequired;
|
||||
using MemoryManager::localMemorySupported;
|
||||
using MemoryManager::reservedMemory;
|
||||
|
||||
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, executionEnvironment) {}
|
||||
|
||||
MockMemoryManager(bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, enableLocalMemory, executionEnvironment) {
|
||||
hostPtrManager.reset(new MockHostPtrManager);
|
||||
};
|
||||
|
||||
MockMemoryManager() : MockMemoryManager(*(new MockExecutionEnvironment(defaultHwInfo.get()))) {
|
||||
mockExecutionEnvironment.reset(static_cast<MockExecutionEnvironment *>(&executionEnvironment));
|
||||
mockExecutionEnvironment->initGmm();
|
||||
};
|
||||
MockMemoryManager(bool enable64pages, bool enableLocalMemory) : MemoryManagerCreate(enable64pages, enableLocalMemory, *(new MockExecutionEnvironment(defaultHwInfo.get()))) {
|
||||
mockExecutionEnvironment.reset(static_cast<MockExecutionEnvironment *>(&executionEnvironment));
|
||||
}
|
||||
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
||||
void setDeferredDeleter(DeferredDeleter *deleter);
|
||||
void overrideAsyncDeleterFlag(bool newValue);
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override;
|
||||
int redundancyRatio = 1;
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
||||
|
||||
void *allocateSystemMemory(size_t size, size_t alignment) override;
|
||||
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override {
|
||||
freeGraphicsMemoryCalled++;
|
||||
OsAgnosticMemoryManager::freeGraphicsMemoryImpl(gfxAllocation);
|
||||
};
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override {
|
||||
lockResourceCalled++;
|
||||
auto pLockedMemory = OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation);
|
||||
lockResourcePointers.push_back(pLockedMemory);
|
||||
return pLockedMemory;
|
||||
}
|
||||
|
||||
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override {
|
||||
unlockResourceCalled++;
|
||||
OsAgnosticMemoryManager::unlockResourceImpl(gfxAllocation);
|
||||
}
|
||||
|
||||
void waitForEnginesCompletion(GraphicsAllocation &graphicsAllocation) override {
|
||||
waitForEnginesCompletionCalled++;
|
||||
if (waitAllocations.get()) {
|
||||
waitAllocations.get()->addAllocation(&graphicsAllocation);
|
||||
}
|
||||
MemoryManager::waitForEnginesCompletion(graphicsAllocation);
|
||||
}
|
||||
|
||||
void handleFenceCompletion(GraphicsAllocation *graphicsAllocation) override {
|
||||
handleFenceCompletionCalled++;
|
||||
OsAgnosticMemoryManager::handleFenceCompletion(graphicsAllocation);
|
||||
}
|
||||
|
||||
void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override {
|
||||
if (failReserveAddress) {
|
||||
return nullptr;
|
||||
}
|
||||
return OsAgnosticMemoryManager::reserveCpuAddressRange(size, rootDeviceIndex);
|
||||
}
|
||||
|
||||
void *createMultiGraphicsAllocationInSystemMemoryPool(std::vector<uint32_t> &rootDeviceIndices,
|
||||
AllocationProperties &properties,
|
||||
MultiGraphicsAllocation &multiGraphicsAllocation) override {
|
||||
if (isMockEventPoolCreateMemoryManager) {
|
||||
return nullptr;
|
||||
}
|
||||
return OsAgnosticMemoryManager::createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphicsAllocation);
|
||||
}
|
||||
|
||||
bool isCpuCopyRequired(const void *ptr) override { return cpuCopyRequired; }
|
||||
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType);
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
||||
|
||||
bool isLimitedGPU(uint32_t rootDeviceIndex) override {
|
||||
return limitedGPU;
|
||||
}
|
||||
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size()); }
|
||||
|
||||
uint32_t freeGraphicsMemoryCalled = 0u;
|
||||
uint32_t unlockResourceCalled = 0u;
|
||||
uint32_t lockResourceCalled = 0u;
|
||||
uint32_t createGraphicsAllocationFromExistingStorageCalled = 0u;
|
||||
std::vector<GraphicsAllocation *> allocationsFromExistingStorage{};
|
||||
AllocationData alignAllocationData;
|
||||
uint32_t successAllocatedGraphicsMemoryIndex = 0u;
|
||||
uint32_t maxSuccessAllocatedGraphicsMemoryIndex = std::numeric_limits<uint32_t>::max();
|
||||
std::vector<void *> lockResourcePointers;
|
||||
uint32_t handleFenceCompletionCalled = 0u;
|
||||
uint32_t waitForEnginesCompletionCalled = 0u;
|
||||
uint32_t allocateGraphicsMemoryWithPropertiesCount = 0;
|
||||
bool allocationCreated = false;
|
||||
bool allocation64kbPageCreated = false;
|
||||
bool allocationInDevicePoolCreated = false;
|
||||
bool failInDevicePool = false;
|
||||
bool failInDevicePoolWithError = false;
|
||||
bool failInAllocateWithSizeAndAlignment = false;
|
||||
bool preferRenderCompressedFlagPassed = false;
|
||||
bool allocateForImageCalled = false;
|
||||
bool allocate32BitGraphicsMemoryImplCalled = false;
|
||||
bool allocateGraphicsMemoryForNonSvmHostPtrCalled = false;
|
||||
bool allocateForShareableCalled = false;
|
||||
bool failReserveAddress = false;
|
||||
bool failAllocateSystemMemory = false;
|
||||
bool failAllocate32Bit = false;
|
||||
bool cpuCopyRequired = false;
|
||||
bool forceRenderCompressed = false;
|
||||
bool forceFailureInPrimaryAllocation = false;
|
||||
bool forceFailureInAllocationWithHostPointer = false;
|
||||
bool isMockHostMemoryManager = false;
|
||||
bool isMockEventPoolCreateMemoryManager = false;
|
||||
bool limitedGPU = false;
|
||||
bool returnFakeAllocation = false;
|
||||
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
|
||||
DeviceBitfield recentlyPassedDeviceBitfield{};
|
||||
std::unique_ptr<MultiGraphicsAllocation> waitAllocations = nullptr;
|
||||
};
|
||||
|
||||
class GMockMemoryManager : public MockMemoryManager {
|
||||
public:
|
||||
GMockMemoryManager(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast<ExecutionEnvironment &>(executionEnvironment)){};
|
||||
MOCK_METHOD2(populateOsHandles, MemoryManager::AllocationStatus(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex));
|
||||
MOCK_METHOD1(allocateGraphicsMemoryForNonSvmHostPtr, GraphicsAllocation *(const AllocationData &));
|
||||
|
||||
MemoryManager::AllocationStatus MemoryManagerPopulateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { return OsAgnosticMemoryManager::populateOsHandles(handleStorage, rootDeviceIndex); }
|
||||
};
|
||||
|
||||
class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager {
|
||||
public:
|
||||
MockAllocSysMemAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment) {
|
||||
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;
|
||||
};
|
||||
|
||||
class FailMemoryManager : public MockMemoryManager {
|
||||
public:
|
||||
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
||||
using MockMemoryManager::MockMemoryManager;
|
||||
FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment);
|
||||
FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment, bool localMemory);
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override {
|
||||
if (failedAllocationsCount <= 0) {
|
||||
return nullptr;
|
||||
}
|
||||
failedAllocationsCount--;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
||||
}
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
}
|
||||
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
}
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override {
|
||||
return nullptr;
|
||||
}
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||
return nullptr;
|
||||
}
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, GraphicsAllocation::AllocationType allocType) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override { return nullptr; };
|
||||
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override{};
|
||||
|
||||
MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override {
|
||||
return AllocationStatus::Error;
|
||||
};
|
||||
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
|
||||
|
||||
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override {
|
||||
return 0;
|
||||
};
|
||||
|
||||
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
};
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
}
|
||||
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t failedAllocationsCount = 0;
|
||||
};
|
||||
|
||||
class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager {
|
||||
public:
|
||||
GMockMemoryManagerFailFirstAllocation(bool enableLocalMemory, const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(enableLocalMemory, const_cast<ExecutionEnvironment &>(executionEnvironment)){};
|
||||
GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : GMockMemoryManagerFailFirstAllocation(false, executionEnvironment){};
|
||||
|
||||
MOCK_METHOD2(allocateGraphicsMemoryInDevicePool, GraphicsAllocation *(const AllocationData &, AllocationStatus &));
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -11,8 +11,7 @@
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_sip.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include "shared/test/common/fixtures/device_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
#include "shared/source/memory_manager/deferred_deleter.h"
|
||||
#include "shared/source/os_interface/os_context.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/libult/ult_command_stream_receiver.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
@@ -9,12 +9,11 @@
|
||||
#include "shared/source/memory_manager/migration_sync_data.h"
|
||||
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_migration_sync_data.h"
|
||||
#include "shared/test/common/mocks/mock_multi_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/ult_device_factory.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "shared/source/gmm_helper/gmm_helper.h"
|
||||
#include "shared/test/common/fixtures/front_window_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "shared/source/helpers/app_resource_helper.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "shared/test/common/fixtures/mock_execution_environment_gmm_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "test.h"
|
||||
|
||||
using MockExecutionEnvironmentGmmTest = Test<NEO::MockExecutionEnvironmentGmmFixture>;
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
#include "shared/source/unified_memory/unified_memory.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/test_macros/test_checks_shared.h"
|
||||
#include "shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests_fixture.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenInsertingAllocsThenAllocsAreTrackedByPageFaultManager) {
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
#include "shared/source/program/program_initialization.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/test_macros/test_checks_shared.h"
|
||||
#include "shared/test/unit_test/compiler_interface/linker_mock.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_svm_manager.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
Reference in New Issue
Block a user