2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-01-10 17:16:08 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-09-17 21:26:09 +02:00
|
|
|
#include "graphics_allocation.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2022-05-05 12:01:59 +00:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2021-05-19 11:20:56 +00:00
|
|
|
#include "shared/source/gmm_helper/gmm.h"
|
2021-10-20 16:16:59 +00:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2022-12-06 11:19:36 +00:00
|
|
|
#include "shared/source/helpers/bit_helpers.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2023-01-10 17:16:08 +00:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2021-09-24 16:40:29 +00:00
|
|
|
#include "shared/source/utilities/logger.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-12-20 17:38:38 +01:00
|
|
|
void GraphicsAllocation::setAllocationType(AllocationType allocationType) {
|
2023-02-02 09:52:35 +00:00
|
|
|
if (this->allocationType != allocationType) {
|
|
|
|
|
this->allocationType = allocationType;
|
|
|
|
|
fileLoggerInstance().logAllocation(this);
|
|
|
|
|
}
|
2018-12-20 17:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-30 14:18:50 +00:00
|
|
|
GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, uint64_t canonizedGpuAddress,
|
2022-06-01 21:13:52 +00:00
|
|
|
uint64_t baseAddress, size_t sizeIn, MemoryPool pool, size_t maxOsContextCount)
|
2019-11-04 16:03:30 +01:00
|
|
|
: rootDeviceIndex(rootDeviceIndex),
|
|
|
|
|
gpuBaseAddress(baseAddress),
|
2022-05-30 14:18:50 +00:00
|
|
|
gpuAddress(canonizedGpuAddress),
|
2019-03-13 15:31:46 +01:00
|
|
|
size(sizeIn),
|
|
|
|
|
cpuPtr(cpuPtrIn),
|
2019-02-26 11:37:51 +01:00
|
|
|
memoryPool(pool),
|
2019-12-17 08:11:16 +01:00
|
|
|
allocationType(allocationType),
|
2022-05-10 10:46:08 +00:00
|
|
|
usageInfos(maxOsContextCount),
|
|
|
|
|
residency(maxOsContextCount) {
|
2020-04-21 13:16:45 +02:00
|
|
|
gmms.resize(numGmms);
|
2019-02-27 14:59:46 +01:00
|
|
|
}
|
2019-02-11 10:02:27 +01:00
|
|
|
|
2020-04-21 13:16:45 +02:00
|
|
|
GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn,
|
2022-06-03 11:48:45 +00:00
|
|
|
osHandle sharedHandleIn, MemoryPool pool, size_t maxOsContextCount, uint64_t canonizedGpuAddress)
|
2019-11-04 16:03:30 +01:00
|
|
|
: rootDeviceIndex(rootDeviceIndex),
|
2022-06-03 11:48:45 +00:00
|
|
|
gpuAddress(canonizedGpuAddress),
|
2019-03-13 15:31:46 +01:00
|
|
|
size(sizeIn),
|
2019-02-11 10:02:27 +01:00
|
|
|
cpuPtr(cpuPtrIn),
|
2019-02-26 11:37:51 +01:00
|
|
|
memoryPool(pool),
|
2019-12-17 08:11:16 +01:00
|
|
|
allocationType(allocationType),
|
2022-05-10 10:46:08 +00:00
|
|
|
usageInfos(maxOsContextCount),
|
|
|
|
|
residency(maxOsContextCount) {
|
2019-02-27 14:59:46 +01:00
|
|
|
sharingInfo.sharedHandle = sharedHandleIn;
|
2020-04-21 13:16:45 +02:00
|
|
|
gmms.resize(numGmms);
|
2019-02-27 14:59:46 +01:00
|
|
|
}
|
2018-11-02 10:01:56 +01:00
|
|
|
|
|
|
|
|
GraphicsAllocation::~GraphicsAllocation() = default;
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
void GraphicsAllocation::updateTaskCount(TaskCountType newTaskCount, uint32_t contextId) {
|
2018-11-07 08:33:55 +00:00
|
|
|
if (usageInfos[contextId].taskCount == objectNotUsed) {
|
2018-11-02 10:01:56 +01:00
|
|
|
registeredContextsNum++;
|
|
|
|
|
}
|
2018-11-07 08:33:55 +00:00
|
|
|
if (newTaskCount == objectNotUsed) {
|
2018-11-02 10:01:56 +01:00
|
|
|
registeredContextsNum--;
|
|
|
|
|
}
|
2018-11-06 11:38:49 +01:00
|
|
|
usageInfos[contextId].taskCount = newTaskCount;
|
2018-11-02 10:01:56 +01:00
|
|
|
}
|
2018-12-20 17:38:38 +01:00
|
|
|
|
|
|
|
|
std::string GraphicsAllocation::getAllocationInfoString() const {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 12:29:21 +02:00
|
|
|
uint32_t GraphicsAllocation::getUsedPageSize() const {
|
|
|
|
|
switch (this->memoryPool) {
|
|
|
|
|
case MemoryPool::System64KBPages:
|
|
|
|
|
case MemoryPool::System64KBPagesWith32BitGpuAddressing:
|
|
|
|
|
case MemoryPool::LocalMemory:
|
|
|
|
|
return MemoryConstants::pageSize64k;
|
|
|
|
|
default:
|
|
|
|
|
return MemoryConstants::pageSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 11:20:56 +00:00
|
|
|
bool GraphicsAllocation::isAllocationLockable() const {
|
|
|
|
|
auto gmm = getDefaultGmm();
|
|
|
|
|
if (!gmm) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return 0 == gmm->resourceParams.Flags.Info.NotLockable;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 16:23:56 +00:00
|
|
|
void GraphicsAllocation::setAubWritable(bool writable, uint32_t banks) {
|
|
|
|
|
UNRECOVERABLE_IF(banks == 0);
|
|
|
|
|
aubInfo.aubWritable = static_cast<uint32_t>(setBits(aubInfo.aubWritable, writable, banks));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GraphicsAllocation::isAubWritable(uint32_t banks) const {
|
|
|
|
|
return isAnyBitSet(aubInfo.aubWritable, banks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphicsAllocation::setTbxWritable(bool writable, uint32_t banks) {
|
|
|
|
|
UNRECOVERABLE_IF(banks == 0);
|
|
|
|
|
aubInfo.tbxWritable = static_cast<uint32_t>(setBits(aubInfo.tbxWritable, writable, banks));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 18:11:27 +00:00
|
|
|
bool GraphicsAllocation::isCompressionEnabled() const {
|
|
|
|
|
return (getDefaultGmm() && getDefaultGmm()->isCompressionEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 16:23:56 +00:00
|
|
|
bool GraphicsAllocation::isTbxWritable(uint32_t banks) const {
|
|
|
|
|
return isAnyBitSet(aubInfo.tbxWritable, banks);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 12:01:59 +00:00
|
|
|
void GraphicsAllocation::prepareHostPtrForResidency(CommandStreamReceiver *csr) {
|
|
|
|
|
if (hostPtrTaskCountAssignment > 0) {
|
|
|
|
|
auto allocTaskCount = getTaskCount(csr->getOsContext().getContextId());
|
|
|
|
|
auto currentTaskCount = csr->peekTaskCount() + 1;
|
2023-05-22 11:07:09 +00:00
|
|
|
if (currentTaskCount > allocTaskCount || allocTaskCount == GraphicsAllocation::objectNotResident) {
|
2022-05-05 12:01:59 +00:00
|
|
|
updateTaskCount(currentTaskCount, csr->getOsContext().getContextId());
|
|
|
|
|
hostPtrTaskCountAssignment--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 23:43:35 +00:00
|
|
|
uint32_t GraphicsAllocation::getNumHandlesForKmdSharedAllocation(uint32_t numBanks) {
|
2023-11-30 08:32:25 +00:00
|
|
|
return (numBanks > 1) && (debugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.get() != 0) ? numBanks : 1u;
|
2022-11-16 23:43:35 +00:00
|
|
|
}
|
2023-07-21 11:55:22 +00:00
|
|
|
|
2023-11-17 13:14:41 +00:00
|
|
|
void GraphicsAllocation::updateCompletionDataForAllocationAndFragments(uint64_t newFenceValue, uint32_t contextId) {
|
|
|
|
|
getResidencyData().updateCompletionData(newFenceValue, contextId);
|
|
|
|
|
|
|
|
|
|
for (uint32_t allocationId = 0; allocationId < fragmentsStorage.fragmentCount; allocationId++) {
|
|
|
|
|
auto residencyData = fragmentsStorage.fragmentStorageData[allocationId].residency;
|
|
|
|
|
residencyData->updateCompletionData(newFenceValue, contextId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
constexpr TaskCountType GraphicsAllocation::objectNotUsed;
|
|
|
|
|
constexpr TaskCountType GraphicsAllocation::objectNotResident;
|
|
|
|
|
constexpr TaskCountType GraphicsAllocation::objectAlwaysResident;
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|