SPIR-V to SPIR-V dialect translation


I’ve been thinking of converting a SPIR-V assembly into its corresponding MLIR dialect, but haven’t found anything in the documentation on this. Have such an option been not implemented yet then?

You mean converting from SPIR-V binary format to SPIR-V’s MLIR representation? It’s in the serialization library. We have a section covers it in the doc. Here is the entry point and here is the implementation. Its tests are bundled together with serialization as roundtrip tests.

1 Like

Thanks! That is what I was looking for!

My issue was that I want to try to test the semantic equivalence of SPIR-V to LLVM conversion in MLIR in the following way:
Proper SPIR-V translate to LLVM using the translator, and compare the result with the conversion in the form SPIR-V → SPIR-V dialect → LLVM IR dialect → LLVM. I also found Alive2 tool for LLVM comparison that will take a refinement into account.

I have more about that in my proposal’s draft and I should be done with it by tomorrow, so we can probably discuss this approach then?

Note that the SPIRV-LLVM-Translator you mentioned is focusing on OpenCL-flavored SPIR-V. SPIR-V is designed as an intermediate language to serve multiple Khronos Group APIs, including Vulkan and OpenCL. Vulkan-flavored SPIR-V (with the Shader capability) is different from OpenCL-flavored SPIR-V (with the Kernel capability). See this link for some points. SPIR-V spec calls this as different execution environment; “the client API will specify its SPIR-V execution environment as well as extra rules, limitations, capabilities, etc. required by the form of SPIR-V it can validly consume.” For example, Vulkan spec’s Appendix A details the requirements for the SPIR-V it can consume and additional validation rules. OpenCL has its requirements too. SPIR-V spec defines common instructions and their base semantics; the execution environment further controls the semantics. Given that we are focusing on Vulkan-flavored SPIR-V here, we cannot use the translator as a comparison.

I have more about that in my proposal’s draft and I should be done with it by tomorrow, so we can probably discuss this approach then?

Awesome! Feel free to share with me after the initial draft. No need to be super polished at the moment; we can iterate on it. :slight_smile:

Oh okay. I was thinking to try to compare the new conversion with some of the existing tools. You mention in one of the posts the IREE’s pipeline. Unfortunately, it has no full documentation yet and I am not fully aware of the status of the project. In one of the MLIR newsletters it was mentioned that there is some current work on LLVM JIT backend for HAL. Is it now possible to generate LLVM from HAL for Vulkan?