2022-04-12 20:53:04 +08:00
/*
2024-08-19 20:50:05 +08:00
* Copyright ( C ) 2022 - 2024 Intel Corporation
2022-04-12 20:53:04 +08:00
*
* SPDX - License - Identifier : MIT
*
*/
# include "shared/offline_compiler/source/ocloc_igc_facade.h"
2023-09-06 01:13:13 +08:00
# include "shared/offline_compiler/source/ocloc_api.h"
2022-04-12 20:53:04 +08:00
# include "shared/offline_compiler/source/ocloc_arg_helper.h"
2022-12-12 22:51:27 +08:00
# include "shared/source/compiler_interface/igc_platform_helper.h"
2023-08-21 20:00:06 +08:00
# include "shared/source/compiler_interface/os_compiler_cache_helper.h"
2023-02-02 22:25:08 +08:00
# include "shared/source/helpers/compiler_product_helper.h"
2024-11-04 18:14:17 +08:00
# include "shared/source/helpers/constants.h"
2022-06-24 21:56:25 +08:00
# include "shared/source/helpers/debug_helpers.h"
2022-04-12 20:53:04 +08:00
# include "shared/source/helpers/hw_info.h"
2023-08-21 20:00:06 +08:00
# include "shared/source/helpers/string.h"
2022-04-12 20:53:04 +08:00
# 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 ) {
2023-11-17 00:48:56 +08:00
if ( initialized ) {
return OCLOC_SUCCESS ;
}
2024-10-15 02:23:13 +08:00
auto compilerProductHelper = NEO : : CompilerProductHelper : : create ( hwInfo . platform . eProductFamily ) ;
igcLib = loadIgcLibrary ( compilerProductHelper ? compilerProductHelper - > getCustomIgcLibraryName ( ) : nullptr ) ;
2022-04-12 20:53:04 +08:00
if ( ! igcLib ) {
2024-10-24 03:55:38 +08:00
argHelper - > printf ( " Error! Loading of IGC library has failed! Filename: %s \n " , ( compilerProductHelper & & compilerProductHelper - > getCustomIgcLibraryName ( ) ) ? compilerProductHelper - > getCustomIgcLibraryName ( ) : Os : : igcDllName ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
2023-08-21 20:00:06 +08:00
std : : string igcPath = igcLib - > getFullPath ( ) ;
igcLibSize = NEO : : getFileSize ( igcPath ) ;
igcLibMTime = NEO : : getFileModificationTime ( igcPath ) ;
2022-04-12 20:53:04 +08:00
const auto igcCreateMainFunction = loadCreateIgcMainFunction ( ) ;
if ( ! igcCreateMainFunction ) {
argHelper - > printf ( " Error! Cannot load required functions from IGC library. \n " ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
igcMain = createIgcMain ( igcCreateMainFunction ) ;
if ( ! igcMain ) {
argHelper - > printf ( " Error! Cannot create IGC main component! \n " ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
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 ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
if ( ! isPatchtokenInterfaceSupported ( ) ) {
argHelper - > printf ( " Error! Patchtoken interface is missing. \n " ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
2023-08-21 20:00:06 +08:00
{
2023-08-29 03:09:29 +08:00
// revision is sha-1 hash
igcRevision . resize ( 41 ) ;
igcRevision [ 0 ] = ' \0 ' ;
auto igcDeviceCtx3 = createIgcDeviceContext3 ( ) ;
2023-08-21 20:00:06 +08:00
if ( igcDeviceCtx3 ) {
const char * revision = igcDeviceCtx3 - > GetIGCRevision ( ) ;
strncpy_s ( igcRevision . data ( ) , 41 , revision , 40 ) ;
}
}
2022-04-12 20:53:04 +08:00
igcDeviceCtx = createIgcDeviceContext ( ) ;
if ( ! igcDeviceCtx ) {
argHelper - > printf ( " Error! Cannot create IGC device context! \n " ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
2024-11-04 18:14:17 +08:00
igcDeviceCtx - > SetProfilingTimerResolution ( static_cast < float > ( CommonConstants : : defaultProfilingTimerResolution ) ) ;
2022-04-12 20:53:04 +08:00
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 " ) ;
2023-09-06 01:13:13 +08:00
return OCLOC_OUT_OF_HOST_MEMORY ;
2022-04-12 20:53:04 +08:00
}
2023-07-27 17:38:15 +08:00
2023-09-18 20:28:40 +08:00
populateIgcPlatform ( * igcPlatform , hwInfo ) ;
IGC : : GtSysInfoHelper : : PopulateInterfaceWith ( * igcGtSystemInfo . get ( ) , hwInfo . gtSystemInfo ) ;
2022-04-12 20:53:04 +08:00
2023-09-18 20:28:40 +08:00
populateWithFeatures ( igcFtrWa . get ( ) , hwInfo , compilerProductHelper . get ( ) ) ;
2022-04-12 20:53:04 +08:00
initialized = true ;
2023-09-06 01:13:13 +08:00
return OCLOC_SUCCESS ;
2022-04-12 20:53:04 +08:00
}
2024-10-15 02:23:13 +08:00
std : : unique_ptr < OsLibrary > OclocIgcFacade : : loadIgcLibrary ( const char * libName ) const {
auto effectiveLibName = libName ? libName : Os : : igcDllName ;
return std : : unique_ptr < OsLibrary > { OsLibrary : : loadFunc ( { effectiveLibName } ) } ;
2022-04-12 20:53:04 +08:00
}
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 > ( ) ;
}
2023-08-29 03:09:29 +08:00
CIF : : RAII : : UPtr_t < IGC : : IgcOclDeviceCtx < 3 > > OclocIgcFacade : : createIgcDeviceContext3 ( ) const {
return igcMain - > CreateInterface < IGC : : IgcOclDeviceCtx < 3 > > ( ) ;
}
2022-04-12 20:53:04 +08:00
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 ( ) ;
}
2022-11-30 22:28:39 +08:00
void OclocIgcFacade : : populateWithFeatures ( IGC : : IgcFeaturesAndWorkaroundsTagOCL * handle , const HardwareInfo & hwInfo , const CompilerProductHelper * compilerProductHelper ) const {
if ( compilerProductHelper ) {
handle - > SetFtrGpGpuMidThreadLevelPreempt ( compilerProductHelper - > isMidThreadPreemptionSupported ( hwInfo ) ) ;
2022-04-12 20:53:04 +08:00
}
handle - > SetFtrWddm2Svm ( hwInfo . featureTable . flags . ftrWddm2Svm ) ;
handle - > SetFtrPooledEuEnabled ( hwInfo . featureTable . flags . ftrPooledEuEnabled ) ;
}
2023-08-21 20:00:06 +08:00
const char * OclocIgcFacade : : getIgcRevision ( ) {
return igcRevision . data ( ) ;
}
size_t OclocIgcFacade : : getIgcLibSize ( ) {
return igcLibSize ;
}
time_t OclocIgcFacade : : getIgcLibMTime ( ) {
return igcLibMTime ;
}
2022-04-12 20:53:04 +08:00
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 ;
}
2022-06-24 21:56:25 +08:00
} // namespace NEO