mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-22 10:17:01 +08:00
Allocate internal allocations through preferred pool
Change-Id: Ib17431ceefc1eb72f86625e0998f679baaa7cb0d Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
303014582a
commit
f157943610
@@ -287,11 +287,11 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
|
||||
auto heapMemory = internalAllocationStorage->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release();
|
||||
|
||||
if (!heapMemory) {
|
||||
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
|
||||
if (requireInternalHeap) {
|
||||
heapMemory = getMemoryManager()->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
} else {
|
||||
heapMemory = getMemoryManager()->allocateGraphicsMemoryWithProperties({finalHeapSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
|
||||
allocationType = GraphicsAllocation::AllocationType::INTERNAL_HEAP;
|
||||
}
|
||||
heapMemory = getMemoryManager()->allocateGraphicsMemoryWithProperties({finalHeapSize, allocationType});
|
||||
} else {
|
||||
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
DYNAMIC_STATE_HEAP,
|
||||
SHARED_RESOURCE_COPY,
|
||||
SVM,
|
||||
KERNEL_ISA,
|
||||
INTERNAL_HEAP,
|
||||
UNDECIDED,
|
||||
};
|
||||
|
||||
|
||||
@@ -260,12 +260,23 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||
case GraphicsAllocation::AllocationType::LINEAR_STREAM:
|
||||
case GraphicsAllocation::AllocationType::FILL_PATTERN:
|
||||
case GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER:
|
||||
case GraphicsAllocation::AllocationType::KERNEL_ISA:
|
||||
case GraphicsAllocation::AllocationType::INTERNAL_HEAP:
|
||||
allocationData.flags.useSystemMemory = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (properties.allocationType) {
|
||||
case GraphicsAllocation::AllocationType::KERNEL_ISA:
|
||||
case GraphicsAllocation::AllocationType::INTERNAL_HEAP:
|
||||
allocationData.allocationOrigin = AllocationOrigin::INTERNAL_ALLOCATION;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
allocationData.flags.mustBeZeroCopy = mustBeZeroCopy;
|
||||
allocationData.flags.allocateMemory = properties.flags.allocateMemory;
|
||||
allocationData.flags.allow32Bit = allow32Bit;
|
||||
@@ -315,8 +326,9 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
|
||||
return allocateGraphicsMemoryForImage(allocationData);
|
||||
}
|
||||
|
||||
if (force32bitAllocations && allocationData.flags.allow32Bit && is64bit) {
|
||||
return allocate32BitGraphicsMemory(allocationData.size, allocationData.hostPtr, AllocationOrigin::EXTERNAL_ALLOCATION);
|
||||
if (allocationData.allocationOrigin == AllocationOrigin::INTERNAL_ALLOCATION ||
|
||||
(force32bitAllocations && allocationData.flags.allow32Bit && is64bit)) {
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData);
|
||||
}
|
||||
if (allocationData.hostPtr) {
|
||||
return allocateGraphicsMemoryWithHostPtr(allocationData);
|
||||
|
||||
@@ -36,7 +36,7 @@ enum AllocationUsage {
|
||||
REUSABLE_ALLOCATION
|
||||
};
|
||||
|
||||
enum AllocationOrigin {
|
||||
enum class AllocationOrigin {
|
||||
EXTERNAL_ALLOCATION,
|
||||
INTERNAL_ALLOCATION
|
||||
};
|
||||
@@ -117,8 +117,6 @@ class MemoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
virtual GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) = 0;
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr);
|
||||
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) = 0;
|
||||
@@ -212,6 +210,7 @@ class MemoryManager {
|
||||
};
|
||||
static_assert(sizeof(AllocationData::flags) == sizeof(AllocationData::allFlags), "");
|
||||
GraphicsAllocation::AllocationType type = GraphicsAllocation::AllocationType::UNKNOWN;
|
||||
AllocationOrigin allocationOrigin = AllocationOrigin::EXTERNAL_ALLOCATION;
|
||||
const void *hostPtr = nullptr;
|
||||
size_t size = 0;
|
||||
size_t alignment = 0;
|
||||
@@ -227,6 +226,7 @@ class MemoryManager {
|
||||
virtual GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData);
|
||||
virtual GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) = 0;
|
||||
virtual GraphicsAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) = 0;
|
||||
virtual GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) = 0;
|
||||
virtual GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
||||
status = AllocationStatus::Error;
|
||||
switch (allocationData.type) {
|
||||
|
||||
@@ -78,15 +78,15 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(Allocati
|
||||
return memoryAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
if (ptr) {
|
||||
auto allocationSize = alignSizeWholePage(ptr, size);
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) {
|
||||
if (allocationData.hostPtr) {
|
||||
auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size);
|
||||
auto gpuVirtualAddress = allocator32Bit->allocate(allocationSize);
|
||||
if (!gpuVirtualAddress) {
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr) & MemoryConstants::pageMask);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(nullptr, const_cast<void *>(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size,
|
||||
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(allocationData.hostPtr) & MemoryConstants::pageMask);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(nullptr, const_cast<void *>(allocationData.hostPtr), GmmHelper::canonize(gpuVirtualAddress + offset), allocationData.size,
|
||||
counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, this->getOsContextCount(), false);
|
||||
memAlloc->is32BitAllocation = true;
|
||||
memAlloc->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
|
||||
@@ -96,17 +96,17 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
return memAlloc;
|
||||
}
|
||||
|
||||
auto allocationSize = alignUp(size, MemoryConstants::pageSize);
|
||||
auto allocationSize = alignUp(allocationData.size, MemoryConstants::pageSize);
|
||||
void *ptrAlloc = nullptr;
|
||||
auto gpuAddress = allocator32Bit->allocate(allocationSize);
|
||||
|
||||
if (size < 0xfffff000) {
|
||||
if (allocationData.size < 0xfffff000) {
|
||||
ptrAlloc = alignedMallocWrapper(allocationSize, MemoryConstants::allocationAlignment);
|
||||
}
|
||||
|
||||
MemoryAllocation *memoryAllocation = nullptr;
|
||||
if (ptrAlloc != nullptr) {
|
||||
memoryAllocation = new MemoryAllocation(ptrAlloc, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter,
|
||||
memoryAllocation = new MemoryAllocation(ptrAlloc, ptrAlloc, GmmHelper::canonize(gpuAddress), allocationData.size, counter,
|
||||
MemoryPool::System4KBPagesWith32BitGpuAddressing, this->getOsContextCount(), false);
|
||||
memoryAllocation->is32BitAllocation = true;
|
||||
memoryAllocation->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
|
||||
|
||||
@@ -45,10 +45,8 @@ class OsAgnosticMemoryManager : public MemoryManager {
|
||||
|
||||
~OsAgnosticMemoryManager() override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
||||
void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
||||
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
||||
@@ -74,6 +72,8 @@ class OsAgnosticMemoryManager : public MemoryManager {
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override { return ptrOffset(graphicsAllocation.getUnderlyingBuffer(), static_cast<size_t>(graphicsAllocation.allocationOffset)); };
|
||||
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override{};
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
||||
private:
|
||||
unsigned long long counter = 0;
|
||||
|
||||
@@ -324,19 +324,19 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
|
||||
return allocation;
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
auto allocatorToUse = allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit.get() : internal32bitAllocator.get();
|
||||
auto allocatorType = allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? BIT32_ALLOCATOR_EXTERNAL : BIT32_ALLOCATOR_INTERNAL;
|
||||
DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) {
|
||||
auto allocatorToUse = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit.get() : internal32bitAllocator.get();
|
||||
auto allocatorType = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? BIT32_ALLOCATOR_EXTERNAL : BIT32_ALLOCATOR_INTERNAL;
|
||||
|
||||
if (ptr) {
|
||||
uintptr_t inputPtr = (uintptr_t)ptr;
|
||||
auto allocationSize = alignSizeWholePage((void *)ptr, size);
|
||||
if (allocationData.hostPtr) {
|
||||
uintptr_t inputPtr = reinterpret_cast<uintptr_t>(allocationData.hostPtr);
|
||||
auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size);
|
||||
auto realAllocationSize = allocationSize;
|
||||
auto gpuVirtualAddress = allocatorToUse->allocate(realAllocationSize);
|
||||
if (!gpuVirtualAddress) {
|
||||
return nullptr;
|
||||
}
|
||||
auto alignedUserPointer = (uintptr_t)alignDown(ptr, MemoryConstants::pageSize);
|
||||
auto alignedUserPointer = reinterpret_cast<uintptr_t>(alignDown(allocationData.hostPtr, MemoryConstants::pageSize));
|
||||
auto inputPointerOffset = inputPtr - alignedUserPointer;
|
||||
|
||||
BufferObject *bo = allocUserptr(alignedUserPointer, allocationSize, 0, true);
|
||||
@@ -351,14 +351,14 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const
|
||||
uintptr_t offset = (uintptr_t)bo->address;
|
||||
bo->softPin((uint64_t)offset);
|
||||
bo->setAllocationType(allocatorType);
|
||||
auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset),
|
||||
auto drmAllocation = new DrmAllocation(bo, const_cast<void *>(allocationData.hostPtr), static_cast<uint64_t>(ptrOffset(gpuVirtualAddress, inputPointerOffset)),
|
||||
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, getOsContextCount(), false);
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
size_t alignedAllocationSize = alignUp(size, MemoryConstants::pageSize);
|
||||
size_t alignedAllocationSize = alignUp(allocationData.size, MemoryConstants::pageSize);
|
||||
auto allocationSize = alignedAllocationSize;
|
||||
auto res = allocatorToUse->allocate(allocationSize);
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ class DrmMemoryManager : public MemoryManager {
|
||||
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
||||
DrmAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
||||
DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
||||
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }
|
||||
@@ -72,6 +71,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
|
||||
Drm *drm;
|
||||
BufferObject *pinBB;
|
||||
|
||||
@@ -167,19 +167,19 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(const AllocationPr
|
||||
return allocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) {
|
||||
Gmm *gmm = nullptr;
|
||||
const void *ptrAligned = nullptr;
|
||||
size_t sizeAligned = size;
|
||||
size_t sizeAligned = allocationData.size;
|
||||
void *pSysMem = nullptr;
|
||||
size_t offset = 0;
|
||||
|
||||
if (ptr) {
|
||||
ptrAligned = alignDown(ptr, MemoryConstants::allocationAlignment);
|
||||
sizeAligned = alignSizeWholePage(ptr, size);
|
||||
offset = ptrDiff(ptr, ptrAligned);
|
||||
if (allocationData.hostPtr) {
|
||||
ptrAligned = alignDown(allocationData.hostPtr, MemoryConstants::allocationAlignment);
|
||||
sizeAligned = alignSizeWholePage(allocationData.hostPtr, sizeAligned);
|
||||
offset = ptrDiff(allocationData.hostPtr, ptrAligned);
|
||||
} else {
|
||||
sizeAligned = alignUp(size, MemoryConstants::allocationAlignment);
|
||||
sizeAligned = alignUp(sizeAligned, MemoryConstants::allocationAlignment);
|
||||
pSysMem = allocateSystemMemory(sizeAligned, MemoryConstants::allocationAlignment);
|
||||
if (pSysMem == nullptr) {
|
||||
return nullptr;
|
||||
@@ -196,14 +196,14 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
|
||||
gmm = new Gmm(ptrAligned, sizeAligned, false);
|
||||
wddmAllocation->gmm = gmm;
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation.get(), allocationOrigin)) {
|
||||
if (!createWddmAllocation(wddmAllocation.get(), allocationData.allocationOrigin)) {
|
||||
delete gmm;
|
||||
freeSystemMemory(pSysMem);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
auto baseAddress = allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getGfxPartition().Heap32[1].Base;
|
||||
auto baseAddress = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getGfxPartition().Heap32[1].Base;
|
||||
wddmAllocation->gpuBaseAddress = GmmHelper::canonize(baseAddress);
|
||||
|
||||
DebugManager.logAllocation(wddmAllocation.get());
|
||||
|
||||
@@ -36,10 +36,8 @@ class WddmMemoryManager : public MemoryManager {
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
||||
GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
||||
void addAllocationToHostPtrManager(GraphicsAllocation *memory) override;
|
||||
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override;
|
||||
@@ -75,6 +73,8 @@ class WddmMemoryManager : public MemoryManager {
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
||||
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle);
|
||||
static bool validateAllocation(WddmAllocation *alloc);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -485,7 +485,7 @@ uint32_t KernelInfo::getConstantBufferSize() const {
|
||||
bool KernelInfo::createKernelAllocation(MemoryManager *memoryManager) {
|
||||
UNRECOVERABLE_IF(kernelAllocation);
|
||||
auto kernelIsaSize = heapInfo.pKernelHeader->KernelHeapSize;
|
||||
kernelAllocation = memoryManager->allocate32BitGraphicsMemory(kernelIsaSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
kernelAllocation = memoryManager->allocateGraphicsMemoryWithProperties({kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA});
|
||||
if (kernelAllocation) {
|
||||
memcpy_s(kernelAllocation->getUnderlyingBuffer(), kernelIsaSize, heapInfo.pKernelHeap, kernelIsaSize);
|
||||
} else {
|
||||
|
||||
@@ -489,12 +489,11 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandStreamReceiverWithReusableAlloc
|
||||
GraphicsAllocation *allocation = nullptr;
|
||||
|
||||
auto &commandStreamReceiver = cmdQ.getCommandStreamReceiver();
|
||||
|
||||
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
|
||||
if (this->GetParam() == IndirectHeap::INDIRECT_OBJECT) {
|
||||
allocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
} else {
|
||||
allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{allocationSize});
|
||||
allocationType = GraphicsAllocation::AllocationType::INTERNAL_HEAP;
|
||||
}
|
||||
allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{allocationSize, allocationType});
|
||||
if (this->GetParam() == IndirectHeap::SURFACE_STATE) {
|
||||
allocation->setSize(commandStreamReceiver.defaultSshSize * 2);
|
||||
}
|
||||
|
||||
@@ -813,8 +813,8 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DispatchWalkerTest, dispatchWalkerWithMultipleDispat
|
||||
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
||||
|
||||
auto memoryManager = this->pDevice->getMemoryManager();
|
||||
auto kernelIsaAllocation = memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
auto kernelIsaWithSamplerAllocation = memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
auto kernelIsaAllocation = memoryManager->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::KERNEL_ISA});
|
||||
auto kernelIsaWithSamplerAllocation = memoryManager->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::KERNEL_ISA});
|
||||
kernelInfo.kernelAllocation = kernelIsaAllocation;
|
||||
kernelInfoWithSampler.kernelAllocation = kernelIsaWithSamplerAllocation;
|
||||
auto gpuAddress1 = kernelIsaAllocation->getGpuAddressToPatch();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "unit_tests/fixtures/memory_management_fixture.h"
|
||||
#include "unit_tests/libult/create_command_stream.h"
|
||||
#include "unit_tests/mocks/mock_memory_manager.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
@@ -21,7 +22,7 @@ class MemoryAllocatorFixture : public MemoryManagementFixture {
|
||||
MemoryManagementFixture::SetUp();
|
||||
executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->initializeCommandStreamReceiver(*platformDevices, 0, 0);
|
||||
memoryManager = new OsAgnosticMemoryManager(false, false, *executionEnvironment);
|
||||
memoryManager = new MockMemoryManager(false, false, *executionEnvironment);
|
||||
executionEnvironment->memoryManager.reset(memoryManager);
|
||||
csr = memoryManager->getDefaultCommandStreamReceiver(0);
|
||||
csr->setupContext(*memoryManager->createAndRegisterOsContext(HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
|
||||
@@ -34,6 +35,6 @@ class MemoryAllocatorFixture : public MemoryManagementFixture {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
|
||||
MemoryManager *memoryManager;
|
||||
MockMemoryManager *memoryManager;
|
||||
CommandStreamReceiver *csr;
|
||||
};
|
||||
|
||||
@@ -210,7 +210,7 @@ HWTEST_F(KernelCommandsTest, givenIndirectHeapNotAllocatedFromInternalPoolWhenSe
|
||||
}
|
||||
|
||||
HWTEST_F(KernelCommandsTest, givenIndirectHeapAllocatedFromInternalPoolWhenSendCrossThreadDataIsCalledThenHeapBaseOffsetIsReturned) {
|
||||
auto internalAllocation = pDevice->getMemoryManager()->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
auto internalAllocation = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties::getPropertiesFor32BitInternalAllocation(MemoryConstants::pageSize, true));
|
||||
IndirectHeap indirectHeap(internalAllocation, true);
|
||||
auto expectedOffset = internalAllocation->getGpuAddressToPatch();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenAllocationIsReturned) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
|
||||
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error;
|
||||
AllocationData allocData;
|
||||
@@ -26,7 +26,7 @@ TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevice
|
||||
|
||||
TEST(MemoryManagerTest, givenImageOrSharedResourceCopyWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
|
||||
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error;
|
||||
AllocationData allocData;
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace OCLRT;
|
||||
|
||||
TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
|
||||
AllocationData allocData;
|
||||
allocData.size = MemoryConstants::pageSize;
|
||||
@@ -32,7 +32,7 @@ TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePool
|
||||
|
||||
TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
memoryManager.setForce32BitAllocations(true);
|
||||
|
||||
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
|
||||
|
||||
@@ -358,8 +358,6 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc
|
||||
auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, AllocationOrigin::EXTERNAL_ALLOCATION);
|
||||
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, AllocationOrigin::EXTERNAL_ALLOCATION);
|
||||
EXPECT_EQ(nullptr, allocation);
|
||||
if (allocation)
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
memoryManager->freeGraphicsMemory(allocationFirst);
|
||||
}
|
||||
|
||||
@@ -369,8 +367,6 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc
|
||||
auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, AllocationOrigin::EXTERNAL_ALLOCATION);
|
||||
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, AllocationOrigin::EXTERNAL_ALLOCATION);
|
||||
EXPECT_EQ(nullptr, allocation);
|
||||
if (allocation)
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
memoryManager->freeGraphicsMemory(allocationFirst);
|
||||
}
|
||||
|
||||
@@ -718,7 +714,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
void *ptr = reinterpret_cast<void *>(0x1001);
|
||||
auto size = MemoryConstants::pageSize;
|
||||
|
||||
@@ -732,7 +728,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithoutPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
void *ptr = nullptr;
|
||||
auto size = MemoryConstants::pageSize;
|
||||
|
||||
@@ -1020,7 +1016,7 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsCalledThenGraphicsAllocationIsReturned) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
auto ptr = (void *)0x100000;
|
||||
size_t allocationSize = 4096;
|
||||
auto graphicsAllocation = memoryManager.allocate32BitGraphicsMemory(allocationSize, ptr, AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
||||
#include "unit_tests/mocks/mock_allocation_properties.h"
|
||||
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
||||
#include <atomic>
|
||||
|
||||
@@ -85,5 +86,15 @@ class TestedDrmMemoryManager : public DrmMemoryManager {
|
||||
|
||||
Allocator32bit *getDrmInternal32BitAllocator() const { return internal32bitAllocator.get(); }
|
||||
AllocatorLimitedRange *getDrmLimitedRangeAllocator() const { return limitedGpuAddressRangeAllocator.get(); }
|
||||
DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
bool allocateMemory = ptr == nullptr;
|
||||
AllocationData allocationData;
|
||||
if (allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION) {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitExternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
} else {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitInternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
}
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData);
|
||||
}
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -14,5 +14,12 @@ struct MockAllocationProperties : public AllocationProperties {
|
||||
MockAllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(size, allocationType) {}
|
||||
MockAllocationProperties(size_t size) : AllocationProperties(size, GraphicsAllocation::AllocationType::UNDECIDED) {}
|
||||
MockAllocationProperties(bool allocateMemory, size_t size) : AllocationProperties(allocateMemory, size, GraphicsAllocation::AllocationType::UNDECIDED) {}
|
||||
|
||||
static AllocationProperties getPropertiesFor32BitInternalAllocation(size_t size, bool allocateMemory) {
|
||||
return AllocationProperties{allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HEAP};
|
||||
}
|
||||
static AllocationProperties getPropertiesFor32BitExternalAllocation(size_t size, bool allocateMemory) {
|
||||
return AllocationProperties{allocateMemory, size, GraphicsAllocation::AllocationType::BUFFER};
|
||||
}
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "runtime/memory_manager/deferred_deleter.h"
|
||||
#include "runtime/gmm_helper/gmm.h"
|
||||
#include "runtime/helpers/surface_formats.h"
|
||||
#include "unit_tests/mocks/mock_allocation_properties.h"
|
||||
#include "unit_tests/mocks/mock_memory_manager.h"
|
||||
#include <cstring>
|
||||
|
||||
@@ -80,6 +81,16 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const
|
||||
allocationCreated = true;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
||||
}
|
||||
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
bool allocateMemory = ptr == nullptr;
|
||||
AllocationData allocationData;
|
||||
if (allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION) {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitExternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
} else {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitInternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
}
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData);
|
||||
}
|
||||
|
||||
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount) {
|
||||
this->failedAllocationsCount = failedAllocationsCount;
|
||||
|
||||
@@ -64,6 +64,7 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
|
||||
unlockResourceCalled++;
|
||||
OsAgnosticMemoryManager::unlockResourceImpl(gfxAllocation);
|
||||
}
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin);
|
||||
|
||||
uint32_t freeGraphicsMemoryCalled = 0u;
|
||||
uint32_t unlockResourceCalled = 0u;
|
||||
@@ -131,7 +132,7 @@ class FailMemoryManager : public MockMemoryManager {
|
||||
GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) override {
|
||||
return nullptr;
|
||||
};
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override {
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override {
|
||||
return nullptr;
|
||||
};
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override {
|
||||
|
||||
@@ -236,8 +236,8 @@ TEST_F(DrmCommandStreamTest, givenDrmContextIdWhenFlushingThenSetIdToAllExecBuff
|
||||
return 0;
|
||||
};
|
||||
|
||||
auto allocation1 = memoryManager->allocate32BitGraphicsMemory(1, reinterpret_cast<void *>(1), AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
auto allocation2 = memoryManager->allocate32BitGraphicsMemory(1, reinterpret_cast<void *>(2), AllocationOrigin::INTERNAL_ALLOCATION);
|
||||
auto allocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
|
||||
auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
|
||||
csr->makeResident(*allocation1);
|
||||
csr->makeResident(*allocation2);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -17,6 +17,7 @@ class MockWddmMemoryManager : public WddmMemoryManager {
|
||||
public:
|
||||
using BaseClass::allocateGraphicsMemory;
|
||||
using BaseClass::allocateGraphicsMemory64kb;
|
||||
using BaseClass::allocateGraphicsMemoryInDevicePool;
|
||||
using BaseClass::createWddmAllocation;
|
||||
using BaseClass::WddmMemoryManager;
|
||||
|
||||
@@ -32,5 +33,15 @@ class MockWddmMemoryManager : public WddmMemoryManager {
|
||||
bool validateAllocationMock(WddmAllocation *graphicsAllocation) {
|
||||
return this->validateAllocation(graphicsAllocation);
|
||||
}
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
bool allocateMemory = ptr == nullptr;
|
||||
AllocationData allocationData;
|
||||
if (allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION) {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitExternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
} else {
|
||||
getAllocationData(allocationData, MockAllocationProperties::getPropertiesFor32BitInternalAllocation(size, allocateMemory), 0u, ptr);
|
||||
}
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData);
|
||||
}
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -130,7 +130,7 @@ TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKerne
|
||||
class MyMemoryManager : public OsAgnosticMemoryManager {
|
||||
public:
|
||||
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override { return nullptr; }
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override { return nullptr; }
|
||||
};
|
||||
|
||||
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) {
|
||||
|
||||
Reference in New Issue
Block a user