@@ -90,18 +90,12 @@ static const bool ReuseDiscardedEvents = [] {
90
90
return std::stoi (ReuseDiscardedEventsFlag) > 0 ;
91
91
}();
92
92
93
- // Controls PI level tracing prints.
94
- static bool PrintPiTrace = false ;
95
-
96
93
// Controls support of the indirect access kernels and deferred memory release.
97
94
static const bool IndirectAccessTrackingEnabled = [] {
98
95
return std::getenv (" SYCL_PI_LEVEL_ZERO_TRACK_INDIRECT_ACCESS_MEMORY" ) !=
99
96
nullptr ;
100
97
}();
101
98
102
- // This will count the calls to Level-Zero
103
- static std::map<const char *, int > *ZeCallCount = nullptr ;
104
-
105
99
// Map from L0 to PI result
106
100
static inline pi_result mapError (ze_result_t Result) {
107
101
return ur2piResult (ze2urResult (Result));
@@ -118,7 +112,7 @@ static inline pi_result mapError(ze_result_t Result) {
118
112
// Trace an internal PI call; returns in case of an error.
119
113
#define PI_CALL (Call ) \
120
114
{ \
121
- if (PrintPiTrace) \
115
+ if (PrintTrace) \
122
116
fprintf (stderr, " PI ---> %s\n " , #Call); \
123
117
pi_result Result = (Call); \
124
118
if (Result != PI_SUCCESS) \
@@ -352,15 +346,6 @@ static bool CopyEngineRequested(pi_device Device) {
352
346
}
353
347
354
348
// Global variables used in PI_Level_Zero
355
- // Note we only create a simple pointer variables such that C++ RT won't
356
- // deallocate them automatically at the end of the main program.
357
- // The heap memory allocated for these global variables reclaimed only when
358
- // Sycl RT calls piTearDown().
359
- static std::vector<pi_platform> *PiPlatformsCache =
360
- new std::vector<pi_platform>;
361
- static sycl::detail::SpinLock *PiPlatformsCacheMutex =
362
- new sycl::detail::SpinLock;
363
- static bool PiPlatformCachePopulated = false ;
364
349
365
350
pi_result
366
351
_pi_context::getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &Pool,
@@ -470,55 +455,6 @@ static pi_result enqueueMemCopyRectHelper(
470
455
const pi_event *EventWaitList, pi_event *Event,
471
456
bool PreferCopyEngine = false );
472
457
473
- inline void zeParseError (ze_result_t ZeError, const char *&ErrorString) {
474
- switch (ZeError) {
475
- #define ZE_ERRCASE (ERR ) \
476
- case ERR: \
477
- ErrorString = " " #ERR; \
478
- break ;
479
-
480
- ZE_ERRCASE (ZE_RESULT_SUCCESS)
481
- ZE_ERRCASE (ZE_RESULT_NOT_READY)
482
- ZE_ERRCASE (ZE_RESULT_ERROR_DEVICE_LOST)
483
- ZE_ERRCASE (ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY)
484
- ZE_ERRCASE (ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY)
485
- ZE_ERRCASE (ZE_RESULT_ERROR_MODULE_BUILD_FAILURE)
486
- ZE_ERRCASE (ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS)
487
- ZE_ERRCASE (ZE_RESULT_ERROR_NOT_AVAILABLE)
488
- ZE_ERRCASE (ZE_RESULT_ERROR_UNINITIALIZED)
489
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_VERSION)
490
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_FEATURE)
491
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_ARGUMENT)
492
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_NULL_HANDLE)
493
- ZE_ERRCASE (ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE)
494
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_NULL_POINTER)
495
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_SIZE)
496
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_SIZE)
497
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT)
498
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT)
499
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_ENUMERATION)
500
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION)
501
- ZE_ERRCASE (ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT)
502
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_NATIVE_BINARY)
503
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_GLOBAL_NAME)
504
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_KERNEL_NAME)
505
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_FUNCTION_NAME)
506
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION)
507
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION)
508
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX)
509
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE)
510
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE)
511
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE)
512
- ZE_ERRCASE (ZE_RESULT_ERROR_OVERLAPPING_REGIONS)
513
- ZE_ERRCASE (ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED)
514
- ZE_ERRCASE (ZE_RESULT_ERROR_UNKNOWN)
515
-
516
- #undef ZE_ERRCASE
517
- default :
518
- assert (false && " Unexpected Error code" );
519
- } // switch
520
- }
521
-
522
458
// Global variables for PI_ERROR_PLUGIN_SPECIFIC_ERROR
523
459
constexpr size_t MaxMessageSize = 256 ;
524
460
thread_local pi_result ErrorMessageCode = PI_SUCCESS;
@@ -538,26 +474,6 @@ pi_result piPluginGetLastError(char **message) {
538
474
return ErrorMessageCode;
539
475
}
540
476
541
- ze_result_t ZeCall::doCall (ze_result_t ZeResult, const char *ZeName,
542
- const char *ZeArgs, bool TraceError) {
543
- zePrint (" ZE ---> %s%s\n " , ZeName, ZeArgs);
544
-
545
- if (ZeDebug & ZE_DEBUG_CALL_COUNT) {
546
- ++(*ZeCallCount)[ZeName];
547
- }
548
-
549
- if (ZeResult && TraceError) {
550
- const char *ErrorString = " Unknown" ;
551
- zeParseError (ZeResult, ErrorString);
552
- zePrint (" Error (%s) in %s\n " , ErrorString, ZeName);
553
- }
554
- return ZeResult;
555
- }
556
-
557
- #define PI_ASSERT (condition, error ) \
558
- if (!(condition)) \
559
- return error;
560
-
561
477
bool _pi_queue::doReuseDiscardedEvents () {
562
478
return ReuseDiscardedEvents && isInOrderQueue () && isDiscardEvents ();
563
479
}
@@ -1580,7 +1496,7 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
1580
1496
// traces incurs much different timings than real execution
1581
1497
// ansyway, and many regression tests use it.
1582
1498
//
1583
- bool CurrentlyEmpty = !PrintPiTrace && this ->LastCommandEvent == nullptr ;
1499
+ bool CurrentlyEmpty = !PrintTrace && this ->LastCommandEvent == nullptr ;
1584
1500
1585
1501
// The list can be empty if command-list only contains signals of proxy
1586
1502
// events. It is possible that executeCommandList is called twice for the same
@@ -2238,117 +2154,7 @@ checkUnresolvedSymbols(ze_module_handle_t ZeModule,
2238
2154
2239
2155
pi_result piPlatformsGet (pi_uint32 NumEntries, pi_platform *Platforms,
2240
2156
pi_uint32 *NumPlatforms) {
2241
-
2242
- static const char *PiTrace = std::getenv (" SYCL_PI_TRACE" );
2243
- static const int PiTraceValue = PiTrace ? std::stoi (PiTrace) : 0 ;
2244
- if (PiTraceValue == -1 || PiTraceValue == 2 ) { // Means print all PI traces
2245
- PrintPiTrace = true ;
2246
- }
2247
-
2248
- static std::once_flag ZeCallCountInitialized;
2249
- try {
2250
- std::call_once (ZeCallCountInitialized, []() {
2251
- if (ZeDebug & ZE_DEBUG_CALL_COUNT) {
2252
- ZeCallCount = new std::map<const char *, int >;
2253
- }
2254
- });
2255
- } catch (const std::bad_alloc &) {
2256
- return PI_ERROR_OUT_OF_HOST_MEMORY;
2257
- } catch (...) {
2258
- return PI_ERROR_UNKNOWN;
2259
- }
2260
-
2261
- if (NumEntries == 0 && Platforms != nullptr ) {
2262
- return PI_ERROR_INVALID_VALUE;
2263
- }
2264
- if (Platforms == nullptr && NumPlatforms == nullptr ) {
2265
- return PI_ERROR_INVALID_VALUE;
2266
- }
2267
-
2268
- // Setting these environment variables before running zeInit will enable the
2269
- // validation layer in the Level Zero loader.
2270
- if (ZeDebug & ZE_DEBUG_VALIDATION) {
2271
- setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
2272
- setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
2273
- }
2274
-
2275
- // Enable SYSMAN support for obtaining the PCI address
2276
- // and maximum memory bandwidth.
2277
- if (getenv (" SYCL_ENABLE_PCI" ) != nullptr ) {
2278
- setEnvVar (" ZES_ENABLE_SYSMAN" , " 1" );
2279
- }
2280
-
2281
- // TODO: We can still safely recover if something goes wrong during the init.
2282
- // Implement handling segfault using sigaction.
2283
-
2284
- // We must only initialize the driver once, even if piPlatformsGet() is called
2285
- // multiple times. Declaring the return value as "static" ensures it's only
2286
- // called once.
2287
- static ze_result_t ZeResult = ZE_CALL_NOCHECK (zeInit, (0 ));
2288
-
2289
- // Absorb the ZE_RESULT_ERROR_UNINITIALIZED and just return 0 Platforms.
2290
- if (ZeResult == ZE_RESULT_ERROR_UNINITIALIZED) {
2291
- PI_ASSERT (NumPlatforms != 0 , PI_ERROR_INVALID_VALUE);
2292
- *NumPlatforms = 0 ;
2293
- return PI_SUCCESS;
2294
- }
2295
-
2296
- if (ZeResult != ZE_RESULT_SUCCESS) {
2297
- zePrint (" zeInit: Level Zero initialization failure\n " );
2298
- return mapError (ZeResult);
2299
- }
2300
-
2301
- // Cache pi_platforms for reuse in the future
2302
- // It solves two problems;
2303
- // 1. sycl::platform equality issue; we always return the same pi_platform.
2304
- // 2. performance; we can save time by immediately return from cache.
2305
- //
2306
-
2307
- const std::lock_guard<sycl::detail::SpinLock> Lock{*PiPlatformsCacheMutex};
2308
- if (!PiPlatformCachePopulated) {
2309
- try {
2310
- // Level Zero does not have concept of Platforms, but Level Zero driver is
2311
- // the closest match.
2312
- uint32_t ZeDriverCount = 0 ;
2313
- ZE_CALL (zeDriverGet, (&ZeDriverCount, nullptr ));
2314
- if (ZeDriverCount == 0 ) {
2315
- PiPlatformCachePopulated = true ;
2316
- } else {
2317
- std::vector<ze_driver_handle_t > ZeDrivers;
2318
- ZeDrivers.resize (ZeDriverCount);
2319
-
2320
- ZE_CALL (zeDriverGet, (&ZeDriverCount, ZeDrivers.data ()));
2321
- for (uint32_t I = 0 ; I < ZeDriverCount; ++I) {
2322
- pi_platform Platform = new _pi_platform (ZeDrivers[I]);
2323
- // Save a copy in the cache for future uses.
2324
- PiPlatformsCache->push_back (Platform);
2325
-
2326
- pi_result Result = Platform->initialize ();
2327
- if (Result != PI_SUCCESS) {
2328
- return Result;
2329
- }
2330
- }
2331
- PiPlatformCachePopulated = true ;
2332
- }
2333
- } catch (const std::bad_alloc &) {
2334
- return PI_ERROR_OUT_OF_HOST_MEMORY;
2335
- } catch (...) {
2336
- return PI_ERROR_UNKNOWN;
2337
- }
2338
- }
2339
-
2340
- // Populate returned platforms from the cache.
2341
- if (Platforms) {
2342
- PI_ASSERT (NumEntries <= PiPlatformsCache->size (),
2343
- PI_ERROR_INVALID_PLATFORM);
2344
- std::copy_n (PiPlatformsCache->begin (), NumEntries, Platforms);
2345
- }
2346
-
2347
- if (NumPlatforms) {
2348
- *NumPlatforms = PiPlatformsCache->size ();
2349
- }
2350
-
2351
- return PI_SUCCESS;
2157
+ return pi2ur::piPlatformsGet (NumEntries, Platforms, NumPlatforms);
2352
2158
}
2353
2159
2354
2160
pi_result piPlatformGetInfo (pi_platform Platform, pi_platform_info ParamName,
@@ -3368,10 +3174,10 @@ pi_result piextDeviceCreateWithNativeHandle(pi_native_handle NativeHandle,
3368
3174
// TODO: maybe we should populate cache of platforms if it wasn't already.
3369
3175
// For now assert that is was populated.
3370
3176
PI_ASSERT (PiPlatformCachePopulated, PI_ERROR_INVALID_VALUE);
3371
- const std::lock_guard<sycl::detail:: SpinLock> Lock{*PiPlatformsCacheMutex};
3177
+ const std::lock_guard<SpinLock> Lock{*PiPlatformsCacheMutex};
3372
3178
3373
3179
pi_device Dev = nullptr ;
3374
- for (auto & ThePlatform : *PiPlatformsCache) {
3180
+ for (pi_platform ThePlatform : *PiPlatformsCache) {
3375
3181
Dev = ThePlatform->getDeviceFromNativeHandle (ZeDevice);
3376
3182
if (Dev) {
3377
3183
// Check that the input Platform, if was given, matches the found one.
@@ -8781,7 +8587,7 @@ pi_result piTearDown(void *PluginParameter) {
8781
8587
(void )PluginParameter;
8782
8588
bool LeakFound = false ;
8783
8589
// reclaim pi_platform objects here since we don't have piPlatformRelease.
8784
- for (pi_platform & Platform : *PiPlatformsCache) {
8590
+ for (pi_platform Platform : *PiPlatformsCache) {
8785
8591
delete Platform;
8786
8592
}
8787
8593
delete PiPlatformsCache;
0 commit comments