2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-07 16:29:49 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-17 20:03:37 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-01-22 23:43:26 +08:00
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-07-23 01:27:33 +08:00
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/event/event.h"
|
2018-07-23 01:27:33 +08:00
|
|
|
#include "runtime/event/hw_timestamps.h"
|
|
|
|
#include "runtime/event/perf_counter.h"
|
2018-12-20 23:58:15 +08:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2019-01-22 19:40:17 +08:00
|
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
|
|
|
#include "runtime/gmm_helper/resource_info.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/helpers/basic_math.h"
|
2018-09-26 06:44:43 +08:00
|
|
|
#include "runtime/helpers/kernel_commands.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/options.h"
|
2019-01-03 21:48:24 +08:00
|
|
|
#include "runtime/memory_manager/deferrable_allocation_deletion.h"
|
2018-07-23 01:27:33 +08:00
|
|
|
#include "runtime/memory_manager/deferred_deleter.h"
|
2018-10-24 14:46:54 +08:00
|
|
|
#include "runtime/memory_manager/host_ptr_manager.h"
|
2018-10-22 21:17:32 +08:00
|
|
|
#include "runtime/memory_manager/internal_allocation_storage.h"
|
2018-12-14 18:24:45 +08:00
|
|
|
#include "runtime/mem_obj/image.h"
|
2018-09-06 15:01:13 +08:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2018-11-21 16:57:51 +08:00
|
|
|
#include "runtime/os_interface/os_interface.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/utilities/stackvec.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
2018-10-01 22:10:54 +08:00
|
|
|
MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory,
|
|
|
|
ExecutionEnvironment &executionEnvironment) : allocator32Bit(nullptr), enable64kbpages(enable64kbpages),
|
|
|
|
localMemorySupported(enableLocalMemory),
|
2018-10-24 14:46:54 +08:00
|
|
|
executionEnvironment(executionEnvironment),
|
2019-01-03 21:48:24 +08:00
|
|
|
hostPtrManager(std::make_unique<HostPtrManager>()),
|
|
|
|
multiContextResourceDestructor(std::make_unique<DeferredDeleter>()) {
|
2018-11-07 20:04:10 +08:00
|
|
|
registeredOsContexts.resize(1);
|
|
|
|
};
|
2018-09-06 16:53:35 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
MemoryManager::~MemoryManager() {
|
2018-09-06 15:01:13 +08:00
|
|
|
for (auto osContext : registeredOsContexts) {
|
2018-11-07 20:04:10 +08:00
|
|
|
if (osContext) {
|
|
|
|
osContext->decRefInternal();
|
|
|
|
}
|
2018-09-06 15:01:13 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *MemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
|
|
|
|
// Establish a minimum alignment of 16bytes.
|
2018-01-22 23:43:26 +08:00
|
|
|
constexpr size_t minAlignment = 16;
|
|
|
|
alignment = std::max(alignment, minAlignment);
|
|
|
|
auto restrictions = getAlignedMallocRestrictions();
|
|
|
|
void *ptr = nullptr;
|
|
|
|
|
|
|
|
ptr = alignedMallocWrapper(size, alignment);
|
|
|
|
if (restrictions == nullptr) {
|
|
|
|
return ptr;
|
|
|
|
} else if (restrictions->minAddress == 0) {
|
|
|
|
return ptr;
|
|
|
|
} else {
|
|
|
|
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
|
|
|
|
StackVec<void *, 100> invalidMemVector;
|
|
|
|
invalidMemVector.push_back(ptr);
|
|
|
|
do {
|
|
|
|
ptr = alignedMallocWrapper(size, alignment);
|
|
|
|
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
|
|
|
|
invalidMemVector.push_back(ptr);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
for (auto &it : invalidMemVector) {
|
|
|
|
alignedFreeWrapper(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-11-30 18:01:33 +08:00
|
|
|
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (deferredDeleter) {
|
|
|
|
deferredDeleter->drain(true);
|
|
|
|
}
|
2018-10-23 17:42:40 +08:00
|
|
|
GraphicsAllocation *graphicsAllocation = nullptr;
|
2018-11-30 18:01:33 +08:00
|
|
|
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, allocationData.size, allocationData.hostPtr);
|
2018-10-23 17:42:40 +08:00
|
|
|
if (osStorage.fragmentCount > 0) {
|
2018-11-30 18:01:33 +08:00
|
|
|
graphicsAllocation = createGraphicsAllocation(osStorage, allocationData.size, allocationData.hostPtr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
return graphicsAllocation;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:40:17 +08:00
|
|
|
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForImageFromHostPtr(const AllocationData &allocationData) {
|
|
|
|
bool copyRequired = Image::isCopyRequired(*allocationData.imgInfo, allocationData.hostPtr);
|
2018-12-14 18:24:45 +08:00
|
|
|
|
2019-01-22 19:40:17 +08:00
|
|
|
if (allocationData.hostPtr && !copyRequired) {
|
|
|
|
return allocateGraphicsMemoryWithHostPtr(allocationData);
|
2018-12-14 18:24:45 +08:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *graphicsAllocation) {
|
2018-10-24 14:46:54 +08:00
|
|
|
hostPtrManager->releaseHandleStorage(graphicsAllocation->fragmentsStorage);
|
2017-12-21 07:45:38 +08:00
|
|
|
cleanOsHandles(graphicsAllocation->fragmentsStorage);
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MemoryManager::createGraphicsAllocationWithPadding(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) {
|
|
|
|
if (!paddingAllocation) {
|
2018-12-12 01:56:37 +08:00
|
|
|
paddingAllocation = allocateGraphicsMemoryWithProperties({paddingBufferSize, GraphicsAllocation::AllocationType::UNDECIDED});
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
return createPaddedAllocation(inputGraphicsAllocation, sizeWithPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) {
|
2018-12-12 01:56:37 +08:00
|
|
|
return allocateGraphicsMemoryWithProperties({sizeWithPadding, GraphicsAllocation::AllocationType::UNDECIDED});
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryManager::freeSystemMemory(void *ptr) {
|
|
|
|
::alignedFree(ptr);
|
|
|
|
}
|
|
|
|
|
2018-02-28 16:27:38 +08:00
|
|
|
void MemoryManager::setForce32BitAllocations(bool newValue) {
|
|
|
|
if (newValue && !this->allocator32Bit) {
|
|
|
|
this->allocator32Bit.reset(new Allocator32bit);
|
|
|
|
}
|
|
|
|
force32bitAllocations = newValue;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void MemoryManager::applyCommonCleanup() {
|
|
|
|
if (this->paddingAllocation) {
|
|
|
|
this->freeGraphicsMemory(this->paddingAllocation);
|
|
|
|
}
|
2018-08-24 14:48:59 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) {
|
2019-01-24 18:51:33 +08:00
|
|
|
if (!gfxAllocation) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-24 22:16:12 +08:00
|
|
|
if (gfxAllocation->isLocked()) {
|
|
|
|
unlockResource(gfxAllocation);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
freeGraphicsMemoryImpl(gfxAllocation);
|
|
|
|
}
|
2018-01-19 17:55:36 +08:00
|
|
|
//if not in use destroy in place
|
|
|
|
//if in use pass to temporary allocation list that is cleaned on blocking calls
|
|
|
|
void MemoryManager::checkGpuUsageAndDestroyGraphicsAllocations(GraphicsAllocation *gfxAllocation) {
|
2019-01-03 21:48:24 +08:00
|
|
|
if (gfxAllocation->isUsed()) {
|
|
|
|
if (gfxAllocation->isUsedByManyOsContexts()) {
|
|
|
|
multiContextResourceDestructor->deferDeletion(new DeferrableAllocationDeletion{*this, *gfxAllocation});
|
|
|
|
multiContextResourceDestructor->drain(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto &deviceCsrs : getCommandStreamReceivers()) {
|
|
|
|
for (auto &csr : deviceCsrs) {
|
2019-01-10 20:57:40 +08:00
|
|
|
auto osContextId = csr->getOsContext().getContextId();
|
|
|
|
auto allocationTaskCount = gfxAllocation->getTaskCount(osContextId);
|
|
|
|
if (gfxAllocation->isUsedByOsContext(osContextId) &&
|
|
|
|
allocationTaskCount > *csr->getTagAddress()) {
|
|
|
|
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(gfxAllocation), TEMPORARY_ALLOCATION);
|
|
|
|
return;
|
2019-01-03 21:48:24 +08:00
|
|
|
}
|
2018-12-10 20:17:52 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 17:55:36 +08:00
|
|
|
}
|
2018-12-10 20:17:52 +08:00
|
|
|
freeGraphicsMemory(gfxAllocation);
|
2018-01-19 17:55:36 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void MemoryManager::waitForDeletions() {
|
|
|
|
if (deferredDeleter) {
|
|
|
|
deferredDeleter->drain(false);
|
|
|
|
}
|
|
|
|
deferredDeleter.reset(nullptr);
|
|
|
|
}
|
|
|
|
bool MemoryManager::isAsyncDeleterEnabled() const {
|
|
|
|
return asyncDeleterEnabled;
|
|
|
|
}
|
|
|
|
|
2018-10-12 21:20:02 +08:00
|
|
|
bool MemoryManager::isLocalMemorySupported() const {
|
|
|
|
return localMemorySupported;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool MemoryManager::isMemoryBudgetExhausted() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-12 18:31:19 +08:00
|
|
|
OsContext *MemoryManager::createAndRegisterOsContext(EngineInstanceT engineType, uint32_t numSupportedDevices, PreemptionMode preemptionMode) {
|
2018-11-21 16:57:51 +08:00
|
|
|
auto contextId = ++latestContextId;
|
2018-09-12 13:47:55 +08:00
|
|
|
if (contextId + 1 > registeredOsContexts.size()) {
|
|
|
|
registeredOsContexts.resize(contextId + 1);
|
|
|
|
}
|
2019-02-12 18:31:19 +08:00
|
|
|
auto osContext = new OsContext(executionEnvironment.osInterface.get(), contextId, numSupportedDevices, engineType, preemptionMode);
|
2018-11-21 16:57:51 +08:00
|
|
|
osContext->incRefInternal();
|
|
|
|
registeredOsContexts[contextId] = osContext;
|
|
|
|
|
|
|
|
return osContext;
|
2018-09-06 15:01:13 +08:00
|
|
|
}
|
|
|
|
|
2018-12-06 22:03:06 +08:00
|
|
|
bool MemoryManager::getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const DevicesBitfield devicesBitfield,
|
2018-12-12 01:56:37 +08:00
|
|
|
const void *hostPtr) {
|
2018-12-06 22:03:06 +08:00
|
|
|
UNRECOVERABLE_IF(hostPtr == nullptr && !properties.flags.allocateMemory);
|
2018-07-09 20:12:32 +08:00
|
|
|
|
|
|
|
bool allow64KbPages = false;
|
|
|
|
bool allow32Bit = false;
|
2018-12-06 22:03:06 +08:00
|
|
|
bool forcePin = properties.flags.forcePin;
|
|
|
|
bool uncacheable = properties.flags.uncacheable;
|
2018-07-25 00:36:26 +08:00
|
|
|
bool mustBeZeroCopy = false;
|
2019-01-07 16:29:49 +08:00
|
|
|
bool multiOsContextCapable = properties.flags.multiOsContextCapable;
|
2018-07-09 20:12:32 +08:00
|
|
|
|
2018-12-12 01:56:37 +08:00
|
|
|
switch (properties.allocationType) {
|
2018-07-09 20:12:32 +08:00
|
|
|
case GraphicsAllocation::AllocationType::BUFFER:
|
2018-07-25 00:36:26 +08:00
|
|
|
case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY:
|
2018-07-23 01:27:33 +08:00
|
|
|
case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED:
|
2018-07-09 20:12:32 +08:00
|
|
|
case GraphicsAllocation::AllocationType::PIPE:
|
|
|
|
case GraphicsAllocation::AllocationType::SCRATCH_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::PRIVATE_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::PRINTF_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::CONSTANT_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::GLOBAL_SURFACE:
|
|
|
|
allow64KbPages = true;
|
|
|
|
allow32Bit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-31 17:40:11 +08:00
|
|
|
switch (properties.allocationType) {
|
|
|
|
case GraphicsAllocation::AllocationType::SVM:
|
|
|
|
allow64KbPages = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-12 01:56:37 +08:00
|
|
|
switch (properties.allocationType) {
|
2018-07-25 00:36:26 +08:00
|
|
|
case GraphicsAllocation::AllocationType::BUFFER:
|
|
|
|
case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY:
|
|
|
|
case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED:
|
|
|
|
forcePin = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-12 01:56:37 +08:00
|
|
|
switch (properties.allocationType) {
|
2018-07-25 00:36:26 +08:00
|
|
|
case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY:
|
|
|
|
case GraphicsAllocation::AllocationType::PIPE:
|
|
|
|
case GraphicsAllocation::AllocationType::PRINTF_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::CONSTANT_SURFACE:
|
|
|
|
case GraphicsAllocation::AllocationType::GLOBAL_SURFACE:
|
2018-12-13 17:18:34 +08:00
|
|
|
case GraphicsAllocation::AllocationType::SVM:
|
2018-07-25 00:36:26 +08:00
|
|
|
mustBeZeroCopy = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-12 01:56:37 +08:00
|
|
|
switch (properties.allocationType) {
|
|
|
|
case GraphicsAllocation::AllocationType::UNDECIDED:
|
|
|
|
case GraphicsAllocation::AllocationType::FILL_PATTERN:
|
2019-02-08 17:27:48 +08:00
|
|
|
case GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER:
|
2018-12-12 01:56:37 +08:00
|
|
|
allocationData.flags.useSystemMemory = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-21 17:16:27 +08:00
|
|
|
switch (properties.allocationType) {
|
|
|
|
case GraphicsAllocation::AllocationType::KERNEL_ISA:
|
|
|
|
case GraphicsAllocation::AllocationType::INTERNAL_HEAP:
|
|
|
|
allocationData.allocationOrigin = AllocationOrigin::INTERNAL_ALLOCATION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-04 21:13:51 +08:00
|
|
|
switch (properties.allocationType) {
|
|
|
|
case GraphicsAllocation::AllocationType::LINEAR_STREAM:
|
|
|
|
case GraphicsAllocation::AllocationType::KERNEL_ISA:
|
|
|
|
case GraphicsAllocation::AllocationType::INTERNAL_HEAP:
|
2019-02-08 15:29:45 +08:00
|
|
|
case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
|
2019-02-04 21:13:51 +08:00
|
|
|
allocationData.flags.requiresCpuAccess = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-09 20:12:32 +08:00
|
|
|
allocationData.flags.mustBeZeroCopy = mustBeZeroCopy;
|
2018-12-06 22:03:06 +08:00
|
|
|
allocationData.flags.allocateMemory = properties.flags.allocateMemory;
|
2018-07-09 20:12:32 +08:00
|
|
|
allocationData.flags.allow32Bit = allow32Bit;
|
|
|
|
allocationData.flags.allow64kbPages = allow64KbPages;
|
|
|
|
allocationData.flags.forcePin = forcePin;
|
|
|
|
allocationData.flags.uncacheable = uncacheable;
|
2018-12-06 22:03:06 +08:00
|
|
|
allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite;
|
2018-12-12 01:56:37 +08:00
|
|
|
allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType;
|
2019-01-07 16:29:49 +08:00
|
|
|
allocationData.flags.multiOsContextCapable = multiOsContextCapable;
|
2018-07-09 20:12:32 +08:00
|
|
|
|
|
|
|
if (allocationData.flags.mustBeZeroCopy) {
|
|
|
|
allocationData.flags.useSystemMemory = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
allocationData.hostPtr = hostPtr;
|
2018-12-06 22:03:06 +08:00
|
|
|
allocationData.size = properties.size;
|
2018-12-12 01:56:37 +08:00
|
|
|
allocationData.type = properties.allocationType;
|
2018-09-23 21:47:27 +08:00
|
|
|
allocationData.devicesBitfield = devicesBitfield;
|
2018-12-06 22:03:06 +08:00
|
|
|
allocationData.alignment = properties.alignment ? properties.alignment : MemoryConstants::preferredAlignment;
|
2018-12-20 23:58:15 +08:00
|
|
|
allocationData.imgInfo = properties.imgInfo;
|
2018-07-09 20:12:32 +08:00
|
|
|
|
|
|
|
if (allocationData.flags.allocateMemory) {
|
|
|
|
allocationData.hostPtr = nullptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-12 01:56:37 +08:00
|
|
|
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr) {
|
2018-07-09 20:12:32 +08:00
|
|
|
AllocationData allocationData;
|
2018-12-12 01:56:37 +08:00
|
|
|
getAllocationData(allocationData, properties, devicesBitfield, hostPtr);
|
2018-07-09 20:12:32 +08:00
|
|
|
|
2019-01-10 18:10:58 +08:00
|
|
|
AllocationStatus status = AllocationStatus::Error;
|
|
|
|
GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
|
2018-07-18 15:48:21 +08:00
|
|
|
if (!allocation && status == AllocationStatus::RetryInNonDevicePool) {
|
|
|
|
allocation = allocateGraphicsMemory(allocationData);
|
|
|
|
}
|
2018-12-12 01:56:37 +08:00
|
|
|
if (allocation) {
|
|
|
|
allocation->setAllocationType(properties.allocationType);
|
|
|
|
}
|
2019-01-29 23:39:48 +08:00
|
|
|
DebugManager.logAllocation(allocation);
|
2018-07-18 15:48:21 +08:00
|
|
|
return allocation;
|
2018-07-09 20:12:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &allocationData) {
|
2019-01-28 20:59:37 +08:00
|
|
|
if (allocationData.type == GraphicsAllocation::AllocationType::IMAGE || allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY) {
|
2018-12-20 23:58:15 +08:00
|
|
|
UNRECOVERABLE_IF(allocationData.imgInfo == nullptr);
|
2019-01-22 19:40:17 +08:00
|
|
|
return allocateGraphicsMemoryForImage(allocationData);
|
2018-12-20 23:58:15 +08:00
|
|
|
}
|
|
|
|
|
2018-12-21 17:16:27 +08:00
|
|
|
if (allocationData.allocationOrigin == AllocationOrigin::INTERNAL_ALLOCATION ||
|
|
|
|
(force32bitAllocations && allocationData.flags.allow32Bit && is64bit)) {
|
|
|
|
return allocate32BitGraphicsMemoryImpl(allocationData);
|
2018-07-09 20:12:32 +08:00
|
|
|
}
|
|
|
|
if (allocationData.hostPtr) {
|
2018-11-30 18:01:33 +08:00
|
|
|
return allocateGraphicsMemoryWithHostPtr(allocationData);
|
2018-07-09 20:12:32 +08:00
|
|
|
}
|
2018-07-11 15:45:20 +08:00
|
|
|
if (peek64kbPagesEnabled() && allocationData.flags.allow64kbPages) {
|
2018-12-06 22:03:06 +08:00
|
|
|
return allocateGraphicsMemory64kb(allocationData);
|
2018-07-09 20:12:32 +08:00
|
|
|
}
|
2018-11-30 18:01:33 +08:00
|
|
|
return allocateGraphicsMemoryWithAlignment(allocationData);
|
2018-07-09 20:12:32 +08:00
|
|
|
}
|
2018-11-29 18:39:10 +08:00
|
|
|
|
2019-01-22 19:40:17 +08:00
|
|
|
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForImage(const AllocationData &allocationData) {
|
|
|
|
auto gmm = std::make_unique<Gmm>(*allocationData.imgInfo);
|
|
|
|
|
|
|
|
// AllocationData needs to be reconfigured for System Memory paths
|
|
|
|
AllocationData allocationDataWithSize = allocationData;
|
|
|
|
allocationDataWithSize.size = allocationData.imgInfo->size;
|
|
|
|
|
|
|
|
auto hostPtrAllocation = allocateGraphicsMemoryForImageFromHostPtr(allocationDataWithSize);
|
|
|
|
|
|
|
|
if (hostPtrAllocation) {
|
|
|
|
hostPtrAllocation->gmm = gmm.release();
|
|
|
|
return hostPtrAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocateGraphicsMemoryForImageImpl(allocationDataWithSize, std::move(gmm));
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:39:10 +08:00
|
|
|
const CsrContainer &MemoryManager::getCommandStreamReceivers() const {
|
|
|
|
return executionEnvironment.commandStreamReceivers;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandStreamReceiver *MemoryManager::getDefaultCommandStreamReceiver(uint32_t deviceId) const {
|
|
|
|
return executionEnvironment.commandStreamReceivers[deviceId][defaultEngineIndex].get();
|
2018-10-01 22:10:54 +08:00
|
|
|
}
|
2018-07-09 20:12:32 +08:00
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
void *MemoryManager::lockResource(GraphicsAllocation *graphicsAllocation) {
|
|
|
|
if (!graphicsAllocation) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-01-24 22:16:12 +08:00
|
|
|
if (graphicsAllocation->isLocked()) {
|
|
|
|
return graphicsAllocation->getLockedPtr();
|
|
|
|
}
|
2019-01-24 18:51:33 +08:00
|
|
|
auto retVal = lockResourceImpl(*graphicsAllocation);
|
2019-01-24 22:16:12 +08:00
|
|
|
graphicsAllocation->lock(retVal);
|
2019-01-24 18:51:33 +08:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) {
|
|
|
|
if (!graphicsAllocation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DEBUG_BREAK_IF(!graphicsAllocation->isLocked());
|
|
|
|
unlockResourceImpl(*graphicsAllocation);
|
2019-01-24 22:16:12 +08:00
|
|
|
graphicsAllocation->unlock();
|
2019-01-24 18:51:33 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|