Skip to content

Commit a4064a0

Browse files
committed
[SYCL][UR] Replace leak checker with L0 validation layer functionality
This ensures that calls to L0 made through UMF and user code are also tracked.
1 parent 9f35584 commit a4064a0

File tree

3 files changed

+6
-110
lines changed

3 files changed

+6
-110
lines changed

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,6 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
310310
}
311311

312312
PlatformCache.Compute = [](Result<PlatformVec> &result) {
313-
static std::once_flag ZeCallCountInitialized;
314-
try {
315-
std::call_once(ZeCallCountInitialized, []() {
316-
if (UrL0LeaksDebug) {
317-
ZeCallCount = new std::map<std::string, int>;
318-
}
319-
});
320-
} catch (...) {
321-
result = exceptionToResult(std::current_exception());
322-
return;
323-
}
324-
325313
uint32_t UserForcedSysManInit = 0;
326314
// Check if the user has disabled the default L0 Env initialization.
327315
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
@@ -523,97 +511,6 @@ void globalAdapterOnDemandCleanup() {
523511
}
524512

525513
ur_result_t adapterStateTeardown() {
526-
// Print the balance of various create/destroy native calls.
527-
// The idea is to verify if the number of create(+) and destroy(-) calls are
528-
// matched.
529-
if (ZeCallCount && (UrL0LeaksDebug) != 0) {
530-
bool LeakFound = false;
531-
// clang-format off
532-
//
533-
// The format of this table is such that each row accounts for a
534-
// specific type of objects, and all elements in the raw except the last
535-
// one are allocating objects of that type, while the last element is known
536-
// to deallocate objects of that type.
537-
//
538-
std::vector<std::vector<std::string>> CreateDestroySet = {
539-
{"zeContextCreate", "zeContextDestroy"},
540-
{"zeCommandQueueCreate", "zeCommandQueueDestroy"},
541-
{"zeModuleCreate", "zeModuleDestroy"},
542-
{"zeKernelCreate", "zeKernelDestroy"},
543-
{"zeEventPoolCreate", "zeEventPoolDestroy"},
544-
{"zeCommandListCreateImmediate", "zeCommandListCreate", "zeCommandListDestroy"},
545-
{"zeEventCreate", "zeEventDestroy"},
546-
{"zeFenceCreate", "zeFenceDestroy"},
547-
{"zeImageCreate","zeImageViewCreateExt", "zeImageDestroy"},
548-
{"zeSamplerCreate", "zeSamplerDestroy"},
549-
{"zeMemAllocDevice", "zeMemAllocHost", "zeMemAllocShared", "zeMemFree"},
550-
};
551-
552-
// A sample output aimed below is this:
553-
// ------------------------------------------------------------------------
554-
// zeContextCreate = 1 \---> zeContextDestroy = 1
555-
// zeCommandQueueCreate = 1 \---> zeCommandQueueDestroy = 1
556-
// zeModuleCreate = 1 \---> zeModuleDestroy = 1
557-
// zeKernelCreate = 1 \---> zeKernelDestroy = 1
558-
// zeEventPoolCreate = 1 \---> zeEventPoolDestroy = 1
559-
// zeCommandListCreateImmediate = 1 |
560-
// zeCommandListCreate = 1 \---> zeCommandListDestroy = 1 ---> LEAK = 1
561-
// zeEventCreate = 2 \---> zeEventDestroy = 2
562-
// zeFenceCreate = 1 \---> zeFenceDestroy = 1
563-
// zeImageCreate = 0 \---> zeImageDestroy = 0
564-
// zeSamplerCreate = 0 \---> zeSamplerDestroy = 0
565-
// zeMemAllocDevice = 0 |
566-
// zeMemAllocHost = 1 |
567-
// zeMemAllocShared = 0 \---> zeMemFree = 1
568-
//
569-
// clang-format on
570-
// TODO: use logger to print this messages
571-
std::cerr << "Check balance of create/destroy calls\n";
572-
std::cerr << "----------------------------------------------------------\n";
573-
std::stringstream ss;
574-
for (const auto &Row : CreateDestroySet) {
575-
int diff = 0;
576-
for (auto I = Row.begin(); I != Row.end();) {
577-
const char *ZeName = (*I).c_str();
578-
const auto &ZeCount = (*ZeCallCount)[*I];
579-
580-
bool First = (I == Row.begin());
581-
bool Last = (++I == Row.end());
582-
583-
if (Last) {
584-
ss << " \\--->";
585-
diff -= ZeCount;
586-
} else {
587-
diff += ZeCount;
588-
if (!First) {
589-
ss << " | ";
590-
std::cerr << ss.str() << "\n";
591-
ss.str("");
592-
ss.clear();
593-
}
594-
}
595-
ss << std::setw(30) << std::right << ZeName;
596-
ss << " = ";
597-
ss << std::setw(5) << std::left << ZeCount;
598-
}
599-
600-
if (diff) {
601-
LeakFound = true;
602-
ss << " ---> LEAK = " << diff;
603-
}
604-
605-
std::cerr << ss.str() << '\n';
606-
ss.str("");
607-
ss.clear();
608-
}
609-
610-
ZeCallCount->clear();
611-
delete ZeCallCount;
612-
ZeCallCount = nullptr;
613-
if (LeakFound)
614-
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
615-
}
616-
617514
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
618515
// Global Adapter after refcnt is 0
619516
#if defined(_WIN32)

unified-runtime/source/adapters/level_zero/common.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
141141
const char *ZeArgs, bool TraceError) {
142142
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);
143143

144-
if (ZeResult == ZE_RESULT_SUCCESS) {
145-
if (UrL0LeaksDebug) {
146-
++(*ZeCallCount)[ZeName];
147-
}
148-
return ZE_RESULT_SUCCESS;
149-
}
150-
151144
if (TraceError) {
152145
const char *ErrorString = "Unknown";
153146
zeParseError(ZeResult, ErrorString);

unified-runtime/source/adapters/level_zero/common.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ const int UrL0LeaksDebug = [] {
218218
const char *UrRet = std::getenv("UR_L0_LEAKS_DEBUG");
219219
if (!UrRet)
220220
return 0;
221+
222+
if (std::atoi(UrRet)) {
223+
setenv("ZE_ENABLE_VALIDATION_LAYER", "1", 1);
224+
setenv("ZEL_ENABLE_BASIC_LEAK_CHECKER", "1", 1);
225+
}
226+
221227
return std::atoi(UrRet);
222228
}();
223229

0 commit comments

Comments
 (0)