mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 12:23:05 +08:00
Refactor and test initialization of IGC in ocloc
This change: - encapsulates initialization of IGC in a separate class - removes code duplication from OfflineLinker and OfflineCompiler - tests the new encapsulated class Related-To: NEO-6834 Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
a970622cc1
commit
303c12bc5b
@@ -63,6 +63,8 @@ set(CLOC_LIB_SRCS_LIB
|
||||
${OCLOC_DIRECTORY}/source/ocloc_error_code.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_fatbinary.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_fatbinary.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_igc_facade.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_igc_facade.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_validator.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_validator.h
|
||||
${OCLOC_DIRECTORY}/source/offline_compiler.cpp
|
||||
|
||||
167
shared/offline_compiler/source/ocloc_igc_facade.cpp
Normal file
167
shared/offline_compiler/source/ocloc_igc_facade.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
|
||||
#include "shared/offline_compiler/source/ocloc_error_code.h"
|
||||
#include "shared/source/helpers/compiler_hw_info_config.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/os_interface/os_inc_base.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include "ocl_igc_interface/platform_helper.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
CIF::CIFMain *createMainNoSanitize(CIF::CreateCIFMainFunc_t createFunc);
|
||||
|
||||
OclocIgcFacade::OclocIgcFacade(OclocArgHelper *argHelper)
|
||||
: argHelper{argHelper} {
|
||||
}
|
||||
|
||||
OclocIgcFacade::~OclocIgcFacade() = default;
|
||||
|
||||
int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
|
||||
igcLib = loadIgcLibrary();
|
||||
if (!igcLib) {
|
||||
argHelper->printf("Error! Loading of IGC library has failed! Filename: %s\n", Os::igcDllName);
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
const auto igcCreateMainFunction = loadCreateIgcMainFunction();
|
||||
if (!igcCreateMainFunction) {
|
||||
argHelper->printf("Error! Cannot load required functions from IGC library.\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
igcMain = createIgcMain(igcCreateMainFunction);
|
||||
if (!igcMain) {
|
||||
argHelper->printf("Error! Cannot create IGC main component!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
const std::vector<CIF::InterfaceId_t> interfacesToIgnore = {IGC::OclGenBinaryBase::GetInterfaceId()};
|
||||
if (!isIgcInterfaceCompatible(interfacesToIgnore)) {
|
||||
const auto incompatibleInterface{getIncompatibleInterface(interfacesToIgnore)};
|
||||
argHelper->printf("Error! Incompatible interface in IGC: %s\n", incompatibleInterface.c_str());
|
||||
|
||||
DEBUG_BREAK_IF(true);
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
if (!isPatchtokenInterfaceSupported()) {
|
||||
argHelper->printf("Error! Patchtoken interface is missing.\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
igcDeviceCtx = createIgcDeviceContext();
|
||||
if (!igcDeviceCtx) {
|
||||
argHelper->printf("Error! Cannot create IGC device context!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
igcDeviceCtx->SetProfilingTimerResolution(static_cast<float>(hwInfo.capabilityTable.defaultProfilingTimerResolution));
|
||||
|
||||
const auto igcPlatform = getIgcPlatformHandle();
|
||||
const auto igcGtSystemInfo = getGTSystemInfoHandle();
|
||||
const auto igcFtrWa = getIgcFeaturesAndWorkaroundsHandle();
|
||||
|
||||
if (!igcPlatform || !igcGtSystemInfo || !igcFtrWa) {
|
||||
argHelper->printf("Error! IGC device context has not been properly created!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
const auto compilerHwInfoConfig = CompilerHwInfoConfig::get(hwInfo.platform.eProductFamily);
|
||||
auto copyHwInfo = hwInfo;
|
||||
if (compilerHwInfoConfig) {
|
||||
compilerHwInfoConfig->adjustHwInfoForIgc(copyHwInfo);
|
||||
}
|
||||
|
||||
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform.get(), copyHwInfo.platform);
|
||||
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo.get(), copyHwInfo.gtSystemInfo);
|
||||
|
||||
populateWithFeatures(igcFtrWa.get(), hwInfo, compilerHwInfoConfig);
|
||||
|
||||
initialized = true;
|
||||
return OclocErrorCode::SUCCESS;
|
||||
}
|
||||
|
||||
std::unique_ptr<OsLibrary> OclocIgcFacade::loadIgcLibrary() const {
|
||||
return std::unique_ptr<OsLibrary>{OsLibrary::load(Os::igcDllName)};
|
||||
}
|
||||
|
||||
CIF::CreateCIFMainFunc_t OclocIgcFacade::loadCreateIgcMainFunction() const {
|
||||
return reinterpret_cast<CIF::CreateCIFMainFunc_t>(igcLib->getProcAddress(CIF::CreateCIFMainFuncName));
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> OclocIgcFacade::createIgcMain(CIF::CreateCIFMainFunc_t createMainFunction) const {
|
||||
return CIF::RAII::UPtr(createMainNoSanitize(createMainFunction));
|
||||
}
|
||||
|
||||
bool OclocIgcFacade::isIgcInterfaceCompatible(const std::vector<CIF::InterfaceId_t> &interfacesToIgnore) const {
|
||||
return igcMain->IsCompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore);
|
||||
}
|
||||
|
||||
std::string OclocIgcFacade::getIncompatibleInterface(const std::vector<CIF::InterfaceId_t> &interfacesToIgnore) const {
|
||||
return CIF::InterfaceIdCoder::Dec(igcMain->FindIncompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore));
|
||||
}
|
||||
|
||||
bool OclocIgcFacade::isPatchtokenInterfaceSupported() const {
|
||||
CIF::Version_t verMin = 0, verMax = 0;
|
||||
return igcMain->FindSupportedVersions<IGC::IgcOclDeviceCtx>(IGC::OclGenBinaryBase::GetInterfaceId(), verMin, verMax);
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> OclocIgcFacade::createIgcDeviceContext() const {
|
||||
return igcMain->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::PlatformTagOCL> OclocIgcFacade::getIgcPlatformHandle() const {
|
||||
return igcDeviceCtx->GetPlatformHandle();
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::GTSystemInfoTagOCL> OclocIgcFacade::getGTSystemInfoHandle() const {
|
||||
return igcDeviceCtx->GetGTSystemInfoHandle();
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::IgcFeaturesAndWorkaroundsTagOCL> OclocIgcFacade::getIgcFeaturesAndWorkaroundsHandle() const {
|
||||
return igcDeviceCtx->GetIgcFeaturesAndWorkaroundsHandle();
|
||||
}
|
||||
|
||||
void OclocIgcFacade::populateWithFeatures(IGC::IgcFeaturesAndWorkaroundsTagOCL *handle, const HardwareInfo &hwInfo, const CompilerHwInfoConfig *compilerHwInfoConfig) const {
|
||||
handle->SetFtrDesktop(hwInfo.featureTable.flags.ftrDesktop);
|
||||
handle->SetFtrChannelSwizzlingXOREnabled(hwInfo.featureTable.flags.ftrChannelSwizzlingXOREnabled);
|
||||
handle->SetFtrIVBM0M1Platform(hwInfo.featureTable.flags.ftrIVBM0M1Platform);
|
||||
handle->SetFtrSGTPVSKUStrapPresent(hwInfo.featureTable.flags.ftrSGTPVSKUStrapPresent);
|
||||
handle->SetFtr5Slice(hwInfo.featureTable.flags.ftr5Slice);
|
||||
|
||||
if (compilerHwInfoConfig) {
|
||||
handle->SetFtrGpGpuMidThreadLevelPreempt(compilerHwInfoConfig->isMidThreadPreemptionSupported(hwInfo));
|
||||
}
|
||||
|
||||
handle->SetFtrIoMmuPageFaulting(hwInfo.featureTable.flags.ftrIoMmuPageFaulting);
|
||||
handle->SetFtrWddm2Svm(hwInfo.featureTable.flags.ftrWddm2Svm);
|
||||
handle->SetFtrPooledEuEnabled(hwInfo.featureTable.flags.ftrPooledEuEnabled);
|
||||
|
||||
handle->SetFtrResourceStreamer(hwInfo.featureTable.flags.ftrResourceStreamer);
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferLatest> OclocIgcFacade::createConstBuffer(const void *data, size_t size) {
|
||||
return CIF::Builtins::CreateConstBuffer(igcMain.get(), data, size);
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> OclocIgcFacade::createTranslationContext(IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) {
|
||||
return igcDeviceCtx->CreateTranslationCtx(inType, outType);
|
||||
}
|
||||
|
||||
bool OclocIgcFacade::isInitialized() const {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
62
shared/offline_compiler/source/ocloc_igc_facade.h
Normal file
62
shared/offline_compiler/source/ocloc_igc_facade.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cif/common/cif_main.h"
|
||||
#include "cif/import/library_api.h"
|
||||
#include "ocl_igc_interface/code_type.h"
|
||||
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class OclocArgHelper;
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class CompilerHwInfoConfig;
|
||||
class OsLibrary;
|
||||
|
||||
struct HardwareInfo;
|
||||
|
||||
class OclocIgcFacade {
|
||||
public:
|
||||
OclocIgcFacade(OclocArgHelper *argHelper);
|
||||
MOCKABLE_VIRTUAL ~OclocIgcFacade();
|
||||
|
||||
OclocIgcFacade(OclocIgcFacade &) = delete;
|
||||
OclocIgcFacade(const OclocIgcFacade &&) = delete;
|
||||
OclocIgcFacade &operator=(const OclocIgcFacade &) = delete;
|
||||
OclocIgcFacade &operator=(OclocIgcFacade &&) = delete;
|
||||
|
||||
int initialize(const HardwareInfo &hwInfo);
|
||||
bool isInitialized() const;
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferLatest> createConstBuffer(const void *data, size_t size);
|
||||
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 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;
|
||||
MOCKABLE_VIRTUAL std::string getIncompatibleInterface(const std::vector<CIF::InterfaceId_t> &interfacesToIgnore) const;
|
||||
MOCKABLE_VIRTUAL bool isPatchtokenInterfaceSupported() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> createIgcDeviceContext() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::PlatformTagOCL> getIgcPlatformHandle() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::GTSystemInfoTagOCL> getGTSystemInfoHandle() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::IgcFeaturesAndWorkaroundsTagOCL> getIgcFeaturesAndWorkaroundsHandle() const;
|
||||
void populateWithFeatures(IGC::IgcFeaturesAndWorkaroundsTagOCL *handle, const HardwareInfo &hwInfo, const CompilerHwInfoConfig *compilerHwInfoConfig) const;
|
||||
|
||||
OclocArgHelper *argHelper{};
|
||||
std::unique_ptr<OsLibrary> igcLib{};
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> igcMain{};
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> igcDeviceCtx{};
|
||||
bool initialized{false};
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -89,6 +89,7 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
|
||||
|
||||
if (pOffCompiler) {
|
||||
pOffCompiler->argHelper = helper;
|
||||
pOffCompiler->igcFacade = std::make_unique<OclocIgcFacade>(helper);
|
||||
retVal = pOffCompiler->initialize(numArgs, allArgs, dumpFiles);
|
||||
}
|
||||
|
||||
@@ -244,7 +245,9 @@ int OfflineCompiler::buildSourceCode() {
|
||||
retVal = INVALID_PROGRAM;
|
||||
break;
|
||||
}
|
||||
UNRECOVERABLE_IF(igcDeviceCtx == nullptr);
|
||||
|
||||
UNRECOVERABLE_IF(!igcFacade->isInitialized());
|
||||
|
||||
auto inputTypeWarnings = validateInputType(sourceCode, inputFileLlvm, inputFileSpirV);
|
||||
this->argHelper->printf(inputTypeWarnings.c_str());
|
||||
|
||||
@@ -255,7 +258,7 @@ int OfflineCompiler::buildSourceCode() {
|
||||
if (retVal != SUCCESS)
|
||||
break;
|
||||
|
||||
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin);
|
||||
auto igcTranslationCtx = igcFacade->createTranslationContext(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin);
|
||||
igcOutput = igcTranslationCtx->Translate(pBuildInfo->fclOutput->GetOutput(), pBuildInfo->fclOptions.get(),
|
||||
pBuildInfo->fclInternalOptions.get(),
|
||||
nullptr, 0);
|
||||
@@ -263,10 +266,10 @@ int OfflineCompiler::buildSourceCode() {
|
||||
} else {
|
||||
storeBinary(irBinary, irBinarySize, sourceCode.c_str(), sourceCode.size());
|
||||
isSpirV = inputFileSpirV;
|
||||
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), sourceCode.c_str(), sourceCode.size());
|
||||
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), options.c_str(), options.size());
|
||||
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), internalOptions.c_str(), internalOptions.size());
|
||||
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
|
||||
auto igcSrc = igcFacade->createConstBuffer(sourceCode.c_str(), sourceCode.size());
|
||||
auto igcOptions = igcFacade->createConstBuffer(options.c_str(), options.size());
|
||||
auto igcInternalOptions = igcFacade->createConstBuffer(internalOptions.c_str(), internalOptions.size());
|
||||
auto igcTranslationCtx = igcFacade->createTranslationContext(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
|
||||
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
|
||||
}
|
||||
if (igcOutput == nullptr) {
|
||||
@@ -568,71 +571,12 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
|
||||
preferredIntermediateRepresentation = IGC::CodeType::spirV;
|
||||
}
|
||||
|
||||
this->igcLib.reset(OsLibrary::load(Os::igcDllName));
|
||||
if (this->igcLib == nullptr) {
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
const auto igcInitializationResult = igcFacade->initialize(hwInfo);
|
||||
if (igcInitializationResult != SUCCESS) {
|
||||
argHelper->printf("Error! IGC initialization failure. Error code = %d\n", igcInitializationResult);
|
||||
return igcInitializationResult;
|
||||
}
|
||||
|
||||
auto igcCreateMain = reinterpret_cast<CIF::CreateCIFMainFunc_t>(this->igcLib->getProcAddress(CIF::CreateCIFMainFuncName));
|
||||
if (igcCreateMain == nullptr) {
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
this->igcMain = CIF::RAII::UPtr(createMainNoSanitize(igcCreateMain));
|
||||
if (this->igcMain == nullptr) {
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
std::vector<CIF::InterfaceId_t> interfacesToIgnore = {IGC::OclGenBinaryBase::GetInterfaceId()};
|
||||
if (false == this->igcMain->IsCompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore)) {
|
||||
argHelper->printf("Incompatible interface in IGC : %s\n", CIF::InterfaceIdCoder::Dec(this->igcMain->FindIncompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore)).c_str());
|
||||
DEBUG_BREAK_IF(true);
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
CIF::Version_t verMin = 0, verMax = 0;
|
||||
if (false == this->igcMain->FindSupportedVersions<IGC::IgcOclDeviceCtx>(IGC::OclGenBinaryBase::GetInterfaceId(), verMin, verMax)) {
|
||||
argHelper->printf("Patchtoken interface is missing");
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
this->igcDeviceCtx = this->igcMain->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
|
||||
if (this->igcDeviceCtx == nullptr) {
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
this->igcDeviceCtx->SetProfilingTimerResolution(static_cast<float>(hwInfo.capabilityTable.defaultProfilingTimerResolution));
|
||||
auto igcPlatform = this->igcDeviceCtx->GetPlatformHandle();
|
||||
auto igcGtSystemInfo = this->igcDeviceCtx->GetGTSystemInfoHandle();
|
||||
auto igcFtrWa = this->igcDeviceCtx->GetIgcFeaturesAndWorkaroundsHandle();
|
||||
if ((igcPlatform == nullptr) || (igcGtSystemInfo == nullptr) || (igcFtrWa == nullptr)) {
|
||||
return OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
auto compilerHwInfoConfig = CompilerHwInfoConfig::get(hwInfo.platform.eProductFamily);
|
||||
auto copyHwInfo = hwInfo;
|
||||
if (compilerHwInfoConfig) {
|
||||
compilerHwInfoConfig->adjustHwInfoForIgc(copyHwInfo);
|
||||
}
|
||||
|
||||
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform.get(), copyHwInfo.platform);
|
||||
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo.get(), copyHwInfo.gtSystemInfo);
|
||||
// populate with features
|
||||
|
||||
igcFtrWa.get()->SetFtrDesktop(hwInfo.featureTable.flags.ftrDesktop);
|
||||
igcFtrWa.get()->SetFtrChannelSwizzlingXOREnabled(hwInfo.featureTable.flags.ftrChannelSwizzlingXOREnabled);
|
||||
igcFtrWa.get()->SetFtrIVBM0M1Platform(hwInfo.featureTable.flags.ftrIVBM0M1Platform);
|
||||
igcFtrWa.get()->SetFtrSGTPVSKUStrapPresent(hwInfo.featureTable.flags.ftrSGTPVSKUStrapPresent);
|
||||
igcFtrWa.get()->SetFtr5Slice(hwInfo.featureTable.flags.ftr5Slice);
|
||||
|
||||
if (compilerHwInfoConfig) {
|
||||
igcFtrWa.get()->SetFtrGpGpuMidThreadLevelPreempt(compilerHwInfoConfig->isMidThreadPreemptionSupported(hwInfo));
|
||||
}
|
||||
igcFtrWa.get()->SetFtrIoMmuPageFaulting(hwInfo.featureTable.flags.ftrIoMmuPageFaulting);
|
||||
igcFtrWa.get()->SetFtrWddm2Svm(hwInfo.featureTable.flags.ftrWddm2Svm);
|
||||
igcFtrWa.get()->SetFtrPooledEuEnabled(hwInfo.featureTable.flags.ftrPooledEuEnabled);
|
||||
|
||||
igcFtrWa.get()->SetFtrResourceStreamer(hwInfo.featureTable.flags.ftrResourceStreamer);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
|
||||
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
#include "shared/source/utilities/arrayref.h"
|
||||
@@ -15,7 +16,6 @@
|
||||
|
||||
#include "cif/common/cif_main.h"
|
||||
#include "ocl_igc_interface/fcl_ocl_device_ctx.h"
|
||||
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -113,6 +113,7 @@ class OfflineCompiler {
|
||||
std::replace(suffix.begin(), suffix.end(), ' ', '_');
|
||||
return suffix;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void writeOutAllFiles();
|
||||
MOCKABLE_VIRTUAL void createDir(const std::string &path);
|
||||
void unifyExcludeIrFlags();
|
||||
@@ -156,11 +157,10 @@ class OfflineCompiler {
|
||||
size_t debugDataBinarySize = 0;
|
||||
struct buildInfo;
|
||||
std::unique_ptr<buildInfo> pBuildInfo;
|
||||
std::unique_ptr<OsLibrary> igcLib = nullptr;
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> igcMain = nullptr;
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> igcDeviceCtx = nullptr;
|
||||
int revisionId = -1;
|
||||
|
||||
std::unique_ptr<OclocIgcFacade> igcFacade{nullptr};
|
||||
|
||||
std::unique_ptr<OsLibrary> fclLib = nullptr;
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> fclMain = nullptr;
|
||||
CIF::RAII::UPtr_t<IGC::FclOclDeviceCtxTagOCL> fclDeviceCtx = nullptr;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include "cif/common/cif_main.h"
|
||||
#include "cif/import/library_api.h"
|
||||
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
|
||||
#include "ocl_igc_interface/platform_helper.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -28,14 +30,14 @@ namespace NEO {
|
||||
CIF::CIFMain *createMainNoSanitize(CIF::CreateCIFMainFunc_t createFunc);
|
||||
|
||||
std::unique_ptr<OfflineLinker> OfflineLinker::create(size_t argsCount, const std::vector<std::string> &args, int &errorCode, OclocArgHelper *argHelper) {
|
||||
std::unique_ptr<OfflineLinker> linker{new OfflineLinker{argHelper}};
|
||||
std::unique_ptr<OfflineLinker> linker{new OfflineLinker{argHelper, std::make_unique<OclocIgcFacade>(argHelper)}};
|
||||
errorCode = linker->initialize(argsCount, args);
|
||||
|
||||
return linker;
|
||||
}
|
||||
|
||||
OfflineLinker::OfflineLinker(OclocArgHelper *argHelper)
|
||||
: argHelper{argHelper}, operationMode{OperationMode::SKIP_EXECUTION}, outputFilename{"linker_output"}, outputFormat{IGC::CodeType::llvmBc} {}
|
||||
OfflineLinker::OfflineLinker(OclocArgHelper *argHelper, std::unique_ptr<OclocIgcFacade> igcFacade)
|
||||
: argHelper{argHelper}, operationMode{OperationMode::SKIP_EXECUTION}, outputFilename{"linker_output"}, outputFormat{IGC::CodeType::llvmBc}, igcFacade{std::move(igcFacade)} {}
|
||||
|
||||
OfflineLinker::~OfflineLinker() = default;
|
||||
|
||||
@@ -65,7 +67,7 @@ int OfflineLinker::initialize(size_t argsCount, const std::vector<std::string> &
|
||||
return hwInfoInitializationResult;
|
||||
}
|
||||
|
||||
const auto igcPreparationResult{prepareIgc()};
|
||||
const auto igcPreparationResult{igcFacade->initialize(hwInfo)};
|
||||
if (igcPreparationResult != OclocErrorCode::SUCCESS) {
|
||||
return igcPreparationResult;
|
||||
}
|
||||
@@ -218,68 +220,6 @@ ArrayRef<const HardwareInfo *> OfflineLinker::getHardwareInfoTable() const {
|
||||
return {hardwareInfoTable};
|
||||
}
|
||||
|
||||
int OfflineLinker::prepareIgc() {
|
||||
igcLib = loadIgcLibrary();
|
||||
if (!igcLib) {
|
||||
argHelper->printf("Error! Loading of IGC library has failed! Filename: %s\n", Os::igcDllName);
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
const auto igcCreateMainFunction = loadCreateIgcMainFunction();
|
||||
if (!igcCreateMainFunction) {
|
||||
argHelper->printf("Error! Cannot load required functions from IGC library.\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
igcMain = createIgcMain(igcCreateMainFunction);
|
||||
if (!igcMain) {
|
||||
argHelper->printf("Error! Cannot create IGC main component!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
igcDeviceCtx = createIgcDeviceContext();
|
||||
if (!igcDeviceCtx) {
|
||||
argHelper->printf("Error! Cannot create IGC device context!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
const auto igcPlatform = getIgcPlatformHandle();
|
||||
const auto igcGtSystemInfo = getGTSystemInfoHandle();
|
||||
if (!igcPlatform || !igcGtSystemInfo) {
|
||||
argHelper->printf("Error! IGC device context has not been properly created!\n");
|
||||
return OclocErrorCode::OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform.get(), hwInfo.platform);
|
||||
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo.get(), hwInfo.gtSystemInfo);
|
||||
|
||||
return OclocErrorCode::SUCCESS;
|
||||
}
|
||||
|
||||
std::unique_ptr<OsLibrary> OfflineLinker::loadIgcLibrary() const {
|
||||
return std::unique_ptr<OsLibrary>{OsLibrary::load(Os::igcDllName)};
|
||||
}
|
||||
|
||||
CIF::CreateCIFMainFunc_t OfflineLinker::loadCreateIgcMainFunction() const {
|
||||
return reinterpret_cast<CIF::CreateCIFMainFunc_t>(igcLib->getProcAddress(CIF::CreateCIFMainFuncName));
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> OfflineLinker::createIgcMain(CIF::CreateCIFMainFunc_t createMainFunction) const {
|
||||
return CIF::RAII::UPtr(createMainNoSanitize(createMainFunction));
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> OfflineLinker::createIgcDeviceContext() const {
|
||||
return igcMain->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::PlatformTagOCL> OfflineLinker::getIgcPlatformHandle() const {
|
||||
return igcDeviceCtx->GetPlatformHandle();
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<IGC::GTSystemInfoTagOCL> OfflineLinker::getGTSystemInfoHandle() const {
|
||||
return igcDeviceCtx->GetGTSystemInfoHandle();
|
||||
}
|
||||
|
||||
int OfflineLinker::execute() {
|
||||
switch (operationMode) {
|
||||
case OperationMode::SHOW_HELP:
|
||||
@@ -366,10 +306,10 @@ std::vector<uint8_t> OfflineLinker::createSingleInputFile() const {
|
||||
}
|
||||
|
||||
std::pair<int, std::vector<uint8_t>> OfflineLinker::translateToOutputFormat(const std::vector<uint8_t> &elfInput) {
|
||||
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), elfInput.data(), elfInput.size());
|
||||
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), options.c_str(), options.size());
|
||||
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), internalOptions.c_str(), internalOptions.size());
|
||||
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(IGC::CodeType::elf, outputFormat);
|
||||
auto igcSrc = igcFacade->createConstBuffer(elfInput.data(), elfInput.size());
|
||||
auto igcOptions = igcFacade->createConstBuffer(options.c_str(), options.size());
|
||||
auto igcInternalOptions = igcFacade->createConstBuffer(internalOptions.c_str(), internalOptions.size());
|
||||
auto igcTranslationCtx = igcFacade->createTranslationContext(IGC::CodeType::elf, outputFormat);
|
||||
|
||||
const auto tracingOptions{nullptr};
|
||||
const auto tracingOptionsSize{0};
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/utilities/arrayref.h"
|
||||
|
||||
#include "cif/common/cif_main.h"
|
||||
#include "cif/import/library_api.h"
|
||||
#include "ocl_igc_interface/code_type.h"
|
||||
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
@@ -52,7 +50,7 @@ class OfflineLinker {
|
||||
std::string getBuildLog() const;
|
||||
|
||||
protected:
|
||||
explicit OfflineLinker(OclocArgHelper *argHelper);
|
||||
explicit OfflineLinker(OclocArgHelper *argHelper, std::unique_ptr<OclocIgcFacade> igcFacade);
|
||||
int initialize(size_t argsCount, const std::vector<std::string> &args);
|
||||
int parseCommand(size_t argsCount, const std::vector<std::string> &args);
|
||||
IGC::CodeType::CodeType_t parseOutputFormat(const std::string &outputFormatName);
|
||||
@@ -60,7 +58,6 @@ class OfflineLinker {
|
||||
int loadInputFilesContent();
|
||||
IGC::CodeType::CodeType_t detectCodeType(char *bytes, size_t size) const;
|
||||
int initHardwareInfo();
|
||||
int prepareIgc();
|
||||
int link();
|
||||
int showHelp();
|
||||
std::vector<uint8_t> createSingleInputFile() const;
|
||||
@@ -68,12 +65,6 @@ class OfflineLinker {
|
||||
void tryToStoreBuildLog(const char *buildLogRaw, size_t size);
|
||||
|
||||
MOCKABLE_VIRTUAL ArrayRef<const HardwareInfo *> getHardwareInfoTable() const;
|
||||
MOCKABLE_VIRTUAL std::unique_ptr<OsLibrary> loadIgcLibrary() const;
|
||||
MOCKABLE_VIRTUAL CIF::CreateCIFMainFunc_t loadCreateIgcMainFunction() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<CIF::CIFMain> createIgcMain(CIF::CreateCIFMainFunc_t createMainFunction) const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> createIgcDeviceContext() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::PlatformTagOCL> getIgcPlatformHandle() const;
|
||||
MOCKABLE_VIRTUAL CIF::RAII::UPtr_t<IGC::GTSystemInfoTagOCL> getGTSystemInfoHandle() const;
|
||||
|
||||
OclocArgHelper *argHelper{};
|
||||
OperationMode operationMode{};
|
||||
@@ -85,9 +76,7 @@ class OfflineLinker {
|
||||
std::string options{};
|
||||
std::string internalOptions{};
|
||||
|
||||
std::unique_ptr<OsLibrary> igcLib{};
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> igcMain{};
|
||||
CIF::RAII::UPtr_t<IGC::IgcOclDeviceCtxTagOCL> igcDeviceCtx{};
|
||||
std::unique_ptr<OclocIgcFacade> igcFacade{};
|
||||
HardwareInfo hwInfo{};
|
||||
std::string buildLog{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user