Skip to content

Commit a818801

Browse files
[SYCL][PI][L0] ZeSerialize false race fix (intel#2672)
Intel Inspector race condition detector doesn't think there is a race that can occur when writing ZeSerialize on one thread while reading it on another. There was never really a race before because all threads would write the same value, and thus there was no issue. But this way of writing the code removes the false race, and makes it obvious this global variable can only be initialized once.
1 parent cf879f3 commit a818801

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

100755100644
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ enum {
3636
ZeSerializeBlock =
3737
2, // blocking ZE calls, where supported (usually in enqueue commands)
3838
};
39-
static pi_uint32 ZeSerialize = 0;
39+
static const pi_uint32 ZeSerialize = [] {
40+
const char *SerializeMode = std::getenv("ZE_SERIALIZE");
41+
const pi_uint32 SerializeModeValue =
42+
SerializeMode ? std::atoi(SerializeMode) : 0;
43+
return SerializeModeValue;
44+
}();
4045

4146
// This class encapsulates actions taken along with a call to Level Zero API.
4247
class ZeCall {
@@ -693,11 +698,6 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
693698
ZeValidationLayer = true;
694699
}
695700

696-
static const char *SerializeMode = std::getenv("ZE_SERIALIZE");
697-
static const pi_uint32 SerializeModeValue =
698-
SerializeMode ? std::atoi(SerializeMode) : 0;
699-
ZeSerialize = SerializeModeValue;
700-
701701
if (NumEntries == 0 && Platforms != nullptr) {
702702
return PI_INVALID_VALUE;
703703
}

0 commit comments

Comments
 (0)