Skip to content

Commit 371048e

Browse files
authored
[mlir][spirv][nfc] Update documentation to describe the testing strategy (#158962)
1 parent ba5ca37 commit 371048e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

mlir/docs/Dialects/SPIR-V.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ the proper file in test/Dialect/SPIRV/.
13751375

13761376
The generated op will automatically gain the logic for (de)serialization.
13771377
However, tests still need to be coupled with the change to make sure no
1378-
surprises. Serialization tests live in test/Dialect/SPIRV/Serialization.
1378+
surprises (see [Add a new test](#add-a-new-test) below).
13791379

13801380
### Add a new enum
13811381

@@ -1416,6 +1416,40 @@ conversion][MlirDialectConversionSignatureConversion] might be needed as well.
14161416
operations contained within its region are valid operations in the SPIR-V
14171417
dialect.
14181418

1419+
### Add a new test
1420+
1421+
Currently the SPIR-V dialect has three types of tests that should be added or
1422+
updated accordingly:
1423+
1424+
1. **Dialect tests** - Those tests check different aspects of the op in isolation.
1425+
They should include both positive and negative case, and exercise the verifier,
1426+
parser and printer. Dialect tests do not have to form a valid SPIR-V code and
1427+
should be kept as simple as possible. They are run with `mlir-opt`; and are
1428+
also used to test transformations.
1429+
1430+
2. **Target tests** - Those tests are designed to exercise serialization and
1431+
deserialization, so each module should be a valid SPIR-V module. (De)serialization
1432+
is tested using the `mlir-translate --test-spirv-roundtrip` option.
1433+
1434+
To ensure that the SPIR-V MLIR forms and serializes into a valid SPIR-V, the
1435+
`spriv-val` tool should be run on a serialized binary (`--serialize-spirv`).
1436+
This can be automated by adding a conditional validation section to the test:
1437+
1438+
```
1439+
// RUN: %if spirv-tools %{ rm -rf %t %}
1440+
// RUN: %if spirv-tools %{ mkdir %t %}
1441+
// RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
1442+
// RUN: %if spirv-tools %{ spirv-val %t %}
1443+
```
1444+
1445+
This sequence serializes and dumps each MLIR SPIR-V module into a separate
1446+
SPIR-V binary (MLIR allows multiple modules per files, however the SPIR-V
1447+
spec restricts each binary to a single module), and then runs `spirv-val`
1448+
on each of the file.
1449+
1450+
3. **Integration tests** - Those tests execute the MLIR code using the `mlir-runner`
1451+
to verify its functional correctness.
1452+
14191453
## Operation definitions
14201454
14211455
[include "Dialects/SPIRVOps.md"]

0 commit comments

Comments
 (0)