-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][E2E] Add logic to react to
REQUIRED
/UNSUPPORTED
in `build-…
…only` (#16725) Adds logic for evaluating `REQUIRES`/`UNSUPPORTED` statements on `build-only` mode by "ignoring" features in these statements that do not affect the compilation (Everything other than OS, triple, and SDK/libraries). More precisely, the ability to ignore features is implemented by extending the boolean expressions to use a third boolean state - `ignore`. If a particular sub-expression includes an `ignore`, and if its result could be changed by setting that `ignore` to either `true` or `false`, then the result of that sub-expression is set to `ignore`. For example `ignore || true = true`, but `ignore || false = ignore`, this is because in the first example there would be no way to set the ignore such that the result is anything other than `true`, while in the second example the result is dependent on the "actual" value of the `ignore`. If the resulting value of a `REQUIRES` predicate is `ignore` we interpret that as `true` (The requirements were met), on the other hand for `UNSUPPORTED` predicates we would interpret `ignore` as `false` instead (The unsupported criteria was not met). The triples that can be used for a given test are then selected by evaluating the `REQUIRES`/`UNSUPPORTED` with the set of features + the target feature corresponding to each triple (mirroring the way we select devices), while ignoring all features that do not affect compilation. The target features available are the following: `target-spir`, `target-amd`, `target-nvidia`, and `target-native_cpu`. Each of these map to a triple. Similarly to how `XFAIL` is handled when using multiple devices if we are compiling for multiple triples, and a single triple is marked as `XFAIL`, then it is treated as unsupported instead. The available target triples in `build-only` mode is determined through the use of the `sycl_build_targets` lit param (i.e., `--param sycl_build_targets=spir;amd`). This is currently set to only `spir`, as the changes in test markup included in this pr do not take into account building for `nvptx` and `amdgcn` triples. In `run-only` and `full` mode the available triples are determined via the available devices.
- Loading branch information
Showing
28 changed files
with
311 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// using --offload-compress without zstd should throw an error. | ||
// REQUIRES: !zstd | ||
// REQUIRES: build-and-run-mode | ||
// RUN: not %{build} %O0 -g --offload-compress %S/Inputs/single_kernel.cpp -o %t_compress.out 2>&1 | FileCheck %s | ||
// CHECK: '--offload-compress' option is specified but zstd is not available. The device image will not be compressed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
from lit.BooleanExpression import BooleanExpression | ||
|
||
|
||
class E2EExpr(BooleanExpression): | ||
build_specific_features = { | ||
"build-and-run-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", | ||
"linux", | ||
"system-linux", | ||
"windows", | ||
"system-windows", | ||
"enable-perf-tests", | ||
"preview-breaking-changes-supported", | ||
"has_ndebug", | ||
"ocloc", | ||
"opencl-aot", | ||
"opencl_icd", | ||
"cm-compiler", | ||
"xptifw", | ||
"level_zero_dev_kit", | ||
"cuda_dev_kit", | ||
"zstd", | ||
"vulkan", | ||
"true", | ||
"false", | ||
} | ||
|
||
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 self.build_specific_features and self.build_only_mode: | ||
self.unknown = True | ||
else: | ||
self.unknown = False | ||
if self.value and self.unknown: | ||
raise ValueError( | ||
'Runtime feature "' + token + '" evaluated to True in build-only' | ||
) | ||
|
||
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 | ||
|
||
|
||
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"}) | ||
) | ||
# runtime feature is present in build-only | ||
with self.assertRaises(ValueError): | ||
RequiresBuildEval("rt_feature", {"rt_feature"}) | ||
with self.assertRaises(ValueError): | ||
UnsupportedBuildEval("rt_feature", {"rt_feature"}) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/EnqueueNativeCommand/custom-command-multiple-dev-cuda.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/HostInteropTask/interop-task-cuda-buffer-migrate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_amdgcn.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_nvptx64.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_several_targets.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// REQUIRES: ocloc, any-device-is-level_zero, any-device-is-gpu, any-device-is-cpu | ||
// REQUIRES: build-and-run-mode | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" %S/Inputs/is_compatible_with_env.cpp -o %t.out | ||
|
||
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu %{run-unfiltered-devices} not %t.out | ||
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %{run-unfiltered-devices} %t.out | ||
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %{run-unfiltered-devices} %t.out | ||
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %{run-unfiltered-devices} %t.out |
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_spir64.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_spir64_fpga.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_spir64_gen.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
sycl/test-e2e/OptionalKernelFeatures/is_compatible/is_compatible_spir64_x86_64.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.