-
Notifications
You must be signed in to change notification settings - Fork 822
Expand file tree
/
Copy pathE2EExpr.py
More file actions
194 lines (179 loc) · 7.01 KB
/
E2EExpr.py
File metadata and controls
194 lines (179 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from lit.BooleanExpression import BooleanExpression
class E2EExpr(BooleanExpression):
build_specific_features = {
"run-mode",
"build-mode",
"preview-mode",
"target-spir",
"target-nvidia",
"target-amd",
"target-native_cpu",
"any-target-is-spir",
"any-target-is-nvidia",
"any-target-is-amd",
"any-target-is-native_cpu",
"opencl-cpu-rt",
"spirv-backend",
"linux",
"system-linux",
"windows",
"system-windows",
"cl_options",
"enable-perf-tests",
"preview-breaking-changes-supported",
"has_ndebug",
"ocloc",
"opencl-aot",
"opencl_icd",
"cm-compiler",
"xptifw",
"level_zero_dev_kit",
"cuda_dev_kit",
"hip_dev_kit",
"zstd",
"vulkan",
"hip_options",
"cuda_options",
"host=None",
"target=None",
"shell",
"symlinks",
"non-root-user",
"llvm-spirv",
"llvm-link",
"true",
"false",
"pdtracker",
"ze_debug",
"device-config-file",
}
def __init__(self, string, variables, build_only_mode, final_unknown_value):
BooleanExpression.__init__(self, string, variables)
self.build_only_mode = build_only_mode
self.unknown = False
self.final_unknown_value = final_unknown_value
@staticmethod
def evaluate(string, variables, build_only_mode, final_unknown_value=True):
"""
string: Expression to evaluate
variables: variables that evaluate to true
build_only_mode: if true enables unknown values
final_unknown_value: final boolean result if evaluation results in `unknown`
"""
try:
parser = E2EExpr(
string, set(variables), build_only_mode, final_unknown_value
)
return parser.parseAll()
except ValueError as e:
raise ValueError(str(e) + ("\nin expression: %r" % string))
def parseMATCH(self):
token = self.token
BooleanExpression.parseMATCH(self)
if token not in E2EExpr.build_specific_features and self.build_only_mode:
self.unknown = True
else:
self.unknown = False
def parseAND(self):
self.parseNOT()
while self.accept("&&"):
left = self.value
left_unknown = self.unknown
self.parseNOT()
right = self.value
right_unknown = self.unknown
self.value = left and right
# Unknown if both are unknown or if one is true and the other is unknown
self.unknown = (
(left_unknown and right_unknown)
or (left_unknown and right)
or (left and right_unknown)
)
def parseOR(self):
self.parseAND()
while self.accept("||"):
left = self.value
left_unknown = self.unknown
self.parseAND()
right = self.value
right_unknown = self.unknown
self.value = left or right
# Unknown if both are unknown or if one is false and the other is unknown
self.unknown = (
(left_unknown and right_unknown)
or (left_unknown and not right)
or (not left and right_unknown)
)
def parseAll(self):
self.token = next(self.tokens)
self.parseOR()
self.expect(BooleanExpression.END)
return self.final_unknown_value if self.unknown else self.value
@staticmethod
def check_build_features(variables):
rt_features = [x for x in variables if x not in E2EExpr.build_specific_features]
if rt_features:
raise ValueError(
"Runtime features: "
+ str(rt_features)
+ " evaluated to True in build-only\n"
+ "If this is a new build specific feature append it to:"
+ "`build_specific_features` in `sycl/test-e2e/E2EExpr.py`"
)
import unittest
class TestE2EExpr(unittest.TestCase):
def test_basic(self):
BuildOnly = True
BuildAndRun = False
RequiresDirective = True
UnsupportedDirective = False
RegularEval = lambda expr, features: E2EExpr.evaluate(
expr, features, BuildAndRun
)
RequiresBuildEval = lambda expr, features: E2EExpr.evaluate(
expr, features, BuildOnly, RequiresDirective
)
UnsupportedBuildEval = lambda expr, features: E2EExpr.evaluate(
expr, features, BuildOnly, UnsupportedDirective
)
# Non build-only expressions should work the same
self.assertTrue(RegularEval("linux", {"linux", "rt_feature"}))
self.assertTrue(RegularEval("rt_feature", {"linux", "rt_feature"}))
self.assertFalse(
RegularEval("rt_feature1 && rt_feature2", {"linux", "rt_feature1"})
)
# build-only expressions with no unknowns should work the same
self.assertTrue(UnsupportedBuildEval("linux", {"linux"}))
self.assertFalse(RequiresBuildEval("linux && windows", {"linux"}))
self.assertTrue(UnsupportedBuildEval("!(windows || zstd)", {"linux"}))
# build-only expressions where unknown affects the resulting value
self.assertTrue(RequiresBuildEval("rt_feature", {}))
self.assertFalse(UnsupportedBuildEval("rt_feature", {}))
self.assertFalse(UnsupportedBuildEval("!rt_feature", {}))
self.assertTrue(RequiresBuildEval("windows || rt_feature", {"linux"}))
self.assertFalse(UnsupportedBuildEval("windows || rt_feature", {"linux"}))
self.assertTrue(RequiresBuildEval("linux && rt_feature", {"linux"}))
self.assertFalse(UnsupportedBuildEval("linux && rt_feature", {"linux"}))
self.assertTrue(RequiresBuildEval("linux && !(zstd || rt_feature)", {"linux"}))
self.assertFalse(
UnsupportedBuildEval("linux && !(zstd || rt_feature)", {"linux"})
)
# build-only expressions where unknown does not affect the resulting value
self.assertTrue(RequiresBuildEval("linux || rt_feature", {"linux"}))
self.assertTrue(UnsupportedBuildEval("linux || rt_feature", {"linux"}))
self.assertFalse(RequiresBuildEval("windows && rt_feature", {"linux"}))
self.assertFalse(UnsupportedBuildEval("windows && rt_feature", {"linux"}))
self.assertFalse(
RequiresBuildEval("linux && (vulkan && rt_feature)", {"linux"})
)
self.assertFalse(
UnsupportedBuildEval("linux && (vulkan && rt_feature)", {"linux"})
)
# Check that no runtime features are present in build-only
with self.assertRaises(ValueError):
E2EExpr.check_build_features({"rt-feature"})
with self.assertRaises(ValueError):
E2EExpr.check_build_features({"build-only", "rt-feature"})
E2EExpr.check_build_features({"build-mode"})
if __name__ == "__main__":
unittest.main()