Skip to content

Commit 42e58fd

Browse files
Fix pNext usage for ZE_STRUCTURE_TYPE_DEVICE_MEMORY_EXT_PROPERTIES
Signed-off-by: Joshua Santosh Ranjan <[email protected]>
1 parent e151bc6 commit 42e58fd

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

level_zero/core/source/device/device_imp.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,11 @@ ze_result_t DeviceImp::getMemoryProperties(uint32_t *pCount, ze_device_memory_pr
488488

489489
pMemProperties->flags = 0;
490490

491-
void *pNext = pMemProperties->pNext;
491+
ze_base_properties_t *pNext = static_cast<ze_base_properties_t *>(pMemProperties->pNext);
492492
while (pNext) {
493-
auto extendedProperties = reinterpret_cast<ze_device_memory_ext_properties_t *>(pMemProperties->pNext);
494-
if (extendedProperties->stype == ZE_STRUCTURE_TYPE_DEVICE_MEMORY_EXT_PROPERTIES) {
493+
494+
if (pNext->stype == ZE_STRUCTURE_TYPE_DEVICE_MEMORY_EXT_PROPERTIES) {
495+
auto extendedProperties = reinterpret_cast<ze_device_memory_ext_properties_t *>(pNext);
495496

496497
// GT_MEMORY_TYPES map to ze_device_memory_ext_type_t
497498
const std::array<ze_device_memory_ext_type_t, 5> sysInfoMemType = {
@@ -516,7 +517,7 @@ ze_result_t DeviceImp::getMemoryProperties(uint32_t *pCount, ze_device_memory_pr
516517
extendedProperties->writeBandwidth = extendedProperties->readBandwidth;
517518
extendedProperties->bandwidthUnit = ZE_BANDWIDTH_UNIT_BYTES_PER_NANOSEC;
518519
}
519-
pNext = const_cast<void *>(extendedProperties->pNext);
520+
pNext = static_cast<ze_base_properties_t *>(pNext->pNext);
520521
}
521522

522523
return ZE_RESULT_SUCCESS;

level_zero/core/test/unit_tests/sources/device/test_device.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,46 @@ HWTEST2_F(DeviceGetMemoryTests, whenCallingGetMemoryPropertiesForMemoryExtProper
16171617
EXPECT_EQ(memExtProperties.bandwidthUnit, ZE_BANDWIDTH_UNIT_BYTES_PER_NANOSEC);
16181618
}
16191619

1620+
HWTEST2_F(DeviceGetMemoryTests, whenCallingGetMemoryPropertiesWith2LevelsOfPnextForMemoryExtPropertiesThenPropertiesAreReturned, MatchAny) {
1621+
uint32_t count = 0;
1622+
ze_result_t res = device->getMemoryProperties(&count, nullptr);
1623+
EXPECT_EQ(res, ZE_RESULT_SUCCESS);
1624+
EXPECT_EQ(1u, count);
1625+
1626+
auto hwInfo = *NEO::defaultHwInfo;
1627+
MockHwInfoConfigHw<productFamily> hwInfoConfig;
1628+
VariableBackup<HwInfoConfig *> hwInfoConfigFactoryBackup{&NEO::hwInfoConfigFactory[static_cast<size_t>(hwInfo.platform.eProductFamily)]};
1629+
hwInfoConfigFactoryBackup = &hwInfoConfig;
1630+
1631+
ze_device_memory_properties_t memProperties = {};
1632+
ze_base_properties_t baseProperties{};
1633+
ze_device_memory_ext_properties_t memExtProperties = {};
1634+
memExtProperties.stype = ZE_STRUCTURE_TYPE_DEVICE_MEMORY_EXT_PROPERTIES;
1635+
// Setting up the 1st level pNext
1636+
memProperties.pNext = &baseProperties;
1637+
// Setting up the 2nd level pNext with device memory properties
1638+
baseProperties.pNext = &memExtProperties;
1639+
1640+
res = device->getMemoryProperties(&count, &memProperties);
1641+
EXPECT_EQ(res, ZE_RESULT_SUCCESS);
1642+
EXPECT_EQ(1u, count);
1643+
const std::array<ze_device_memory_ext_type_t, 5> sysInfoMemType = {
1644+
ZE_DEVICE_MEMORY_EXT_TYPE_LPDDR4,
1645+
ZE_DEVICE_MEMORY_EXT_TYPE_LPDDR5,
1646+
ZE_DEVICE_MEMORY_EXT_TYPE_HBM2,
1647+
ZE_DEVICE_MEMORY_EXT_TYPE_HBM2,
1648+
ZE_DEVICE_MEMORY_EXT_TYPE_GDDR6,
1649+
};
1650+
1651+
auto bandwidthPerNanoSecond = hwInfoConfig.getDeviceMemoryMaxBandWidthInBytesPerSecond(hwInfo, nullptr, 0) / 1000000000;
1652+
1653+
EXPECT_EQ(memExtProperties.type, sysInfoMemType[hwInfo.gtSystemInfo.MemoryType]);
1654+
EXPECT_EQ(memExtProperties.physicalSize, hwInfoConfig.getDeviceMemoryPhysicalSizeInBytes(nullptr, 0));
1655+
EXPECT_EQ(memExtProperties.readBandwidth, bandwidthPerNanoSecond);
1656+
EXPECT_EQ(memExtProperties.writeBandwidth, memExtProperties.readBandwidth);
1657+
EXPECT_EQ(memExtProperties.bandwidthUnit, ZE_BANDWIDTH_UNIT_BYTES_PER_NANOSEC);
1658+
}
1659+
16201660
TEST_F(DeviceGetMemoryTests, whenCallingGetMemoryPropertiesWhenPnextIsNonNullAndStypeIsUnSupportedThenNoErrorIsReturned) {
16211661
uint32_t count = 0;
16221662
ze_result_t res = device->getMemoryProperties(&count, nullptr);

0 commit comments

Comments
 (0)