From 4234a19b69c3997f8982a26e27795cbc3a6ed1d5 Mon Sep 17 00:00:00 2001 From: Young Jin Yoon Date: Fri, 10 Sep 2021 00:37:27 +0000 Subject: [PATCH] Add support for ze_scheduling_hint_exp_properties Related-To: LOCI-2319 Signed-off-by: Young Jin Yoon --- level_zero/core/source/device/device_imp.cpp | 27 ++++- .../unit_tests/sources/device/test_device.cpp | 111 ++++++++++++++++++ .../os_interface/hw_info_config_tests.cpp | 3 + shared/source/os_interface/hw_info_config.h | 2 + shared/source/os_interface/hw_info_config.inl | 7 ++ .../os_agnostic_hw_info_config_tests.cpp | 5 + 6 files changed, 152 insertions(+), 3 deletions(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 66b5db727d..f8196e9919 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -356,17 +356,38 @@ ze_result_t DeviceImp::getKernelProperties(ze_device_module_properties_t *pKerne pKernelProperties->printfBufferSize = static_cast(this->neoDevice->getDeviceInfo().printfBufferSize); - if (pKernelProperties->pNext) { + auto &hwInfo = this->getHwInfo(); + auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily); + + void *pNext = pKernelProperties->pNext; + while (pNext) { ze_base_desc_t *extendedProperties = reinterpret_cast(pKernelProperties->pNext); if (extendedProperties->stype == ZE_STRUCTURE_TYPE_FLOAT_ATOMIC_EXT_PROPERTIES) { ze_float_atomic_ext_properties_t *floatProperties = reinterpret_cast(extendedProperties); - auto &hwInfo = this->getHwInfo(); - auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily); hwInfoConfig.getKernelExtendedProperties(&floatProperties->fp16Flags, &floatProperties->fp32Flags, &floatProperties->fp64Flags); + } else if (extendedProperties->stype == ZE_STRUCTURE_TYPE_SCHEDULING_HINT_EXP_PROPERTIES) { + ze_scheduling_hint_exp_properties_t *hintProperties = + reinterpret_cast(extendedProperties); + auto supportedThreadArbitrationPolicies = hwInfoConfig.getKernelSupportedThreadArbitrationPolicies(); + hintProperties->schedulingHintFlags = 0; + for (uint32_t &p : supportedThreadArbitrationPolicies) { + switch (p) { + case NEO::ThreadArbitrationPolicy::AgeBased: + hintProperties->schedulingHintFlags |= ZE_SCHEDULING_HINT_EXP_FLAG_OLDEST_FIRST; + break; + case NEO::ThreadArbitrationPolicy::RoundRobin: + hintProperties->schedulingHintFlags |= ZE_SCHEDULING_HINT_EXP_FLAG_ROUND_ROBIN; + break; + case NEO::ThreadArbitrationPolicy::RoundRobinAfterDependency: + hintProperties->schedulingHintFlags |= ZE_SCHEDULING_HINT_EXP_FLAG_STALL_BASED_ROUND_ROBIN; + break; + } + } } + pNext = const_cast(extendedProperties->pNext); } return ZE_RESULT_SUCCESS; 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 e69ec5fb60..02294fddf6 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 @@ -7,6 +7,7 @@ #include "shared/source/device/root_device.h" #include "shared/source/helpers/bindless_heaps_helper.h" +#include "shared/source/helpers/preamble.h" #include "shared/source/os_interface/hw_info_config.h" #include "shared/source/os_interface/os_inc_base.h" #include "shared/source/os_interface/os_time.h" @@ -509,6 +510,116 @@ TEST_F(DeviceTest, givenKernelExtendedPropertiesStructureWhenKernelPropertiesCal EXPECT_EQ(maxValue, kernelExtendedProperties.fp64Flags); } +HWTEST_F(DeviceTest, whenPassingSchedulingHintExpStructToGetPropertiesThenPropertiesWithCorrectFlagIsReturned) { + + ze_device_module_properties_t kernelProperties = {}; + kernelProperties.stype = ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES; + + ze_scheduling_hint_exp_properties_t schedulingHintProperties = {}; + schedulingHintProperties.stype = ZE_STRUCTURE_TYPE_SCHEDULING_HINT_EXP_PROPERTIES; + schedulingHintProperties.schedulingHintFlags = ZE_SCHEDULING_HINT_EXP_FLAG_FORCE_UINT32; + + kernelProperties.pNext = &schedulingHintProperties; + + ze_result_t res = device->getKernelProperties(&kernelProperties); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + EXPECT_NE(ZE_SCHEDULING_HINT_EXP_FLAG_FORCE_UINT32, schedulingHintProperties.schedulingHintFlags); + auto supportedThreadArbitrationPolicies = NEO::PreambleHelper::getSupportedThreadArbitrationPolicies(); + for (uint32_t &p : supportedThreadArbitrationPolicies) { + switch (p) { + case ThreadArbitrationPolicy::AgeBased: + EXPECT_NE(0u, (schedulingHintProperties.schedulingHintFlags & + ZE_SCHEDULING_HINT_EXP_FLAG_OLDEST_FIRST)); + break; + case ThreadArbitrationPolicy::RoundRobin: + EXPECT_NE(0u, (schedulingHintProperties.schedulingHintFlags & + ZE_SCHEDULING_HINT_EXP_FLAG_ROUND_ROBIN)); + break; + case ThreadArbitrationPolicy::RoundRobinAfterDependency: + EXPECT_NE(0u, (schedulingHintProperties.schedulingHintFlags & + ZE_SCHEDULING_HINT_EXP_FLAG_STALL_BASED_ROUND_ROBIN)); + break; + default: + FAIL(); + } + } +} + +HWTEST_F(DeviceTest, givenAllThreadArbitrationPoliciesWhenPassingSchedulingHintExpStructToGetPropertiesThenPropertiesWithAllFlagsAreReturned) { + struct MockHwInfoConfig : NEO::HwInfoConfigHw { + std::vector getKernelSupportedThreadArbitrationPolicies() override { + return threadArbPolicies; + } + std::vector threadArbPolicies; + }; + + const uint32_t rootDeviceIndex = 0u; + auto hwInfo = *NEO::defaultHwInfo; + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, + rootDeviceIndex); + + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + MockHwInfoConfig hwInfoConfig{}; + hwInfoConfig.threadArbPolicies = {ThreadArbitrationPolicy::AgeBased, + ThreadArbitrationPolicy::RoundRobin, + ThreadArbitrationPolicy::RoundRobinAfterDependency}; + VariableBackup hwInfoConfigFactoryBackup{&NEO::hwInfoConfigFactory[static_cast(hwInfo.platform.eProductFamily)]}; + hwInfoConfigFactoryBackup = &hwInfoConfig; + + ze_device_module_properties_t kernelProperties = {}; + kernelProperties.stype = ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES; + + ze_scheduling_hint_exp_properties_t schedulingHintProperties = {}; + schedulingHintProperties.stype = ZE_STRUCTURE_TYPE_SCHEDULING_HINT_EXP_PROPERTIES; + schedulingHintProperties.schedulingHintFlags = ZE_SCHEDULING_HINT_EXP_FLAG_FORCE_UINT32; + + kernelProperties.pNext = &schedulingHintProperties; + + ze_result_t res = deviceImp.getKernelProperties(&kernelProperties); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + ze_scheduling_hint_exp_flags_t expected = (ZE_SCHEDULING_HINT_EXP_FLAG_OLDEST_FIRST | + ZE_SCHEDULING_HINT_EXP_FLAG_ROUND_ROBIN | + ZE_SCHEDULING_HINT_EXP_FLAG_STALL_BASED_ROUND_ROBIN); + EXPECT_EQ(expected, schedulingHintProperties.schedulingHintFlags); +} + +HWTEST_F(DeviceTest, givenIncorrectThreadArbitrationPolicyWhenPassingSchedulingHintExpStructToGetPropertiesThenNoneIsReturned) { + struct MockHwInfoConfig : NEO::HwInfoConfigHw { + std::vector getKernelSupportedThreadArbitrationPolicies() override { + return threadArbPolicies; + } + std::vector threadArbPolicies; + }; + + const uint32_t rootDeviceIndex = 0u; + auto hwInfo = *NEO::defaultHwInfo; + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, + rootDeviceIndex); + + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + MockHwInfoConfig hwInfoConfig{}; + hwInfoConfig.threadArbPolicies = {ThreadArbitrationPolicy::NotPresent}; + VariableBackup hwInfoConfigFactoryBackup{&NEO::hwInfoConfigFactory[static_cast(hwInfo.platform.eProductFamily)]}; + hwInfoConfigFactoryBackup = &hwInfoConfig; + + ze_device_module_properties_t kernelProperties = {}; + kernelProperties.stype = ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES; + + ze_scheduling_hint_exp_properties_t schedulingHintProperties = {}; + schedulingHintProperties.stype = ZE_STRUCTURE_TYPE_SCHEDULING_HINT_EXP_PROPERTIES; + schedulingHintProperties.schedulingHintFlags = ZE_SCHEDULING_HINT_EXP_FLAG_FORCE_UINT32; + + kernelProperties.pNext = &schedulingHintProperties; + + ze_result_t res = deviceImp.getKernelProperties(&kernelProperties); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(0u, schedulingHintProperties.schedulingHintFlags); +} + TEST_F(DeviceTest, givenKernelPropertiesStructureWhenKernelPropertiesCalledThenAllPropertiesAreAssigned) { const auto &hardwareInfo = this->neoDevice->getHardwareInfo(); diff --git a/opencl/test/unit_test/os_interface/hw_info_config_tests.cpp b/opencl/test/unit_test/os_interface/hw_info_config_tests.cpp index 302951e324..3b73bf7779 100644 --- a/opencl/test/unit_test/os_interface/hw_info_config_tests.cpp +++ b/opencl/test/unit_test/os_interface/hw_info_config_tests.cpp @@ -184,6 +184,9 @@ HWTEST_F(HwInfoConfigTest, givenVariousValuesWhenGettingAubStreamSteppingFromHwR uint32_t getSteppingFromHwRevId(const HardwareInfo &hwInfo) const override { return returnedStepping; } + std::vector getKernelSupportedThreadArbitrationPolicies() override { + return std::vector(); + } uint32_t returnedStepping = 0; }; MockHwInfoConfig mockHwInfoConfig; diff --git a/shared/source/os_interface/hw_info_config.h b/shared/source/os_interface/hw_info_config.h index dcceec2c57..544c79349a 100644 --- a/shared/source/os_interface/hw_info_config.h +++ b/shared/source/os_interface/hw_info_config.h @@ -38,6 +38,7 @@ class HwInfoConfig { virtual uint64_t getSingleDeviceSharedMemCapabilities() = 0; virtual uint64_t getCrossDeviceSharedMemCapabilities() = 0; virtual void getKernelExtendedProperties(uint32_t *fp16, uint32_t *fp32, uint32_t *fp64) = 0; + virtual std::vector getKernelSupportedThreadArbitrationPolicies() = 0; virtual uint64_t getSharedSystemMemCapabilities() = 0; virtual void convertTimestampsFromOaToCsDomain(uint64_t ×tampData) = 0; virtual uint32_t getDeviceMemoryMaxClkRate(const HardwareInfo *hwInfo) = 0; @@ -81,6 +82,7 @@ class HwInfoConfigHw : public HwInfoConfig { uint64_t getSingleDeviceSharedMemCapabilities() override; uint64_t getCrossDeviceSharedMemCapabilities() override; void getKernelExtendedProperties(uint32_t *fp16, uint32_t *fp32, uint32_t *fp64) override; + std::vector getKernelSupportedThreadArbitrationPolicies() override; uint64_t getSharedSystemMemCapabilities() override; void convertTimestampsFromOaToCsDomain(uint64_t ×tampData) override; uint32_t getDeviceMemoryMaxClkRate(const HardwareInfo *hwInfo) override; diff --git a/shared/source/os_interface/hw_info_config.inl b/shared/source/os_interface/hw_info_config.inl index 019af1171b..084707bd7a 100644 --- a/shared/source/os_interface/hw_info_config.inl +++ b/shared/source/os_interface/hw_info_config.inl @@ -8,6 +8,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/hw_helper.h" +#include "shared/source/helpers/preamble.h" #include "shared/source/os_interface/hw_info_config.h" namespace NEO { @@ -27,6 +28,12 @@ void HwInfoConfigHw::getKernelExtendedProperties(uint32_t *fp16, uin *fp64 = 0u; } +template +std::vector HwInfoConfigHw::getKernelSupportedThreadArbitrationPolicies() { + using GfxFamily = typename HwMapper::GfxFamily; + return PreambleHelper::getSupportedThreadArbitrationPolicies(); +} + template uint64_t HwInfoConfigHw::getSharedSystemMemCapabilities() { return 0; diff --git a/shared/test/unit_test/os_interface/os_agnostic_hw_info_config_tests.cpp b/shared/test/unit_test/os_interface/os_agnostic_hw_info_config_tests.cpp index 4b88598c8c..e8e78640fe 100644 --- a/shared/test/unit_test/os_interface/os_agnostic_hw_info_config_tests.cpp +++ b/shared/test/unit_test/os_interface/os_agnostic_hw_info_config_tests.cpp @@ -156,6 +156,11 @@ LocalMemoryAccessMode HwInfoConfigHw::getLocalMemoryAccessMode(con return LocalMemoryAccessMode::Default; } +template <> +std::vector HwInfoConfigHw::getKernelSupportedThreadArbitrationPolicies() { + return std::vector(); +} + void OsAgnosticHwInfoConfigTest::SetUp() { DeviceFixture::SetUp(); }