Commit d82720f
committed
[mlir][spirv] Enable serializer to write SPIR-V modules into separate files
By default, `mlir-translate` writes all output into a single file even
when `--split-input-file` is used. This is not an issue for text files
as they can be easily split with an output separator. However, this
causes issues with binary SPIR-V modules.
Firstly, a binary file with multiple modules is not a valid SPIR-V,
but will be created if multiple modules are specified in the same
file and separated by "// -----". This does not cause issues with
MLIR internal tools but does not work with SPIRV-Tools.
Secondly, splitting binary files after serialization is non-trivial,
when compared to text files, so using an external tool is not
desirable.
This patch adds a SPIR-V serialization option that write SPIR-V modules
to separate files in addition to writing them to the `mlir-translate`
output file. This is not the ideal solution and ideally `mlir-translate`
would allow generating multiple output files when `--split-input-file`
is used, however adding such functionality is again non-trival due to
how processing and splitting is done: function handles writing to
a single `os` that are passed around, and number of split buffers is not
known ahead of time. As such a I propose to have a SPIR-V internal option
that will dump modules to files in the form they can be processed by
`spirv-val`. The behaviour of the new added argument may be confusing,
but benefits from being internal to SPIR-V target.
Alternatively, we could expose the spirv option in `mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp`,
and slice the output file on the SPIR-V magic number, and not keep
the file generated by default by `mlir-translate`. This would be a bit
cleaner in API sense, as it would not generate the additional file
containing all modules together. However, it pushes SPIR-V specific
code into the generic part of the `mlir-translate` and slicing is
potentially more error prone that just writing a single module
after it was serialized.1 parent e80e7e7 commit d82720f
File tree
2 files changed
+47
-5
lines changed- mlir
- include/mlir/Target/SPIRV
- lib/Target/SPIRV
2 files changed
+47
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | | - | |
86 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
87 | 109 | | |
88 | 110 | | |
89 | 111 | | |
90 | 112 | | |
91 | 113 | | |
92 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
93 | 125 | | |
94 | 126 | | |
95 | 127 | | |
96 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
97 | 131 | | |
98 | 132 | | |
99 | 133 | | |
| |||
0 commit comments