-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement compatibility for external LLVM-IL #1325
Comments
This is a related PR from which it all began, just for the record. |
I think this would have to be done before linking with the builtins library as we link in lazy mode to be efficient (both time-wise and size-wise). We would need to parse each instruction of the module in Then |
Can you provide an example of a translation from the spirv-llvm-translator you wish to replace? Would the replacement be directly using a SPIR-V instruction (or extended instruction) or an emulation? If it is an emulation, would it be different than libclc? |
All files in frem.zip There 2 compilations:
FYI. fmod function is equal to OpFRem instuction in spirv and the OpFMod instruction is similar but not equal. In this case, I want to replace the OpFMod instruction with the fmod function and take the body of this instruction from libclc. |
If I understand correctly if you compile directly from the spirv-llvm-translator you end up If that's correct then it sounds like almost like a reverse of the native math pass. Specify a list of functions you wish to emulate using the libclc implementation. That seems reasonable if the source is a single instruction. It's probably a little more complicated if you need to replace a sequence of instructions, but maybe the pattern matcher LLVM uses in InstCombine could be used for such cases. I could image an early pass in the flow where that does this before we discard the unused libclc functions. Is it the case that the libclc functions are all you need? That you don't require a different emulation than what clspv normally uses? |
Native math pass do not discard that much the unused libclc functios anymore. |
That's unfortunate and not ideal as we don't currently run any passes prior to linking. |
The OpFMod instruction is only an example. Maybe it is a bad example. I have deal with a fork of the clspv witch is somewhat outdated. |
The test list you can find here: |
Maybe it would make sense to implement the translation directly in the LLVM-SPIRV-TRANSLATOR? |
I would suggest documenting what the various translations need to be then. You can also compare Vulkan's accuracy to OpenCL's accuracy. I wouldn't expect + or - to need special translations. In any event, before finalizing any design it would be good to know the full extent of changes that are necessary. |
The same instructions have different precision requirements based on different memory models (Vulka/OpenCL). Take a look: Vulkan SPIRV Precision & OpenCL SPIRVPrecision. Even if it does. Where is the guaranty what they would use a solution identical to the solution in clspv? The problem is that results are not identical. CTS tests don't check that one of the results is not good enough. Both versions can produce results with valid precision, but if the are not identical, then the test will fails. |
The idea is to support only builtin functions from libclc. I think this library with math functions is there to solve the same problem. I don't want to do more delta between spirv and Opencl-C sources. I want only reduce it. In this case, I only need to use what exists for the Opencl-C sources. |
My thought here is that when the LLVM-SPIRV-TRANSLATOR maps But this is just an idea. It might be easier architecture-wise to do that in the LLVM-SPIRV-TRANSLATOR, but this is just a guess, an idea to consider. Maybe it's much harder to do it in LLVM-SPIRV-TRANSLATOR and we should focus on clspv. |
What I found about the LLVM IR fmod/frem instruction. My opinion is this: I will do an issue for LLVM-SPIRV-TRANSLATOR in parallels. |
The compiler has an API to compile LLVM-IL code directly.
The idea of clspv is to use the semi-compiled sources (from cl to IL) for future compilation with other parameters or to compile with a different combination of the semi-compiled sources. In this case all IL-sources are generated by the internal (LLVM) clspv FrontEnd.
The clvk has mode CLVK_ENABLE_SPIRV_IL.
In this case the driver prepares the IL using SPIRV-LLVM-Translator.
The problem with "use-native-builtins". The SPIRV-LLVM-Translator doesn't use this option and generate LLVM-IL using it native instructions instead of to using the built-ins from clspv--.bc.
The proposal is to implement a new Pass that should intercept instructions that not in the list of "use-native-builtins" and replace them with the one of built-ins from clspv--.bc.
This pass could implemented for all external IL or directly to support the SPIRV-LLVM-Translator only.
The text was updated successfully, but these errors were encountered: