Skip to content

Commit eab67e5

Browse files
Konstantin Vladimirovigcbot
authored andcommitted
Support for platform information from OpenCL runtime
1 parent 48ee004 commit eab67e5

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

IGC/AdaptorOCL/ocl_igc_interface/impl/fcl_ocl_translation_ctx_impl.cpp

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ static std::vector<const char*>
269269
processFeOptions(llvm::sys::DynamicLibrary &LibInfo,
270270
const std::string& inputFile,
271271
CIF::Builtins::BufferSimple* options,
272-
llvm::StringSaver& stringSaver) {
272+
llvm::StringSaver& stringSaver,
273+
const char *platform,
274+
unsigned stepping) {
273275

274276
llvm::SmallVector<const char*, 20> userArgs;
275277

@@ -283,17 +285,8 @@ static std::vector<const char*>
283285
[](const auto& Item) { return std::strcmp(Item, "-cmc") == 0; });
284286
userArgs.erase(toErase, userArgs.end());
285287

286-
// WARNING-WARNING-WARNING*****DIRTY HACK*****WARNING-WARNING-WARNING
287-
// The concept of a "default architecuture" for CM Frontend is a temporary
288-
// workaround.
289-
// The problem is that in order to process CM code CM Frontend must know
290-
// the target architecture.
291-
// Currentl,y OCL runtime does not expose the target architecture
292-
// in a format which CM Frontend understands. The information about
293-
// the target architecture is available only when backend is invoked
294-
// (through PLATFORM data structure).
295-
// The expectation is that we should modify the behavior of OCL runtime
296-
// to propagate the necessary arguments for CMFE
288+
// this was old hack before FE can pass platform, now we prefer to use argument
289+
// but if it is null, it may be still useful, so let it be for a while
297290
auto cmfeDefaultArchOpt = llvm::sys::Process::GetEnv("IGC_CMFE_DEFAULT_ARCH");
298291
const std::string& cmfeDefaultArch =
299292
cmfeDefaultArchOpt ? cmfeDefaultArchOpt.getValue() : "SKL";
@@ -305,14 +298,20 @@ static std::vector<const char*>
305298
};
306299
auto ItArchScanEnd = std::find_if(userArgs.begin(), userArgs.end(),
307300
[](const auto& Arg) { return std::strcmp(Arg, "--") == 0; });
301+
302+
// if user specified exact arch we are in trouble
303+
// but then user knows what to do
308304
auto CmArchPresent = std::any_of(userArgs.begin(), ItArchScanEnd,
309305
[](const auto& Arg) {
310306
llvm::StringRef S = Arg;
311307
return S.startswith("-march=") || S.startswith("-mcpu=");
312308
});
313309
if (!CmArchPresent) {
314-
// Pass the default architecture if user hasn't specified one
315-
result.push_back(stringSaver.save("-march=" + cmfeDefaultArch).data());
310+
// Pass the runtime-specified architecture if user hasn't specified one
311+
if (platform)
312+
result.push_back(stringSaver.save("-march=" + std::string(platform)).data());
313+
else
314+
result.push_back(stringSaver.save("-march=" + cmfeDefaultArch).data());
316315
}
317316

318317
llvm::StringRef FeIncludesPath;
@@ -410,6 +409,31 @@ static std::string getCMFEWrapperDir() {
410409

411410
#endif // !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
412411

412+
// this is copied from Vectorcompiler/igcdeps/src/cmc.cpp
413+
// TODO: converge this code
414+
static const char* getPlatformStr(PLATFORM platform)
415+
{
416+
switch (platform.eDisplayCoreFamily) {
417+
case IGFX_GEN9_CORE:
418+
return "SKL";
419+
case IGFX_GEN10_CORE:
420+
return "CNL";
421+
case IGFX_GEN11_CORE:
422+
if (platform.eProductFamily == IGFX_ICELAKE_LP ||
423+
platform.eProductFamily == IGFX_LAKEFIELD)
424+
return "ICLLP";
425+
return "ICL";
426+
case IGFX_GEN12_CORE:
427+
case IGFX_GEN12LP_CORE:
428+
if (platform.eProductFamily == IGFX_TIGERLAKE_LP ||
429+
platform.eProductFamily == IGFX_DG1)
430+
return "TGLLP";
431+
default:
432+
break;
433+
}
434+
return "SKL";
435+
}
436+
413437
OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
414438
CIF::Version_t outVersion,
415439
CIF::Builtins::BufferSimple* src,
@@ -425,17 +449,14 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
425449
if (outputInterface == nullptr)
426450
return nullptr;
427451

428-
PRODUCT_FAMILY product = IGFX_UNKNOWN;
452+
const char *platform = nullptr;
429453
uint32_t stepping = 0U;
430454

431455
if(globalState.GetPlatformImpl()){
432-
product = globalState.GetPlatformImpl()->p.eProductFamily;
456+
platform = getPlatformStr(globalState.GetPlatformImpl()->p);
433457
stepping = globalState.GetPlatformImpl()->p.usRevId;
434458
}
435459

436-
(void)product;
437-
(void)stepping;
438-
439460
OclTranslationOutputBase& Out = *outputInterface;
440461

441462
#if !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
@@ -454,7 +475,7 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
454475
llvm::BumpPtrAllocator A;
455476
llvm::StringSaver Saver(A);
456477
auto& FE = MaybeFE.getValue();
457-
auto FeArgs = processFeOptions(FE.LibInfo(), OptSrc.getValue(), options, Saver);
478+
auto FeArgs = processFeOptions(FE.LibInfo(), OptSrc.getValue(), options, Saver, platform, stepping);
458479

459480
auto Drv = FE.buildDriverInvocation(FeArgs);
460481
if (!Drv)

0 commit comments

Comments
 (0)