Skip to content

Commit 72862fa

Browse files
[SYCL]Added support for L0 loader validation layer
Extended debugging capabilities by setting two new environment variables ( ZE_ENABLE_VALIDATION_LAYER and ZE_ENABLE_PARAMETER_VALIDATION) that will enable the Level Zero loader validation layer. Also, implemented ZE_DEBUG as a bit mask.
1 parent d76a6a0 commit 72862fa

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include "usm_allocator.hpp"
2727

28+
#ifdef _WIN32
29+
#define setenv(name, value, overwrite) _putenv_s(name, value)
30+
#endif
31+
2832
namespace {
2933

3034
// Controls Level Zero calls serialization to w/a Level Zero driver being not MT
@@ -65,6 +69,15 @@ std::mutex ZeCall::GlobalLock;
6569
// Controls Level Zero calls tracing in zePrint.
6670
static bool ZeDebug = false;
6771

72+
// Controls Level Zero validation layer and parameter validation.
73+
static bool ZeValidationLayer = false;
74+
75+
enum DebugLevel {
76+
ZE_DEBUG_BASIC = 0x1,
77+
ZE_DEBUG_VALIDATION = 0x2,
78+
ZE_DEBUG_ALL = -1
79+
};
80+
6881
static void zePrint(const char *Format, ...) {
6982
if (ZeDebug) {
7083
va_list Args;
@@ -567,8 +580,16 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
567580
pi_uint32 *NumPlatforms) {
568581

569582
static const char *DebugMode = std::getenv("ZE_DEBUG");
570-
if (DebugMode)
583+
static const int DebugModeValue = DebugMode ? std::stoi(DebugMode) : 0;
584+
if (DebugModeValue == ZE_DEBUG_ALL) {
571585
ZeDebug = true;
586+
ZeValidationLayer = true;
587+
} else {
588+
if (DebugModeValue & ZE_DEBUG_BASIC)
589+
ZeDebug = true;
590+
if (DebugModeValue & ZE_DEBUG_VALIDATION)
591+
ZeValidationLayer = true;
592+
}
572593

573594
static const char *SerializeMode = std::getenv("ZE_SERIALIZE");
574595
static const pi_uint32 SerializeModeValue =
@@ -589,6 +610,11 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
589610
static std::vector<pi_platform> PiPlatformsCache;
590611
static std::mutex PiPlatformsCacheMutex;
591612

613+
if (ZeValidationLayer) {
614+
setenv("ZE_ENABLE_VALIDATION_LAYER", "1", 1);
615+
setenv("ZE_ENABLE_PARAMETER_VALIDATION", "1", 1);
616+
}
617+
592618
// This is a good time to initialize Level Zero.
593619
static const char *CommandListCacheSize =
594620
std::getenv("SYCL_PI_LEVEL0_MAX_COMMAND_LIST_CACHE");

0 commit comments

Comments
 (0)