diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 054e7306aec9e..6f26e75ec60eb 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -1529,8 +1529,17 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms, PrintPiTrace = true; } - if (ZeDebug & ZE_DEBUG_CALL_COUNT) { - ZeCallCount = new std::map; + static std::once_flag ZeCallCountInitialized; + try { + std::call_once(ZeCallCountInitialized, []() { + if (ZeDebug & ZE_DEBUG_CALL_COUNT) { + ZeCallCount = new std::map; + } + }); + } catch (const std::bad_alloc &) { + return PI_OUT_OF_HOST_MEMORY; + } catch (...) { + return PI_ERROR_UNKNOWN; } if (NumEntries == 0 && Platforms != nullptr) {