KhronosGroup / SPIRV-LLVM-Translator

A tool and a library for bi-directional translation between SPIR-V and LLVM IR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

translation from cuda file to spv file

zzj-github opened this issue · comments

commented

I realize the conversion from cuda file to spv file.
I first use LLVM to generate the .bc file corresponding to cuda file, and then use llvm-spirv to convert the .bc file into the .spv file.
get an error:

InvalidTargetTriple: Expects spir-unknown-unknown or spir64-unknown-unknown. Actual target triple is x86_64-pc-linux-gnu

how to solve it?

Per https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/main/docs/SPIRVRepresentationInLLVM.rst#target-triple-and-datalayout-string triple must be spir. I'm not sure if clang has support to compile cuda to spir target. I can only suggest a non-official workaround, which is definitely must not be used in a product code, but might help with the research: modify triple manually and try to translate. It's not guarantied it would work out of the box, as per triple rules clang would restrict supported types, vector sizes, add address space generation rules etc which are mandatory for SPIR environment and that the translator expects, but it still might work.
TBH I would try out SPIR-V Backend, which is a part of LLVM project, you can just feed .bc to llc targeting SPIR-V and see how it goes. While it's a work in progress project, it should be more promising for your flow.