2019-10-24 13:34:25 +02:00
/*
2024-12-20 17:29:21 +00:00
* Copyright ( C ) 2019 - 2025 Intel Corporation
2019-10-24 13:34:25 +02:00
*
* SPDX - License - Identifier : MIT
*
*/
2020-02-23 22:44:01 +01:00
# include "shared/source/execution_environment/root_device_environment.h"
2019-10-24 13:34:25 +02:00
2021-07-21 08:47:43 +00:00
# include "shared/source/ail/ail_configuration.h"
2023-03-07 16:39:25 +00:00
# include "shared/source/assert_handler/assert_handler.h"
2020-10-16 12:10:52 +02:00
# include "shared/source/aub/aub_center.h"
2020-02-27 15:32:57 +01:00
# include "shared/source/built_ins/built_ins.h"
2023-01-02 09:56:45 +00:00
# include "shared/source/built_ins/sip.h"
2020-02-27 15:32:57 +01:00
# include "shared/source/compiler_interface/compiler_interface.h"
# include "shared/source/compiler_interface/default_cache_config.h"
2020-03-11 08:56:55 +01:00
# include "shared/source/debugger/debugger.h"
2022-07-07 12:01:53 +00:00
# include "shared/source/debugger/debugger_l0.h"
2023-01-03 10:27:35 +00:00
# include "shared/source/device/device.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/execution_environment/execution_environment.h"
2020-02-24 18:04:30 +01:00
# include "shared/source/gmm_helper/gmm_helper.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/gmm_helper/page_table_mngr.h"
2023-01-03 10:27:35 +00:00
# include "shared/source/helpers/api_gfx_core_helper.h"
2022-08-30 16:12:04 +00:00
# include "shared/source/helpers/api_specific_config.h"
2022-12-01 19:42:57 +00:00
# include "shared/source/helpers/bindless_heaps_helper.h"
2023-02-02 14:25:08 +00:00
# include "shared/source/helpers/compiler_product_helper.h"
2023-02-01 16:23:01 +00:00
# include "shared/source/helpers/gfx_core_helper.h"
2020-03-04 08:51:02 +01:00
# include "shared/source/helpers/hw_info.h"
2023-02-28 21:08:09 +00:00
# include "shared/source/memory_manager/allocation_properties.h"
# include "shared/source/memory_manager/graphics_allocation.h"
2021-01-27 14:31:29 +01:00
# include "shared/source/memory_manager/memory_manager.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/memory_manager/memory_operations_handler.h"
# include "shared/source/os_interface/os_interface.h"
2021-09-24 10:51:57 +00:00
# include "shared/source/os_interface/os_time.h"
2023-03-10 12:28:11 +00:00
# include "shared/source/os_interface/product_helper.h"
2025-04-30 21:36:42 +00:00
# include "shared/source/program/print_formatter.h"
2023-04-13 14:16:49 +00:00
# include "shared/source/release_helper/release_helper.h"
2025-03-18 18:19:14 +00:00
# include "shared/source/sip_external_lib/sip_external_lib.h"
2021-01-26 11:22:10 +00:00
# include "shared/source/utilities/software_tags_manager.h"
2025-03-26 12:53:38 +00:00
# include "shared/source/utilities/wait_util.h"
2020-02-24 10:22:30 +01:00
2019-10-24 13:34:25 +02:00
namespace NEO {
2020-03-04 08:51:02 +01:00
RootDeviceEnvironment : : RootDeviceEnvironment ( ExecutionEnvironment & executionEnvironment ) : executionEnvironment ( executionEnvironment ) {
hwInfo = std : : make_unique < HardwareInfo > ( ) ;
2021-01-26 11:22:10 +00:00
2023-11-30 08:32:25 +00:00
if ( debugManager . flags . EnableSWTags . get ( ) ) {
2021-01-26 11:22:10 +00:00
tagsManager = std : : make_unique < SWTagsManager > ( ) ;
}
2020-03-04 08:51:02 +01:00
}
2019-10-24 13:34:25 +02:00
RootDeviceEnvironment : : ~ RootDeviceEnvironment ( ) = default ;
2019-11-15 09:59:48 +01:00
void RootDeviceEnvironment : : initAubCenter ( bool localMemoryEnabled , const std : : string & aubFileName , CommandStreamReceiverType csrType ) {
if ( ! aubCenter ) {
2021-03-05 11:14:21 +00:00
UNRECOVERABLE_IF ( ! getGmmHelper ( ) ) ;
2022-11-25 07:58:15 +00:00
aubCenter . reset ( new AubCenter ( * this , localMemoryEnabled , aubFileName , csrType ) ) ;
2019-11-15 09:59:48 +01:00
}
2025-04-30 21:36:42 +00:00
if ( debugManager . flags . UseAubStream . get ( ) & & aubCenter - > getAubManager ( ) = = nullptr ) {
printToStderr ( " ERROR: Simulation mode detected but Aubstream is not available. \n " ) ;
UNRECOVERABLE_IF ( true ) ;
}
2019-11-15 09:59:48 +01:00
}
2020-03-11 08:56:55 +01:00
2022-07-07 12:01:53 +00:00
void RootDeviceEnvironment : : initDebuggerL0 ( Device * neoDevice ) {
2023-09-29 09:04:05 +00:00
DEBUG_BREAK_IF ( this - > debugger . get ( ) ! = nullptr ) ;
2022-07-07 12:01:53 +00:00
this - > getMutableHardwareInfo ( ) - > capabilityTable . fusedEuEnabled = false ;
this - > getMutableHardwareInfo ( ) - > capabilityTable . ftrRenderCompressedBuffers = false ;
this - > getMutableHardwareInfo ( ) - > capabilityTable . ftrRenderCompressedImages = false ;
this - > debugger = DebuggerL0 : : create ( neoDevice ) ;
}
2025-03-27 14:00:16 +00:00
void RootDeviceEnvironment : : initWaitUtils ( ) {
WaitUtils : : init ( WaitUtils : : WaitpkgUse : : tpause , * hwInfo ) ;
}
2020-01-30 15:04:19 +01:00
const HardwareInfo * RootDeviceEnvironment : : getHardwareInfo ( ) const {
2020-03-04 08:51:02 +01:00
return hwInfo . get ( ) ;
}
HardwareInfo * RootDeviceEnvironment : : getMutableHardwareInfo ( ) const {
return hwInfo . get ( ) ;
}
2023-01-03 10:27:35 +00:00
void RootDeviceEnvironment : : setHwInfoAndInitHelpers ( const HardwareInfo * hwInfo ) {
2024-06-03 13:42:29 +00:00
setHwInfo ( hwInfo ) ;
2023-01-03 10:27:35 +00:00
initHelpers ( ) ;
2020-03-04 08:51:02 +01:00
}
2023-06-06 11:41:57 +00:00
void RootDeviceEnvironment : : setHwInfo ( const HardwareInfo * hwInfo ) {
* this - > hwInfo = * hwInfo ;
2024-06-03 13:42:29 +00:00
if ( debugManager . flags . DisableSupportForL0Debugger . get ( ) = = 1 ) {
this - > hwInfo - > capabilityTable . l0DebuggerSupported = false ;
}
2023-06-06 11:41:57 +00:00
}
2020-03-04 08:51:02 +01:00
bool RootDeviceEnvironment : : isFullRangeSvm ( ) const {
return hwInfo - > capabilityTable . gpuAddressSpace > = maxNBitValue ( 47 ) ;
2020-01-30 15:04:19 +01:00
}
2020-02-24 18:04:30 +01:00
GmmHelper * RootDeviceEnvironment : : getGmmHelper ( ) const {
2020-02-25 16:38:47 +01:00
return gmmHelper . get ( ) ;
2020-02-24 18:04:30 +01:00
}
GmmClientContext * RootDeviceEnvironment : : getGmmClientContext ( ) const {
2020-02-25 16:38:47 +01:00
return gmmHelper - > getClientContext ( ) ;
2020-02-24 18:04:30 +01:00
}
2020-02-25 16:38:47 +01:00
2022-05-17 15:23:15 +00:00
void RootDeviceEnvironment : : prepareForCleanup ( ) const {
if ( osInterface & & osInterface - > getDriverModel ( ) ) {
2022-10-20 11:51:13 +02:00
osInterface - > getDriverModel ( ) - > isDriverAvailable ( ) ;
2022-05-17 15:23:15 +00:00
}
}
2021-07-21 08:47:43 +00:00
bool RootDeviceEnvironment : : initAilConfiguration ( ) {
if ( ailConfiguration = = nullptr ) {
2023-11-28 15:15:25 +00:00
return ( false = = debugManager . flags . EnableAIL . get ( ) ) ;
2021-07-21 08:47:43 +00:00
}
auto result = ailConfiguration - > initProcessExecutableName ( ) ;
if ( result ! = true ) {
return false ;
}
2024-12-20 17:29:21 +00:00
ailConfiguration - > apply ( * hwInfo ) ;
2021-07-21 08:47:43 +00:00
return true ;
}
2020-02-25 16:38:47 +01:00
void RootDeviceEnvironment : : initGmm ( ) {
if ( ! gmmHelper ) {
2022-11-25 07:53:05 +00:00
gmmHelper . reset ( new GmmHelper ( * this ) ) ;
2020-02-25 16:38:47 +01:00
}
}
2021-09-24 10:51:57 +00:00
void RootDeviceEnvironment : : initOsTime ( ) {
if ( ! osTime ) {
osTime = OSTime : : create ( osInterface . get ( ) ) ;
2024-11-04 10:14:17 +00:00
osTime - > setDeviceTimerResolution ( ) ;
2021-09-24 10:51:57 +00:00
}
}
2021-01-27 14:31:29 +01:00
BindlessHeapsHelper * RootDeviceEnvironment : : getBindlessHeapsHelper ( ) const {
return bindlessHeapsHelper . get ( ) ;
}
2022-12-12 16:43:41 +00:00
const ProductHelper & RootDeviceEnvironment : : getProductHelper ( ) const {
2023-02-01 03:12:09 +00:00
return * productHelper ;
2022-11-07 14:47:17 +00:00
}
2024-03-20 11:45:31 +00:00
void RootDeviceEnvironment : : createBindlessHeapsHelper ( Device * rootDevice , bool availableDevices ) {
bindlessHeapsHelper = std : : make_unique < BindlessHeapsHelper > ( rootDevice , availableDevices ) ;
2021-01-27 14:31:29 +01:00
}
2020-02-27 15:32:57 +01:00
CompilerInterface * RootDeviceEnvironment : : getCompilerInterface ( ) {
if ( this - > compilerInterface . get ( ) = = nullptr ) {
std : : lock_guard < std : : mutex > autolock ( this - > mtx ) ;
if ( this - > compilerInterface . get ( ) = = nullptr ) {
auto cache = std : : make_unique < CompilerCache > ( getDefaultCompilerCacheConfig ( ) ) ;
2025-10-10 14:00:20 +00:00
this - > compilerInterface . reset ( CompilerInterface : : createInstance ( std : : move ( cache ) , true ) ) ;
2020-02-27 15:32:57 +01:00
}
}
return this - > compilerInterface . get ( ) ;
}
2025-03-18 18:19:14 +00:00
SipExternalLib * RootDeviceEnvironment : : getSipExternalLibInterface ( ) {
if ( sipExternalLib . get ( ) = = nullptr ) {
if ( gfxCoreHelper - > getSipBinaryFromExternalLib ( ) ) {
std : : lock_guard < std : : mutex > autolock ( this - > mtx ) ;
sipExternalLib . reset ( SipExternalLib : : getSipExternalLibInstance ( ) ) ;
}
}
return sipExternalLib . get ( ) ;
}
2023-01-03 10:27:35 +00:00
void RootDeviceEnvironment : : initHelpers ( ) {
2023-02-01 03:12:09 +00:00
initProductHelper ( ) ;
2023-01-09 14:59:10 +00:00
initGfxCoreHelper ( ) ;
2025-01-24 10:50:51 +00:00
initializeGfxCoreHelperFromProductHelper ( ) ;
2024-09-12 13:00:25 +00:00
initializeGfxCoreHelperFromHwInfo ( ) ;
2023-01-03 10:27:35 +00:00
initApiGfxCoreHelper ( ) ;
2023-01-31 12:34:59 +00:00
initCompilerProductHelper ( ) ;
2023-04-13 14:16:49 +00:00
initReleaseHelper ( ) ;
2023-10-31 02:33:24 +00:00
initAilConfigurationHelper ( ) ;
2025-03-27 14:00:16 +00:00
initWaitUtils ( ) ;
2023-01-03 10:27:35 +00:00
}
2024-09-12 13:00:25 +00:00
void RootDeviceEnvironment : : initializeGfxCoreHelperFromHwInfo ( ) {
if ( gfxCoreHelper ! = nullptr ) {
gfxCoreHelper - > initializeDefaultHpCopyEngine ( * this - > getHardwareInfo ( ) ) ;
}
}
2025-01-24 10:50:51 +00:00
void RootDeviceEnvironment : : initializeGfxCoreHelperFromProductHelper ( ) {
if ( this - > productHelper ) {
gfxCoreHelper - > initializeFromProductHelper ( * this - > productHelper . get ( ) ) ;
}
}
2023-01-09 14:59:10 +00:00
void RootDeviceEnvironment : : initGfxCoreHelper ( ) {
if ( gfxCoreHelper = = nullptr ) {
gfxCoreHelper = GfxCoreHelper : : create ( this - > getHardwareInfo ( ) - > platform . eRenderCoreFamily ) ;
}
}
2023-01-31 12:34:59 +00:00
2023-02-01 03:12:09 +00:00
void RootDeviceEnvironment : : initProductHelper ( ) {
if ( productHelper = = nullptr ) {
productHelper = ProductHelper : : create ( this - > getHardwareInfo ( ) - > platform . eProductFamily ) ;
}
}
2023-01-31 12:34:59 +00:00
void RootDeviceEnvironment : : initCompilerProductHelper ( ) {
if ( compilerProductHelper = = nullptr ) {
compilerProductHelper = CompilerProductHelper : : create ( this - > getHardwareInfo ( ) - > platform . eProductFamily ) ;
}
}
2023-01-09 14:59:10 +00:00
2023-04-13 14:16:49 +00:00
void RootDeviceEnvironment : : initReleaseHelper ( ) {
if ( releaseHelper = = nullptr ) {
releaseHelper = ReleaseHelper : : create ( this - > getHardwareInfo ( ) - > ipVersion ) ;
}
}
2023-10-31 02:33:24 +00:00
void RootDeviceEnvironment : : initAilConfigurationHelper ( ) {
2023-11-30 08:32:25 +00:00
if ( ailConfiguration = = nullptr & & debugManager . flags . EnableAIL . get ( ) ) {
2023-10-31 02:33:24 +00:00
ailConfiguration = AILConfiguration : : create ( this - > getHardwareInfo ( ) - > platform . eProductFamily ) ;
}
}
2023-04-13 14:16:49 +00:00
ReleaseHelper * RootDeviceEnvironment : : getReleaseHelper ( ) const {
return releaseHelper . get ( ) ;
}
2023-10-31 02:33:24 +00:00
AILConfiguration * RootDeviceEnvironment : : getAILConfigurationHelper ( ) const {
return ailConfiguration . get ( ) ;
}
2020-02-27 15:32:57 +01:00
BuiltIns * RootDeviceEnvironment : : getBuiltIns ( ) {
if ( this - > builtins . get ( ) = = nullptr ) {
std : : lock_guard < std : : mutex > autolock ( this - > mtx ) ;
if ( this - > builtins . get ( ) = = nullptr ) {
this - > builtins = std : : make_unique < BuiltIns > ( ) ;
}
}
return this - > builtins . get ( ) ;
}
2022-07-25 12:13:27 +00:00
2025-11-05 13:01:04 +00:00
bool RootDeviceEnvironment : : setNumberOfCcs ( uint32_t numberOfCcs ) {
if ( hwInfo - > gtSystemInfo . CCSInfo . NumberOfCCSEnabled < numberOfCcs | | numberOfCcs = = 0 ) {
NEO : : printDebugString ( NEO : : debugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error: Invalid number of CCS - %u (max: %u) \n " , numberOfCcs , hwInfo - > gtSystemInfo . CCSInfo . NumberOfCCSEnabled ) ;
return false ;
}
hwInfo - > gtSystemInfo . CCSInfo . NumberOfCCSEnabled = numberOfCcs ;
2022-07-25 12:13:27 +00:00
limitedNumberOfCcs = true ;
2025-07-07 17:22:27 +00:00
if ( aubCenter ) {
aubCenter - > getAubManager ( ) - > setCCSMode ( hwInfo - > gtSystemInfo . CCSInfo . NumberOfCCSEnabled ) ;
}
2025-11-05 13:01:04 +00:00
return true ;
2022-07-25 12:13:27 +00:00
}
2025-09-24 12:44:57 +00:00
uint32_t RootDeviceEnvironment : : getNumberOfCcs ( ) const {
return hwInfo - > gtSystemInfo . CCSInfo . NumberOfCCSEnabled ;
}
2022-07-25 12:13:27 +00:00
bool RootDeviceEnvironment : : isNumberOfCcsLimited ( ) const {
return limitedNumberOfCcs ;
}
2022-11-08 16:16:37 +00:00
2023-09-15 10:28:08 +00:00
void RootDeviceEnvironment : : setRcsExposure ( ) {
if ( releaseHelper ) {
if ( releaseHelper - > isRcsExposureDisabled ( ) ) {
hwInfo - > featureTable . flags . ftrRcsNode = false ;
2023-11-30 08:32:25 +00:00
if ( ( debugManager . flags . NodeOrdinal . get ( ) = = static_cast < int32_t > ( aub_stream : : EngineType : : ENGINE_RCS ) ) | | ( debugManager . flags . NodeOrdinal . get ( ) = = static_cast < int32_t > ( aub_stream : : EngineType : : ENGINE_CCCS ) ) ) {
2023-09-15 10:28:08 +00:00
hwInfo - > featureTable . flags . ftrRcsNode = true ;
}
}
}
}
2023-02-28 21:08:09 +00:00
void RootDeviceEnvironment : : initDummyAllocation ( ) {
std : : call_once ( isDummyAllocationInitialized , [ this ] ( ) {
auto customDeleter = [ this ] ( GraphicsAllocation * dummyAllocation ) {
this - > executionEnvironment . memoryManager - > freeGraphicsMemory ( dummyAllocation ) ;
} ;
auto dummyBlitAllocation = this - > executionEnvironment . memoryManager - > allocateGraphicsMemoryWithProperties (
* this - > dummyBlitProperties . get ( ) ) ;
this - > dummyAllocation = GraphicsAllocationUniquePtrType ( dummyBlitAllocation , customDeleter ) ;
} ) ;
}
void RootDeviceEnvironment : : setDummyBlitProperties ( uint32_t rootDeviceIndex ) {
2024-04-11 12:23:06 +00:00
size_t size = 32 * MemoryConstants : : kiloByte ;
this - > dummyBlitProperties = std : : make_unique < AllocationProperties > ( rootDeviceIndex , size , NEO : : AllocationType : : buffer , systemMemoryBitfield ) ;
2023-02-28 21:08:09 +00:00
}
GraphicsAllocation * RootDeviceEnvironment : : getDummyAllocation ( ) const {
return dummyAllocation . get ( ) ;
}
2024-05-15 17:26:24 +00:00
void RootDeviceEnvironment : : releaseDummyAllocation ( ) {
dummyAllocation . reset ( ) ;
}
2023-03-07 16:39:25 +00:00
AssertHandler * RootDeviceEnvironment : : getAssertHandler ( Device * neoDevice ) {
if ( this - > assertHandler . get ( ) = = nullptr ) {
std : : lock_guard < std : : mutex > autolock ( this - > mtx ) ;
if ( this - > assertHandler . get ( ) = = nullptr ) {
this - > assertHandler = std : : make_unique < AssertHandler > ( neoDevice ) ;
}
}
return this - > assertHandler . get ( ) ;
}
2023-05-29 11:11:44 +00:00
bool RootDeviceEnvironment : : isWddmOnLinux ( ) const {
return isWddmOnLinuxEnable ;
}
2022-11-08 16:16:37 +00:00
template < typename HelperType >
HelperType & RootDeviceEnvironment : : getHelper ( ) const {
2023-01-03 09:01:43 +00:00
if constexpr ( std : : is_same_v < HelperType , CompilerProductHelper > ) {
2023-01-31 12:34:59 +00:00
UNRECOVERABLE_IF ( compilerProductHelper = = nullptr ) ;
return * compilerProductHelper ;
2023-01-03 09:01:43 +00:00
} else if constexpr ( std : : is_same_v < HelperType , ProductHelper > ) {
2023-02-01 03:12:09 +00:00
UNRECOVERABLE_IF ( productHelper = = nullptr ) ;
return * productHelper ;
2022-11-10 15:23:21 +00:00
} else {
2023-01-03 09:01:43 +00:00
static_assert ( std : : is_same_v < HelperType , GfxCoreHelper > , " Only CompilerProductHelper, ProductHelper and GfxCoreHelper are supported " ) ;
2023-01-09 14:59:10 +00:00
UNRECOVERABLE_IF ( gfxCoreHelper = = nullptr ) ;
return * gfxCoreHelper ;
2022-11-08 16:16:37 +00:00
}
}
template ProductHelper & RootDeviceEnvironment : : getHelper ( ) const ;
2023-01-03 09:01:43 +00:00
template CompilerProductHelper & RootDeviceEnvironment : : getHelper ( ) const ;
2022-12-08 12:22:35 +00:00
template GfxCoreHelper & RootDeviceEnvironment : : getHelper ( ) const ;
2022-11-08 16:16:37 +00:00
2019-10-24 13:34:25 +02:00
} // namespace NEO