2019-02-20 21:03:04 +08:00
|
|
|
/*
|
2022-01-12 23:32:07 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2019-02-20 21:03:04 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-04-24 00:43:48 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
#include "shared/source/helpers/app_resource_helper.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2019-02-20 21:03:04 +08:00
|
|
|
|
2021-04-24 00:43:48 +08:00
|
|
|
#include <bitset>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-05-06 16:35:49 +08:00
|
|
|
StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationProperties &properties) {
|
2021-04-24 00:43:48 +08:00
|
|
|
if (properties.subDevicesBitfield.count() == 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto deviceCount = HwHelper::getSubDevicesCount(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getHardwareInfo());
|
2021-07-22 14:36:45 +08:00
|
|
|
const auto leastOccupiedBank = getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->getLeastOccupiedBank(properties.subDevicesBitfield);
|
2021-04-24 00:43:48 +08:00
|
|
|
const auto subDevicesMask = executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->deviceAffinityMask.getGenericSubDevicesMask().to_ulong();
|
|
|
|
|
|
|
|
const DeviceBitfield allTilesValue(properties.subDevicesBitfield.count() == 1
|
|
|
|
? maxNBitValue(deviceCount) & subDevicesMask
|
|
|
|
: properties.subDevicesBitfield);
|
|
|
|
DeviceBitfield preferredTile;
|
|
|
|
if (properties.subDevicesBitfield.count() == 1) {
|
|
|
|
preferredTile = properties.subDevicesBitfield;
|
|
|
|
} else {
|
|
|
|
UNRECOVERABLE_IF(!properties.subDevicesBitfield.test(leastOccupiedBank));
|
|
|
|
preferredTile.set(leastOccupiedBank);
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageInfo storageInfo{preferredTile, allTilesValue};
|
2021-08-04 19:56:36 +08:00
|
|
|
storageInfo.subDeviceBitfield = properties.subDevicesBitfield;
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.isLockable = GraphicsAllocation::isLockable(properties.allocationType);
|
|
|
|
storageInfo.cpuVisibleSegment = GraphicsAllocation::isCpuAccessRequired(properties.allocationType);
|
|
|
|
|
|
|
|
AppResourceHelper::copyResourceTagStr(storageInfo.resourceTag, properties.allocationType,
|
|
|
|
sizeof(storageInfo.resourceTag));
|
|
|
|
|
|
|
|
switch (properties.allocationType) {
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::KERNEL_ISA:
|
|
|
|
case AllocationType::KERNEL_ISA_INTERNAL:
|
|
|
|
case AllocationType::DEBUG_MODULE_AREA: {
|
2021-08-02 19:36:19 +08:00
|
|
|
auto placeIsaOnMultiTile = (properties.subDevicesBitfield.count() != 1);
|
2021-04-24 00:43:48 +08:00
|
|
|
|
2021-09-08 15:44:06 +08:00
|
|
|
if (executionEnvironment.isDebuggingEnabled()) {
|
2021-04-24 00:43:48 +08:00
|
|
|
placeIsaOnMultiTile = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugManager.flags.MultiTileIsaPlacement.get() != -1) {
|
|
|
|
placeIsaOnMultiTile = !!DebugManager.flags.MultiTileIsaPlacement.get();
|
|
|
|
}
|
|
|
|
if (placeIsaOnMultiTile) {
|
|
|
|
storageInfo.cloningOfPageTables = false;
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.tileInstanced = true;
|
|
|
|
} else {
|
|
|
|
storageInfo.cloningOfPageTables = true;
|
2021-08-02 19:36:19 +08:00
|
|
|
storageInfo.memoryBanks = preferredTile;
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.tileInstanced = false;
|
|
|
|
}
|
|
|
|
} break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::DEBUG_CONTEXT_SAVE_AREA:
|
|
|
|
case AllocationType::WORK_PARTITION_SURFACE:
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.cloningOfPageTables = false;
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.tileInstanced = true;
|
|
|
|
break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::PRIVATE_SURFACE:
|
2021-08-20 17:46:20 +08:00
|
|
|
storageInfo.cloningOfPageTables = false;
|
|
|
|
|
|
|
|
if (properties.subDevicesBitfield.count() == 1) {
|
|
|
|
storageInfo.memoryBanks = preferredTile;
|
|
|
|
storageInfo.pageTablesVisibility = preferredTile;
|
|
|
|
} else {
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.tileInstanced = true;
|
|
|
|
}
|
|
|
|
break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::COMMAND_BUFFER:
|
|
|
|
case AllocationType::INTERNAL_HEAP:
|
|
|
|
case AllocationType::LINEAR_STREAM:
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.cloningOfPageTables = properties.flags.multiOsContextCapable;
|
|
|
|
storageInfo.memoryBanks = preferredTile;
|
|
|
|
if (!properties.flags.multiOsContextCapable) {
|
|
|
|
storageInfo.pageTablesVisibility = preferredTile;
|
|
|
|
}
|
|
|
|
break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::SCRATCH_SURFACE:
|
|
|
|
case AllocationType::PREEMPTION:
|
2021-04-24 00:43:48 +08:00
|
|
|
if (properties.flags.multiOsContextCapable) {
|
|
|
|
storageInfo.cloningOfPageTables = false;
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.tileInstanced = true;
|
|
|
|
} else {
|
|
|
|
storageInfo.memoryBanks = preferredTile;
|
|
|
|
storageInfo.pageTablesVisibility = preferredTile;
|
|
|
|
}
|
|
|
|
break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER:
|
2022-02-24 05:42:23 +08:00
|
|
|
storageInfo.cloningOfPageTables = true;
|
|
|
|
if (!properties.flags.multiOsContextCapable) {
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.pageTablesVisibility = preferredTile;
|
|
|
|
}
|
|
|
|
break;
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::BUFFER:
|
|
|
|
case AllocationType::SVM_GPU: {
|
2021-10-04 23:23:42 +08:00
|
|
|
auto colouringPolicy = properties.colouringPolicy;
|
|
|
|
auto granularity = properties.colouringGranularity;
|
|
|
|
|
2021-10-21 01:07:51 +08:00
|
|
|
if (DebugManager.flags.MultiStoragePolicy.get() != -1) {
|
|
|
|
colouringPolicy = static_cast<ColouringPolicy>(DebugManager.flags.MultiStoragePolicy.get());
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:23:42 +08:00
|
|
|
if (DebugManager.flags.MultiStorageGranularity.get() != -1) {
|
|
|
|
granularity = DebugManager.flags.MultiStorageGranularity.get() * MemoryConstants::kiloByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_BREAK_IF(colouringPolicy == ColouringPolicy::DeviceCountBased && granularity != MemoryConstants::pageSize64k);
|
|
|
|
|
2021-04-24 00:43:48 +08:00
|
|
|
if (this->supportsMultiStorageResources &&
|
|
|
|
properties.multiStorageResource &&
|
2021-10-04 23:23:42 +08:00
|
|
|
properties.size >= deviceCount * granularity &&
|
2021-04-24 00:43:48 +08:00
|
|
|
properties.subDevicesBitfield.count() != 1u) {
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.multiStorage = true;
|
2021-10-04 23:23:42 +08:00
|
|
|
storageInfo.colouringPolicy = colouringPolicy;
|
|
|
|
storageInfo.colouringGranularity = granularity;
|
2021-04-24 00:43:48 +08:00
|
|
|
if (DebugManager.flags.OverrideMultiStoragePlacement.get() != -1) {
|
|
|
|
storageInfo.memoryBanks = DebugManager.flags.OverrideMultiStoragePlacement.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (properties.flags.readOnlyMultiStorage) {
|
|
|
|
storageInfo.readOnlyMultiStorage = true;
|
|
|
|
storageInfo.cloningOfPageTables = false;
|
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
storageInfo.tileInstanced = true;
|
|
|
|
}
|
|
|
|
storageInfo.localOnlyRequired = true;
|
2022-01-12 23:32:07 +08:00
|
|
|
|
|
|
|
if (properties.flags.shareable) {
|
|
|
|
storageInfo.isLockable = false;
|
|
|
|
}
|
2021-04-24 00:43:48 +08:00
|
|
|
break;
|
2021-10-04 23:23:42 +08:00
|
|
|
}
|
2022-02-04 21:59:01 +08:00
|
|
|
case AllocationType::UNIFIED_SHARED_MEMORY:
|
2021-04-24 00:43:48 +08:00
|
|
|
storageInfo.memoryBanks = allTilesValue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-03-17 02:41:29 +08:00
|
|
|
|
2022-03-23 23:04:33 +08:00
|
|
|
bool forceLocalMemoryForDirectSubmission = true;
|
2022-03-17 02:41:29 +08:00
|
|
|
switch (DebugManager.flags.DirectSubmissionForceLocalMemoryStorageMode.get()) {
|
|
|
|
case 0:
|
|
|
|
forceLocalMemoryForDirectSubmission = false;
|
|
|
|
break;
|
2022-03-23 23:04:33 +08:00
|
|
|
case 1:
|
|
|
|
forceLocalMemoryForDirectSubmission = properties.flags.multiOsContextCapable;
|
2022-03-17 02:41:29 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forceLocalMemoryForDirectSubmission) {
|
|
|
|
if (properties.allocationType == AllocationType::COMMAND_BUFFER ||
|
|
|
|
properties.allocationType == AllocationType::RING_BUFFER ||
|
|
|
|
properties.allocationType == AllocationType::SEMAPHORE_BUFFER) {
|
2022-03-23 23:04:33 +08:00
|
|
|
if (properties.flags.multiOsContextCapable) {
|
|
|
|
storageInfo.memoryBanks = {};
|
|
|
|
for (auto bank = 0u; bank < deviceCount; bank++) {
|
|
|
|
if (allTilesValue.test(bank)) {
|
|
|
|
storageInfo.memoryBanks.set(bank);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-17 02:41:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UNRECOVERABLE_IF(storageInfo.memoryBanks.none());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-24 00:43:48 +08:00
|
|
|
return storageInfo;
|
|
|
|
}
|
|
|
|
uint32_t StorageInfo::getNumBanks() const {
|
|
|
|
if (memoryBanks == 0) {
|
|
|
|
return 1u;
|
|
|
|
}
|
|
|
|
return static_cast<uint32_t>(memoryBanks.count());
|
2019-02-20 21:03:04 +08:00
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|