feature: adding support for custom compiler backends

This adds abbility to load different versions of the backend
compiler based on underlying device.

Related-To: NEO-12747

Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
Chodor, Jaroslaw
2024-09-20 20:51:18 +00:00
committed by Compute-Runtime-Automation
parent ec66d9e82d
commit 8098bcc48d
13 changed files with 487 additions and 461 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -14,11 +14,11 @@ namespace NEO {
MockOclocIgcFacade::MockOclocIgcFacade(OclocArgHelper *argHelper) : OclocIgcFacade(argHelper){};
MockOclocIgcFacade::~MockOclocIgcFacade() = default;
std::unique_ptr<OsLibrary> MockOclocIgcFacade::loadIgcLibrary() const {
std::unique_ptr<OsLibrary> MockOclocIgcFacade::loadIgcLibrary(const char *libName) const {
if (shouldFailLoadingOfIgcLib) {
return nullptr;
} else {
return OclocIgcFacade::loadIgcLibrary();
return OclocIgcFacade::loadIgcLibrary(libName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -33,7 +33,7 @@ class MockOclocIgcFacade : public OclocIgcFacade {
MockOclocIgcFacade(OclocArgHelper *argHelper);
~MockOclocIgcFacade() override;
std::unique_ptr<OsLibrary> loadIgcLibrary() const override;
std::unique_ptr<OsLibrary> loadIgcLibrary(const char *libName) const override;
CIF::CreateCIFMainFunc_t loadCreateIgcMainFunction() const override;

View File

@@ -37,7 +37,9 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
return OCLOC_SUCCESS;
}
igcLib = loadIgcLibrary();
auto compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
igcLib = loadIgcLibrary(compilerProductHelper ? compilerProductHelper->getCustomIgcLibraryName() : nullptr);
if (!igcLib) {
argHelper->printf("Error! Loading of IGC library has failed! Filename: %s\n", Os::igcDllName);
return OCLOC_OUT_OF_HOST_MEMORY;
@@ -100,7 +102,6 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
argHelper->printf("Error! IGC device context has not been properly created!\n");
return OCLOC_OUT_OF_HOST_MEMORY;
}
auto compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
populateIgcPlatform(*igcPlatform, hwInfo);
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo.get(), hwInfo.gtSystemInfo);
@@ -111,8 +112,9 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
return OCLOC_SUCCESS;
}
std::unique_ptr<OsLibrary> OclocIgcFacade::loadIgcLibrary() const {
return std::unique_ptr<OsLibrary>{OsLibrary::loadFunc(Os::igcDllName)};
std::unique_ptr<OsLibrary> OclocIgcFacade::loadIgcLibrary(const char *libName) const {
auto effectiveLibName = libName ? libName : Os::igcDllName;
return std::unique_ptr<OsLibrary>{OsLibrary::loadFunc(effectiveLibName)};
}
CIF::CreateCIFMainFunc_t OclocIgcFacade::loadCreateIgcMainFunction() const {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -43,7 +43,7 @@ class OclocIgcFacade {
CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> createTranslationContext(IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType);
protected:
MOCKABLE_VIRTUAL std::unique_ptr<OsLibrary> loadIgcLibrary() const;
MOCKABLE_VIRTUAL std::unique_ptr<OsLibrary> loadIgcLibrary(const char *libName) const;
MOCKABLE_VIRTUAL CIF::CreateCIFMainFunc_t loadCreateIgcMainFunction() const;
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<CIF::CIFMain> createIgcMain(CIF::CreateCIFMainFunc_t createMainFunction) const;
MOCKABLE_VIRTUAL bool isIgcInterfaceCompatible(const std::vector<CIF::InterfaceId_t> &interfacesToIgnore) const;

View File

@@ -52,6 +52,9 @@ void TranslationOutput::makeCopy(MemAndSize &dst, CIF::Builtins::BufferSimple *s
CompilerInterface::CompilerInterface()
: cache() {
if (debugManager.flags.FinalizerInputType.get() != 0) {
this->finalizerInputType = debugManager.flags.FinalizerInputType.get();
}
}
CompilerInterface::~CompilerInterface() = default;
@@ -59,7 +62,7 @@ TranslationOutput::ErrorCode CompilerInterface::build(
const NEO::Device &device,
const TranslationInput &input,
TranslationOutput &output) {
if (false == isCompilerAvailable(input.srcType, input.outType)) {
if (false == isCompilerAvailable(&device, input.srcType, input.outType)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
@@ -82,10 +85,11 @@ TranslationOutput::ErrorCode CompilerInterface::build(
std::string kernelFileHash;
if (cachingMode == CachingMode::Direct) {
const auto &igc = *getIgc(&device);
kernelFileHash = cache->getCachedFileName(device.getHardwareInfo(),
input.src,
input.apiOptions,
input.internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igcRevision, igcLibSize, igcLibMTime);
input.internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igc.revision, igc.libSize, igc.libMTime);
bool success = CompilerCacheHelper::loadCacheAndSetOutput(*cache, kernelFileHash, output, device);
if (success) {
@@ -93,12 +97,15 @@ TranslationOutput::ErrorCode CompilerInterface::build(
}
}
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.src.begin(), input.src.size());
auto fclOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.apiOptions.begin(), input.apiOptions.size());
auto fclInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.internalOptions.begin(), input.internalOptions.size());
const auto &igc = *getIgc(&device);
auto *igcMain = igc.entryPoint.get();
auto idsBuffer = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
auto valuesBuffer = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain, input.src.begin(), input.src.size());
auto fclOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.apiOptions.begin(), input.apiOptions.size());
auto fclInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.internalOptions.begin(), input.internalOptions.size());
auto idsBuffer = CIF::Builtins::CreateConstBuffer(igcMain, nullptr, 0);
auto valuesBuffer = CIF::Builtins::CreateConstBuffer(igcMain, nullptr, 0);
for (const auto &specConst : input.specializedValues) {
idsBuffer->PushBackRawCopy(specConst.first);
valuesBuffer->PushBackRawCopy(specConst.second);
@@ -140,9 +147,10 @@ TranslationOutput::ErrorCode CompilerInterface::build(
const ArrayRef<const char> irRef(intermediateRepresentation->GetMemory<char>(), intermediateRepresentation->GetSize<char>());
const ArrayRef<const char> specIdsRef(idsBuffer->GetMemory<char>(), idsBuffer->GetSize<char>());
const ArrayRef<const char> specValuesRef(valuesBuffer->GetMemory<char>(), valuesBuffer->GetSize<char>());
const auto &igc = *getIgc(&device);
kernelFileHash = cache->getCachedFileName(device.getHardwareInfo(), irRef,
input.apiOptions,
input.internalOptions, specIdsRef, specValuesRef, igcRevision, igcLibSize, igcLibMTime);
input.internalOptions, specIdsRef, specValuesRef, igc.revision, igc.libSize, igc.libMTime);
bool success = CompilerCacheHelper::loadCacheAndSetOutput(*cache, kernelFileHash, output, device);
if (success) {
@@ -150,23 +158,43 @@ TranslationOutput::ErrorCode CompilerInterface::build(
}
}
auto igcTranslationCtx = createIgcTranslationCtx(device, intermediateCodeType, IGC::CodeType::oclGenBin);
auto igcOutputType = IGC::CodeType::oclGenBin;
if (this->finalizerInputType != IGC::CodeType::undefined) {
igcOutputType = this->finalizerInputType;
}
auto igcOutput = translate(igcTranslationCtx.get(), intermediateRepresentation.get(), idsBuffer.get(), valuesBuffer.get(),
fclOptions.get(), fclInternalOptions.get(), input.gtPinInput);
auto igcTranslationCtx = createIgcTranslationCtx(device, intermediateCodeType, igcOutputType);
if (igcOutput == nullptr) {
auto buildOutput = translate(igcTranslationCtx.get(), intermediateRepresentation.get(), idsBuffer.get(), valuesBuffer.get(),
fclOptions.get(), fclInternalOptions.get(), input.gtPinInput);
if (buildOutput == nullptr) {
return TranslationOutput::ErrorCode::unknownError;
}
TranslationOutput::makeCopy(output.backendCompilerLog, igcOutput->GetBuildLog());
TranslationOutput::makeCopy(output.backendCompilerLog, buildOutput->GetBuildLog());
if (igcOutput->Successful() == false) {
if (buildOutput->Successful() == false) {
return TranslationOutput::ErrorCode::buildFailure;
}
TranslationOutput::makeCopy(output.deviceBinary, igcOutput->GetOutput());
TranslationOutput::makeCopy(output.debugData, igcOutput->GetDebugData());
if (igcOutputType == this->finalizerInputType) {
TranslationOutput::makeCopy(output.finalizerInputRepresentation, buildOutput->GetOutput());
auto finalizerTranslationCtx = createFinalizerTranslationCtx(device, this->finalizerInputType, IGC::CodeType::oclGenBin);
auto finalizerOutput = translate(finalizerTranslationCtx.get(), buildOutput->GetOutput(),
fclOptions.get(), fclInternalOptions.get(), nullptr);
buildOutput = std::move(finalizerOutput);
TranslationOutput::append(output.backendCompilerLog, buildOutput->GetBuildLog(), "\n", 0);
if (buildOutput->Successful() == false) {
return TranslationOutput::ErrorCode::buildFailure;
}
}
TranslationOutput::makeCopy(output.deviceBinary, buildOutput->GetOutput());
TranslationOutput::makeCopy(output.debugData, buildOutput->GetDebugData());
if (cache != nullptr && cache->getConfig().enabled) {
CompilerCacheHelper::packAndCacheBinary(*cache, kernelFileHash, NEO::getTargetDevice(device.getRootDeviceEnvironment()), output);
@@ -184,7 +212,7 @@ TranslationOutput::ErrorCode CompilerInterface::compile(
return TranslationOutput::ErrorCode::alreadyCompiled;
}
if (false == isCompilerAvailable(input.srcType, input.outType)) {
if (false == isCompilerAvailable(&device, input.srcType, input.outType)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
@@ -194,9 +222,10 @@ TranslationOutput::ErrorCode CompilerInterface::compile(
outType = getPreferredIntermediateRepresentation(device);
}
auto fclSrc = CIF::Builtins::CreateConstBuffer(fclMain.get(), input.src.begin(), input.src.size());
auto fclOptions = CIF::Builtins::CreateConstBuffer(fclMain.get(), input.apiOptions.begin(), input.apiOptions.size());
auto fclInternalOptions = CIF::Builtins::CreateConstBuffer(fclMain.get(), input.internalOptions.begin(), input.internalOptions.size());
auto *fclMain = fcl.entryPoint.get();
auto fclSrc = CIF::Builtins::CreateConstBuffer(fclMain, input.src.begin(), input.src.size());
auto fclOptions = CIF::Builtins::CreateConstBuffer(fclMain, input.apiOptions.begin(), input.apiOptions.size());
auto fclInternalOptions = CIF::Builtins::CreateConstBuffer(fclMain, input.internalOptions.begin(), input.internalOptions.size());
auto fclTranslationCtx = createFclTranslationCtx(device, input.srcType, outType);
@@ -223,13 +252,14 @@ TranslationOutput::ErrorCode CompilerInterface::link(
const NEO::Device &device,
const TranslationInput &input,
TranslationOutput &output) {
if (false == isCompilerAvailable(input.srcType, input.outType)) {
if (false == isCompilerAvailable(&device, input.srcType, input.outType)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.src.begin(), input.src.size());
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.apiOptions.begin(), input.apiOptions.size());
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.internalOptions.begin(), input.internalOptions.size());
auto *igcMain = getIgc(&device)->entryPoint.get();
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain, input.src.begin(), input.src.size());
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.apiOptions.begin(), input.apiOptions.size());
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.internalOptions.begin(), input.internalOptions.size());
if (inSrc == nullptr) {
return TranslationOutput::ErrorCode::unknownError;
@@ -269,15 +299,16 @@ TranslationOutput::ErrorCode CompilerInterface::link(
}
TranslationOutput::ErrorCode CompilerInterface::getSpecConstantsInfo(const NEO::Device &device, ArrayRef<const char> srcSpirV, SpecConstantInfo &output) {
if (false == isIgcAvailable()) {
if (false == isIgcAvailable(&device)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
auto igcTranslationCtx = createIgcTranslationCtx(device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), srcSpirV.begin(), srcSpirV.size());
output.idsBuffer = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
output.sizesBuffer = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
auto *igcMain = getIgc(&device)->entryPoint.get();
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain, srcSpirV.begin(), srcSpirV.size());
output.idsBuffer = CIF::Builtins::CreateConstBuffer(igcMain, nullptr, 0);
output.sizesBuffer = CIF::Builtins::CreateConstBuffer(igcMain, nullptr, 0);
auto retVal = getSpecConstantsInfoImpl(igcTranslationCtx.get(), inSrc.get(), output.idsBuffer.get(), output.sizesBuffer.get());
@@ -292,13 +323,14 @@ TranslationOutput::ErrorCode CompilerInterface::createLibrary(
NEO::Device &device,
const TranslationInput &input,
TranslationOutput &output) {
if (false == isIgcAvailable()) {
if (false == isIgcAvailable(&device)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.src.begin(), input.src.size());
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.apiOptions.begin(), input.apiOptions.size());
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), input.internalOptions.begin(), input.internalOptions.size());
auto *igcMain = getIgc(&device)->entryPoint.get();
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain, input.src.begin(), input.src.size());
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.apiOptions.begin(), input.apiOptions.size());
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain, input.internalOptions.begin(), input.internalOptions.size());
auto intermediateRepresentation = IGC::CodeType::llvmBc;
auto igcTranslationCtx = createIgcTranslationCtx(device, IGC::CodeType::elf, intermediateRepresentation);
@@ -324,7 +356,7 @@ TranslationOutput::ErrorCode CompilerInterface::createLibrary(
TranslationOutput::ErrorCode CompilerInterface::getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector<char> &retBinary,
std::vector<char> &stateSaveAreaHeader) {
if (false == isIgcAvailable()) {
if (false == isIgcAvailable(&device)) {
return TranslationOutput::ErrorCode::compilerNotAvailable;
}
@@ -358,6 +390,7 @@ TranslationOutput::ErrorCode CompilerInterface::getSipKernelBinary(NEO::Device &
return TranslationOutput::ErrorCode::unknownError;
}
auto *igcMain = getIgc(&device)->entryPoint.get();
auto systemRoutineBuffer = igcMain->CreateBuiltin<CIF::Builtins::BufferLatest>();
auto stateSaveAreaBuffer = igcMain->CreateBuiltin<CIF::Builtins::BufferLatest>();
@@ -381,37 +414,41 @@ CIF::RAII::UPtr_t<IGC::IgcFeaturesAndWorkaroundsTagOCL> CompilerInterface::getIg
}
bool CompilerInterface::loadFcl() {
return NEO::loadCompiler<IGC::FclOclDeviceCtx>(Os::frontEndDllName, fclLib, fclMain);
return NEO::loadCompiler<IGC::FclOclDeviceCtx>(Os::frontEndDllName, fcl.library, fcl.entryPoint);
}
bool CompilerInterface::loadIgc() {
bool result = NEO::loadCompiler<IGC::IgcOclDeviceCtx>(Os::igcDllName, igcLib, igcMain);
bool CompilerInterface::loadIgcBasedCompiler(CompilerLibraryEntry &entry, const char *libName) {
bool result = NEO::loadCompiler<IGC::IgcOclDeviceCtx>(libName, entry.library, entry.entryPoint);
if (result) {
std::string igcPath = igcLib->getFullPath();
igcLibSize = NEO::getFileSize(igcPath);
igcLibMTime = NEO::getFileModificationTime(igcPath);
std::string libPath = entry.library->getFullPath();
entry.libSize = NEO::getFileSize(libPath);
entry.libMTime = NEO::getFileModificationTime(libPath);
auto igcDeviceCtx3 = igcMain->CreateInterface<IGC::IgcOclDeviceCtx<3>>();
auto igcDeviceCtx3 = entry.entryPoint->CreateInterface<IGC::IgcOclDeviceCtx<3>>();
if (igcDeviceCtx3) {
igcRevision = igcDeviceCtx3->GetIGCRevision();
entry.revision = igcDeviceCtx3->GetIGCRevision();
}
}
return result;
}
bool CompilerInterface::loadFinalizer(CompilerLibraryEntry &entry, const char *libName) {
std::string finalizerLibName = libName;
if (debugManager.flags.FinalizerLibraryName.get() != "unk") {
finalizerLibName = debugManager.flags.FinalizerLibraryName.get();
}
return NEO::loadCompiler<IGC::IgcOclDeviceCtx>(libName, entry.library, entry.entryPoint);
}
bool CompilerInterface::initialize(std::unique_ptr<CompilerCache> &&cache, bool requireFcl) {
bool fclAvailable = requireFcl ? this->loadFcl() : false;
bool igcAvailable = this->loadIgc();
bool compilerVersionCorrect = true;
if (!debugManager.flags.ZebinIgnoreIcbeVersion.get()) {
compilerVersionCorrect = verifyIcbeVersion();
}
bool igcAvailable = this->loadIgcBasedCompiler(defaultIgc, Os::igcDllName);
this->cache.swap(cache);
return this->cache && igcAvailable && (fclAvailable || (false == requireFcl)) && compilerVersionCorrect;
return this->cache && igcAvailable && (fclAvailable || (false == requireFcl));
}
IGC::FclOclDeviceCtxTagOCL *CompilerInterface::getFclDeviceCtx(const Device &device) {
@@ -421,12 +458,12 @@ IGC::FclOclDeviceCtxTagOCL *CompilerInterface::getFclDeviceCtx(const Device &dev
return it->second.get();
}
if (fclMain == nullptr) {
if (fcl.entryPoint == nullptr) {
DEBUG_BREAK_IF(true); // compiler not available
return nullptr;
}
auto newDeviceCtx = fclMain->CreateInterface<IGC::FclOclDeviceCtxTagOCL>();
auto newDeviceCtx = fcl.entryPoint->CreateInterface<IGC::FclOclDeviceCtxTagOCL>();
if (newDeviceCtx == nullptr) {
DEBUG_BREAK_IF(true); // could not create device context
return nullptr;
@@ -453,10 +490,12 @@ IGC::IgcOclDeviceCtxTagOCL *CompilerInterface::getIgcDeviceCtx(const Device &dev
return it->second.get();
}
if (igcMain == nullptr) {
auto *igc = getIgc(&device);
if (igc == nullptr) {
DEBUG_BREAK_IF(true); // compiler not available
return nullptr;
}
auto *igcMain = igc->entryPoint.get();
auto newDeviceCtx = igcMain->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
if (newDeviceCtx == nullptr) {
@@ -490,6 +529,51 @@ IGC::IgcOclDeviceCtxTagOCL *CompilerInterface::getIgcDeviceCtx(const Device &dev
return igcDeviceContexts[&device].get();
}
IGC::IgcOclDeviceCtxTagOCL *CompilerInterface::getFinalizerDeviceCtx(const Device &device) {
auto ulock = this->lock();
auto it = finalizerDeviceContexts.find(&device);
if (it != finalizerDeviceContexts.end()) {
return it->second.get();
}
auto finalizer = this->getFinalizer(&device);
if (finalizer == nullptr) {
DEBUG_BREAK_IF(true); // compiler not available
return nullptr;
}
auto newDeviceCtx = finalizer->entryPoint->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
if (newDeviceCtx == nullptr) {
DEBUG_BREAK_IF(true); // could not create device context
return nullptr;
}
newDeviceCtx->SetProfilingTimerResolution(static_cast<float>(device.getDeviceInfo().outProfilingTimerResolution));
auto igcPlatform = newDeviceCtx->GetPlatformHandle();
auto igcGtSystemInfo = newDeviceCtx->GetGTSystemInfoHandle();
auto igcFtrWa = newDeviceCtx->GetIgcFeaturesAndWorkaroundsHandle();
if (false == NEO::areNotNullptr(igcPlatform.get(), igcGtSystemInfo.get(), igcFtrWa.get())) {
DEBUG_BREAK_IF(true); // could not acquire handles to device descriptors
return nullptr;
}
const HardwareInfo *hwInfo = &device.getHardwareInfo();
auto productFamily = debugManager.flags.ForceCompilerUsePlatform.get();
if (productFamily != "unk") {
getHwInfoForPlatformString(productFamily, hwInfo);
}
populateIgcPlatform(*igcPlatform, *hwInfo);
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo, hwInfo->gtSystemInfo);
auto &compilerProductHelper = device.getCompilerProductHelper();
igcFtrWa->SetFtrGpGpuMidThreadLevelPreempt(compilerProductHelper.isMidThreadPreemptionSupported(*hwInfo));
igcFtrWa->SetFtrWddm2Svm(device.getHardwareInfo().featureTable.flags.ftrWddm2Svm);
igcFtrWa->SetFtrPooledEuEnabled(device.getHardwareInfo().featureTable.flags.ftrPooledEuEnabled);
finalizerDeviceContexts[&device] = std::move(newDeviceCtx);
return finalizerDeviceContexts[&device].get();
}
IGC::CodeType::CodeType_t CompilerInterface::getPreferredIntermediateRepresentation(const Device &device) {
return getFclDeviceCtx(device)->GetPreferredIntermediateRepresentation();
}
@@ -521,50 +605,18 @@ CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> CompilerInterface::createIgcT
return deviceCtx->CreateTranslationCtx(inType, outType);
}
template <template <CIF::Version_t> class EntryPointT>
void checkIcbeVersion(CIF::CIFMain *main, const char *libName, bool &ret) {
if (false == main->IsCompatible<EntryPointT>()) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Installed Compiler Library %s is incompatible\n", libName);
DEBUG_BREAK_IF(true); // given compiler library is not compatible
ret = false;
return;
CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> CompilerInterface::createFinalizerTranslationCtx(const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) {
auto deviceCtx = getFinalizerDeviceCtx(device);
if (deviceCtx == nullptr) {
DEBUG_BREAK_IF(true); // could not create device context
return nullptr;
}
ret = true;
}
template <>
std::once_flag &CompilerInterface::getIcbeVersionCallOnceFlag<IGC::IgcOclDeviceCtx>() {
return igcIcbeCheckVersionCallOnce;
}
template <>
std::once_flag &CompilerInterface::getIcbeVersionCallOnceFlag<IGC::FclOclDeviceCtx>() {
return fclIcbeCheckVersionCallOnce;
}
template <template <CIF::Version_t> class EntryPointT>
bool CompilerInterface::checkIcbeVersionOnce(CIF::CIFMain *main, const char *libName) {
bool ret = true;
std::call_once(getIcbeVersionCallOnceFlag<EntryPointT>(), checkIcbeVersion<EntryPointT>, main, libName, ret);
return ret;
}
bool CompilerInterface::verifyIcbeVersion() {
bool versionIsCorrect = true;
if (isFclAvailable()) {
versionIsCorrect = checkIcbeVersionOnce<IGC::FclOclDeviceCtx>(fclMain.get(), Os::frontEndDllName);
}
if (isIgcAvailable()) {
versionIsCorrect &= checkIcbeVersionOnce<IGC::IgcOclDeviceCtx>(igcMain.get(), Os::igcDllName);
}
return versionIsCorrect;
return deviceCtx->CreateTranslationCtx(inType, outType);
}
bool CompilerInterface::addOptionDisableZebin(std::string &options, std::string &internalOptions) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::disableZebin);
if (!verifyIcbeVersion()) {
return false;
}
return true;
}
@@ -572,8 +624,47 @@ bool CompilerInterface::disableZebin(std::string &options, std::string &internal
return addOptionDisableZebin(options, internalOptions);
}
template bool CompilerInterface::checkIcbeVersionOnce<IGC::FclOclDeviceCtx>(CIF::CIFMain *main, const char *libName);
template bool CompilerInterface::checkIcbeVersionOnce<IGC::IgcOclDeviceCtx>(CIF::CIFMain *main, const char *libName);
bool CompilerInterface::isIgcAvailable(const Device *device) {
return nullptr != getIgc(device);
}
bool CompilerInterface::isFinalizerAvailable(const Device *device) {
return nullptr != getFinalizer(device);
}
const CompilerInterface::CompilerLibraryEntry *CompilerInterface::getIgc(const Device *device) {
if (nullptr == device) {
if (defaultIgc.entryPoint == nullptr) {
return nullptr;
}
return &defaultIgc;
}
return getIgc(device->getCompilerProductHelper().getCustomIgcLibraryName());
}
const CompilerInterface::CompilerLibraryEntry *CompilerInterface::getFinalizer(const Device *device) {
if (nullptr == device) {
return nullptr;
}
return getFinalizer(device->getCompilerProductHelper().getFinalizerLibraryName());
}
const CompilerInterface::CompilerLibraryEntry *CompilerInterface::getCustomCompilerLibrary(const char *libName) {
auto it = customCompilerLibraries.find(libName);
if (it != customCompilerLibraries.end()) {
return it->second.get();
}
CompilerLibraryEntry newEntry = {};
this->loadIgcBasedCompiler(newEntry, libName);
if (newEntry.entryPoint == nullptr) {
return nullptr;
}
customCompilerLibraries[libName].reset(new CompilerLibraryEntry(std::move(newEntry)));
return customCompilerLibraries[libName].get();
}
void CompilerCacheHelper::packAndCacheBinary(CompilerCache &compilerCache, const std::string &kernelFileHash, const NEO::TargetDevice &targetDevice, const NEO::TranslationOutput &translationOutput) {
NEO::SingleDeviceBinary singleDeviceBinary = {};

View File

@@ -64,6 +64,7 @@ struct TranslationOutput {
IGC::CodeType::CodeType_t intermediateCodeType = IGC::CodeType::invalid;
MemAndSize intermediateRepresentation;
MemAndSize finalizerInputRepresentation;
MemAndSize deviceBinary;
MemAndSize debugData;
std::string frontendCompilerLog;
@@ -78,6 +79,22 @@ struct TranslationOutput {
dst.assign(src->GetMemory<char>(), src->GetSize<char>());
}
template <typename ContainerT, typename SeparatorT>
static void append(ContainerT &dst, CIF::Builtins::BufferSimple *src, const SeparatorT *separator, size_t separatorLen) {
if ((nullptr == src) || (src->GetSizeRaw() == 0)) {
return;
}
if ((false == dst.empty()) && separator && (separatorLen > 0)) {
dst.append(separator, separatorLen);
}
dst.append(src->GetMemory<char>(), src->GetSize<char>());
}
template <typename ContainerT, typename SeparatorT>
static void append(ContainerT &dst, CIF::Builtins::BufferSimple *src, const SeparatorT *separator) {
append(dst, src, separator, 1);
}
static void makeCopy(MemAndSize &dst, CIF::Builtins::BufferSimple *src);
};
@@ -133,18 +150,22 @@ class CompilerInterface {
bool disableZebin(std::string &options, std::string &internalOptions);
protected:
struct CompilerLibraryEntry {
std::string revision;
size_t libSize{};
time_t libMTime{};
std::unique_ptr<OsLibrary> library;
CIF::RAII::UPtr_t<CIF::CIFMain> entryPoint;
};
MOCKABLE_VIRTUAL bool initialize(std::unique_ptr<CompilerCache> &&cache, bool requireFcl);
MOCKABLE_VIRTUAL bool loadFcl();
MOCKABLE_VIRTUAL bool loadIgc();
MOCKABLE_VIRTUAL bool loadIgcBasedCompiler(CompilerLibraryEntry &entryPoint, const char *libName);
MOCKABLE_VIRTUAL bool loadFinalizer(CompilerLibraryEntry &entryPoint, const char *libName);
template <template <CIF::Version_t> class EntryPointT>
std::once_flag &getIcbeVersionCallOnceFlag();
template <template <CIF::Version_t> class EntryPointT>
bool checkIcbeVersionOnce(CIF::CIFMain *main, const char *libName);
bool verifyIcbeVersion();
static SpinLock spinlock;
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> lock() {
return std::unique_lock<SpinLock>{spinlock};
@@ -152,22 +173,23 @@ class CompilerInterface {
std::unique_ptr<CompilerCache> cache;
using igcDevCtxUptr = CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL>;
using finalizerDevCtxUptr = CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL>;
using fclDevCtxUptr = CIF::RAII::UPtr_t<IGC::FclOclDeviceCtxTagOCL>;
std::unique_ptr<OsLibrary> igcLib;
CIF::RAII::UPtr_t<CIF::CIFMain> igcMain;
std::map<const Device *, igcDevCtxUptr> igcDeviceContexts;
std::string igcRevision;
size_t igcLibSize{};
time_t igcLibMTime{};
CompilerLibraryEntry defaultIgc;
std::unordered_map<std::string, std::unique_ptr<CompilerLibraryEntry>> customCompilerLibraries;
std::unordered_map<const Device *, igcDevCtxUptr> igcDeviceContexts;
std::unique_ptr<OsLibrary> fclLib;
CIF::RAII::UPtr_t<CIF::CIFMain> fclMain;
std::map<const Device *, fclDevCtxUptr> fclDeviceContexts;
CompilerLibraryEntry fcl;
std::unordered_map<const Device *, fclDevCtxUptr> fclDeviceContexts;
CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> fclBaseTranslationCtx;
std::unordered_map<const Device *, finalizerDevCtxUptr> finalizerDeviceContexts;
IGC::CodeType::CodeType_t finalizerInputType = IGC::CodeType::undefined;
MOCKABLE_VIRTUAL IGC::FclOclDeviceCtxTagOCL *getFclDeviceCtx(const Device &device);
MOCKABLE_VIRTUAL IGC::IgcOclDeviceCtxTagOCL *getIgcDeviceCtx(const Device &device);
MOCKABLE_VIRTUAL IGC::IgcOclDeviceCtxTagOCL *getFinalizerDeviceCtx(const Device &device);
MOCKABLE_VIRTUAL IGC::CodeType::CodeType_t getPreferredIntermediateRepresentation(const Device &device);
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> createFclTranslationCtx(const Device &device,
@@ -176,18 +198,46 @@ class CompilerInterface {
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> createIgcTranslationCtx(const Device &device,
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType);
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> createFinalizerTranslationCtx(const Device &device,
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType);
bool isFclAvailable() const {
return (fclMain != nullptr);
return (fcl.entryPoint.get() != nullptr);
}
bool isIgcAvailable() const {
return (igcMain != nullptr);
bool isIgcAvailable(const Device *device);
bool isFinalizerAvailable(const Device *device);
const CompilerLibraryEntry *getCustomCompilerLibrary(const char *libName);
const CompilerLibraryEntry *getIgc(const char *libName) {
if (libName == nullptr) {
if (defaultIgc.entryPoint == nullptr) {
return nullptr;
}
return &defaultIgc;
}
return getCustomCompilerLibrary(libName);
}
bool isCompilerAvailable(IGC::CodeType::CodeType_t translationSrc, IGC::CodeType::CodeType_t translationDst) const {
const CompilerLibraryEntry *getIgc(const Device *device);
const CompilerLibraryEntry *getFinalizer(const char *libName) {
if (libName == nullptr) {
return nullptr;
}
return getCustomCompilerLibrary(libName);
}
const CompilerLibraryEntry *getFinalizer(const Device *device);
bool isCompilerAvailable(const Device *device, IGC::CodeType::CodeType_t translationSrc, IGC::CodeType::CodeType_t translationDst) {
bool requiresFcl = (IGC::CodeType::oclC == translationSrc);
bool requiresIgc = (IGC::CodeType::oclC != translationSrc) || ((IGC::CodeType::spirV != translationDst) && (IGC::CodeType::llvmBc != translationDst) && (IGC::CodeType::llvmLl != translationDst));
return (isFclAvailable() || (false == requiresFcl)) && (isIgcAvailable() || (false == requiresIgc));
bool requiresFinalizer = (finalizerInputType != IGC::CodeType::undefined) && ((translationDst == IGC::CodeType::oclGenBin) || (translationSrc == finalizerInputType));
return (isFclAvailable() || (false == requiresFcl)) && (isIgcAvailable(device) || (false == requiresIgc)) && ((false == requiresFinalizer) || isFinalizerAvailable(device));
}
std::once_flag igcIcbeCheckVersionCallOnce;

View File

@@ -638,6 +638,8 @@ DECLARE_DEBUG_VARIABLE(int32_t, EnableSetPair, -1, "Use SET_PAIR to pair two buf
DECLARE_DEBUG_VARIABLE(int32_t, ForcePreferredAllocationMethod, -1, "Sets preferred allocation method for Wddm paths; values = -1: driver default, 0: UseUmdSystemPtr, 1: AllocateByKmd")
DECLARE_DEBUG_VARIABLE(int32_t, EventTimestampRefreshIntervalInMilliSec, -1, "-1: use driver default, This value sets the refresh interval for getting synchronized GPU and CPU timestamp")
DECLARE_DEBUG_VARIABLE(int64_t, ReadOnlyAllocationsTypeMask, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, set as read only resource.")
DECLARE_DEBUG_VARIABLE(int64_t, FinalizerInputType, 0, "0: default (N/A), input type for finalizer")
DECLARE_DEBUG_VARIABLE(std::string, FinalizerLibraryName, std::string("unk"), "Library name for finalizer")
/* Binary Cache */
DECLARE_DEBUG_VARIABLE(bool, BinaryCacheTrace, false, "enable cl_cache to produce .trace files with information about hash computation")

View File

@@ -86,6 +86,8 @@ class CompilerProductHelper {
virtual void getKernelFp64AtomicCapabilities(uint32_t &fp64Caps) const = 0;
virtual void getKernelCapabilitiesExtra(const ReleaseHelper *releaseHelper, uint32_t &extraCaps) const = 0;
virtual bool isBindlessAddressingDisabled(const ReleaseHelper *releaseHelper) const = 0;
virtual const char *getCustomIgcLibraryName() const = 0;
virtual const char *getFinalizerLibraryName() const = 0;
virtual ~CompilerProductHelper() = default;
uint32_t getHwIpVersion(const HardwareInfo &hwInfo) const;
@@ -137,6 +139,8 @@ class CompilerProductHelperHw : public CompilerProductHelper {
void getKernelFp64AtomicCapabilities(uint32_t &fp64Caps) const override;
void getKernelCapabilitiesExtra(const ReleaseHelper *releaseHelper, uint32_t &extraCaps) const override;
bool isBindlessAddressingDisabled(const ReleaseHelper *releaseHelper) const override;
const char *getCustomIgcLibraryName() const override;
const char *getFinalizerLibraryName() const override;
~CompilerProductHelperHw() override = default;

View File

@@ -13,6 +13,7 @@
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/hw_info_helper.h"
#include "shared/source/kernel/kernel_properties.h"
#include "shared/source/os_interface/os_inc_base.h"
#include "shared/source/release_helper/release_helper.h"
namespace NEO {
@@ -317,6 +318,7 @@ void CompilerProductHelperHw<gfxProduct>::getKernelCapabilitiesExtra(const Relea
extraCaps |= releaseHelper->getAdditionalExtraCaps();
}
}
template <PRODUCT_FAMILY gfxProduct>
bool CompilerProductHelperHw<gfxProduct>::isBindlessAddressingDisabled(const ReleaseHelper *releaseHelper) const {
if (releaseHelper) {
@@ -325,4 +327,14 @@ bool CompilerProductHelperHw<gfxProduct>::isBindlessAddressingDisabled(const Rel
return true;
}
template <PRODUCT_FAMILY gfxProduct>
const char *CompilerProductHelperHw<gfxProduct>::getCustomIgcLibraryName() const {
return nullptr;
}
template <PRODUCT_FAMILY gfxProduct>
const char *CompilerProductHelperHw<gfxProduct>::getFinalizerLibraryName() const {
return nullptr;
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -15,6 +15,7 @@
#include <functional>
#include <map>
#include <optional>
#include <string>
namespace NEO {
@@ -22,17 +23,18 @@ namespace NEO {
class MockCompilerInterface : public CompilerInterface {
public:
using CompilerInterface::cache;
using CompilerInterface::checkIcbeVersionOnce;
using CompilerInterface::fclBaseTranslationCtx;
using CompilerInterface::fclDeviceContexts;
using CompilerInterface::initialize;
using CompilerInterface::isCompilerAvailable;
using CompilerInterface::isFclAvailable;
using CompilerInterface::isIgcAvailable;
using CompilerInterface::verifyIcbeVersion;
using CompilerInterface::fclMain;
using CompilerInterface::igcMain;
using CompilerInterface::defaultIgc;
using CompilerInterface::fcl;
using CompilerInterface::customCompilerLibraries;
using CompilerInterface::finalizerDeviceContexts;
bool loadFcl() override {
if (failLoadFcl) {
@@ -41,18 +43,23 @@ class MockCompilerInterface : public CompilerInterface {
return CompilerInterface::loadFcl();
}
bool loadIgc() override {
bool loadIgcBasedCompiler(CompilerLibraryEntry &entryPoint, const char *libName) override {
if (failLoadIgc) {
return false;
}
return CompilerInterface::loadIgc();
if (igcLibraryNameOverride.has_value()) {
libName = *igcLibraryNameOverride;
}
return CompilerInterface::loadIgcBasedCompiler(entryPoint, libName);
}
void setFclDeviceCtx(const Device &d, IGC::FclOclDeviceCtxTagOCL *ctx) {
this->fclDeviceContexts[&d] = CIF::RAII::RetainAndPack<IGC::FclOclDeviceCtxTagOCL>(ctx);
}
std::map<const Device *, fclDevCtxUptr> &getFclDeviceContexts() {
std::unordered_map<const Device *, fclDevCtxUptr> &getFclDeviceContexts() {
return this->fclDeviceContexts;
}
@@ -60,7 +67,11 @@ class MockCompilerInterface : public CompilerInterface {
this->igcDeviceContexts[&d] = CIF::RAII::RetainAndPack<IGC::IgcOclDeviceCtxTagOCL>(ctx);
}
std::map<const Device *, igcDevCtxUptr> &getIgcDeviceContexts() {
void setFinalizerDeviceCtx(const Device &d, IGC::IgcOclDeviceCtxTagOCL *ctx) {
this->finalizerDeviceContexts[&d] = CIF::RAII::RetainAndPack<IGC::IgcOclDeviceCtxTagOCL>(ctx);
}
std::unordered_map<const Device *, igcDevCtxUptr> &getIgcDeviceContexts() {
return this->igcDeviceContexts;
}
@@ -73,7 +84,7 @@ class MockCompilerInterface : public CompilerInterface {
}
template <typename DeviceCtx>
std::map<const Device *, CIF::RAII::UPtr_t<DeviceCtx>> &getDeviceContexts();
std::unordered_map<const Device *, CIF::RAII::UPtr_t<DeviceCtx>> &getDeviceContexts();
std::unique_lock<SpinLock> lock() override {
if (lockListener != nullptr) {
@@ -84,13 +95,13 @@ class MockCompilerInterface : public CompilerInterface {
}
void setIgcMain(CIF::CIFMain *main) {
this->igcMain.release();
this->igcMain.reset(main);
this->defaultIgc.entryPoint.release();
this->defaultIgc.entryPoint.reset(main);
}
void setFclMain(CIF::CIFMain *main) {
this->fclMain.release();
this->fclMain.reset(main);
this->fcl.entryPoint.release();
this->fcl.entryPoint.reset(main);
}
IGC::IgcOclDeviceCtxTagOCL *getIgcDeviceCtx(const Device &device) override {
@@ -123,6 +134,17 @@ class MockCompilerInterface : public CompilerInterface {
return CompilerInterface::createIgcTranslationCtx(device, inType, outType);
}
CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> createFinalizerTranslationCtx(const Device &device,
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType) override {
requestedTranslationCtxs.emplace_back(inType, outType);
if (failCreateFinalizerTranslationCtx) {
return nullptr;
}
return CompilerInterface::createFinalizerTranslationCtx(device, inType, outType);
}
IGC::FclOclTranslationCtxTagOCL *getFclBaseTranslationCtx() {
return this->fclBaseTranslationCtx.get();
}
@@ -154,9 +176,11 @@ class MockCompilerInterface : public CompilerInterface {
IGC::IgcFeaturesAndWorkaroundsTagOCL *igcFeaturesAndWorkaroundsTagOCL = nullptr;
bool failCreateFclTranslationCtx = false;
bool failCreateIgcTranslationCtx = false;
bool failCreateFinalizerTranslationCtx = false;
bool failLoadFcl = false;
bool failLoadIgc = false;
bool failGetIgcDeviceCtx = false;
std::optional<const char *> igcLibraryNameOverride;
using TranslationOpT = std::pair<IGC::CodeType::CodeType_t, IGC::CodeType::CodeType_t>;
std::vector<TranslationOpT> requestedTranslationCtxs;
@@ -168,12 +192,12 @@ class MockCompilerInterface : public CompilerInterface {
};
template <>
inline std::map<const Device *, MockCompilerInterface::igcDevCtxUptr> &MockCompilerInterface::getDeviceContexts<IGC::IgcOclDeviceCtxTagOCL>() {
inline std::unordered_map<const Device *, MockCompilerInterface::igcDevCtxUptr> &MockCompilerInterface::getDeviceContexts<IGC::IgcOclDeviceCtxTagOCL>() {
return getIgcDeviceContexts();
}
template <>
inline std::map<const Device *, MockCompilerInterface::fclDevCtxUptr> &MockCompilerInterface::getDeviceContexts<IGC::FclOclDeviceCtxTagOCL>() {
inline std::unordered_map<const Device *, MockCompilerInterface::fclDevCtxUptr> &MockCompilerInterface::getDeviceContexts<IGC::FclOclDeviceCtxTagOCL>() {
return getFclDeviceContexts();
}

View File

@@ -61,8 +61,9 @@ class MockCompilerProductHelper : public CompilerProductHelper {
ADDMETHOD_CONST_NOBASE_VOIDRETURN(getKernelFp64AtomicCapabilities, (uint32_t & fp64Caps));
ADDMETHOD_CONST_NOBASE_VOIDRETURN(getKernelCapabilitiesExtra, (const ReleaseHelper *releaseHelper, uint32_t &extraCaps));
ADDMETHOD_CONST_NOBASE(isBindlessAddressingDisabled, bool, false, (const ReleaseHelper *releaseHelper));
ADDMETHOD_CONST_NOBASE(getProductConfigFromHwInfo, uint32_t, 0, (const HardwareInfo &hwInfo));
ADDMETHOD_CONST_NOBASE(getCustomIgcLibraryName, const char *, nullptr, ());
ADDMETHOD_CONST_NOBASE(getFinalizerLibraryName, const char *, nullptr, ());
};
} // namespace NEO

View File

@@ -624,6 +624,8 @@ DirectSubmissionPrintSemaphoreUsage = -1
ForceNonCoherentModeForTimestamps = 0
ExperimentalUSMAllocationReuseVersion = -1
ForceNonWalkerSplitMemoryCopy = -1
FinalizerInputType = 0
FinalizerLibraryName = unk
DirectSubmissionSwitchSemaphoreMode = -1
OverrideTimestampWidth = -1
# Please don't edit below this line

View File

@@ -21,6 +21,7 @@
#include "shared/test/common/libult/global_environment.h"
#include "shared/test/common/mocks/mock_cif.h"
#include "shared/test/common/mocks/mock_compiler_interface.h"
#include "shared/test/common/mocks/mock_compiler_product_helper.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -169,7 +170,7 @@ TEST_F(CompilerInterfaceTest, WhenPreferredIntermediateRepresentationSpecifiedTh
}
TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenBuildFailsGracefully) {
pCompilerInterface->igcMain.reset(nullptr);
pCompilerInterface->defaultIgc.entryPoint.reset(nullptr);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
EXPECT_EQ(TranslationOutput::ErrorCode::compilerNotAvailable, err);
@@ -256,7 +257,7 @@ TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenCompileFailsGraceful
MockCompilerDebugVars fclDebugVars;
fclDebugVars.fileName = clFiles + "copybuffer.elf";
gEnvironment->fclPushDebugVars(fclDebugVars);
pCompilerInterface->igcMain->Release();
pCompilerInterface->defaultIgc.entryPoint->Release();
pCompilerInterface->setIgcMain(nullptr);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->compile(*pDevice, inputArgs, translationOutput);
@@ -321,7 +322,7 @@ TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenLinkFailsGracefully)
MockCompilerDebugVars igcDebugVars;
igcDebugVars.fileName = clFiles + "copybuffer.ll";
gEnvironment->igcPushDebugVars(igcDebugVars);
pCompilerInterface->igcMain->Release();
pCompilerInterface->defaultIgc.entryPoint->Release();
pCompilerInterface->setIgcMain(nullptr);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->link(*pDevice, inputArgs, translationOutput);
@@ -387,7 +388,7 @@ TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenCreateLibraryFailsGr
MockCompilerDebugVars igcDebugVars;
igcDebugVars.fileName = clFiles + "copybuffer.ll";
gEnvironment->igcPushDebugVars(igcDebugVars);
pCompilerInterface->igcMain->Release();
pCompilerInterface->defaultIgc.entryPoint->Release();
pCompilerInterface->setIgcMain(nullptr);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->createLibrary(*pDevice, inputArgs, translationOutput);
@@ -836,9 +837,12 @@ TEST_F(CompilerInterfaceTest, GivenRequestForNewTranslationCtxWhenCouldNotCreate
auto retFcl = pCompilerInterface->createFclTranslationCtx(*device, IGC::CodeType::oclC, IGC::CodeType::spirV);
EXPECT_EQ(nullptr, retFcl);
auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::oclC, IGC::CodeType::spirV);
auto retIgc = pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::elf);
EXPECT_EQ(nullptr, retIgc);
auto retFinalizer = pCompilerInterface->createFinalizerTranslationCtx(*device, IGC::CodeType::undefined, IGC::CodeType::elf);
EXPECT_EQ(nullptr, retFinalizer);
NEO::MockCIFMain::setGlobalCreatorFunc<NEO::MockFclOclDeviceCtx>(befFclMock);
NEO::MockCIFMain::setGlobalCreatorFunc<NEO::MockIgcOclDeviceCtx>(befIgcMock);
}
@@ -852,6 +856,53 @@ TEST_F(CompilerInterfaceTest, GivenRequestForNewIgcTranslationCtxWhenDeviceCtxIs
EXPECT_EQ(deviceCtx->returned, ret.get());
}
TEST_F(CompilerInterfaceTest, GivenRequestForNewFinalizerTranslationCtxWhenDeviceCtxIsAlreadyAvailableThenUseItToReturnValidTranslationCtx) {
auto device = this->pDevice;
auto deviceCtx = CIF::RAII::UPtr(new MockCompilerDeviceCtx<MockIgcOclDeviceCtx, MockIgcOclTranslationCtx>);
this->pCompilerInterface->setFinalizerDeviceCtx(*device, deviceCtx.get());
auto ret = this->pCompilerInterface->createFinalizerTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
EXPECT_NE(nullptr, ret.get());
EXPECT_EQ(deviceCtx->returned, ret.get());
}
TEST_F(CompilerInterfaceTest, GivenRequestForNewFinalizerTranslationCtxWhenDeviceCtxIsNotAlreadyAvailableThenCreateNewDeviceCtx) {
MockCompilerProductHelper *mockCompilerProductHelper = nullptr;
auto device = this->pDevice;
{
auto tmp = std::make_unique<MockCompilerProductHelper>();
mockCompilerProductHelper = tmp.get();
device->getRootDeviceEnvironmentRef().compilerProductHelper = std::move(tmp);
}
mockCompilerProductHelper->getFinalizerLibraryNameResult = "finalzer_lib";
this->pCompilerInterface->igcLibraryNameOverride = "";
auto ret = this->pCompilerInterface->createFinalizerTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
EXPECT_NE(nullptr, ret.get());
}
TEST_F(CompilerInterfaceTest, GivenRequestForNewFinalizerTranslationCtxWhenDeviceCtxIsAlreadyAvailableThenReuseThatDeviceCtx) {
MockCompilerProductHelper *mockCompilerProductHelper = nullptr;
auto device = this->pDevice;
{
auto tmp = std::make_unique<MockCompilerProductHelper>();
mockCompilerProductHelper = tmp.get();
device->getRootDeviceEnvironmentRef().compilerProductHelper = std::move(tmp);
}
mockCompilerProductHelper->getFinalizerLibraryNameResult = "finalzer_lib";
this->pCompilerInterface->igcLibraryNameOverride = "";
auto ret = this->pCompilerInterface->createFinalizerTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
EXPECT_NE(nullptr, ret.get());
ret = this->pCompilerInterface->createFinalizerTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
EXPECT_NE(nullptr, ret.get());
EXPECT_EQ(1U, this->pCompilerInterface->customCompilerLibraries.size());
EXPECT_EQ(1U, this->pCompilerInterface->finalizerDeviceContexts.size());
}
TEST_F(CompilerInterfaceTest, GivenSimultaneousRequestForNewIgcTranslationContextsWhenDeviceCtxIsNotAlreadyAvailableThenSynchronizeToCreateOnlyOneNewDeviceCtx) {
auto device = this->pDevice;
@@ -947,66 +998,66 @@ HWTEST_F(CompilerInterfaceTest, givenDbgKeyForceUseDifferentPlatformWhenRequestF
}
TEST_F(CompilerInterfaceTest, GivenCompilerWhenGettingCompilerAvailabilityThenCompilerHasCorrectCapabilities) {
ASSERT_TRUE(this->pCompilerInterface->igcMain && this->pCompilerInterface->fclMain);
ASSERT_TRUE(this->pCompilerInterface->defaultIgc.entryPoint && this->pCompilerInterface->fcl.entryPoint);
EXPECT_TRUE(this->pCompilerInterface->isFclAvailable());
EXPECT_TRUE(this->pCompilerInterface->isIgcAvailable());
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isIgcAvailable(nullptr));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::oclGenBin));
auto befIgcImain = std::move(this->pCompilerInterface->igcMain);
auto befIgcImain = std::move(this->pCompilerInterface->defaultIgc.entryPoint);
EXPECT_TRUE(this->pCompilerInterface->isFclAvailable());
EXPECT_FALSE(this->pCompilerInterface->isIgcAvailable());
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->igcMain = std::move(befIgcImain);
EXPECT_FALSE(this->pCompilerInterface->isIgcAvailable(nullptr));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->defaultIgc.entryPoint = std::move(befIgcImain);
auto befFclImain = std::move(this->pCompilerInterface->fclMain);
auto befFclImain = std::move(this->pCompilerInterface->fcl.entryPoint);
EXPECT_FALSE(this->pCompilerInterface->isFclAvailable());
EXPECT_TRUE(this->pCompilerInterface->isIgcAvailable());
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->fclMain = std::move(befFclImain);
EXPECT_TRUE(this->pCompilerInterface->isIgcAvailable(nullptr));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->fcl.entryPoint = std::move(befFclImain);
befIgcImain = std::move(this->pCompilerInterface->igcMain);
befFclImain = std::move(this->pCompilerInterface->fclMain);
befIgcImain = std::move(this->pCompilerInterface->defaultIgc.entryPoint);
befFclImain = std::move(this->pCompilerInterface->fcl.entryPoint);
EXPECT_FALSE(this->pCompilerInterface->isFclAvailable());
EXPECT_FALSE(this->pCompilerInterface->isIgcAvailable());
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->igcMain = std::move(befIgcImain);
this->pCompilerInterface->fclMain = std::move(befFclImain);
EXPECT_FALSE(this->pCompilerInterface->isIgcAvailable(nullptr));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::spirV));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::oclC, IGC::CodeType::llvmLl));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::spirV, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::llvmBc));
EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(nullptr, IGC::CodeType::elf, IGC::CodeType::oclGenBin));
this->pCompilerInterface->defaultIgc.entryPoint = std::move(befIgcImain);
this->pCompilerInterface->fcl.entryPoint = std::move(befFclImain);
}
TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenGetSipKernelBinaryFailsGracefully) {
pCompilerInterface->igcMain.reset();
pCompilerInterface->defaultIgc.entryPoint.reset();
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::csr, sipBinary, stateAreaHeader);
@@ -1119,7 +1170,7 @@ TEST_F(CompilerInterfaceTest, whenRequestingInvalidSipKernelBinaryThenErrorIsRet
}
TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenGetSpecializationConstantsFails) {
pCompilerInterface->igcMain.reset();
pCompilerInterface->defaultIgc.entryPoint.reset();
NEO::SpecConstantInfo sci;
auto err = pCompilerInterface->getSpecConstantsInfo(*pDevice, ArrayRef<char>{}, sci);
EXPECT_EQ(TranslationOutput::ErrorCode::compilerNotAvailable, err);
@@ -1257,16 +1308,16 @@ struct UnknownInterfaceCIFMain : MockCIFMain {
struct MockCompilerInterfaceWithUnknownInterfaceCIFMain : MockCompilerInterface {
bool loadFcl() override {
CompilerInterface::loadFcl();
fclMain.reset(new UnknownInterfaceCIFMain());
fcl.entryPoint.reset(new UnknownInterfaceCIFMain());
if (failLoadFcl) {
return false;
}
return true;
}
bool loadIgc() override {
CompilerInterface::loadIgc();
igcMain.reset(new UnknownInterfaceCIFMain());
bool loadIgc() {
CompilerInterface::loadIgcBasedCompiler(defaultIgc, Os::igcDllName);
defaultIgc.entryPoint.reset(new UnknownInterfaceCIFMain());
if (failLoadIgc) {
return false;
}
@@ -1274,267 +1325,6 @@ struct MockCompilerInterfaceWithUnknownInterfaceCIFMain : MockCompilerInterface
}
};
TEST(TestCompilerInterface, givenNullCompilerCacheAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
ci.failLoadFcl = false;
ci.failLoadIgc = false;
bool initSuccess = ci.initialize(nullptr, true);
EXPECT_FALSE(initSuccess);
}
TEST(TestCompilerInterface, givenRequiredFclAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = true;
ci.failLoadFcl = false;
ci.failLoadIgc = false;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenNotRequiredFclAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = false;
ci.failLoadFcl = false;
ci.failLoadIgc = false;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenNotRequiredFclAndFclLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = false;
ci.failLoadFcl = true;
ci.failLoadIgc = false;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenRequiredFclAndFclLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = true;
ci.failLoadFcl = true;
ci.failLoadIgc = false;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenRequiredFclAndIgcLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = true;
ci.failLoadFcl = false;
ci.failLoadIgc = true;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenNotRequiredFclAndIgcLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = false;
ci.failLoadFcl = false;
ci.failLoadIgc = true;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenNotRequiredFclAndFclAndIgcLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = false;
ci.failLoadFcl = true;
ci.failLoadIgc = true;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenRequiredFclAndFclAndIgcLoadFaildAndFlagZebinIgnoreIcbeVersionDisabledWhenVerifyIcbeVersionReturnFalseThenInitializationNotSuccess) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
MockCompilerInterfaceWithUnknownInterfaceCIFMain ci;
bool requireFcl = true;
ci.failLoadFcl = true;
ci.failLoadIgc = true;
EXPECT_FALSE(ci.initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), requireFcl));
}
TEST(TestCompilerInterface, givenZebinIgnoreIcbeVersionFlagWhenVerifyIcbeVersionFailThenInitializationReturnProperValues) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(1);
debugManager.flags.ZebinIgnoreIcbeVersion.set(1);
auto mockCompilerInterface = std::make_unique<MockCompilerInterfaceWithUnknownInterfaceCIFMain>();
testing::internal::CaptureStderr();
bool initializationOfCompilerInterfaceSuccessed = mockCompilerInterface->initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), true);
EXPECT_TRUE(initializationOfCompilerInterfaceSuccessed);
std::string stderrString = testing::internal::GetCapturedStderr();
EXPECT_TRUE(stderrString.empty());
debugManager.flags.ZebinIgnoreIcbeVersion.set(0);
testing::internal::CaptureStderr();
initializationOfCompilerInterfaceSuccessed = mockCompilerInterface->initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), true);
EXPECT_FALSE(initializationOfCompilerInterfaceSuccessed);
stderrString = testing::internal::GetCapturedStderr();
EXPECT_FALSE(stderrString.empty());
}
TEST(TestCompilerInterface, givenUnknownInterfaceForIgcAndFclWhenCheckIcbeVersionThenPrintProperDebugMessageOnce) {
auto dummy = std::make_unique<UnknownInterfaceCIFMain>();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(1);
std::string dummyString = "dummy";
std::string expectedError = "Installed Compiler Library " + dummyString + " is incompatible\n";
testing::internal::CaptureStderr();
auto err = mockCompilerInterface->checkIcbeVersionOnce<IGC::FclOclDeviceCtx>(dummy.get(), dummyString.c_str());
EXPECT_FALSE(err);
std::string stderrString = testing::internal::GetCapturedStderr();
EXPECT_EQ(expectedError, stderrString);
testing::internal::CaptureStderr();
err = mockCompilerInterface->checkIcbeVersionOnce<IGC::IgcOclDeviceCtx>(dummy.get(), dummyString.c_str());
EXPECT_FALSE(err);
stderrString = testing::internal::GetCapturedStderr();
EXPECT_EQ(expectedError, stderrString);
// second check for the same EntryPointTs
testing::internal::CaptureStderr();
mockCompilerInterface->checkIcbeVersionOnce<IGC::FclOclDeviceCtx>(dummy.get(), dummyString.c_str());
stderrString = testing::internal::GetCapturedStderr();
EXPECT_TRUE(stderrString.empty());
testing::internal::CaptureStderr();
mockCompilerInterface->checkIcbeVersionOnce<IGC::IgcOclDeviceCtx>(dummy.get(), dummyString.c_str());
stderrString = testing::internal::GetCapturedStderr();
EXPECT_TRUE(stderrString.empty());
}
TEST(TestCompilerInterface, givenUnknownInterfaceAndFclMainWhenverifyIcbeVersionThenPrintProperDebugMessage) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(1);
auto dummy = new UnknownInterfaceCIFMain();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
mockCompilerInterface->fclMain.reset(dummy);
mockCompilerInterface->igcMain.reset(nullptr);
std::string expectedError = "Installed Compiler Library " + std::string(Os::frontEndDllName) + " is incompatible\n";
testing::internal::CaptureStderr();
auto err = mockCompilerInterface->verifyIcbeVersion();
EXPECT_FALSE(err);
std::string stderrString = testing::internal::GetCapturedStderr();
EXPECT_FALSE(stderrString.empty());
}
TEST(TestCompilerInterface, givenUnknownInterfaceAndIgcMainWhenverifyIcbeVersionThenPrintProperDebugMessage) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(1);
auto dummy = new UnknownInterfaceCIFMain();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
mockCompilerInterface->igcMain.reset(dummy);
mockCompilerInterface->fclMain.reset(nullptr);
std::string expectedError = "Installed Compiler Library " + std::string(Os::igcDllName) + " is incompatible\n";
testing::internal::CaptureStderr();
EXPECT_FALSE(mockCompilerInterface->verifyIcbeVersion());
std::string stderrString = testing::internal::GetCapturedStderr();
EXPECT_EQ(expectedError, stderrString);
}
TEST(TestCompilerInterface, givenUnknownInterfaceAndFclMainAndIgcMainWhenVerifyIcbeVersionThenPrintProperDebugMessage) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(1);
auto dummyIgc = new UnknownInterfaceCIFMain();
auto dummyFcl = new UnknownInterfaceCIFMain();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
mockCompilerInterface->igcMain.reset(dummyIgc);
mockCompilerInterface->fclMain.reset(dummyFcl);
std::string expectedError = "Installed Compiler Library " + std::string(Os::frontEndDllName) + " is incompatible\n" + "Installed Compiler Library " + std::string(Os::igcDllName) + " is incompatible\n";
testing::internal::CaptureStderr();
EXPECT_FALSE(mockCompilerInterface->verifyIcbeVersion());
std::string stderrString = testing::internal::GetCapturedStderr();
EXPECT_EQ(expectedError, stderrString);
}
TEST(TestCompilerInterface, givenInvalidIcbeVersionWhenAddOptionDisableZebinThenFalseIsReturned) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
debugManager.flags.PrintDebugMessages.set(0);
auto dummyInValid = new UnknownInterfaceCIFMain();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
mockCompilerInterface->igcMain.reset(dummyInValid);
std::string option = "";
std::string internalOption = "";
EXPECT_FALSE(mockCompilerInterface->addOptionDisableZebin(option, internalOption));
}
TEST(TestCompilerInterface, givenOptionsWhenCallDisableZebinThenProperOptionsAreSet) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableDebugBreak.set(0);
@@ -1543,7 +1333,7 @@ TEST(TestCompilerInterface, givenOptionsWhenCallDisableZebinThenProperOptionsAre
auto dummyValid = new MockCIFMain();
auto mockCompilerInterface = std::make_unique<MockCompilerInterface>();
mockCompilerInterface->igcMain.reset(dummyValid);
mockCompilerInterface->defaultIgc.entryPoint.reset(dummyValid);
std::string options = "";
std::string internalOptions = "";
@@ -1610,6 +1400,54 @@ TEST(TranslationOutput, givenZeroSizeWhenMakingCopyThenClearOutOutput) {
EXPECT_EQ(nullptr, dstBuffer.mem);
}
TEST(TranslationOutputAppend, givenEmptyInputThenDontChangeContents) {
const std::string originalContents = "some text";
std::string dstString = originalContents;
TranslationOutput::append(dstString, nullptr, "", 0);
EXPECT_STREQ(originalContents.c_str(), dstString.c_str());
dstString = originalContents;
TranslationOutput::append(dstString, nullptr, " ", 1);
EXPECT_STREQ(originalContents.c_str(), dstString.c_str());
dstString = originalContents;
MockCIFBuffer empty;
TranslationOutput::append(dstString, &empty, "", 0);
EXPECT_STREQ(originalContents.c_str(), dstString.c_str());
dstString = originalContents;
TranslationOutput::append(dstString, &empty, " ", 1);
EXPECT_STREQ(originalContents.c_str(), dstString.c_str());
}
TEST(TranslationOutputAppend, givenNonEmptyInputThenConcatenate) {
const std::string originalContents = "some text";
const std::string suffix = "newtext";
std::string dstString = originalContents;
MockCIFBuffer suffixBuffer;
suffixBuffer.PushBackRawBytes(suffix.c_str(), suffix.size());
TranslationOutput::append(dstString, &suffixBuffer, "", 0);
EXPECT_STREQ((originalContents + suffix).c_str(), dstString.c_str());
dstString = originalContents;
const char *nullSep = nullptr;
TranslationOutput::append(dstString, &suffixBuffer, nullSep, 0);
EXPECT_STREQ((originalContents + suffix).c_str(), dstString.c_str());
dstString = originalContents;
TranslationOutput::append(dstString, &suffixBuffer, "SEP", 3);
EXPECT_STREQ((originalContents + "SEP" + suffix).c_str(), dstString.c_str());
dstString = "";
TranslationOutput::append(dstString, &suffixBuffer, "", 0);
EXPECT_STREQ(suffix.c_str(), dstString.c_str());
dstString = "";
TranslationOutput::append(dstString, &suffixBuffer, "SEP", 3);
EXPECT_STREQ(suffix.c_str(), dstString.c_str());
}
TEST(getOclCExtensionVersion, whenQueryingVersionOfIntegerDotProductExtensionThenReturns200) {
cl_version defaultVer = CL_MAKE_VERSION(7, 2, 5);
cl_version ver = NEO::getOclCExtensionVersion("cl_khr_integer_dot_product", defaultVer);