diff --git a/runtime/os_interface/linux/device_factory.cpp b/runtime/os_interface/linux/device_factory.cpp index 3c674543ea..504720b08e 100644 --- a/runtime/os_interface/linux/device_factory.cpp +++ b/runtime/os_interface/linux/device_factory.cpp @@ -40,10 +40,10 @@ HardwareInfo *DeviceFactory::hwInfos = nullptr; bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { std::vector tHwInfos; - int retVal; unsigned int devNum = 0; Drm *drm = nullptr; std::unique_ptr osInterface = std::unique_ptr(new OSInterface()); + while ((drm = Drm::create(devNum)) != nullptr) { const HardwareInfo *pCurrDevice = platformDevices[devNum]; @@ -53,8 +53,7 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { osInterface.get()->get()->setDrm(drm); HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->pPlatform->eProductFamily); - retVal = hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, osInterface.get()); - if (retVal != 0) { + if (hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, osInterface.get())) { return false; } tHwInfos.push_back(tmpHwInfo); diff --git a/runtime/os_interface/windows/device_factory.cpp b/runtime/os_interface/windows/device_factory.cpp index 2980529710..05caad038c 100644 --- a/runtime/os_interface/windows/device_factory.cpp +++ b/runtime/os_interface/windows/device_factory.cpp @@ -22,13 +22,10 @@ #ifdef _WIN32 -#include "runtime/command_stream/preemption.h" #include "runtime/device/device.h" -#include "runtime/helpers/debug_helpers.h" -#include "runtime/helpers/hw_helper.h" -#include "runtime/memory_manager/memory_constants.h" -#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/device_factory.h" +#include "runtime/os_interface/hw_info_config.h" +#include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm.h" namespace OCLRT { @@ -40,39 +37,16 @@ HardwareInfo *DeviceFactory::hwInfos = nullptr; bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { HardwareInfo *tempHwInfos = new HardwareInfo[1]; - unsigned int devNum = 0; + constexpr unsigned int devNum = 0; numDevices = 0; if (Wddm::enumAdapters(devNum, tempHwInfos[devNum])) { - // Overwrite dynamic parameters - tempHwInfos[devNum].capabilityTable.ftrSvm = tempHwInfos[devNum].pSkuTable->ftrSVM; + std::unique_ptr osInterface = std::unique_ptr(new OSInterface()); - HwHelper &hwHelper = HwHelper::get(tempHwInfos[devNum].pPlatform->eRenderCoreFamily); - - hwHelper.adjustDefaultEngineType(&tempHwInfos[devNum]); - tempHwInfos[devNum].capabilityTable.defaultEngineType = DebugManager.flags.NodeOrdinal.get() == -1 - ? tempHwInfos[devNum].capabilityTable.defaultEngineType - : static_cast(DebugManager.flags.NodeOrdinal.get()); - - hwHelper.setCapabilityCoherencyFlag(&tempHwInfos[devNum], tempHwInfos[devNum].capabilityTable.ftrSupportsCoherency); - - hwHelper.setupPreemptionRegisters(&tempHwInfos[devNum], !!tempHwInfos[devNum].pWaTable->waEnablePreemptionGranularityControlByUMD); - PreemptionHelper::adjustDefaultPreemptionMode(tempHwInfos[devNum].capabilityTable, - static_cast(tempHwInfos[devNum].pSkuTable->ftrGpGpuMidThreadLevelPreempt), - static_cast(tempHwInfos[devNum].pSkuTable->ftrGpGpuThreadGroupLevelPreempt), - static_cast(tempHwInfos[devNum].pSkuTable->ftrGpGpuMidBatchPreempt)); - tempHwInfos->capabilityTable.requiredPreemptionSurfaceSize = tempHwInfos->pSysInfo->CsrSizeInMb * MemoryConstants::megaByte; - - // Instrumentation - tempHwInfos[devNum].capabilityTable.instrumentationEnabled &= haveInstrumentation; - - auto &kmdNotifyProperties = tempHwInfos[devNum].capabilityTable.kmdNotifyProperties; - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableKmdNotify.get(), kmdNotifyProperties.enableKmdNotify); - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideKmdNotifyDelayMicroseconds.get(), kmdNotifyProperties.delayKmdNotifyMicroseconds); - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableQuickKmdSleep.get(), kmdNotifyProperties.enableQuickKmdSleep); - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideQuickKmdSleepDelayMicroseconds.get(), kmdNotifyProperties.delayQuickKmdSleepMicroseconds); - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.get(), kmdNotifyProperties.enableQuickKmdSleepForSporadicWaits); - KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.get(), kmdNotifyProperties.delayQuickKmdSleepForSporadicWaitsMicroseconds); + HwInfoConfig *hwConfig = HwInfoConfig::get(tempHwInfos->pPlatform->eProductFamily); + if (hwConfig->configureHwInfo(tempHwInfos, tempHwInfos, osInterface.get())) { + return false; + } numDevices = 1; *pHWInfos = tempHwInfos; @@ -80,11 +54,11 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices) { DeviceFactory::hwInfos = tempHwInfos; return true; + } else { delete[] tempHwInfos; + return false; } - - return false; } void DeviceFactory::releaseDevices() { diff --git a/runtime/os_interface/windows/hw_info_config.cpp b/runtime/os_interface/windows/hw_info_config.cpp index eac1c9da16..2ab7766f9e 100644 --- a/runtime/os_interface/windows/hw_info_config.cpp +++ b/runtime/os_interface/windows/hw_info_config.cpp @@ -20,16 +20,55 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "runtime/helpers/hw_info.h" -#include "runtime/os_interface/hw_info_config.h" +#include "runtime/command_stream/preemption.h" #include "runtime/gen_common/hw_cmds.h" +#include "runtime/helpers/hw_info.h" +#include "runtime/helpers/hw_helper.h" +#include "runtime/instrumentation/instrumentation.h" +#include "runtime/memory_manager/memory_constants.h" +#include "runtime/os_interface/hw_info_config.h" +#include "runtime/os_interface/debug_settings_manager.h" namespace OCLRT { HwInfoConfig *hwInfoConfigFactory[IGFX_MAX_PRODUCT] = {}; int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, OSInterface *osIface) { - return 0; + HwHelper &hwHelper = HwHelper::get(outHwInfo->pPlatform->eRenderCoreFamily); + + outHwInfo->capabilityTable.ftrSvm = outHwInfo->pSkuTable->ftrSVM; + + hwHelper.adjustDefaultEngineType(outHwInfo); + const auto nodeOrdinal = DebugManager.flags.NodeOrdinal.get(); + outHwInfo->capabilityTable.defaultEngineType = nodeOrdinal == -1 + ? outHwInfo->capabilityTable.defaultEngineType + : static_cast(nodeOrdinal); + + hwHelper.setCapabilityCoherencyFlag(outHwInfo, outHwInfo->capabilityTable.ftrSupportsCoherency); + + hwHelper.setupPreemptionRegisters(outHwInfo, outHwInfo->pWaTable->waEnablePreemptionGranularityControlByUMD); + PreemptionHelper::adjustDefaultPreemptionMode(outHwInfo->capabilityTable, + static_cast(outHwInfo->pSkuTable->ftrGpGpuMidThreadLevelPreempt), + static_cast(outHwInfo->pSkuTable->ftrGpGpuThreadGroupLevelPreempt), + static_cast(outHwInfo->pSkuTable->ftrGpGpuMidBatchPreempt)); + outHwInfo->capabilityTable.requiredPreemptionSurfaceSize = outHwInfo->pSysInfo->CsrSizeInMb * MemoryConstants::megaByte; + + outHwInfo->capabilityTable.instrumentationEnabled &= haveInstrumentation; + + auto &kmdNotifyProperties = outHwInfo->capabilityTable.kmdNotifyProperties; + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableKmdNotify.get(), kmdNotifyProperties.enableKmdNotify); + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideKmdNotifyDelayMicroseconds.get(), kmdNotifyProperties.delayKmdNotifyMicroseconds); + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableQuickKmdSleep.get(), kmdNotifyProperties.enableQuickKmdSleep); + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideQuickKmdSleepDelayMicroseconds.get(), kmdNotifyProperties.delayQuickKmdSleepMicroseconds); + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.get(), kmdNotifyProperties.enableQuickKmdSleepForSporadicWaits); + KmdNotifyProperties::overrideFromDebugVariable(DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.get(), kmdNotifyProperties.delayQuickKmdSleepForSporadicWaitsMicroseconds); + + // Product specific config + int ret = configureHardwareCustom(outHwInfo, osIface); + if (ret != 0) { + memset(outHwInfo, 0, sizeof(HardwareInfo)); + } + return ret; } } // namespace OCLRT diff --git a/runtime/os_interface/windows/os_interface.cpp b/runtime/os_interface/windows/os_interface.cpp index 7c1a5e7324..9496e17eac 100644 --- a/runtime/os_interface/windows/os_interface.cpp +++ b/runtime/os_interface/windows/os_interface.cpp @@ -20,9 +20,10 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "os_interface.h" + #include "runtime/os_interface/windows/wddm.h" #include "runtime/os_interface/windows/sys_calls.h" -#include "os_interface.h" namespace OCLRT { diff --git a/runtime/os_interface/windows/os_interface.h b/runtime/os_interface/windows/os_interface.h index 603a5c1a10..3f8f66afca 100644 --- a/runtime/os_interface/windows/os_interface.h +++ b/runtime/os_interface/windows/os_interface.h @@ -21,10 +21,13 @@ */ #pragma once + #include "runtime/os_interface/os_interface.h" -#include "profileapi.h" #include "runtime/os_interface/windows/windows_wrapper.h" + #include +#include "profileapi.h" +#include "umKmInc/sharedata.h" namespace OCLRT { class Wddm; diff --git a/unit_tests/os_interface/windows/CMakeLists.txt b/unit_tests/os_interface/windows/CMakeLists.txt index 3f606558ed..2fa991587d 100644 --- a/unit_tests/os_interface/windows/CMakeLists.txt +++ b/unit_tests/os_interface/windows/CMakeLists.txt @@ -25,6 +25,8 @@ set(IGDRCL_SRCS_tests_os_interface_windows ${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_kmdaf_listener.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_os_time_win.h diff --git a/unit_tests/os_interface/windows/hw_info_config_tests.cpp b/unit_tests/os_interface/windows/hw_info_config_tests.cpp new file mode 100644 index 0000000000..8d7c260f68 --- /dev/null +++ b/unit_tests/os_interface/windows/hw_info_config_tests.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "hw_info_config_tests.h" + +#include "runtime/os_interface/windows/os_interface.h" +#include "runtime/os_interface/windows/wddm.h" + +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/libult/mock_gfx_family.h" + +namespace OCLRT { + +template <> +int HwInfoConfigHw::configureHardwareCustom(HardwareInfo *hwInfo, OSInterface *osIface) { + return 0; +} + +void HwInfoConfigTestWindows::SetUp() { + HwInfoConfigTest::SetUp(); + + osInterface = std::make_unique(); + Wddm::enumAdapters(0, outHwInfo); +} + +void HwInfoConfigTestWindows::TearDown() { + ReleaseOutHwInfoStructs(); + + HwInfoConfigTest::TearDown(); +} + +TEST_F(HwInfoConfigTestWindows, givenCorrectParametersWhenConfiguringHwInfoThenReturnSuccess) { + int ret = hwConfig.configureHwInfo(pInHwInfo, &outHwInfo, osInterface.get()); + EXPECT_EQ(0, ret); +} + +TEST_F(HwInfoConfigTestWindows, givenCorrectParametersWhenConfiguringHwInfoThenSetFtrSvmCorrectly) { + auto ftrSvm = outHwInfo.pSkuTable->ftrSVM; + + int ret = hwConfig.configureHwInfo(pInHwInfo, &outHwInfo, osInterface.get()); + ASSERT_EQ(0, ret); + + EXPECT_EQ(outHwInfo.capabilityTable.ftrSvm, ftrSvm); +} + +TEST_F(HwInfoConfigTestWindows, givenInstrumentationForHardwareIsEnabledOrDisabledWhenConfiguringHwInfoThenOverrideItUsingHaveInstrumentation) { + int ret; + + outHwInfo.capabilityTable.instrumentationEnabled = false; + ret = hwConfig.configureHwInfo(pInHwInfo, &outHwInfo, osInterface.get()); + ASSERT_EQ(0, ret); + EXPECT_FALSE(outHwInfo.capabilityTable.instrumentationEnabled); + + outHwInfo.capabilityTable.instrumentationEnabled = true; + ret = hwConfig.configureHwInfo(pInHwInfo, &outHwInfo, osInterface.get()); + ASSERT_EQ(0, ret); + EXPECT_TRUE(outHwInfo.capabilityTable.instrumentationEnabled == haveInstrumentation); +} + +} // namespace OCLRT diff --git a/unit_tests/os_interface/windows/hw_info_config_tests.h b/unit_tests/os_interface/windows/hw_info_config_tests.h new file mode 100644 index 0000000000..726a0bab6d --- /dev/null +++ b/unit_tests/os_interface/windows/hw_info_config_tests.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "runtime/os_interface/hw_info_config.h" + +#include "unit_tests/os_interface/hw_info_config_tests.h" + +#include + +namespace OCLRT { + +struct DummyHwConfig : HwInfoConfigHw { +}; + +struct HwInfoConfigTestWindows : public HwInfoConfigTest { + void SetUp() override; + void TearDown() override; + + std::unique_ptr osInterface; + DummyHwConfig hwConfig; +}; + +} // namespace OCLRT