From 86c8b87c8b5331af473677deb2be4c64f2ff12bd Mon Sep 17 00:00:00 2001 From: Brandon Yates Date: Mon, 6 Apr 2020 16:34:35 -0400 Subject: [PATCH] Fixing unset bytes in device properties Change-Id: I2c5cb68e013b26c43c9f1bad45507e4a03e939f4 Signed-off-by: Brandon Yates --- level_zero/core/source/device/device_imp.cpp | 2 + .../unit_tests/sources/device/test_device.cpp | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 22cbd252b6..2f56f1c388 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -310,6 +310,7 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) uint32_t rootDeviceIndex = this->neoDevice->getRootDeviceIndex(); + memset(pDeviceProperties->uuid.id, 0, ZE_MAX_DEVICE_UUID_SIZE); memcpy_s(pDeviceProperties->uuid.id, sizeof(uint32_t), &pDeviceProperties->vendorId, sizeof(pDeviceProperties->vendorId)); memcpy_s(pDeviceProperties->uuid.id + sizeof(uint32_t), sizeof(uint32_t), &pDeviceProperties->deviceId, sizeof(pDeviceProperties->deviceId)); memcpy_s(pDeviceProperties->uuid.id + (2 * sizeof(uint32_t)), sizeof(uint32_t), &rootDeviceIndex, sizeof(rootDeviceIndex)); @@ -346,6 +347,7 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) pDeviceProperties->timerResolution = this->neoDevice->getDeviceInfo().outProfilingTimerResolution; + memset(pDeviceProperties->name, 0, ZE_MAX_DEVICE_NAME); std::string name = "Intel(R) "; name += NEO::familyName[hardwareInfo.platform.eRenderCoreFamily]; name += '\0'; diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index a9ce17f8c5..4c766a8faf 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -95,6 +95,57 @@ TEST_F(DeviceTest, givenDeviceWithCopyEngineThenNumAsyncCopyEnginesDevicePropert EXPECT_EQ(expecteNumOfCopyEngines, deviceProperties.numAsyncCopyEngines); } +TEST_F(DeviceTest, givenDevicePropertiesStructureWhenDevicePropertiesCalledThenAllPropertiesAreAssigned) { + ze_device_properties_t deviceProperties, devicePropertiesBefore; + + deviceProperties.type = ZE_DEVICE_TYPE_FPGA; + memset(&deviceProperties.vendorId, std::numeric_limits::max(), sizeof(deviceProperties.vendorId)); + memset(&deviceProperties.deviceId, std::numeric_limits::max(), sizeof(deviceProperties.deviceId)); + memset(&deviceProperties.uuid, std::numeric_limits::max(), sizeof(deviceProperties.uuid)); + memset(&deviceProperties.isSubdevice, std::numeric_limits::max(), sizeof(deviceProperties.isSubdevice)); + memset(&deviceProperties.subdeviceId, std::numeric_limits::max(), sizeof(deviceProperties.subdeviceId)); + memset(&deviceProperties.coreClockRate, std::numeric_limits::max(), sizeof(deviceProperties.coreClockRate)); + memset(&deviceProperties.unifiedMemorySupported, std::numeric_limits::max(), sizeof(deviceProperties.unifiedMemorySupported)); + memset(&deviceProperties.eccMemorySupported, std::numeric_limits::max(), sizeof(deviceProperties.eccMemorySupported)); + memset(&deviceProperties.onDemandPageFaultsSupported, std::numeric_limits::max(), sizeof(deviceProperties.onDemandPageFaultsSupported)); + memset(&deviceProperties.maxCommandQueues, std::numeric_limits::max(), sizeof(deviceProperties.maxCommandQueues)); + memset(&deviceProperties.numAsyncComputeEngines, std::numeric_limits::max(), sizeof(deviceProperties.numAsyncComputeEngines)); + memset(&deviceProperties.numAsyncCopyEngines, std::numeric_limits::max(), sizeof(deviceProperties.numAsyncCopyEngines)); + memset(&deviceProperties.maxCommandQueuePriority, std::numeric_limits::max(), sizeof(deviceProperties.maxCommandQueuePriority)); + memset(&deviceProperties.numThreadsPerEU, std::numeric_limits::max(), sizeof(deviceProperties.numThreadsPerEU)); + memset(&deviceProperties.physicalEUSimdWidth, std::numeric_limits::max(), sizeof(deviceProperties.physicalEUSimdWidth)); + memset(&deviceProperties.numEUsPerSubslice, std::numeric_limits::max(), sizeof(deviceProperties.numEUsPerSubslice)); + memset(&deviceProperties.numSubslicesPerSlice, std::numeric_limits::max(), sizeof(deviceProperties.numSubslicesPerSlice)); + memset(&deviceProperties.numSlices, std::numeric_limits::max(), sizeof(deviceProperties.numSlices)); + memset(&deviceProperties.timerResolution, std::numeric_limits::max(), sizeof(deviceProperties.timerResolution)); + memset(&deviceProperties.name, std::numeric_limits::max(), sizeof(deviceProperties.name)); + + devicePropertiesBefore = deviceProperties; + device->getProperties(&deviceProperties); + + EXPECT_NE(deviceProperties.type, devicePropertiesBefore.type); + EXPECT_NE(deviceProperties.vendorId, devicePropertiesBefore.vendorId); + EXPECT_NE(deviceProperties.deviceId, devicePropertiesBefore.deviceId); + EXPECT_NE(0, memcmp(&deviceProperties.uuid, &devicePropertiesBefore.uuid, sizeof(devicePropertiesBefore.uuid))); + EXPECT_NE(deviceProperties.isSubdevice, devicePropertiesBefore.isSubdevice); + EXPECT_NE(deviceProperties.subdeviceId, devicePropertiesBefore.subdeviceId); + EXPECT_NE(deviceProperties.coreClockRate, devicePropertiesBefore.coreClockRate); + EXPECT_NE(deviceProperties.unifiedMemorySupported, devicePropertiesBefore.unifiedMemorySupported); + EXPECT_NE(deviceProperties.eccMemorySupported, devicePropertiesBefore.eccMemorySupported); + EXPECT_NE(deviceProperties.onDemandPageFaultsSupported, devicePropertiesBefore.onDemandPageFaultsSupported); + EXPECT_NE(deviceProperties.maxCommandQueues, devicePropertiesBefore.maxCommandQueues); + EXPECT_NE(deviceProperties.numAsyncComputeEngines, devicePropertiesBefore.numAsyncComputeEngines); + EXPECT_NE(deviceProperties.numAsyncCopyEngines, devicePropertiesBefore.numAsyncCopyEngines); + EXPECT_NE(deviceProperties.maxCommandQueuePriority, devicePropertiesBefore.maxCommandQueuePriority); + EXPECT_NE(deviceProperties.numThreadsPerEU, devicePropertiesBefore.numThreadsPerEU); + EXPECT_NE(deviceProperties.physicalEUSimdWidth, devicePropertiesBefore.physicalEUSimdWidth); + EXPECT_NE(deviceProperties.numEUsPerSubslice, devicePropertiesBefore.numEUsPerSubslice); + EXPECT_NE(deviceProperties.numSubslicesPerSlice, devicePropertiesBefore.numSubslicesPerSlice); + EXPECT_NE(deviceProperties.numSlices, devicePropertiesBefore.numSlices); + EXPECT_NE(deviceProperties.timerResolution, devicePropertiesBefore.timerResolution); + EXPECT_NE(0, memcmp(&deviceProperties.name, &devicePropertiesBefore.name, sizeof(devicePropertiesBefore.name))); +} + struct MockMemoryManagerMultiDevice : public MemoryManagerMock { MockMemoryManagerMultiDevice(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast(executionEnvironment)) {} };