<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 21, 2015, at 10:06 PM, Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" class="">Yaxun.Liu@amd.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)" class="">
<style class=""><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->

<div lang="EN-US" link="blue" vlink="purple" class="">
<div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class="">The objective of SPIR-V is to provide a portable binary format for OpenCL kernels and GLSL shaders. For OpenCL 1.2 and 2.0 kernels, there is already spir-unknown-unknown
 and spir64-unknown-unknown target triple and corresponding data layout. Since many OpenCL vendors already support them, it is natural to extend them to support SPIR-V. Hopefully there will be a document about the restrictions, data types and metadata format
 of LLVM bitcode which can be translated to SPIR-V.<o:p class=""></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class=""> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class="">For optimizations, I think most of them should be allowed since they do not change the semantics. However, they should not change or delete the struct type
 names and metadata which carry information about OpenCL kernels.</span></p></div></div></div></blockquote><div><br class=""></div><div>I’m not sure what you mean exactly by “they do not change the semantics”. Optimizations are data layout dependent and operate with some assumptions related to it, and having the IR optimized with one data layout and processed by a target with a different data layout is not supported. The IR after optimization should only be reused for targets that have a compatible data layout AFAIK. </div><div><br class=""></div><div>I’m not sure how this fit in SPIR-V? It seems that SPIR-V serialized from LLVM after optimization won't be target independent, and I’m not sure how is it handled/expressed in SPIR-V?</div><div><br class=""></div><div>Thanks,</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class=""><o:p class=""></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class=""> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class="">Sam<o:p class=""></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D" class=""> </span></p><p class="MsoNormal"><b class=""><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class=""> <a href="mailto:llvmdev-bounces@cs.uiuc.edu" class="">llvmdev-bounces@cs.uiuc.edu</a> [<a href="mailto:llvmdev-bounces@cs.uiuc.edu" class="">mailto:llvmdev-bounces@cs.uiuc.edu</a>]
<b class="">On Behalf Of </b>David Majnemer<br class="">
<b class="">Sent:</b> Thursday, May 21, 2015 5:59 PM<br class="">
<b class="">To:</b> Sean Silva<br class="">
<b class="">Cc:</b> <a href="mailto:llvmdev@cs.uiuc.edu" class="">llvmdev@cs.uiuc.edu</a><br class="">
<b class="">Subject:</b> Re: [LLVMdev] [RFC] Upstreaming LLVM/SPIR-V converter<o:p class=""></o:p></span></p><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal">On Thu, May 21, 2015 at 1:50 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank" class="">chisophugis@gmail.com</a>> wrote:<o:p class=""></o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal">On Thu, May 21, 2015 at 8:03 AM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>> wrote:<o:p class=""></o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class="">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="">
<div class=""><p class="MsoNormal">On May 20, 2015, at 7:13 AM, Neil Henning <<a href="mailto:llvm@duskborn.com" target="_blank" class="">llvm@duskborn.com</a>> wrote:<o:p class=""></o:p></p>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class="">
<div class=""><p class="MsoNormal">On 20/05/15 08:37, Owen Anderson wrote:<br class="">
<br class="">
<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class="">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="">
<div class=""><p class="MsoNormal">On May 19, 2015, at 7:32 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank" class="">chisophugis@gmail.com</a>> wrote:<o:p class=""></o:p></p>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class="">
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal">On Tue, May 19, 2015 at 4:05 PM, Owen Anderson <<a href="mailto:resistor@mac.com" target="_blank" class="">resistor@mac.com</a>> wrote:<o:p class=""></o:p></p>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class="">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="">
<div class=""><p class="MsoNormal">On May 19, 2015, at 9:48 AM, Neil Henning <<a href="mailto:llvm@duskborn.com" target="_blank" class="">llvm@duskborn.com</a>> wrote:<o:p class=""></o:p></p>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"" class="">The 'backend' in this context is purely so that we can then enable Clang to target SPIR-V in the same consistent manner to all the other targets it supports.</span><o:p class=""></o:p></p>
</div>
</blockquote>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal">This seems like a terrible reason to choose the architecture of how it’s implemented in LLVM.  The clang driver is part of the LLVM project.  If we need to add support for some kind of special SPIR-V flag akin to -emit-llvm, we can do that. 
 If a particular frontend vendor wants to customize the flags, they can always do so themselves.<o:p class=""></o:p></p>
</div>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">What do you envision as the triple and datalayout when a frontend is compiling to SPIR-V?<o:p class=""></o:p></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">I’d recommend having its own Triple.  Not that triples are *not* linked to targets in LLVM.  My understanding of SPIR-V (and a look through the documentation seems to confirm) that it doesn’t specify anything about data layouts, presumably
 because it needs to accommodate both many GPUs with varying ideas of what sizes and alignments should be.  If anything this pushes me even more strongly that you do *not* want to run SPIR-V-destined IR through any more of LLVM (and particularly the CodeGen
 infrastructure) than you have to, since a lot of that will want to bake in DataLayout knowledge.<o:p class=""></o:p></p>
</div>
</div><p class="MsoNormal"><br class="">
At present in SPIR-V we have a decoration for alignment, so a user could decorate a type to specify a required alignment (which I would have thought in turn would become part of the data layout). Also if we are using a non-logical addressing mode the data layout
 would have a different pointer width specified (similar to the SPIR/SPIR64 targets in Clang at present). I'll bring it up with the SPIR group at Khronos what the expected behaviour of the alignment decoration is in this context, but at present I would say
 it would be legal for an LLVM module that is being turned into SPIR-V to have a user-defined data layout.<o:p class=""></o:p></p>
</div>
</div>
</blockquote>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">Are we supposed to be able to optimize this IR? I mean is a valid use-case: frontend->IR-(optimizer)->IR->SPIRV?<o:p class=""></o:p></p>
</div>
</div>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">I would hope that we would run at least mem2reg/sroa, do those need data layout?<o:p class=""></o:p></p>
</div>
</div>
</div>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">SROA assumes that it has DataLayout.<o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal"> <o:p class=""></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in" class="">
<div class="">
<div class="">
<div class="">
<div class=""><p class="MsoNormal"><span style="color:#888888" class=""> </span></p>
</div>
<div class=""><p class="MsoNormal"><span style="color:#888888" class="">-- Sean Silva<o:p class=""></o:p></span></p>
</div>
<div class=""><p class="MsoNormal"> <o:p class=""></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in" class="">
<div class="">
<div class="">
<div class=""><p class="MsoNormal">I think it has been acknowledged that the optimizer need to be aware of the data layout, and that optimizations/transformations that are performed on one data layout are not necessarily valid with another one.<o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">If there is not a single blessed data layout for SPIR-V in the spec, and the front-end can chose one, it seems to me that it has to be “serialized” in SPIR-V as well, isn’t it?<o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal">The round-trip SPIR-V -> IR -> SPIR-V does not sound as usuful as it could be if the data layout is not specified.<o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">— <o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal"><span style="color:#888888" class="">Mehdi<o:p class=""></o:p></span></p>
</div>
<div class=""><p class="MsoNormal"><span style="color:#888888" class=""> </span></p>
</div>
<div class=""><p class="MsoNormal"><span style="color:#888888" class=""> </span></p>
</div>
<div class=""><p class="MsoNormal"><span style="color:#888888" class=""> </span></p>
</div><p class="MsoNormal"><span style="color:#888888" class=""><br class="">
<br class="">
</span><o:p class=""></o:p></p>
<div class="">
<div class=""><p class="MsoNormal"><br class="">
<br class="">
<o:p class=""></o:p></p>
<div class="">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="">
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><p class="MsoNormal">I'm pretty sure that a wide class of frontends for SPIR-V will literally be interested in just generating SPIR-V, with no knowledge about what the ultimate GPU target is; it is in that sense that they are "targeting" SPIR-V. That is, their
 frontend isn't generating $SPECIFICGPU targeted IR, and then being merely asking to have it serialized in a specific way (a la -emit-llvm); they are generating IR that is meant to be turned into SPIR-V. That is fundamentally different from -emit-llvm (on the
 other hand, it may not be a target; but it sure smells like one).<o:p class=""></o:p></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div><p class="MsoNormal">I completely agree with you… except for the last sentence.<o:p class=""></o:p></p>
</div>
<div class=""><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
<div class=""><p class="MsoNormal">Honestly, the command line option aspect of this seems like a complete red herring to me.  We are talking about adding support to a data format which we will need to support both serializing IR to and deserializing IR from.  This is exactly
 the same as the bitcode use case, and not at all like the use case of a target.  We should structure the implementation according to the ways it will actually be used; rewiring a clang driver command line flag to “make it look pretty” is the most trivial part
 of the entire process.<o:p class=""></o:p></p>
</div><p class="MsoNormal"><br class="">
So it seems to me that we can at least agree on the location of the mainstay of the code - it should reside in lib/SPIRV and be both a reader and writer akin to the Bitcode reader/writer pair. Why don't we at Khronos work on a patch to tip LLVM that will do
 that, and then we can revisit how a user actually uses our code after that. We should be able to easily follow Owen's approach and see how that works out, worst case if it turns out to not work it would then be trivial to turn that into a thin backend. Seem
 reasonable?<br class="">
<br class="">
Cheers,<br class="">
-Neil.<o:p class=""></o:p></p>
</div><p class="MsoNormal">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p class=""></o:p></p>
</div>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
</blockquote>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
</div><p class="MsoNormal" style="margin-bottom:12.0pt"><br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p class=""></o:p></p>
</blockquote>
</div><p class="MsoNormal"><o:p class=""> </o:p></p>
</div>
</div>
</div>
</div>

_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class=""></div></blockquote></div><br class=""></body></html>