Skip to content

Commit c1782b8

Browse files
Add debug flag to override platform used by compiler
Change-Id: I6fc4254f928158d0cb07f53436d1ddd09fcef7d5
1 parent bbe4edd commit c1782b8

File tree

8 files changed

+117
-13
lines changed

8 files changed

+117
-13
lines changed

runtime/command_stream/create_command_stream_impl.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,7 @@ bool getDevicesImpl(HardwareInfo **hwInfo, size_t &numDevicesReturned) {
8383
case CSR_TBX_WITH_AUB:
8484
auto productFamily = DebugManager.flags.ProductFamilyOverride.get();
8585
auto hwInfoConst = *platformDevices;
86-
for (int j = 0; j < IGFX_MAX_PRODUCT; j++) {
87-
if (hardwarePrefix[j] == nullptr)
88-
continue;
89-
if (strcmp(hardwarePrefix[j], productFamily.c_str()) == 0) {
90-
hwInfoConst = hardwareInfoTable[j];
91-
break;
92-
}
93-
}
86+
getHwInfoForPlatformString(productFamily.c_str(), hwInfoConst);
9487
*hwInfo = const_cast<HardwareInfo *>(hwInfoConst);
9588
hardwareInfoSetupGt[hwInfoConst->pPlatform->eProductFamily](const_cast<GT_SYSTEM_INFO *>(hwInfo[0]->pSysInfo));
9689
numDevicesReturned = 1;

runtime/compiler_interface/compiler_interface.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include "runtime/compiler_interface/binary_cache.h"
3131
#include "runtime/compiler_interface/compiler_interface.h"
3232
#include "runtime/compiler_interface/compiler_interface.inl"
33+
#include "runtime/helpers/hw_info.h"
3334
#include "runtime/program/program.h"
35+
#include "runtime/os_interface/debug_settings_manager.h"
3436
#include "runtime/os_interface/os_inc_base.h"
3537

3638
#include <fstream>
@@ -426,9 +428,13 @@ CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> CompilerInterface::createIgcT
426428
DEBUG_BREAK_IF(true); // could not acquire handles to device descriptors
427429
return nullptr;
428430
}
429-
430-
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform, *device.getHardwareInfo().pPlatform);
431-
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo, *device.getHardwareInfo().pSysInfo);
431+
const HardwareInfo *hwInfo = &device.getHardwareInfo();
432+
auto productFamily = DebugManager.flags.ForceCompilerUsePlatform.get();
433+
if (productFamily != "unk") {
434+
getHwInfoForPlatformString(productFamily.c_str(), hwInfo);
435+
}
436+
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform, *hwInfo->pPlatform);
437+
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo, *hwInfo->pSysInfo);
432438

433439
igcFeWa.get()->SetFtrDesktop(device.getHardwareInfo().pSkuTable->ftrDesktop);
434440
igcFeWa.get()->SetFtrChannelSwizzlingXOREnabled(device.getHardwareInfo().pSkuTable->ftrChannelSwizzlingXOREnabled);

runtime/helpers/hw_info.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,18 @@ const char *getPlatformType(const HardwareInfo &hwInfo) {
6060
}
6161
return "lp";
6262
}
63+
64+
bool getHwInfoForPlatformString(const char *str, const HardwareInfo *&hwInfoIn) {
65+
bool ret = false;
66+
for (int j = 0; j < IGFX_MAX_PRODUCT; j++) {
67+
if (hardwarePrefix[j] == nullptr)
68+
continue;
69+
if (strcmp(hardwarePrefix[j], str) == 0) {
70+
hwInfoIn = hardwareInfoTable[j];
71+
ret = true;
72+
break;
73+
}
74+
}
75+
return ret;
76+
}
6377
} // namespace OCLRT

runtime/helpers/hw_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ struct EnableGfxFamilyHw {
117117
};
118118

119119
const char *getPlatformType(const HardwareInfo &hwInfo);
120-
120+
bool getHwInfoForPlatformString(const char *str, const HardwareInfo *&hwInfoIn);
121121
} // namespace OCLRT

runtime/os_interface/DebugVariables.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont o
9595
DECLARE_DEBUG_VARIABLE(bool, HwQueueSupported, false, "Windows only. Pass flag to KMD during Wddm Context creation")
9696
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")
9797
DECLARE_DEBUG_VARIABLE(int32_t, OverrideAubDeviceId, -1, "-1 dont override, any other: use this value for AUB generation device id")
98+
DECLARE_DEBUG_VARIABLE(std::string, ForceCompilerUsePlatform, std::string("unk"), "Specify product for use in compiler interface")

unit_tests/compiler_interface/compiler_interface_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
#include "runtime/compiler_interface/compiler_interface.inl"
2525
#include "runtime/context/context.h"
2626
#include "runtime/helpers/file_io.h"
27+
#include "runtime/helpers/hw_info.h"
28+
#include "runtime/os_interface/debug_settings_manager.h"
2729
#include "runtime/platform/platform.h"
2830
#include "unit_tests/fixtures/device_fixture.h"
2931
#include "unit_tests/global_environment.h"
3032
#include "unit_tests/helpers/test_files.h"
33+
#include "unit_tests/helpers/debug_manager_state_restore.h"
3134
#include "unit_tests/helpers/memory_management.h"
3235
#include "unit_tests/mocks/mock_cif.h"
3336
#include "unit_tests/mocks/mock_compilers.h"
@@ -797,6 +800,44 @@ TEST_F(CompilerInterfaceTest, GivenRequestForNewIgcTranslationCtxWhenCouldNotPop
797800
setIgcDebugVars(prevDebugVars);
798801
}
799802

803+
TEST_F(CompilerInterfaceTest, givenNoDbgKeyForceUseDifferentPlatformWhenRequestForNewTranslationCtxThenUseDefaultPlatform) {
804+
auto device = this->pContext->getDevice(0);
805+
auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
806+
EXPECT_NE(nullptr, retIgc);
807+
IGC::IgcOclDeviceCtxTagOCL *devCtx = pCompilerInterface->peekIgcDeviceCtx(device);
808+
auto igcPlatform = devCtx->GetPlatformHandle();
809+
auto igcSysInfo = devCtx->GetGTSystemInfoHandle();
810+
EXPECT_EQ(device->getHardwareInfo().pPlatform->eProductFamily, igcPlatform->GetProductFamily());
811+
EXPECT_EQ(device->getHardwareInfo().pPlatform->eRenderCoreFamily, igcPlatform->GetRenderCoreFamily());
812+
EXPECT_EQ(device->getHardwareInfo().pSysInfo->SliceCount, igcSysInfo->GetSliceCount());
813+
EXPECT_EQ(device->getHardwareInfo().pSysInfo->SubSliceCount, igcSysInfo->GetSubSliceCount());
814+
EXPECT_EQ(device->getHardwareInfo().pSysInfo->EUCount, igcSysInfo->GetEUCount());
815+
EXPECT_EQ(device->getHardwareInfo().pSysInfo->ThreadCount, igcSysInfo->GetThreadCount());
816+
}
817+
818+
TEST_F(CompilerInterfaceTest, givenDbgKeyForceUseDifferentPlatformWhenRequestForNewTranslationCtxThenUseDbgKeyPlatform) {
819+
DebugManagerStateRestore dbgRestore;
820+
auto dbgProdFamily = DEFAULT_TEST_PLATFORM::hwInfo.pPlatform->eProductFamily;
821+
std::string dbgPlatformString(hardwarePrefix[dbgProdFamily]);
822+
const PLATFORM dbgPlatform = *hardwareInfoTable[dbgProdFamily]->pPlatform;
823+
const GT_SYSTEM_INFO dbgSystemInfo = *hardwareInfoTable[dbgProdFamily]->pSysInfo;
824+
DebugManager.flags.ForceCompilerUsePlatform.set(dbgPlatformString);
825+
826+
auto device = this->pContext->getDevice(0);
827+
auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
828+
EXPECT_NE(nullptr, retIgc);
829+
IGC::IgcOclDeviceCtxTagOCL *devCtx = pCompilerInterface->peekIgcDeviceCtx(device);
830+
auto igcPlatform = devCtx->GetPlatformHandle();
831+
auto igcSysInfo = devCtx->GetGTSystemInfoHandle();
832+
833+
EXPECT_EQ(dbgPlatform.eProductFamily, igcPlatform->GetProductFamily());
834+
EXPECT_EQ(dbgPlatform.eRenderCoreFamily, igcPlatform->GetRenderCoreFamily());
835+
EXPECT_EQ(dbgSystemInfo.SliceCount, igcSysInfo->GetSliceCount());
836+
EXPECT_EQ(dbgSystemInfo.SubSliceCount, igcSysInfo->GetSubSliceCount());
837+
EXPECT_EQ(dbgSystemInfo.EUCount, igcSysInfo->GetEUCount());
838+
EXPECT_EQ(dbgSystemInfo.ThreadCount, igcSysInfo->GetThreadCount());
839+
}
840+
800841
TEST_F(CompilerInterfaceTest, IsCompilerAvailable) {
801842
ASSERT_TRUE(this->pCompilerInterface->GetIgcMain() && this->pCompilerInterface->GetFclMain());
802843
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable());

unit_tests/mocks/mock_compilers.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,55 @@ MockCompilerDebugVars getFclDebugVars();
7373
MockCompilerDebugVars getIgcDebugVars();
7474

7575
struct MockPlatform : MockCIF<IGC::PlatformTagOCL> {
76+
IGC::TypeErasedEnum GetProductFamily() const override {
77+
return productFamily;
78+
}
79+
void SetProductFamily(IGC::TypeErasedEnum v) override {
80+
productFamily = v;
81+
}
82+
IGC::TypeErasedEnum GetRenderCoreFamily() const override {
83+
return renderCoreFamily;
84+
}
85+
void SetRenderCoreFamily(IGC::TypeErasedEnum v) override {
86+
renderCoreFamily = v;
87+
}
88+
89+
protected:
90+
IGC::TypeErasedEnum productFamily;
91+
IGC::TypeErasedEnum renderCoreFamily;
7692
};
7793

7894
struct MockGTSystemInfo : MockCIF<IGC::GTSystemInfoTagOCL> {
95+
uint32_t GetEUCount() const override {
96+
return this->euCount;
97+
}
98+
void SetEUCount(uint32_t v) override {
99+
euCount = v;
100+
}
101+
uint32_t GetThreadCount() const override {
102+
return this->threadCount;
103+
}
104+
void SetThreadCount(uint32_t v) override {
105+
threadCount = v;
106+
}
107+
uint32_t GetSliceCount() const override {
108+
return this->sliceCount;
109+
}
110+
void SetSliceCount(uint32_t v) override {
111+
sliceCount = v;
112+
}
113+
uint32_t GetSubSliceCount() const override {
114+
return this->subsliceCount;
115+
}
116+
void SetSubSliceCount(uint32_t v) override {
117+
subsliceCount = v;
118+
}
119+
120+
protected:
121+
uint32_t euCount;
122+
uint32_t threadCount;
123+
uint32_t sliceCount;
124+
uint32_t subsliceCount;
79125
};
80126

81127
struct MockIgcFeaturesAndWorkarounds : MockCIF<IGC::IgcFeaturesAndWorkaroundsTagOCL> {
@@ -305,6 +351,8 @@ class MockCompilerInterface : public CompilerInterface {
305351

306352
std::vector<char> sipKernelBinaryOverride;
307353
SipKernelType requestedSipKernel = SipKernelType::COUNT;
354+
355+
IGC::IgcOclDeviceCtxTagOCL *peekIgcDeviceCtx(Device *device) { return igcDeviceContexts[device].get(); }
308356
};
309357

310358
template <>

unit_tests/test_files/igdrcl.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ HwQueueSupported = false
6666
DisableZeroCopyForUseHostPtr = false
6767
SchedulerGWS = 0
6868
DisableZeroCopyForBuffers = false
69-
OverrideAubDeviceId = -1
69+
OverrideAubDeviceId = -1
70+
ForceCompilerUsePlatform = unk

0 commit comments

Comments
 (0)