25
25
26
26
#include " usm_allocator.hpp"
27
27
28
- #ifdef _WIN32
29
- #define setenv (name, value, overwrite ) _putenv_s(name, value)
30
- #endif
31
-
32
28
namespace {
33
29
34
30
// Controls Level Zero calls serialization to w/a Level Zero driver being not MT
@@ -561,6 +557,8 @@ static pi_result copyModule(ze_context_handle_t ZeContext,
561
557
ze_module_handle_t SrcMod,
562
558
ze_module_handle_t *DestMod);
563
559
560
+ static void setEnvVar (const char *var, const char *value);
561
+
564
562
// Forward declarations for mock implementations of Level Zero APIs that
565
563
// do not yet work in the driver.
566
564
// TODO: Remove these mock definitions when they work in the driver.
@@ -576,6 +574,16 @@ static bool isOnlineLinkEnabled();
576
574
// End forward declarations for mock Level Zero APIs
577
575
std::once_flag OnceFlag;
578
576
577
+ // This function will ensure compatibility with both Linux and Windowns for
578
+ // setting environment variables.
579
+ static void setEnvVar (const char *name, const char *value) {
580
+ #ifdef _WIN32
581
+ _putenv_s (name, value);
582
+ #else
583
+ setenv (name, value, 1 );
584
+ #endif
585
+ }
586
+
579
587
pi_result piPlatformsGet (pi_uint32 NumEntries, pi_platform *Platforms,
580
588
pi_uint32 *NumPlatforms) {
581
589
@@ -610,9 +618,11 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
610
618
static std::vector<pi_platform> PiPlatformsCache;
611
619
static std::mutex PiPlatformsCacheMutex;
612
620
621
+ // Setting these environment variables before running zeInit will enable the
622
+ // validation layer in the Level Zero loader.
613
623
if (ZeValidationLayer) {
614
- setenv (" ZE_ENABLE_VALIDATION_LAYER" , " 1" , 1 );
615
- setenv (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" , 1 );
624
+ setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
625
+ setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
616
626
}
617
627
618
628
// This is a good time to initialize Level Zero.
0 commit comments