2017-12-21 00:45:38 +01:00
/*
2023-01-02 11:14:39 +00:00
* Copyright (C) 2018-2023 Intel Corporation
2017-12-21 00:45:38 +01:00
*
2018-09-18 09:11:08 +02:00
* SPDX-License-Identifier: MIT
2017-12-21 00:45:38 +01:00
*
*/
#pragma once
2020-07-30 13:18:54 +02:00
#include "shared/source/debug_settings/debug_settings_manager.h"
2022-08-28 23:20:29 +00:00
#include "shared/source/helpers/debug_helpers.h"
2021-10-12 18:58:51 +00:00
#include "shared/source/helpers/validators.h"
2023-01-02 11:14:39 +00:00
#include "shared/source/os_interface/os_library.h"
2020-02-24 10:22:30 +01:00
2017-12-21 00:45:38 +01:00
#include "cif/import/library_api.h"
#include "ocl_igc_interface/ocl_translation_output.h"
2019-03-26 11:59:46 +01:00
namespace NEO {
2017-12-21 00:45:38 +01:00
using CIFBuffer = CIF::Builtins::BufferSimple;
2022-11-23 15:09:23 +00:00
class OsLibrary;
2017-12-21 00:45:38 +01:00
template <typename TranslationCtx>
inline CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> translate(TranslationCtx *tCtx, CIFBuffer *src, CIFBuffer *options,
CIFBuffer *internalOptions) {
2019-03-26 11:59:46 +01:00
if (false == NEO::areNotNullptr(tCtx, src, options, internalOptions)) {
2017-12-21 00:45:38 +01:00
return nullptr;
}
auto ret = tCtx->Translate(src, options, internalOptions, nullptr, 0);
if (ret == nullptr) {
return nullptr; // assume OOM or internal error
}
if ((ret->GetOutput() == nullptr) || (ret->GetBuildLog() == nullptr) || (ret->GetDebugData() == nullptr)) {
return nullptr; // assume OOM or internal error
}
return ret;
}
2018-08-06 04:19:32 -07:00
template <typename TranslationCtx>
inline CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> translate(TranslationCtx *tCtx, CIFBuffer *src, CIFBuffer *options,
CIFBuffer *internalOptions, void *gtpinInit) {
2019-03-26 11:59:46 +01:00
if (false == NEO::areNotNullptr(tCtx, src, options, internalOptions)) {
2018-08-06 04:19:32 -07:00
return nullptr;
}
auto ret = tCtx->Translate(src, options, internalOptions, nullptr, 0, gtpinInit);
if (ret == nullptr) {
return nullptr; // assume OOM or internal error
}
if ((ret->GetOutput() == nullptr) || (ret->GetBuildLog() == nullptr) || (ret->GetDebugData() == nullptr)) {
return nullptr; // assume OOM or internal error
}
return ret;
}
2017-12-21 00:45:38 +01:00
2019-04-25 12:46:43 +02:00
template <typename TranslationCtx>
inline bool getSpecConstantsInfoImpl(TranslationCtx *tCtx,
CIFBuffer *src,
CIFBuffer *outSpecConstantsIds,
2020-03-19 08:58:12 +01:00
CIFBuffer *outSpecConstantsSizes) {
if (!NEO::areNotNullptr(tCtx, src, outSpecConstantsIds, outSpecConstantsSizes)) {
2019-04-25 12:46:43 +02:00
return false;
}
return tCtx->GetSpecConstantsInfoImpl(src, outSpecConstantsIds, outSpecConstantsSizes);
}
template <typename TranslationCtx>
inline CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> translate(TranslationCtx *tCtx, CIFBuffer *src, CIFBuffer *specConstantsIds, CIFBuffer *specConstantsValues, CIFBuffer *options,
CIFBuffer *internalOptions, void *gtpinInit) {
if (false == NEO::areNotNullptr(tCtx, src, options, internalOptions)) {
return nullptr;
}
auto ret = tCtx->Translate(src, specConstantsIds, specConstantsValues, options, internalOptions, nullptr, 0, gtpinInit);
if (ret == nullptr) {
return nullptr; // assume OOM or internal error
}
if (!NEO::areNotNullptr(ret->GetOutput(), ret->GetBuildLog(), ret->GetDebugData())) {
return nullptr; // assume OOM or internal error
}
return ret;
}
2017-12-21 00:45:38 +01:00
CIF::CIFMain *createMainNoSanitize(CIF::CreateCIFMainFunc_t createFunc);
2023-05-23 17:14:25 +00:00
template <template <CIF::Version_t> class EntryPointT>
2017-12-21 00:45:38 +01:00
inline bool loadCompiler(const char *libName, std::unique_ptr<OsLibrary> &outLib,
2018-06-12 21:54:39 +02:00
CIF::RAII::UPtr_t<CIF::CIFMain> &outLibMain) {
2021-03-11 17:01:51 -08:00
std::string loadLibraryError;
auto lib = std::unique_ptr<OsLibrary>(OsLibrary::load(libName, &loadLibraryError));
2017-12-21 00:45:38 +01:00
if (lib == nullptr) {
2021-03-11 17:01:51 -08:00
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Compiler Library %s could not be loaded with error: %s\n", libName, loadLibraryError.c_str());
2017-12-21 00:45:38 +01:00
DEBUG_BREAK_IF(true); // could not load library
return false;
}
auto createMain = reinterpret_cast<CIF::CreateCIFMainFunc_t>(lib->getProcAddress(CIF::CreateCIFMainFuncName));
UNRECOVERABLE_IF(createMain == nullptr); // invalid compiler library
auto main = CIF::RAII::UPtr(createMainNoSanitize(createMain));
if (main == nullptr) {
DEBUG_BREAK_IF(true); // could not create main entry point
return false;
}
2023-05-23 17:14:25 +00:00
std::vector<CIF::InterfaceId_t> interfacesToIgnore{IGC::OclGenBinaryBase::GetInterfaceId()};
if (false == main->IsCompatible<EntryPointT>(&interfacesToIgnore)) {
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
return false;
}
2017-12-21 00:45:38 +01:00
outLib = std::move(lib);
outLibMain = std::move(main);
return true;
}
2019-03-26 11:59:46 +01:00
} // namespace NEO