<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 18, 2015 at 10:26 AM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On Jun 18, 2015, at 9:31 AM, Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>> wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span></div><div><div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0in 0in"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"><span> </span>Mehdi Amini [<a href="mailto:mehdi.amini@apple.com" style="color:purple;text-decoration:underline" target="_blank">mailto:mehdi.amini@apple.com</a>]<span> </span><br><b>Sent:</b><span> </span>Thursday, June 18, 2015 11:24 AM<br><b>To:</b><span> </span>Liu, Yaxun (Sam)<br><b>Cc:</b><span> </span><a href="mailto:llvmdev@cs.uiuc.edu" style="color:purple;text-decoration:underline" target="_blank">llvmdev@cs.uiuc.edu</a><br><b>Subject:</b><span> </span>Re: [LLVMdev] [RFC] Proposal for Adding SPIRV Target<u></u><u></u></span></div></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div><blockquote style="margin-top:5pt;margin-bottom:5pt"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">On Jun 18, 2015, at 6:23 AM, Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" style="color:purple;text-decoration:underline" target="_blank">Yaxun.Liu@amd.com</a>> wrote:<u></u><u></u></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Mehdi,</span><u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Thank you for your comments. My comments are below.</span><u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Sam</span><u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></div></div><div><div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0in 0in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span><span style="font-size:10pt;font-family:Tahoma,sans-serif"> </span></span><span style="font-size:10pt;font-family:Tahoma,sans-serif">Mehdi Amini [<a href="mailto:mehdi.amini@apple.com" style="color:purple;text-decoration:underline" target="_blank"><span style="color:purple">mailto:mehdi.amini@apple.com</span></a>]<span> </span><br><b>Sent:</b><span> </span>Wednesday, June 17, 2015 12:43 PM<br><b>To:</b><span> </span>Liu, Yaxun (Sam)<br><b>Cc:</b><span> </span><a href="mailto:llvmdev@cs.uiuc.edu" style="color:purple;text-decoration:underline" target="_blank"><span style="color:purple">llvmdev@cs.uiuc.edu</span></a><br><b>Subject:</b><span> </span>Re: [LLVMdev] [RFC] Proposal for Adding SPIRV Target</span><u></u><u></u></div></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Hi Liu,<u></u><u></u></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Thanks for the detailed proposal.<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div><div><blockquote style="margin-top:5pt;margin-bottom:5pt"><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">On Jun 17, 2015, at 5:44 AM, Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" style="color:purple;text-decoration:underline" target="_blank"><span style="color:purple">Yaxun.Liu@amd.com</span></a>> wrote:<u></u><u></u></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div><div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">Here is the revised proposal for the LLVM/SPIR-V converter. Please comment. Thanks.</span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></div></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;text-align:center"><span style="font-size:11pt;font-family:Calibri,sans-serif">Proposal of Adding SPIRV Target</span><u></u><u></u></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;text-align:center"><span style="font-size:11pt;font-family:Calibri,sans-serif">Background</span><u></u><u></u></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">SPIR-V is a portable binary format for OpenCL kernels and GLSL shaders. A typical use case of SPIR-V is as follows:</span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div style="margin-left:0.5in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">1.</span><span style="font-size:7pt">     <span> </span></span><span style="font-size:11pt;font-family:Calibri,sans-serif">An application developer uses Clang to compile an OpenCL kernel source code to a SPIR-V binary which is common for all OpenCL platforms.</span><u></u><u></u></div></div></div><div style="margin-left:0.5in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">2.</span><span style="font-size:7pt">     <span> </span></span><span style="font-size:11pt;font-family:Calibri,sans-serif">The application developer ships the application containing the SPIR-V binary to customers.</span><u></u><u></u></div></div></div><div style="margin-left:0.5in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">3.</span><span style="font-size:7pt">     <span> </span></span><span style="font-size:11pt;font-family:Calibri,sans-serif">A customer runs the application on an OpenCL platform, which loads the SPIR-V binary through an OpenCL API function.</span><u></u><u></u></div></div></div><div style="margin-left:0.5in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">4.</span><span style="font-size:7pt">     <span> </span></span><span style="font-size:11pt;font-family:Calibri,sans-serif">The vendor-specific OpenCL runtime translates SPIR-V to LLVM IR, changes the target triple and data layout to suit the device which will execute the kernel, performs target specific optimizations, generates the ISA and executes the ISA on the device.</span><u></u><u></u></div></div></div></div></blockquote><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Step 4 of your “typical use case” includes "changes the target triple and data layout to suit the device which will execute the kernel”. It implies that SPIR-V is data layout agnostic since you can load it with any data layout, or there are (to be specified) constraint on what a “compatible” data layout is, or you considered that it is up to the OpenCL vendor to figure out what will work or not, with the drawback that any LLVM update can break its use case.<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="color:rgb(31,73,125)">+ For OpenCL, LLVM IR translated from SPIR-V has specific data layouts, which are the data layouts for target spir/spir64. OpenCL vendor’s target data layout are assumed to be consistent with them.</span><br><br><br><u></u><u></u></div></div><div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">For OpenCL kernels, there is implicit data layout dependence when compiling the source to LLVM. Since SPIR-V is for common OpenCL platforms, a common data layout accepted by different OpenCL vendors is required. We choose the data layout which has been adopted by SPIR 1.2/2.0 for SPIR-V, since it has been successfully used for supporting consumption of SPIR 1.2/2.0 on various OpenCL platforms. For GLSL shaders, it is still under discussion whether to choose the same data layout as OpenCL, or a different data layout, or no data layout at all.</span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;text-align:center"><span style="font-size:11pt;font-family:Calibri,sans-serif">Location</span><u></u><u></u></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">From feedback of the previous version of the proposal, there are several suggestions about the location for the LLVM/SPIR-V converter:</span><u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif"> </span><u></u><u></u></div></div></div><div style="margin-left:0.5in"><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif">1.</span><span style="font-size:7pt">     <span> </span></span><span style="font-size:11pt;font-family:Calibri,sans-serif">llvm/lib/SPIRV only, adding an option to Clang for outputting SPIR-V. The advantage is ease of use for bi-way translation. However it does not reflect the fact that only LLVM IR with specific target triple and data layout can be translated to SPIR-V.</span><u></u><u></u></div></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">How important is it to “reflect it”? <u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">The SPIR-V emitter could just assert on the data layout matching what is expected.<u></u><u></u></div></div></div><div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="color:rgb(31,73,125)">+ Putting the converter at llvm/lib/SPIRV may encourage misuse of the converter, i.e., using the converter to convert LLVM IR of arbitrary target, whereas the converter can only convert LLVM IR with spir/spir64 target.</span><u></u><u></u></div></div></div></div></div></div></blockquote><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">I don’t know how the discussion about SelectionDAG impact your plan. <u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">If the IR -> SPIR-V path is implemented as a “regular” target using the legalization framework and so on, almost all the code will be in lib/Target/SPIRV.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">However it is not clear to me why the SPIR-V -> IR path would benefit in any way to be there as well?<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Conceptually I should be able to compile LLVM and disable the SPIR-V backend but still be able to read-in SPIR-V and target my fancy OpenCL compliant device with my backend.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="color:rgb(31,73,125)">+ The rationale is that SPIR-V is an alternative representation of LLVM IR for spir/spir64 target. Therefore bi-way translation between LLVM and SPIR-V is possible. Such functionality naturally belongs to the target. The user who needs the translation functionality needs to link to the SPIRV target library.</span></div></div></div></div></div></blockquote><div><br></div><div><br></div></div></div><div>It doesn’t not seem “natural” to me that a “target” backend would operate as a “source”. </div><div>It is not clear also what piece of the target infrastructure would be helpful to convert from SPIR-V to IR.</div><div>At some point there was a C target backend, it still would seem silly to implement clang as a target. </div><div><br></div></div></div></blockquote><div><br></div><div>+1 </div><div><br></div><div>It's highly unusual for lib/Target to implement X-to-LLVM-IR conversions.</div><div><br></div><div>Eli</div><div><br></div><div> </div></div><br></div></div>