@@ -309,32 +309,23 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
309309
310310 if (UrL0Debug & UR_L0_DEBUG_BASIC) {
311311 logger.setLegacySink (std::make_unique<ur_legacy_sink>());
312- #ifdef UR_ADAPTER_LEVEL_ZERO_V2
313312 setEnvVar (" ZEL_ENABLE_LOADER_LOGGING" , " 1" );
314313 setEnvVar (" ZEL_LOADER_LOGGING_LEVEL" , " trace" );
315314 setEnvVar (" ZEL_LOADER_LOG_CONSOLE" , " 1" );
316315 setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
317- #endif
318316 };
319317
320318 if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
321319 setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
322320 setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
323321 }
324322
325- PlatformCache.Compute = [](Result<PlatformVec> &result) {
326- static std::once_flag ZeCallCountInitialized;
327- try {
328- std::call_once (ZeCallCountInitialized, []() {
329- if (UrL0LeaksDebug) {
330- ZeCallCount = new std::map<std::string, int >;
331- }
332- });
333- } catch (...) {
334- result = exceptionToResult (std::current_exception ());
335- return ;
336- }
323+ if (UrL0LeaksDebug) {
324+ setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
325+ setEnvVar (" ZEL_ENABLE_BASIC_LEAK_CHECKER" , " 1" );
326+ }
337327
328+ PlatformCache.Compute = [](Result<PlatformVec> &result) {
338329 uint32_t UserForcedSysManInit = 0 ;
339330 // Check if the user has disabled the default L0 Env initialization.
340331 const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
@@ -426,7 +417,6 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
426417 useInitDrivers = true ;
427418 }
428419
429- #ifdef UR_ADAPTER_LEVEL_ZERO_V2
430420 if ((loader_version.major == 1 && loader_version.minor < 21 ) ||
431421 (loader_version.major == 1 && loader_version.minor == 21 &&
432422 loader_version.patch < 2 )) {
@@ -435,7 +425,6 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
435425 " WARNING: Level Zero Loader version is older than 1.21.2. "
436426 " Please update to the latest version for API logging support.\n " );
437427 }
438- #endif
439428 }
440429
441430 if (useInitDrivers) {
@@ -552,97 +541,6 @@ void globalAdapterOnDemandCleanup() {
552541}
553542
554543ur_result_t adapterStateTeardown () {
555- // Print the balance of various create/destroy native calls.
556- // The idea is to verify if the number of create(+) and destroy(-) calls are
557- // matched.
558- if (ZeCallCount && (UrL0LeaksDebug) != 0 ) {
559- bool LeakFound = false ;
560- // clang-format off
561- //
562- // The format of this table is such that each row accounts for a
563- // specific type of objects, and all elements in the raw except the last
564- // one are allocating objects of that type, while the last element is known
565- // to deallocate objects of that type.
566- //
567- std::vector<std::vector<std::string>> CreateDestroySet = {
568- {" zeContextCreate" , " zeContextDestroy" },
569- {" zeCommandQueueCreate" , " zeCommandQueueDestroy" },
570- {" zeModuleCreate" , " zeModuleDestroy" },
571- {" zeKernelCreate" , " zeKernelDestroy" },
572- {" zeEventPoolCreate" , " zeEventPoolDestroy" },
573- {" zeCommandListCreateImmediate" , " zeCommandListCreate" , " zeCommandListDestroy" },
574- {" zeEventCreate" , " zeEventDestroy" },
575- {" zeFenceCreate" , " zeFenceDestroy" },
576- {" zeImageCreate" ," zeImageViewCreateExt" , " zeImageDestroy" },
577- {" zeSamplerCreate" , " zeSamplerDestroy" },
578- {" zeMemAllocDevice" , " zeMemAllocHost" , " zeMemAllocShared" , " zeMemFree" },
579- };
580-
581- // A sample output aimed below is this:
582- // ------------------------------------------------------------------------
583- // zeContextCreate = 1 \---> zeContextDestroy = 1
584- // zeCommandQueueCreate = 1 \---> zeCommandQueueDestroy = 1
585- // zeModuleCreate = 1 \---> zeModuleDestroy = 1
586- // zeKernelCreate = 1 \---> zeKernelDestroy = 1
587- // zeEventPoolCreate = 1 \---> zeEventPoolDestroy = 1
588- // zeCommandListCreateImmediate = 1 |
589- // zeCommandListCreate = 1 \---> zeCommandListDestroy = 1 ---> LEAK = 1
590- // zeEventCreate = 2 \---> zeEventDestroy = 2
591- // zeFenceCreate = 1 \---> zeFenceDestroy = 1
592- // zeImageCreate = 0 \---> zeImageDestroy = 0
593- // zeSamplerCreate = 0 \---> zeSamplerDestroy = 0
594- // zeMemAllocDevice = 0 |
595- // zeMemAllocHost = 1 |
596- // zeMemAllocShared = 0 \---> zeMemFree = 1
597- //
598- // clang-format on
599- // TODO: use logger to print this messages
600- std::cerr << " Check balance of create/destroy calls\n " ;
601- std::cerr << " ----------------------------------------------------------\n " ;
602- std::stringstream ss;
603- for (const auto &Row : CreateDestroySet) {
604- int diff = 0 ;
605- for (auto I = Row.begin (); I != Row.end ();) {
606- const char *ZeName = (*I).c_str ();
607- const auto &ZeCount = (*ZeCallCount)[*I];
608-
609- bool First = (I == Row.begin ());
610- bool Last = (++I == Row.end ());
611-
612- if (Last) {
613- ss << " \\ --->" ;
614- diff -= ZeCount;
615- } else {
616- diff += ZeCount;
617- if (!First) {
618- ss << " | " ;
619- std::cerr << ss.str () << " \n " ;
620- ss.str (" " );
621- ss.clear ();
622- }
623- }
624- ss << std::setw (30 ) << std::right << ZeName;
625- ss << " = " ;
626- ss << std::setw (5 ) << std::left << ZeCount;
627- }
628-
629- if (diff) {
630- LeakFound = true ;
631- ss << " ---> LEAK = " << diff;
632- }
633-
634- std::cerr << ss.str () << ' \n ' ;
635- ss.str (" " );
636- ss.clear ();
637- }
638-
639- ZeCallCount->clear ();
640- delete ZeCallCount;
641- ZeCallCount = nullptr ;
642- if (LeakFound)
643- return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
644- }
645-
646544 // Due to multiple DLLMain definitions with SYCL, register to cleanup the
647545 // Global Adapter after refcnt is 0
648546#if defined(_WIN32)
0 commit comments