OpenCL SPIR/NVPTX code generation

Hi Guy,

Thanks a lot for the clarification.

I tried using the triple for SPIR as

$ clang -x cl -fno-builtin -emit-llvm -c -Xclang -triple -Xclang spir-unknown-unknown Simple_Kernel.cl

However I get the following error.
error: unknown target triple ‘spir-unknown-unknown’, please use -triple or -arch

I also tried with triple nvptx-unknown-unknown
clang -x cl -fno-builtin -emit-llvm -S -Xclang -triple -Xclang nvptx-unknown-unknown Simple_Kernel.cl

Then I get following error.
error: unknown target CPU ‘pentium4’

If I dont specify the triple, it compiles fine. However in the llvm generated, it shows the target triple as
target triple = “i386-pc-linux-gnu”

So it crashes with the llc ( due to the address space errors).

I also tried building llvm with only nvptx target, still the target triple is the same.

Please help.

Thanks a ton,
Ankur

image001.png

Hi Ankur,

Since you use –Xclang, the clang executable passes multiple triples to “clang -cc1”. You can see that if you add the -v option. I’m sure there is someone here who can explain it better than I…

Anyhow, I think you better use clang -cc1. Make sure -cc1 is the first command line option you use.

$ clang -cc1 -fno-builtin -emit-llvm-bc -triple spir-unknown-unknown Simple_Kernel.cl -o Simple_Kernel.bc

should work for you.

Thanks

image001.png

Hi Guy,

Thanks a lot for the clarification.

I tried using the triple for SPIR as

$ clang -x cl -fno-builtin -emit-llvm -c -Xclang -triple -Xclang
spir-unknown-unknown Simple_Kernel.cl

However I get the following error.
error: unknown target triple 'spir-unknown-unknown', please use -triple or
-arch

I also tried with triple nvptx-unknown-unknown
clang -x cl -fno-builtin -emit-llvm -S -Xclang -triple -Xclang
nvptx-unknown-unknown Simple_Kernel.cl

Then I get following error.
error: unknown target CPU 'pentium4'

For some reason clang wants to use the default x86 CPU for the NVPTX
target; I need to look into that. To fix this, just set the CPU to sm_20:

clang -x cl -fno-builtin -emit-llvm -c -Xclang -triple -Xclang
nvptx-unknown-unknown Simple_Kernel.cl -Xclang -target-cpu -Xclang sm_20

If you want to generate code for NV GPUs, this is the route to go. Though
note that the IR you get will *not* be SPIR-conformant. Use the SPIR
triple if you want/need SPIR.

image001.png

clang -cc1 shouldn't ever be necessary for end users of clang, particularly because cc1 options are not guaranteed to be stable. You also lose all the default options that the driver normally passes down. It's possible this doesn't matter much for SPIR, at least not right now, but it's not something we should be recommending or supporting.

-target is the driver version of -triple. This "worked" for me, where by "worked" I mean "generated some output but I don't know enough about SPIR to validate it".

% clang -x cl -fno-builtin -target spir -c -emit-llvm

Jordan

Hi Jordan,

You’re right, and the driver -target option works perfectly with the SPIR triples.

Thanks

Guy Benyei

image001.png

Hello everyone,

Thanks a lot for the help.

-target nvptx worked great with llvm-3.2. However it gives error with -target spir.

LLVM/Clang trunk although works good for both options ( probably because spir is still work in progress ).

Thanks again.

  • Ankur

image001.png

Hi Ankur,

If you took the 3.2 release, that doesn’t contain SPIR target for Clang. The SPIR target was committed to Clang after the 3.2 branch was created, so 3.2 only has spir and spir64 triples defined in LLVM, but not in Clang.

Thanks

image001.png