From c1782b802ae1304c143450dc9a3e53d7b06e65b4 Mon Sep 17 00:00:00 2001 From: "Zdanowicz, Zbigniew" Date: Thu, 7 Jun 2018 16:18:53 +0200 Subject: [PATCH] Add debug flag to override platform used by compiler Change-Id: I6fc4254f928158d0cb07f53436d1ddd09fcef7d5 --- .../create_command_stream_impl.cpp | 9 +--- .../compiler_interface/compiler_interface.cpp | 12 +++-- runtime/helpers/hw_info.cpp | 14 ++++++ runtime/helpers/hw_info.h | 2 +- runtime/os_interface/DebugVariables.inl | 1 + .../compiler_interface_tests.cpp | 41 ++++++++++++++++ unit_tests/mocks/mock_compilers.h | 48 +++++++++++++++++++ unit_tests/test_files/igdrcl.config | 3 +- 8 files changed, 117 insertions(+), 13 deletions(-) diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index 4d5f93a04a..730c708cbb 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -83,14 +83,7 @@ bool getDevicesImpl(HardwareInfo **hwInfo, size_t &numDevicesReturned) { case CSR_TBX_WITH_AUB: auto productFamily = DebugManager.flags.ProductFamilyOverride.get(); auto hwInfoConst = *platformDevices; - for (int j = 0; j < IGFX_MAX_PRODUCT; j++) { - if (hardwarePrefix[j] == nullptr) - continue; - if (strcmp(hardwarePrefix[j], productFamily.c_str()) == 0) { - hwInfoConst = hardwareInfoTable[j]; - break; - } - } + getHwInfoForPlatformString(productFamily.c_str(), hwInfoConst); *hwInfo = const_cast(hwInfoConst); hardwareInfoSetupGt[hwInfoConst->pPlatform->eProductFamily](const_cast(hwInfo[0]->pSysInfo)); numDevicesReturned = 1; diff --git a/runtime/compiler_interface/compiler_interface.cpp b/runtime/compiler_interface/compiler_interface.cpp index a7babd9d55..9e130aea5d 100644 --- a/runtime/compiler_interface/compiler_interface.cpp +++ b/runtime/compiler_interface/compiler_interface.cpp @@ -30,7 +30,9 @@ #include "runtime/compiler_interface/binary_cache.h" #include "runtime/compiler_interface/compiler_interface.h" #include "runtime/compiler_interface/compiler_interface.inl" +#include "runtime/helpers/hw_info.h" #include "runtime/program/program.h" +#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_inc_base.h" #include @@ -426,9 +428,13 @@ CIF::RAII::UPtr_t CompilerInterface::createIgcT DEBUG_BREAK_IF(true); // could not acquire handles to device descriptors return nullptr; } - - IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform, *device.getHardwareInfo().pPlatform); - IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo, *device.getHardwareInfo().pSysInfo); + const HardwareInfo *hwInfo = &device.getHardwareInfo(); + auto productFamily = DebugManager.flags.ForceCompilerUsePlatform.get(); + if (productFamily != "unk") { + getHwInfoForPlatformString(productFamily.c_str(), hwInfo); + } + IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform, *hwInfo->pPlatform); + IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo, *hwInfo->pSysInfo); igcFeWa.get()->SetFtrDesktop(device.getHardwareInfo().pSkuTable->ftrDesktop); igcFeWa.get()->SetFtrChannelSwizzlingXOREnabled(device.getHardwareInfo().pSkuTable->ftrChannelSwizzlingXOREnabled); diff --git a/runtime/helpers/hw_info.cpp b/runtime/helpers/hw_info.cpp index 1621cab3ba..d6519a9bd0 100644 --- a/runtime/helpers/hw_info.cpp +++ b/runtime/helpers/hw_info.cpp @@ -60,4 +60,18 @@ const char *getPlatformType(const HardwareInfo &hwInfo) { } return "lp"; } + +bool getHwInfoForPlatformString(const char *str, const HardwareInfo *&hwInfoIn) { + bool ret = false; + for (int j = 0; j < IGFX_MAX_PRODUCT; j++) { + if (hardwarePrefix[j] == nullptr) + continue; + if (strcmp(hardwarePrefix[j], str) == 0) { + hwInfoIn = hardwareInfoTable[j]; + ret = true; + break; + } + } + return ret; +} } // namespace OCLRT diff --git a/runtime/helpers/hw_info.h b/runtime/helpers/hw_info.h index 8eb26c6846..f6dbe04ed3 100644 --- a/runtime/helpers/hw_info.h +++ b/runtime/helpers/hw_info.h @@ -117,5 +117,5 @@ struct EnableGfxFamilyHw { }; const char *getPlatformType(const HardwareInfo &hwInfo); - +bool getHwInfoForPlatformString(const char *str, const HardwareInfo *&hwInfoIn); } // namespace OCLRT diff --git a/runtime/os_interface/DebugVariables.inl b/runtime/os_interface/DebugVariables.inl index d1c1458205..193286a22e 100644 --- a/runtime/os_interface/DebugVariables.inl +++ b/runtime/os_interface/DebugVariables.inl @@ -95,3 +95,4 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont o DECLARE_DEBUG_VARIABLE(bool, HwQueueSupported, false, "Windows only. Pass flag to KMD during Wddm Context creation") DECLARE_DEBUG_VARIABLE(bool, UseMaxSimdSizeToDeduceMaxWorkgroupSize, false, "With this flag on, max workgroup size is deduced using SIMD32 instead of SIMD8, this causes the max wkg size to be 4 times bigger") DECLARE_DEBUG_VARIABLE(int32_t, OverrideAubDeviceId, -1, "-1 dont override, any other: use this value for AUB generation device id") +DECLARE_DEBUG_VARIABLE(std::string, ForceCompilerUsePlatform, std::string("unk"), "Specify product for use in compiler interface") \ No newline at end of file diff --git a/unit_tests/compiler_interface/compiler_interface_tests.cpp b/unit_tests/compiler_interface/compiler_interface_tests.cpp index f52958b7a8..a5fe579122 100644 --- a/unit_tests/compiler_interface/compiler_interface_tests.cpp +++ b/unit_tests/compiler_interface/compiler_interface_tests.cpp @@ -24,10 +24,13 @@ #include "runtime/compiler_interface/compiler_interface.inl" #include "runtime/context/context.h" #include "runtime/helpers/file_io.h" +#include "runtime/helpers/hw_info.h" +#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/platform/platform.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/global_environment.h" #include "unit_tests/helpers/test_files.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/memory_management.h" #include "unit_tests/mocks/mock_cif.h" #include "unit_tests/mocks/mock_compilers.h" @@ -797,6 +800,44 @@ TEST_F(CompilerInterfaceTest, GivenRequestForNewIgcTranslationCtxWhenCouldNotPop setIgcDebugVars(prevDebugVars); } +TEST_F(CompilerInterfaceTest, givenNoDbgKeyForceUseDifferentPlatformWhenRequestForNewTranslationCtxThenUseDefaultPlatform) { + auto device = this->pContext->getDevice(0); + auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin); + EXPECT_NE(nullptr, retIgc); + IGC::IgcOclDeviceCtxTagOCL *devCtx = pCompilerInterface->peekIgcDeviceCtx(device); + auto igcPlatform = devCtx->GetPlatformHandle(); + auto igcSysInfo = devCtx->GetGTSystemInfoHandle(); + EXPECT_EQ(device->getHardwareInfo().pPlatform->eProductFamily, igcPlatform->GetProductFamily()); + EXPECT_EQ(device->getHardwareInfo().pPlatform->eRenderCoreFamily, igcPlatform->GetRenderCoreFamily()); + EXPECT_EQ(device->getHardwareInfo().pSysInfo->SliceCount, igcSysInfo->GetSliceCount()); + EXPECT_EQ(device->getHardwareInfo().pSysInfo->SubSliceCount, igcSysInfo->GetSubSliceCount()); + EXPECT_EQ(device->getHardwareInfo().pSysInfo->EUCount, igcSysInfo->GetEUCount()); + EXPECT_EQ(device->getHardwareInfo().pSysInfo->ThreadCount, igcSysInfo->GetThreadCount()); +} + +TEST_F(CompilerInterfaceTest, givenDbgKeyForceUseDifferentPlatformWhenRequestForNewTranslationCtxThenUseDbgKeyPlatform) { + DebugManagerStateRestore dbgRestore; + auto dbgProdFamily = DEFAULT_TEST_PLATFORM::hwInfo.pPlatform->eProductFamily; + std::string dbgPlatformString(hardwarePrefix[dbgProdFamily]); + const PLATFORM dbgPlatform = *hardwareInfoTable[dbgProdFamily]->pPlatform; + const GT_SYSTEM_INFO dbgSystemInfo = *hardwareInfoTable[dbgProdFamily]->pSysInfo; + DebugManager.flags.ForceCompilerUsePlatform.set(dbgPlatformString); + + auto device = this->pContext->getDevice(0); + auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin); + EXPECT_NE(nullptr, retIgc); + IGC::IgcOclDeviceCtxTagOCL *devCtx = pCompilerInterface->peekIgcDeviceCtx(device); + auto igcPlatform = devCtx->GetPlatformHandle(); + auto igcSysInfo = devCtx->GetGTSystemInfoHandle(); + + EXPECT_EQ(dbgPlatform.eProductFamily, igcPlatform->GetProductFamily()); + EXPECT_EQ(dbgPlatform.eRenderCoreFamily, igcPlatform->GetRenderCoreFamily()); + EXPECT_EQ(dbgSystemInfo.SliceCount, igcSysInfo->GetSliceCount()); + EXPECT_EQ(dbgSystemInfo.SubSliceCount, igcSysInfo->GetSubSliceCount()); + EXPECT_EQ(dbgSystemInfo.EUCount, igcSysInfo->GetEUCount()); + EXPECT_EQ(dbgSystemInfo.ThreadCount, igcSysInfo->GetThreadCount()); +} + TEST_F(CompilerInterfaceTest, IsCompilerAvailable) { ASSERT_TRUE(this->pCompilerInterface->GetIgcMain() && this->pCompilerInterface->GetFclMain()); EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable()); diff --git a/unit_tests/mocks/mock_compilers.h b/unit_tests/mocks/mock_compilers.h index f8e07439b3..e34b175ed1 100644 --- a/unit_tests/mocks/mock_compilers.h +++ b/unit_tests/mocks/mock_compilers.h @@ -73,9 +73,55 @@ MockCompilerDebugVars getFclDebugVars(); MockCompilerDebugVars getIgcDebugVars(); struct MockPlatform : MockCIF { + IGC::TypeErasedEnum GetProductFamily() const override { + return productFamily; + } + void SetProductFamily(IGC::TypeErasedEnum v) override { + productFamily = v; + } + IGC::TypeErasedEnum GetRenderCoreFamily() const override { + return renderCoreFamily; + } + void SetRenderCoreFamily(IGC::TypeErasedEnum v) override { + renderCoreFamily = v; + } + + protected: + IGC::TypeErasedEnum productFamily; + IGC::TypeErasedEnum renderCoreFamily; }; struct MockGTSystemInfo : MockCIF { + uint32_t GetEUCount() const override { + return this->euCount; + } + void SetEUCount(uint32_t v) override { + euCount = v; + } + uint32_t GetThreadCount() const override { + return this->threadCount; + } + void SetThreadCount(uint32_t v) override { + threadCount = v; + } + uint32_t GetSliceCount() const override { + return this->sliceCount; + } + void SetSliceCount(uint32_t v) override { + sliceCount = v; + } + uint32_t GetSubSliceCount() const override { + return this->subsliceCount; + } + void SetSubSliceCount(uint32_t v) override { + subsliceCount = v; + } + + protected: + uint32_t euCount; + uint32_t threadCount; + uint32_t sliceCount; + uint32_t subsliceCount; }; struct MockIgcFeaturesAndWorkarounds : MockCIF { @@ -305,6 +351,8 @@ class MockCompilerInterface : public CompilerInterface { std::vector sipKernelBinaryOverride; SipKernelType requestedSipKernel = SipKernelType::COUNT; + + IGC::IgcOclDeviceCtxTagOCL *peekIgcDeviceCtx(Device *device) { return igcDeviceContexts[device].get(); } }; template <> diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 216a132b69..7c244a94b8 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -66,4 +66,5 @@ HwQueueSupported = false DisableZeroCopyForUseHostPtr = false SchedulerGWS = 0 DisableZeroCopyForBuffers = false -OverrideAubDeviceId = -1 \ No newline at end of file +OverrideAubDeviceId = -1 +ForceCompilerUsePlatform = unk \ No newline at end of file