[cfe-dev] Question on Clang OpenCL to SPIR Compilation

Alastair Murray via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 8 09:51:34 PST 2017


Hi Andrew,


On 08/03/17 17:07, Andrew Gozillon via cfe-dev wrote:
>
> Hi guys,
>
>
> I've been trying to get Clang 5.0 to compile a very simple 
> OpenCL kernel example to SPIR (1.2) so that I can run it through 
> another program that basically loads the SPIR binary and executes it.
>
>
> However I've been having some issues in that the program loads up the 
> binary fine and executes it getting the wrong result. Now I don't 
> believe this is an issue with the program that loads the binary or the 
> OpenCL kernel itself for a couple of reasons 1) Is that I can compile 
> the OpenCL kernel to SPIR using the Intel Offline Compiler and the 
> Khronos SPIR compiler (based off of Clang/LLVM 3.3) and the returned 
> SPIR binary will run through the program and output as expected and 2) 
> I can just run the OpenCL code through it and output the compiled 
> binary and then run that binary back through and get the correct results.
>
> So at the moment I'm unsure if this is to do with the compile command 
> I'm giving to Clang is slightly off or if the output llvm from Clang 
> 5.0 no longer supports SPIR 1.0/1.2 (although the Clang 
> 5 documentation leads me to believe it does still support it)?
>
The bitcode emitted by a modern Clang is not strictly SPIR, even when 
setting the spir64-unknown-unknown triple.  It is not intended to be 
SPIR either, i.e. this is not a bug.  LLVM IR has changed since the SPIR 
specification was written.  If you want to produce valid SPIR that an 
OpenCL driver will consume you should use something like the Khronos 
SPIR generator that you already mentioned.

However, some drivers will actually consume bitcode like you are 
producing as if it were SPIR, but only up to the version of Clang/LLVM 
that there are built using (if they are built using Clang/LLVM).  So it 
is unlikely to work when producing bitcode from a tip Clang/LLVM, but 
may still work for something newer than 3.2.  This is because newer 
versions of LLVM can consume older bitcode files (SPIR), but cannot 
produce them.

Regards,
Alastair Murray.

>
> The compiler command I'm feeding to Clang at the moment is:
>
> clang -cc1 -isystem $LIBCLC/generic/include -include clc/clc.h 
> -Dcl_clang_storage_class_specifiers -triple spir64-unknown-unknown -x 
> cl -cl-std=CL1.2 -emit-llvm -o $NAME.ll $NAME.cl
>
> Although I've tried a number of variations from the documentation with 
> no luck.
>
>
> Thank you very much for your time, and help with this matter.
>
>
> Best Regards,
>
> Andrew Gozillon
>
>
>
> Please consider the environment and think before you print.
>
> The University of the West of Scotland is a registered Scottish 
> charity. Charity number SC002520.
>
> This e-mail and any attachment is for authorised use by the intended 
> recipient(s) only. It may contain proprietary material, confidential 
> information and/or be subject to legal privilege. It should not be 
> copied, disclosed to, retained or used by, any other party. If you are 
> not an intended recipient then please promptly delete this e-mail and 
> any attachment and all copies and inform the sender.
>
> Please note that any views or opinions presented in this email are 
> solely those of the author and do not necessarily represent those of 
> the University of the West of Scotland.
>
> As a public body, the University of the West of Scotland may be 
> required to make available emails as well as other written forms of 
> information as a result of a request made under the Freedom of 
> Information (Scotland) Act 2002.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-- 
Alastair Murray
Senior Software Engineer, Compilers
Codeplay Software Ltd
Level C, Argyle House, 3 Lady Lawson St., Edinburgh, EH3 9DR
Tel: 0131 466 0503
Fax: 0131 557 6600
Website: http://www.codeplay.com
Twitter: https://twitter.com/codeplaysoft

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170308/30168b73/attachment.html>


More information about the cfe-dev mailing list