1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "shared/source/os_interface/linux/allocator_helper.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
#include "opencl/test/unit_test/mocks/mock_host_ptr_manager.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include <atomic>
namespace NEO {
off_t lseekReturn = 4096u;
std::atomic<int> lseekCalledCount(0);
TestedDrmMemoryManager::TestedDrmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(gemCloseWorkerMode::gemCloseWorkerInactive,
false,
false,
executionEnvironment) {
this->mmapFunction = &mmapMock;
this->munmapFunction = &munmapMock;
this->lseekFunction = &lseekMock;
this->closeFunction = &closeMock;
lseekReturn = 4096;
lseekCalledCount = 0;
hostPtrManager.reset(new MockHostPtrManager);
};
TestedDrmMemoryManager::TestedDrmMemoryManager(bool enableLocalMemory,
bool allowForcePin,
bool validateHostPtrMemory,
ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, enableLocalMemory,
gemCloseWorkerMode::gemCloseWorkerInactive,
allowForcePin,
validateHostPtrMemory,
executionEnvironment) {
this->mmapFunction = &mmapMock;
this->munmapFunction = &munmapMock;
this->lseekFunction = &lseekMock;
this->closeFunction = &closeMock;
lseekReturn = 4096;
lseekCalledCount = 0;
}
void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB, uint32_t rootDeviceIndex) {
BufferObject *currentPinBB = pinBBs[rootDeviceIndex];
pinBBs[rootDeviceIndex] = nullptr;
DrmMemoryManager::unreference(currentPinBB, true);
pinBBs[rootDeviceIndex] = newPinBB;
}
DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->gemCloseWorker.get(); }
void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) {
for (auto &gfxPartition : gfxPartitions) {
gfxPartition->init(range, getSizeToReserve(), 0, 1);
}
}
void TestedDrmMemoryManager::overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); }
DrmAllocation *TestedDrmMemoryManager::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);
}
TestedDrmMemoryManager::~TestedDrmMemoryManager() {
DrmMemoryManager::commonCleanup();
}
}; // namespace NEO
|