KhronosGroup / SPIRV-LLVM-Translator

A tool and a library for bi-directional translation between SPIR-V and LLVM IR
Other
478 stars 213 forks source link

Add SPIR-V backend - SPIR-V Translator cross validation #2569

Open MrSidims opened 4 months ago

MrSidims commented 4 months ago

In this repository we have .cl tests which are being compiled for spir target emitting LLVM IR, that will be translated to SPIR-V and backwards. The suggestion is to compile them for spirv target as well using SPIR-V backend and then translate it back to LLVM IR by the translator. It might be not in the spirit of unit tests for a single project, but we already have an external dependency on clang here and rely on its output, modifying our expectations from time to time depending on the changes there. Meanwhile such cross validation would add sanity checks improving quality of the both projects. WDYT?

MrSidims commented 4 months ago

@VyacheslavLevytskyy @svenvh @asudarsa please express your opinion about that

VyacheslavLevytskyy commented 4 months ago

I like both this way of thinking in general, and this suggestion in particular. SPIR-V Backend is a client of SPIRV-LLVM-Translator in a sense of reverse translation from SPIR-V to LLVM IR, so such step would help to define some guarantees.

I'd expect a caveat at least in that SPIR-V Backend is an experimental backend at the moment, but this can be addressed with additional checks of the config in a style of ; RUN: %if spirv-backend %{ llc ... }, and anyway current plans is to make SPIR-V Backend non-experimental sooner than later.

asudarsa commented 4 months ago

Thanks @MrSidims. I am fully in support of this idea. There are two ways in which we can accomplish this. (1) Run llc/clang explicitly in the tests. or (2) Modify translator code to call llc (under an option) instead of spir-v writer logic. We are already looking at option 2, so we can complete that. I am ok with either approach though. Adding to caveats, one thing is we will need to start building LLVM with SPIR-V backend. This is not a big overhead though.

svenvh commented 4 months ago

I support the idea, great to see the SPIR-V backend progress!

Some thoughts on how we go about implementing it: