2018-09-18 22:31:47 +08:00
/*
2025-01-15 00:36:45 +08:00
* Copyright ( C ) 2018 - 2025 Intel Corporation
2018-09-18 22:31:47 +08:00
*
2018-09-18 15:11:08 +08:00
* SPDX - License - Identifier : MIT
2018-09-18 22:31:47 +08:00
*
*/
2020-02-24 05:44:01 +08:00
# include "shared/source/os_interface/device_factory.h"
2024-12-11 18:18:07 +08:00
# include "shared/source/ail/ail_configuration.h"
2020-10-16 18:10:52 +08:00
# include "shared/source/aub/aub_center.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/debug_settings/debug_settings_manager.h"
# include "shared/source/device/root_device.h"
2022-12-16 01:32:03 +08:00
# include "shared/source/execution_environment/execution_environment.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/execution_environment/root_device_environment.h"
2023-02-02 22:25:08 +08:00
# include "shared/source/helpers/compiler_product_helper.h"
2023-02-02 00:23:01 +08:00
# include "shared/source/helpers/gfx_core_helper.h"
2023-02-07 20:53:53 +08:00
# include "shared/source/helpers/hw_info.h"
2022-07-20 18:13:10 +08:00
# include "shared/source/helpers/product_config_helper.h"
2021-04-29 16:58:16 +08:00
# include "shared/source/memory_manager/memory_manager.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/os_interface/aub_memory_operations_handler.h"
# include "shared/source/os_interface/os_interface.h"
2023-03-10 20:28:11 +08:00
# include "shared/source/os_interface/product_helper.h"
2020-02-24 17:22:30 +08:00
2020-02-13 20:26:40 +08:00
# include "hw_device_id.h"
2019-03-26 18:59:46 +08:00
namespace NEO {
2018-09-18 22:31:47 +08:00
2020-03-23 16:13:25 +08:00
bool DeviceFactory : : prepareDeviceEnvironmentsForProductFamilyOverride ( ExecutionEnvironment & executionEnvironment ) {
2019-10-23 22:17:06 +08:00
auto numRootDevices = 1u ;
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . CreateMultipleRootDevices . get ( ) ) {
numRootDevices = debugManager . flags . CreateMultipleRootDevices . get ( ) ;
2018-09-18 22:31:47 +08:00
}
2019-11-15 16:59:48 +08:00
executionEnvironment . prepareRootDeviceEnvironments ( numRootDevices ) ;
2019-10-22 17:44:06 +08:00
2023-11-30 16:32:25 +08:00
auto productFamily = debugManager . flags . ProductFamilyOverride . get ( ) ;
2022-07-20 18:13:10 +08:00
auto configStr = productFamily ;
2023-04-18 00:11:43 +08:00
auto productConfigHelper = std : : make_unique < ProductConfigHelper > ( ) ;
2022-07-20 18:13:10 +08:00
ProductConfigHelper : : adjustDeviceName ( configStr ) ;
2023-05-12 21:46:58 +08:00
uint32_t productConfig = productConfigHelper - > getProductConfigFromDeviceName ( configStr ) ;
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . OverrideHwIpVersion . get ( ) ! = - 1 & & productConfigHelper - > isSupportedProductConfig ( debugManager . flags . OverrideHwIpVersion . get ( ) ) ) {
productConfig = debugManager . flags . OverrideHwIpVersion . get ( ) ;
2023-05-12 21:46:58 +08:00
}
2022-07-20 18:13:10 +08:00
2022-02-04 21:41:04 +08:00
const HardwareInfo * hwInfoConst = getDefaultHwInfo ( ) ;
2022-07-20 18:13:10 +08:00
DeviceAotInfo aotInfo { } ;
auto productConfigFound = productConfigHelper - > getDeviceAotInfoForProductConfig ( productConfig , aotInfo ) ;
if ( productConfigFound ) {
hwInfoConst = aotInfo . hwInfo ;
} else {
getHwInfoForPlatformString ( productFamily , hwInfoConst ) ;
}
2020-01-25 00:19:06 +08:00
std : : string hwInfoConfigStr ;
uint64_t hwInfoConfig = 0x0 ;
2023-11-30 16:32:25 +08:00
debugManager . getHardwareInfoOverride ( hwInfoConfigStr ) ;
2019-03-19 22:09:33 +08:00
2020-03-04 15:51:02 +08:00
for ( auto rootDeviceIndex = 0u ; rootDeviceIndex < numRootDevices ; rootDeviceIndex + + ) {
2022-11-07 22:47:17 +08:00
auto & rootDeviceEnvironment = * executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] . get ( ) ;
2023-06-06 19:41:57 +08:00
rootDeviceEnvironment . setHwInfo ( hwInfoConst ) ;
rootDeviceEnvironment . initProductHelper ( ) ;
rootDeviceEnvironment . initGfxCoreHelper ( ) ;
rootDeviceEnvironment . initApiGfxCoreHelper ( ) ;
rootDeviceEnvironment . initCompilerProductHelper ( ) ;
2023-11-28 23:15:25 +08:00
rootDeviceEnvironment . initAilConfigurationHelper ( ) ;
if ( false = = rootDeviceEnvironment . initAilConfiguration ( ) ) {
return false ;
}
2023-06-06 19:41:57 +08:00
2022-11-07 22:47:17 +08:00
auto hardwareInfo = rootDeviceEnvironment . getMutableHardwareInfo ( ) ;
2019-03-19 22:09:33 +08:00
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . OverrideRevision . get ( ) ! = - 1 ) {
hardwareInfo - > platform . usRevId = static_cast < unsigned short > ( debugManager . flags . OverrideRevision . get ( ) ) ;
2023-02-28 21:26:21 +08:00
}
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . ForceDeviceId . get ( ) ! = " unk " ) {
hardwareInfo - > platform . usDeviceID = static_cast < unsigned short > ( std : : stoi ( debugManager . flags . ForceDeviceId . get ( ) , nullptr , 16 ) ) ;
2023-02-28 21:26:21 +08:00
}
const auto & compilerProductHelper = rootDeviceEnvironment . getHelper < CompilerProductHelper > ( ) ;
2020-03-04 15:51:02 +08:00
if ( hwInfoConfigStr = = " default " ) {
2023-02-28 21:26:21 +08:00
hwInfoConfig = compilerProductHelper . getHwInfoConfig ( * hwInfoConst ) ;
2020-03-04 15:51:02 +08:00
} else if ( ! parseHwInfoConfigString ( hwInfoConfigStr , hwInfoConfig ) ) {
return false ;
}
2023-02-28 21:26:21 +08:00
2022-07-20 18:13:10 +08:00
if ( productConfigFound ) {
2022-11-30 22:28:39 +08:00
compilerProductHelper . setProductConfigForHwInfo ( * hardwareInfo , aotInfo . aotConfig ) ;
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . ForceDeviceId . get ( ) = = " unk " ) {
2023-05-12 21:46:58 +08:00
hardwareInfo - > platform . usDeviceID = aotInfo . deviceIds - > front ( ) ;
2025-03-17 19:24:00 +08:00
} else if ( aotInfo . deviceIds - > front ( ) ! = hardwareInfo - > platform . usDeviceID ) {
std : : stringstream devIds { } ;
for ( auto id : * aotInfo . deviceIds )
devIds < < " 0x " < < std : : hex < < id < < " , " ;
NEO : : printDebugString ( NEO : : debugManager . flags . PrintDebugMessages . get ( ) ,
stdout , " Info@ %s(): Mismatch of device ids. ForceDeviceId %s is used for platform with multiple deviceIds: [%s]. Consider using OverrideHwIpVersion flag. \n " ,
__FUNCTION__ ,
debugManager . flags . ForceDeviceId . get ( ) . c_str ( ) ,
devIds . str ( ) . substr ( 0 , devIds . str ( ) . size ( ) - 2 ) . c_str ( ) ) ;
2023-05-12 21:46:58 +08:00
}
}
2023-07-31 20:48:31 +08:00
hardwareInfo - > ipVersion . value = compilerProductHelper . getHwIpVersion ( * hardwareInfo ) ;
2023-06-06 19:41:57 +08:00
rootDeviceEnvironment . initReleaseHelper ( ) ;
2023-11-16 22:24:12 +08:00
setHwInfoValuesFromConfig ( hwInfoConfig , * hardwareInfo ) ;
hardwareInfoSetup [ hwInfoConst - > platform . eProductFamily ] ( hardwareInfo , true , hwInfoConfig , rootDeviceEnvironment . getReleaseHelper ( ) ) ;
2024-10-21 20:06:30 +08:00
if ( debugManager . flags . MaxSubSlicesSupportedOverride . get ( ) > 0 ) {
hardwareInfo - > gtSystemInfo . MaxSubSlicesSupported = debugManager . flags . MaxSubSlicesSupportedOverride . get ( ) ;
hardwareInfo - > gtSystemInfo . MaxDualSubSlicesSupported = debugManager . flags . MaxSubSlicesSupportedOverride . get ( ) ;
}
2024-05-11 00:29:31 +08:00
if ( debugManager . flags . BlitterEnableMaskOverride . get ( ) > 0 ) {
hardwareInfo - > featureTable . ftrBcsInfo = debugManager . flags . BlitterEnableMaskOverride . get ( ) ;
2024-05-07 23:01:01 +08:00
}
2023-11-16 22:24:12 +08:00
auto & productHelper = rootDeviceEnvironment . getProductHelper ( ) ;
productHelper . configureHardwareCustom ( hardwareInfo , nullptr ) ;
2023-11-16 19:17:43 +08:00
rootDeviceEnvironment . setRcsExposure ( ) ;
2023-06-06 19:41:57 +08:00
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . OverrideGpuAddressSpace . get ( ) ! = - 1 ) {
hardwareInfo - > capabilityTable . gpuAddressSpace = maxNBitValue ( static_cast < uint64_t > ( debugManager . flags . OverrideGpuAddressSpace . get ( ) ) ) ;
2020-03-31 20:59:02 +08:00
}
2024-07-05 22:14:50 +08:00
if ( debugManager . flags . OverrideSlmSize . get ( ) ! = - 1 ) {
2025-04-15 01:38:10 +08:00
hardwareInfo - > capabilityTable . maxProgrammableSlmSize = debugManager . flags . OverrideSlmSize . get ( ) ;
2024-07-05 22:14:50 +08:00
hardwareInfo - > gtSystemInfo . SLMSizeInKb = debugManager . flags . OverrideSlmSize . get ( ) ;
}
2024-11-19 21:56:27 +08:00
if ( debugManager . flags . OverrideRegionCount . get ( ) ! = - 1 ) {
hardwareInfo - > featureTable . regionCount = static_cast < uint32_t > ( debugManager . flags . OverrideRegionCount . get ( ) ) ;
}
2020-03-31 20:59:02 +08:00
2022-11-07 22:47:17 +08:00
[[maybe_unused]] bool result = rootDeviceEnvironment . initAilConfiguration ( ) ;
2021-08-09 16:38:18 +08:00
DEBUG_BREAK_IF ( ! result ) ;
2023-11-30 16:32:25 +08:00
auto csrType = debugManager . flags . SetCommandStreamReceiver . get ( ) ;
2020-03-04 15:51:02 +08:00
if ( csrType > 0 ) {
2022-12-12 20:39:04 +08:00
auto & gfxCoreHelper = rootDeviceEnvironment . getHelper < GfxCoreHelper > ( ) ;
2022-12-08 20:22:35 +08:00
auto localMemoryEnabled = gfxCoreHelper . getEnableLocalMemory ( * hardwareInfo ) ;
2022-11-07 22:47:17 +08:00
rootDeviceEnvironment . initGmm ( ) ;
rootDeviceEnvironment . initAubCenter ( localMemoryEnabled , " " , static_cast < CommandStreamReceiverType > ( csrType ) ) ;
auto aubCenter = rootDeviceEnvironment . aubCenter . get ( ) ;
rootDeviceEnvironment . memoryOperationsInterface = std : : make_unique < AubMemoryOperationsHandler > ( aubCenter - > getAubManager ( ) ) ;
2019-11-15 16:59:48 +08:00
}
2020-02-14 23:37:48 +08:00
}
2025-01-15 00:36:45 +08:00
executionEnvironment . setDeviceHierarchyMode ( executionEnvironment . rootDeviceEnvironments [ 0 ] - > getHelper < GfxCoreHelper > ( ) ) ;
2021-01-25 17:24:00 +08:00
executionEnvironment . parseAffinityMask ( ) ;
2022-07-25 20:13:27 +08:00
executionEnvironment . adjustCcsCount ( ) ;
2020-03-04 15:51:02 +08:00
executionEnvironment . calculateMaxOsContextCount ( ) ;
2018-09-18 22:31:47 +08:00
return true ;
}
2020-02-07 16:00:25 +08:00
bool DeviceFactory : : isHwModeSelected ( ) {
2024-04-09 20:43:12 +08:00
CommandStreamReceiverType csrType = obtainCsrTypeFromIntegerValue ( debugManager . flags . SetCommandStreamReceiver . get ( ) , CommandStreamReceiverType : : hardware ) ;
switch ( csrType ) {
case CommandStreamReceiverType : : aub :
case CommandStreamReceiverType : : tbx :
case CommandStreamReceiverType : : tbxWithAub :
case CommandStreamReceiverType : : nullAub :
2020-02-07 16:00:25 +08:00
return false ;
default :
return true ;
}
}
2020-02-13 20:26:40 +08:00
2021-10-11 23:34:03 +08:00
static bool initHwDeviceIdResources ( ExecutionEnvironment & executionEnvironment ,
std : : unique_ptr < NEO : : HwDeviceId > & & hwDeviceId , uint32_t rootDeviceIndex ) {
if ( ! executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > initOsInterface ( std : : move ( hwDeviceId ) , rootDeviceIndex ) ) {
return false ;
}
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . OverrideGpuAddressSpace . get ( ) ! = - 1 ) {
2021-10-11 23:34:03 +08:00
executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > getMutableHardwareInfo ( ) - > capabilityTable . gpuAddressSpace =
2023-11-30 16:32:25 +08:00
maxNBitValue ( static_cast < uint64_t > ( debugManager . flags . OverrideGpuAddressSpace . get ( ) ) ) ;
2021-10-11 23:34:03 +08:00
}
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . OverrideRevision . get ( ) ! = - 1 ) {
2021-10-11 23:34:03 +08:00
executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > getMutableHardwareInfo ( ) - > platform . usRevId =
2023-11-30 16:32:25 +08:00
static_cast < unsigned short > ( debugManager . flags . OverrideRevision . get ( ) ) ;
2021-10-11 23:34:03 +08:00
}
2024-07-05 22:14:50 +08:00
if ( debugManager . flags . OverrideSlmSize . get ( ) ! = - 1 ) {
auto hardwareInfo = executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > getMutableHardwareInfo ( ) ;
2025-04-15 01:38:10 +08:00
hardwareInfo - > capabilityTable . maxProgrammableSlmSize = debugManager . flags . OverrideSlmSize . get ( ) ;
2024-07-05 22:14:50 +08:00
hardwareInfo - > gtSystemInfo . SLMSizeInKb = debugManager . flags . OverrideSlmSize . get ( ) ;
}
2024-11-19 21:56:27 +08:00
if ( debugManager . flags . OverrideRegionCount . get ( ) ! = - 1 ) {
executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > getMutableHardwareInfo ( ) - > featureTable . regionCount = static_cast < uint32_t > ( debugManager . flags . OverrideRegionCount . get ( ) ) ;
}
2022-04-20 03:24:19 +08:00
executionEnvironment . rootDeviceEnvironments [ rootDeviceIndex ] - > initGmm ( ) ;
2021-10-11 23:34:03 +08:00
return true ;
}
2020-03-23 16:13:25 +08:00
bool DeviceFactory : : prepareDeviceEnvironments ( ExecutionEnvironment & executionEnvironment ) {
2024-03-15 21:14:45 +08:00
executionEnvironment . configureCcsMode ( ) ;
2020-02-13 20:26:40 +08:00
2024-03-15 21:14:45 +08:00
using HwDeviceIds = std : : vector < std : : unique_ptr < HwDeviceId > > ;
2020-03-17 14:26:46 +08:00
HwDeviceIds hwDeviceIds = OSInterface : : discoverDevices ( executionEnvironment ) ;
2020-03-20 23:54:09 +08:00
if ( hwDeviceIds . empty ( ) ) {
2020-02-13 20:26:40 +08:00
return false ;
}
2020-03-20 23:54:09 +08:00
executionEnvironment . prepareRootDeviceEnvironments ( static_cast < uint32_t > ( hwDeviceIds . size ( ) ) ) ;
2020-02-13 20:26:40 +08:00
uint32_t rootDeviceIndex = 0u ;
for ( auto & hwDeviceId : hwDeviceIds ) {
2021-10-11 23:34:03 +08:00
if ( initHwDeviceIdResources ( executionEnvironment , std : : move ( hwDeviceId ) , rootDeviceIndex ) = = false ) {
2023-11-21 01:47:53 +08:00
continue ;
2020-02-13 20:26:40 +08:00
}
rootDeviceIndex + + ;
}
2023-11-21 01:47:53 +08:00
executionEnvironment . rootDeviceEnvironments . resize ( rootDeviceIndex ) ;
if ( rootDeviceIndex = = 0 ) {
return false ;
}
2025-01-15 00:36:45 +08:00
executionEnvironment . setDeviceHierarchyMode ( executionEnvironment . rootDeviceEnvironments [ 0 ] - > getHelper < GfxCoreHelper > ( ) ) ;
2021-07-11 08:12:15 +08:00
executionEnvironment . sortNeoDevices ( ) ;
2021-01-25 17:24:00 +08:00
executionEnvironment . parseAffinityMask ( ) ;
2023-07-11 18:55:25 +08:00
executionEnvironment . adjustRootDeviceEnvironments ( ) ;
2022-07-25 20:13:27 +08:00
executionEnvironment . adjustCcsCount ( ) ;
2020-02-13 20:26:40 +08:00
executionEnvironment . calculateMaxOsContextCount ( ) ;
2020-02-14 23:37:48 +08:00
2020-02-13 20:26:40 +08:00
return true ;
}
2021-10-11 23:34:03 +08:00
bool DeviceFactory : : prepareDeviceEnvironment ( ExecutionEnvironment & executionEnvironment , std : : string & osPciPath , const uint32_t rootDeviceIndex ) {
using HwDeviceIds = std : : vector < std : : unique_ptr < HwDeviceId > > ;
HwDeviceIds hwDeviceIds = OSInterface : : discoverDevice ( executionEnvironment , osPciPath ) ;
if ( hwDeviceIds . empty ( ) ) {
return false ;
}
executionEnvironment . prepareRootDeviceEnvironment ( rootDeviceIndex ) ;
// HwDeviceIds should contain only one entry corresponding to osPciPath
UNRECOVERABLE_IF ( hwDeviceIds . size ( ) > 1 ) ;
2022-09-22 16:48:55 +08:00
if ( ! initHwDeviceIdResources ( executionEnvironment , std : : move ( hwDeviceIds [ 0 ] ) , rootDeviceIndex ) ) {
return false ;
}
executionEnvironment . adjustCcsCount ( rootDeviceIndex ) ;
return true ;
2021-10-11 23:34:03 +08:00
}
std : : unique_ptr < Device > DeviceFactory : : createDevice ( ExecutionEnvironment & executionEnvironment , std : : string & osPciPath , const uint32_t rootDeviceIndex ) {
std : : unique_ptr < Device > device ;
if ( ! NEO : : prepareDeviceEnvironment ( executionEnvironment , osPciPath , rootDeviceIndex ) ) {
return device ;
}
2024-12-12 20:38:40 +08:00
executionEnvironment . memoryManager - > reInitDeviceSpecificGfxPartition ( rootDeviceIndex ) ;
2021-10-11 23:34:03 +08:00
executionEnvironment . memoryManager - > createDeviceSpecificMemResources ( rootDeviceIndex ) ;
executionEnvironment . memoryManager - > reInitLatestContextId ( ) ;
device = createRootDeviceFunc ( executionEnvironment , rootDeviceIndex ) ;
return device ;
}
2020-02-15 00:36:30 +08:00
std : : vector < std : : unique_ptr < Device > > DeviceFactory : : createDevices ( ExecutionEnvironment & executionEnvironment ) {
std : : vector < std : : unique_ptr < Device > > devices ;
2020-09-18 22:19:41 +08:00
if ( ! NEO : : prepareDeviceEnvironments ( executionEnvironment ) ) {
2020-02-15 00:36:30 +08:00
return devices ;
}
2020-09-18 22:19:41 +08:00
2021-01-13 05:39:04 +08:00
if ( ! DeviceFactory : : createMemoryManagerFunc ( executionEnvironment ) ) {
2020-09-18 22:19:41 +08:00
return devices ;
}
2020-02-15 00:36:30 +08:00
for ( uint32_t rootDeviceIndex = 0u ; rootDeviceIndex < executionEnvironment . rootDeviceEnvironments . size ( ) ; rootDeviceIndex + + ) {
auto device = createRootDeviceFunc ( executionEnvironment , rootDeviceIndex ) ;
if ( device ) {
devices . push_back ( std : : move ( device ) ) ;
}
}
2021-04-29 16:58:16 +08:00
2020-02-15 00:36:30 +08:00
return devices ;
}
std : : unique_ptr < Device > ( * DeviceFactory : : createRootDeviceFunc ) ( ExecutionEnvironment & , uint32_t ) = [ ] ( ExecutionEnvironment & executionEnvironment , uint32_t rootDeviceIndex ) - > std : : unique_ptr < Device > {
return std : : unique_ptr < Device > ( Device : : create < RootDevice > ( & executionEnvironment , rootDeviceIndex ) ) ;
} ;
2020-11-20 19:04:46 +08:00
2021-01-13 05:39:04 +08:00
bool ( * DeviceFactory : : createMemoryManagerFunc ) ( ExecutionEnvironment & ) = [ ] ( ExecutionEnvironment & executionEnvironment ) - > bool {
return executionEnvironment . initializeMemoryManager ( ) ;
2020-11-20 19:04:46 +08:00
} ;
2022-02-01 01:43:42 +08:00
bool DeviceFactory : : isAllowedDeviceId ( uint32_t deviceId , const std : : string & deviceIdString ) {
if ( deviceIdString ! = " unk " ) {
char * endptr = nullptr ;
auto reqDeviceId = strtoul ( deviceIdString . c_str ( ) , & endptr , 16 ) ;
return ( static_cast < uint32_t > ( reqDeviceId ) = = deviceId ) ;
}
return true ;
}
2019-03-26 18:59:46 +08:00
} // namespace NEO