mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 15:12:56 +08:00
Simplify code by removing AllocationOrigin.
Change-Id: Ie73cefc1ae1ee846fb9a5ef1054af01cd1867a4d
This commit is contained in:
@@ -26,11 +26,6 @@ namespace OCLRT {
|
||||
|
||||
using osHandle = unsigned int;
|
||||
|
||||
enum class AllocationOrigin {
|
||||
EXTERNAL_ALLOCATION,
|
||||
INTERNAL_ALLOCATION
|
||||
};
|
||||
|
||||
enum class HeapIndex : uint32_t {
|
||||
HEAP_INTERNAL_DEVICE_MEMORY = 0u,
|
||||
HEAP_INTERNAL = 1u,
|
||||
@@ -60,7 +55,6 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
void *driverAllocatedCpuPointer = nullptr;
|
||||
DevicesBitfield devicesBitfield = {};
|
||||
bool flushL3Required = false;
|
||||
AllocationOrigin origin = AllocationOrigin::EXTERNAL_ALLOCATION;
|
||||
|
||||
enum class AllocationType {
|
||||
UNKNOWN = 0,
|
||||
|
||||
@@ -258,15 +258,6 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||
break;
|
||||
}
|
||||
|
||||
switch (properties.allocationType) {
|
||||
case GraphicsAllocation::AllocationType::KERNEL_ISA:
|
||||
case GraphicsAllocation::AllocationType::INTERNAL_HEAP:
|
||||
allocationData.allocationOrigin = AllocationOrigin::INTERNAL_ALLOCATION;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
allocationData.flags.requiresCpuAccess = GraphicsAllocation::isCpuAccessRequired(properties.allocationType);
|
||||
allocationData.flags.mustBeZeroCopy = mustBeZeroCopy;
|
||||
allocationData.flags.allocateMemory = properties.flags.allocateMemory;
|
||||
@@ -317,7 +308,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
|
||||
return allocateGraphicsMemoryForImage(allocationData);
|
||||
}
|
||||
|
||||
if (allocationData.allocationOrigin == AllocationOrigin::INTERNAL_ALLOCATION ||
|
||||
if (useInternal32BitAllocator(allocationData.type) ||
|
||||
(force32bitAllocations && allocationData.flags.allow32Bit && is64bit)) {
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData);
|
||||
}
|
||||
@@ -378,7 +369,7 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) {
|
||||
|
||||
HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, const void *ptr, const HardwareInfo &hwInfo) {
|
||||
if (allocation) {
|
||||
if (allocation->origin == AllocationOrigin::INTERNAL_ALLOCATION) {
|
||||
if (useInternal32BitAllocator(allocation->getAllocationType())) {
|
||||
return internalHeapIndex;
|
||||
} else if (allocation->is32BitAllocation) {
|
||||
return HeapIndex::HEAP_EXTERNAL;
|
||||
|
||||
@@ -211,7 +211,6 @@ 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;
|
||||
@@ -221,6 +220,10 @@ class MemoryManager {
|
||||
|
||||
static bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const DevicesBitfield devicesBitfield,
|
||||
const void *hostPtr);
|
||||
static bool useInternal32BitAllocator(GraphicsAllocation::AllocationType allocationType) {
|
||||
return allocationType == GraphicsAllocation::AllocationType::KERNEL_ISA ||
|
||||
allocationType == GraphicsAllocation::AllocationType::INTERNAL_HEAP;
|
||||
}
|
||||
|
||||
virtual GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) = 0;
|
||||
GraphicsAllocation *allocateGraphicsMemory(const AllocationData &allocationData);
|
||||
|
||||
@@ -240,9 +240,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc
|
||||
if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) {
|
||||
pinBB->pin(&bo, 1, getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId());
|
||||
}
|
||||
auto allocation = new DrmAllocation(bo, res, castToUint64(res), cSize, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable);
|
||||
allocation->origin = allocationData.allocationOrigin;
|
||||
return allocation;
|
||||
return new DrmAllocation(bo, res, castToUint64(res), cSize, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable);
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) {
|
||||
@@ -328,13 +326,13 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
|
||||
auto allocation = new DrmAllocation(bo, nullptr, (uint64_t)gpuRange, allocationData.imgInfo->size, MemoryPool::SystemCpuInaccessible, false);
|
||||
bo->setAllocationType(allocatorType);
|
||||
allocation->gmm = gmm.release();
|
||||
allocation->origin = allocationData.allocationOrigin;
|
||||
return allocation;
|
||||
}
|
||||
|
||||
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;
|
||||
auto internal = useInternal32BitAllocator(allocationData.type);
|
||||
auto allocatorToUse = internal ? internal32bitAllocator.get() : allocator32Bit.get();
|
||||
auto allocatorType = internal ? BIT32_ALLOCATOR_INTERNAL : BIT32_ALLOCATOR_EXTERNAL;
|
||||
|
||||
if (allocationData.hostPtr) {
|
||||
uintptr_t inputPtr = reinterpret_cast<uintptr_t>(allocationData.hostPtr);
|
||||
@@ -361,7 +359,6 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
|
||||
drmAllocation->origin = allocationData.allocationOrigin;
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
@@ -415,7 +412,6 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
|
||||
drmAllocation->driverAllocatedCpuPointer = ptrAlloc;
|
||||
drmAllocation->origin = allocationData.allocationOrigin;
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImageImpl(const
|
||||
|
||||
auto allocation = std::make_unique<WddmAllocation>(nullptr, allocationData.imgInfo->size, nullptr, MemoryPool::SystemCpuInaccessible, false);
|
||||
allocation->gmm = gmm.get();
|
||||
allocation->origin = allocationData.allocationOrigin;
|
||||
if (!createWddmAllocation(allocation.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -98,7 +97,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const
|
||||
gmm = new Gmm(pSysMem, sizeAligned, allocationData.flags.uncacheable);
|
||||
|
||||
wddmAllocation->gmm = gmm;
|
||||
wddmAllocation->origin = allocationData.allocationOrigin;
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation.get())) {
|
||||
delete gmm;
|
||||
@@ -192,10 +190,10 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
|
||||
wddmAllocation->driverAllocatedCpuPointer = pSysMem;
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
wddmAllocation->allocationOffset = offset;
|
||||
wddmAllocation->setAllocationType(allocationData.type);
|
||||
|
||||
gmm = new Gmm(ptrAligned, sizeAligned, false);
|
||||
wddmAllocation->gmm = gmm;
|
||||
wddmAllocation->origin = allocationData.allocationOrigin;
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation.get())) {
|
||||
delete gmm;
|
||||
@@ -204,7 +202,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
|
||||
}
|
||||
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
auto baseAddress = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : getInternalHeapBaseAddress();
|
||||
auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress() : allocator32Bit->getBase();
|
||||
wddmAllocation->gpuBaseAddress = GmmHelper::canonize(baseAddress);
|
||||
|
||||
DebugManager.logAllocation(wddmAllocation.get());
|
||||
|
||||
Reference in New Issue
Block a user