@@ -74,7 +74,7 @@ std::mutex ZeCall::GlobalLock;
74
74
// Controls PI level tracing prints.
75
75
static bool PrintPiTrace = false ;
76
76
77
- // Map Level Zero runtime error code to PI error code
77
+ // Map Level Zero runtime error code to PI error code.
78
78
static pi_result mapError (ze_result_t ZeResult) {
79
79
// TODO: these mapping need to be clarified and synced with the PI API return
80
80
// values, which is TBD.
@@ -592,6 +592,26 @@ pi_result _pi_queue::resetCommandListFenceEntry(
592
592
return PI_SUCCESS;
593
593
}
594
594
595
+ // Maximum Number of Command Lists that can be created.
596
+ // This Value is initialized to 20000, but can be changed by the user
597
+ // thru the environment variable SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE
598
+ // ie SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE =10000.
599
+ static const int ZeMaxCommandListCacheSize = [] {
600
+ const char *CommandListCacheSize =
601
+ std::getenv (" SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE" );
602
+ pi_uint32 CommandListCacheSizeValue;
603
+ try {
604
+ CommandListCacheSizeValue =
605
+ CommandListCacheSize ? std::stoi (CommandListCacheSize) : 20000 ;
606
+ } catch (std::exception const &) {
607
+ zePrint (
608
+ " SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE: invalid value provided, "
609
+ " default set.\n " );
610
+ CommandListCacheSizeValue = 20000 ;
611
+ }
612
+ return CommandListCacheSizeValue;
613
+ }();
614
+
595
615
static const pi_uint32 ZeCommandListBatchSize = [] {
596
616
// Default value of 0. This specifies to use dynamic batch size adjustment.
597
617
pi_uint32 BatchSizeVal = 0 ;
@@ -692,7 +712,7 @@ pi_result _pi_context::getAvailableCommandList(
692
712
// map.
693
713
if ((*ZeCommandList == nullptr ) &&
694
714
(Queue->Device ->Platform ->ZeGlobalCommandListCount <
695
- Queue-> Device -> Platform -> ZeMaxCommandListCache )) {
715
+ ZeMaxCommandListCacheSize )) {
696
716
ZE_CALL (zeCommandListCreate,
697
717
(Queue->Context ->ZeContext , Queue->Device ->ZeDevice ,
698
718
&ZeCommandListDesc, ZeCommandList));
@@ -982,6 +1002,27 @@ static bool setEnvVar(const char *name, const char *value) {
982
1002
return true ;
983
1003
}
984
1004
1005
+ pi_result _pi_platform::initialize () {
1006
+ // Cache driver properties
1007
+ ze_driver_properties_t ZeDriverProperties;
1008
+ ZE_CALL (zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
1009
+ uint32_t DriverVersion = ZeDriverProperties.driverVersion ;
1010
+ // Intel Level-Zero GPU driver stores version as:
1011
+ // | 31 - 24 | 23 - 16 | 15 - 0 |
1012
+ // | Major | Minor | Build |
1013
+ auto VersionMajor = std::to_string ((DriverVersion & 0xFF000000 ) >> 24 );
1014
+ auto VersionMinor = std::to_string ((DriverVersion & 0x00FF0000 ) >> 16 );
1015
+ auto VersionBuild = std::to_string (DriverVersion & 0x0000FFFF );
1016
+ ZeDriverVersion = VersionMajor + " ." + VersionMinor + " ." + VersionBuild;
1017
+
1018
+ ze_api_version_t ZeApiVersion;
1019
+ ZE_CALL (zeDriverGetApiVersion, (ZeDriver, &ZeApiVersion));
1020
+ ZeDriverApiVersion = std::to_string (ZE_MAJOR_VERSION (ZeApiVersion)) + " ." +
1021
+ std::to_string (ZE_MINOR_VERSION (ZeApiVersion));
1022
+
1023
+ return PI_SUCCESS;
1024
+ }
1025
+
985
1026
pi_result piPlatformsGet (pi_uint32 NumEntries, pi_platform *Platforms,
986
1027
pi_uint32 *NumPlatforms) {
987
1028
@@ -1048,58 +1089,27 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
1048
1089
1049
1090
const std::lock_guard<sycl::detail::SpinLock> Lock{*PiPlatformsCacheMutex};
1050
1091
if (!PiPlatformCachePopulated) {
1051
- const char *CommandListCacheSize =
1052
- std::getenv (" SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE" );
1053
- pi_uint32 CommandListCacheSizeValue;
1054
1092
try {
1055
- CommandListCacheSizeValue =
1056
- CommandListCacheSize ? std::stoi (CommandListCacheSize) : 20000 ;
1057
- } catch (std::exception const &) {
1058
- zePrint (
1059
- " SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE: invalid value provided, "
1060
- " default set.\n " );
1061
- CommandListCacheSizeValue = 20000 ;
1062
- }
1063
-
1064
- try {
1065
-
1066
1093
// Level Zero does not have concept of Platforms, but Level Zero driver is
1067
1094
// the closest match.
1068
1095
uint32_t ZeDriverCount = 0 ;
1069
1096
ZE_CALL (zeDriverGet, (&ZeDriverCount, nullptr ));
1070
1097
if (ZeDriverCount == 0 ) {
1071
1098
PiPlatformCachePopulated = true ;
1072
1099
} else {
1073
- ze_driver_handle_t ZeDriver;
1074
- PI_ASSERT (ZeDriverCount == 1 , PI_INVALID_VALUE);
1075
-
1076
- ZE_CALL (zeDriverGet, (&ZeDriverCount, &ZeDriver));
1077
- pi_platform Platform = new _pi_platform (ZeDriver);
1078
-
1079
- // Cache driver properties
1080
- ze_driver_properties_t ZeDriverProperties;
1081
- ZE_CALL (zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
1082
- uint32_t ZeDriverVersion = ZeDriverProperties.driverVersion ;
1083
- // Intel Level-Zero GPU driver stores version as:
1084
- // | 31 - 24 | 23 - 16 | 15 - 0 |
1085
- // | Major | Minor | Build |
1086
- auto VersionMajor =
1087
- std::to_string ((ZeDriverVersion & 0xFF000000 ) >> 24 );
1088
- auto VersionMinor =
1089
- std::to_string ((ZeDriverVersion & 0x00FF0000 ) >> 16 );
1090
- auto VersionBuild = std::to_string (ZeDriverVersion & 0x0000FFFF );
1091
- Platform->ZeDriverVersion =
1092
- VersionMajor + " ." + VersionMinor + " ." + VersionBuild;
1093
-
1094
- ze_api_version_t ZeApiVersion;
1095
- ZE_CALL (zeDriverGetApiVersion, (ZeDriver, &ZeApiVersion));
1096
- Platform->ZeDriverApiVersion =
1097
- std::to_string (ZE_MAJOR_VERSION (ZeApiVersion)) + " ." +
1098
- std::to_string (ZE_MINOR_VERSION (ZeApiVersion));
1099
-
1100
- Platform->ZeMaxCommandListCache = CommandListCacheSizeValue;
1101
- // Save a copy in the cache for future uses.
1102
- PiPlatformsCache->push_back (Platform);
1100
+ std::vector<ze_driver_handle_t > ZeDrivers;
1101
+ ZeDrivers.resize (ZeDriverCount);
1102
+
1103
+ ZE_CALL (zeDriverGet, (&ZeDriverCount, ZeDrivers.data ()));
1104
+ for (uint32_t I = 0 ; I < ZeDriverCount; ++I) {
1105
+ pi_platform Platform = new _pi_platform (ZeDrivers[I]);
1106
+ pi_result Result = Platform->initialize ();
1107
+ if (Result != PI_SUCCESS) {
1108
+ return Result;
1109
+ }
1110
+ // Save a copy in the cache for future uses.
1111
+ PiPlatformsCache->push_back (Platform);
1112
+ }
1103
1113
PiPlatformCachePopulated = true ;
1104
1114
}
1105
1115
} catch (const std::bad_alloc &) {
@@ -1109,16 +1119,10 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
1109
1119
}
1110
1120
}
1111
1121
1112
- if (Platforms && NumEntries > 0 ) {
1113
- uint32_t I = 0 ;
1114
- for (const pi_platform &CachedPlatform : *PiPlatformsCache) {
1115
- if (I < NumEntries) {
1116
- *Platforms++ = CachedPlatform;
1117
- I++;
1118
- } else {
1119
- break ;
1120
- }
1121
- }
1122
+ // Populate returned platforms from the cache.
1123
+ if (Platforms) {
1124
+ PI_ASSERT (NumEntries <= PiPlatformsCache->size (), PI_INVALID_PLATFORM);
1125
+ std::copy_n (PiPlatformsCache->begin (), NumEntries, Platforms);
1122
1126
}
1123
1127
1124
1128
if (NumPlatforms)
0 commit comments