@@ -308,26 +308,25 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
308
308
309
309
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
310
310
logger.setLegacySink (std::make_unique<ur_legacy_sink>());
311
+ #ifdef UR_ADAPTER_LEVEL_ZERO_V2
312
+ setEnvVar (" ZEL_ENABLE_LOADER_LOGGING" , " 1" );
313
+ setEnvVar (" ZEL_LOADER_LOGGING_LEVEL" , " trace" );
314
+ setEnvVar (" ZEL_LOADER_LOG_CONSOLE" , " 1" );
315
+ setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
316
+ #endif
311
317
};
312
318
313
319
if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
314
320
setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
315
321
setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
316
322
}
317
323
318
- PlatformCache.Compute = [](Result<PlatformVec> &result) {
319
- static std::once_flag ZeCallCountInitialized;
320
- try {
321
- std::call_once (ZeCallCountInitialized, []() {
322
- if (UrL0LeaksDebug) {
323
- ZeCallCount = new std::map<std::string, int >;
324
- }
325
- });
326
- } catch (...) {
327
- result = exceptionToResult (std::current_exception ());
328
- return ;
329
- }
324
+ if (UrL0LeaksDebug) {
325
+ setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
326
+ setEnvVar (" ZEL_ENABLE_BASIC_LEAK_CHECKER" , " 1" );
327
+ }
330
328
329
+ PlatformCache.Compute = [](Result<PlatformVec> &result) {
331
330
uint32_t UserForcedSysManInit = 0 ;
332
331
// Check if the user has disabled the default L0 Env initialization.
333
332
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
@@ -417,6 +416,16 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
417
416
loader_version.patch >= 2 )) {
418
417
useInitDrivers = true ;
419
418
}
419
+
420
+ #ifdef UR_ADAPTER_LEVEL_ZERO_V2
421
+ if ((loader_version.major == 1 && loader_version.minor < 21 ) ||
422
+ (loader_version.major == 1 && loader_version.minor == 21 &&
423
+ loader_version.patch < 2 )) {
424
+ logger::warning (
425
+ " WARNING: Level Zero Loader version is older than 1.21.2. "
426
+ " Please update to the latest version for API logging support.\n " );
427
+ }
428
+ #endif
420
429
}
421
430
422
431
if (useInitDrivers) {
@@ -533,97 +542,6 @@ void globalAdapterOnDemandCleanup() {
533
542
}
534
543
535
544
ur_result_t adapterStateTeardown () {
536
- // Print the balance of various create/destroy native calls.
537
- // The idea is to verify if the number of create(+) and destroy(-) calls are
538
- // matched.
539
- if (ZeCallCount && (UrL0LeaksDebug) != 0 ) {
540
- bool LeakFound = false ;
541
- // clang-format off
542
- //
543
- // The format of this table is such that each row accounts for a
544
- // specific type of objects, and all elements in the raw except the last
545
- // one are allocating objects of that type, while the last element is known
546
- // to deallocate objects of that type.
547
- //
548
- std::vector<std::vector<std::string>> CreateDestroySet = {
549
- {" zeContextCreate" , " zeContextDestroy" },
550
- {" zeCommandQueueCreate" , " zeCommandQueueDestroy" },
551
- {" zeModuleCreate" , " zeModuleDestroy" },
552
- {" zeKernelCreate" , " zeKernelDestroy" },
553
- {" zeEventPoolCreate" , " zeEventPoolDestroy" },
554
- {" zeCommandListCreateImmediate" , " zeCommandListCreate" , " zeCommandListDestroy" },
555
- {" zeEventCreate" , " zeEventDestroy" },
556
- {" zeFenceCreate" , " zeFenceDestroy" },
557
- {" zeImageCreate" ," zeImageViewCreateExt" , " zeImageDestroy" },
558
- {" zeSamplerCreate" , " zeSamplerDestroy" },
559
- {" zeMemAllocDevice" , " zeMemAllocHost" , " zeMemAllocShared" , " zeMemFree" },
560
- };
561
-
562
- // A sample output aimed below is this:
563
- // ------------------------------------------------------------------------
564
- // zeContextCreate = 1 \---> zeContextDestroy = 1
565
- // zeCommandQueueCreate = 1 \---> zeCommandQueueDestroy = 1
566
- // zeModuleCreate = 1 \---> zeModuleDestroy = 1
567
- // zeKernelCreate = 1 \---> zeKernelDestroy = 1
568
- // zeEventPoolCreate = 1 \---> zeEventPoolDestroy = 1
569
- // zeCommandListCreateImmediate = 1 |
570
- // zeCommandListCreate = 1 \---> zeCommandListDestroy = 1 ---> LEAK = 1
571
- // zeEventCreate = 2 \---> zeEventDestroy = 2
572
- // zeFenceCreate = 1 \---> zeFenceDestroy = 1
573
- // zeImageCreate = 0 \---> zeImageDestroy = 0
574
- // zeSamplerCreate = 0 \---> zeSamplerDestroy = 0
575
- // zeMemAllocDevice = 0 |
576
- // zeMemAllocHost = 1 |
577
- // zeMemAllocShared = 0 \---> zeMemFree = 1
578
- //
579
- // clang-format on
580
- // TODO: use logger to print this messages
581
- std::cerr << " Check balance of create/destroy calls\n " ;
582
- std::cerr << " ----------------------------------------------------------\n " ;
583
- std::stringstream ss;
584
- for (const auto &Row : CreateDestroySet) {
585
- int diff = 0 ;
586
- for (auto I = Row.begin (); I != Row.end ();) {
587
- const char *ZeName = (*I).c_str ();
588
- const auto &ZeCount = (*ZeCallCount)[*I];
589
-
590
- bool First = (I == Row.begin ());
591
- bool Last = (++I == Row.end ());
592
-
593
- if (Last) {
594
- ss << " \\ --->" ;
595
- diff -= ZeCount;
596
- } else {
597
- diff += ZeCount;
598
- if (!First) {
599
- ss << " | " ;
600
- std::cerr << ss.str () << " \n " ;
601
- ss.str (" " );
602
- ss.clear ();
603
- }
604
- }
605
- ss << std::setw (30 ) << std::right << ZeName;
606
- ss << " = " ;
607
- ss << std::setw (5 ) << std::left << ZeCount;
608
- }
609
-
610
- if (diff) {
611
- LeakFound = true ;
612
- ss << " ---> LEAK = " << diff;
613
- }
614
-
615
- std::cerr << ss.str () << ' \n ' ;
616
- ss.str (" " );
617
- ss.clear ();
618
- }
619
-
620
- ZeCallCount->clear ();
621
- delete ZeCallCount;
622
- ZeCallCount = nullptr ;
623
- if (LeakFound)
624
- return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
625
- }
626
-
627
545
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
628
546
// Global Adapter after refcnt is 0
629
547
#if defined(_WIN32)
0 commit comments