Skip to content

Commit 71f48c8

Browse files
CacheSettingsHelper - timestamp allocations
Related-To: NEO-6664 Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent c672930 commit 71f48c8

File tree

9 files changed

+78
-33
lines changed

9 files changed

+78
-33
lines changed

opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,13 @@ TEST(GmmTest, givenHwInfoWhenDeviceIsCreatedThenSetThisHwInfoToGmmHelper) {
835835
}
836836

837837
TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) {
838+
const auto hwInfoConfig = HwInfoConfig::get(defaultHwInfo->platform.eProductFamily);
839+
838840
for (uint32_t i = 0; i < static_cast<uint32_t>(AllocationType::COUNT); i++) {
839841
auto allocationType = static_cast<AllocationType>(i);
840842

841843
for (auto forceUncached : {true, false}) {
842-
auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, forceUncached);
844+
auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, forceUncached, *defaultHwInfo);
843845
auto expectedUsage = GMM_RESOURCE_USAGE_UNKNOWN;
844846

845847
switch (allocationType) {
@@ -853,6 +855,11 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) {
853855
case AllocationType::LINEAR_STREAM:
854856
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER;
855857
break;
858+
case AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER:
859+
case AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
860+
expectedUsage = (forceUncached || hwInfoConfig->isDcFlushAllowed()) ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED
861+
: GMM_RESOURCE_USAGE_OCL_BUFFER;
862+
break;
856863
default:
857864
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_BUFFER;
858865
break;
@@ -867,10 +874,10 @@ TEST(GmmTest, givenInternalHeapOrLinearStreamWhenDebugFlagIsSetThenReturnUncache
867874
DebugManagerStateRestore restore;
868875
DebugManager.flags.DisableCachingForHeaps.set(true);
869876

870-
auto usage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, false);
877+
auto usage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, false, *defaultHwInfo);
871878
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage);
872879

873-
usage = CacheSettingsHelper::getGmmUsageType(AllocationType::LINEAR_STREAM, false);
880+
usage = CacheSettingsHelper::getGmmUsageType(AllocationType::LINEAR_STREAM, false, *defaultHwInfo);
874881
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage);
875882
}
876883

shared/source/gmm_helper/cache_settings_helper.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
#include "shared/source/gmm_helper/cache_settings_helper.h"
99

1010
#include "shared/source/debug_settings/debug_settings_manager.h"
11+
#include "shared/source/helpers/hw_info.h"
1112
#include "shared/source/memory_manager/allocation_type.h"
13+
#include "shared/source/os_interface/hw_info_config.h"
1214

1315
namespace NEO {
1416

15-
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType allocationType, bool forceUncached) {
17+
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType allocationType, bool forceUncached, const HardwareInfo &hwInfo) {
1618
if (forceUncached) {
1719
return getDefaultUsageTypeWithCachingDisabled(allocationType);
1820
} else {
19-
return getDefaultUsageTypeWithCachingEnabled(allocationType);
21+
return getDefaultUsageTypeWithCachingEnabled(allocationType, hwInfo);
2022
}
2123
}
2224

23-
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType) {
25+
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const HardwareInfo &hwInfo) {
26+
const auto hwInfoConfig = HwInfoConfig::get(hwInfo.platform.eProductFamily);
27+
2428
switch (allocationType) {
2529
case AllocationType::IMAGE:
2630
return GMM_RESOURCE_USAGE_OCL_IMAGE;
@@ -30,6 +34,12 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching
3034
return getDefaultUsageTypeWithCachingDisabled(allocationType);
3135
}
3236
return GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER;
37+
case AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER:
38+
case AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
39+
if (hwInfoConfig->isDcFlushAllowed()) {
40+
return getDefaultUsageTypeWithCachingDisabled(allocationType);
41+
}
42+
[[fallthrough]];
3343
default:
3444
return GMM_RESOURCE_USAGE_OCL_BUFFER;
3545
}

shared/source/gmm_helper/cache_settings_helper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
namespace NEO {
1212
enum class AllocationType;
13+
struct HardwareInfo;
1314

1415
struct CacheSettingsHelper {
15-
static GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached);
16+
static GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached, const HardwareInfo &hwInfo);
1617

1718
protected:
18-
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType);
19+
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const HardwareInfo &hwInfo);
1920
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType);
2021
};
2122
} // namespace NEO

shared/source/gmm_helper/gmm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void Gmm::setupImageResourceParams(ImageInfo &imgInfo, bool preferCompressed) {
117117

118118
resourceParams.NoGfxMemory = 1; // dont allocate, only query for params
119119

120-
resourceParams.Usage = CacheSettingsHelper::getGmmUsageType(AllocationType::IMAGE, false);
120+
resourceParams.Usage = CacheSettingsHelper::getGmmUsageType(AllocationType::IMAGE, false, *clientContext->getHardwareInfo());
121121

122122
resourceParams.Format = imgInfo.surfaceFormat->GMMSurfaceFormat;
123123
resourceParams.Flags.Gpu.Texture = 1;

shared/source/helpers/state_base_address_base.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(
7777
stateBaseAddress->setInstructionBufferSizeModifyEnable(true);
7878
stateBaseAddress->setInstructionBufferSize(MemoryConstants::sizeOf4GBinPageEntities);
7979

80-
auto resourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get());
80+
auto resourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get(), *gmmHelper->getHardwareInfo());
8181

8282
stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(resourceUsage));
8383
}

shared/source/helpers/state_base_address_xehp_and_later.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void StateBaseAddressHelper<GfxFamily>::appendStateBaseAddressParameters(
5353

5454
stateBaseAddress->setBindlessSamplerStateBaseAddressModifyEnable(true);
5555

56-
auto heapResourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get());
56+
auto heapResourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get(), *gmmHelper->getHardwareInfo());
5757
auto heapMocsValue = gmmHelper->getMOCS(heapResourceUsage);
5858

5959
stateBaseAddress->setSurfaceStateMemoryObjectControlState(heapMocsValue);

shared/source/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
111111
allocationData.hostPtr,
112112
sizeAligned,
113113
alignment,
114-
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable),
114+
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable, *pHwInfo),
115115
true,
116116
allocationData.storageInfo,
117117
true);
@@ -162,7 +162,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al
162162
allocationData.hostPtr,
163163
allocationDataAlign.size,
164164
allocationDataAlign.alignment,
165-
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable),
165+
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable, *hwInfo),
166166
allocationData.flags.preferCompressed,
167167
allocationData.storageInfo, true);
168168
memoryAllocation->setDefaultGmm(gmm.release());
@@ -348,8 +348,10 @@ void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uin
348348
}
349349

350350
GraphicsAllocation *OsAgnosticMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
351+
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
352+
351353
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr,
352-
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable),
354+
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable, *hwInfo),
353355
allocationData.flags.preferCompressed, allocationData.storageInfo, true);
354356

355357
GraphicsAllocation *alloc = nullptr;
@@ -478,11 +480,12 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(
478480
sizeAligned64k = alignUp(allocationData.size, MemoryConstants::pageSize64k);
479481
if (DebugManager.flags.RenderCompressedBuffersEnabled.get() &&
480482
allocationData.flags.preferCompressed) {
483+
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
481484
gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(),
482485
allocationData.hostPtr,
483486
sizeAligned64k,
484487
MemoryConstants::pageSize64k,
485-
CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable),
488+
CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable, *hwInfo),
486489
true,
487490
allocationData.storageInfo,
488491
true);

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/source/execution_environment/execution_environment.h"
1212
#include "shared/source/execution_environment/root_device_environment.h"
1313
#include "shared/source/gmm_helper/cache_settings_helper.h"
14+
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
1415
#include "shared/source/gmm_helper/gmm.h"
1516
#include "shared/source/gmm_helper/gmm_helper.h"
1617
#include "shared/source/gmm_helper/resource_info.h"
@@ -482,9 +483,11 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory64kb(const AllocationData
482483
}
483484

484485
GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
486+
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
487+
485488
StorageInfo systemMemoryStorageInfo = {};
486489
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr,
487-
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable), false, systemMemoryStorageInfo, true);
490+
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable, *hwInfo), false, systemMemoryStorageInfo, true);
488491
size_t bufferSize = allocationData.size;
489492
uint64_t gpuRange = acquireGpuRange(bufferSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD64KB);
490493

@@ -1210,7 +1213,7 @@ void createColouredGmms(GmmClientContext *clientContext, DrmAllocation &allocati
12101213
nullptr,
12111214
currentSize,
12121215
0u,
1213-
CacheSettingsHelper::getGmmUsageType(allocation.getAllocationType(), false),
1216+
CacheSettingsHelper::getGmmUsageType(allocation.getAllocationType(), false, *clientContext->getHardwareInfo()),
12141217
compression,
12151218
limitedStorageInfo,
12161219
true);
@@ -1224,7 +1227,8 @@ void fillGmmsInAllocation(GmmClientContext *clientContext, DrmAllocation *alloca
12241227
StorageInfo limitedStorageInfo = storageInfo;
12251228
limitedStorageInfo.memoryBanks &= 1u << handleId;
12261229
limitedStorageInfo.pageTablesVisibility &= 1u << handleId;
1227-
auto gmm = new Gmm(clientContext, nullptr, alignedSize, 0u, CacheSettingsHelper::getGmmUsageType(allocation->getAllocationType(), false), false, limitedStorageInfo, true);
1230+
auto gmm = new Gmm(clientContext, nullptr, alignedSize, 0u,
1231+
CacheSettingsHelper::getGmmUsageType(allocation->getAllocationType(), false, *clientContext->getHardwareInfo()), false, limitedStorageInfo, true);
12281232
allocation->setGmm(gmm, handleId);
12291233
}
12301234
}
@@ -1273,6 +1277,8 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
12731277
return allocation;
12741278
}
12751279

1280+
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
1281+
12761282
std::unique_ptr<Gmm> gmm;
12771283
size_t sizeAligned = 0;
12781284
auto numHandles = allocationData.storageInfo.getNumBanks();
@@ -1289,11 +1295,12 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
12891295
sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k);
12901296
}
12911297
if (createSingleHandle) {
1298+
12921299
gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(),
12931300
nullptr,
12941301
sizeAligned,
12951302
0u,
1296-
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable),
1303+
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable, *hwInfo),
12971304
allocationData.flags.preferCompressed,
12981305
allocationData.storageInfo,
12991306
true);
@@ -1302,7 +1309,6 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
13021309

13031310
auto sizeAllocated = sizeAligned;
13041311
auto gfxPartition = getGfxPartition(allocationData.rootDeviceIndex);
1305-
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
13061312
auto gpuAddress = getGpuAddress(this->alignmentSelector, this->heapAssigner, *hwInfo,
13071313
allocationData.type, gfxPartition, sizeAllocated,
13081314
allocationData.hostPtr, allocationData.flags.resource48Bit, allocationData.flags.use32BitFrontWindow);

0 commit comments

Comments
 (0)