<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></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 Jun 17, 2015, at 5:44 AM, 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=us-ascii" class="">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)" class="">
<style class=""><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-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;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.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;}
/* List Definitions */
@list l0
{mso-list-id:492457304;
mso-list-type:hybrid;
mso-list-template-ids:-1565094398 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1
{mso-list-id:1214730668;
mso-list-type:hybrid;
mso-list-template-ids:-763203304 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
--></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">Here is the revised proposal for the LLVM/SPIR-V converter. Please comment. Thanks.<o:p class=""></o:p></p><p class="MsoNormal"><span style="color:#1F497D" class=""> </span></p><p class="MsoNormal" align="center" style="text-align:center">Proposal of Adding SPIRV Target<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Background<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">SPIR-V is a portable binary format for OpenCL kernels and GLSL shaders. A typical use case of SPIR-V is as follows:
<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">1.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->An application developer uses Clang to compile an OpenCL kernel source code to a SPIR-V binary which is common for all OpenCL platforms.<o:p class=""></o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">2.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->The application developer ships the application containing the SPIR-V binary to customers.<o:p class=""></o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">3.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->A customer runs the application on an OpenCL platform, which loads the SPIR-V binary through an OpenCL API function.<o:p class=""></o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">4.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->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.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">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.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Location<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">From feedback of the previous version of the proposal, there are several suggestions about the location for the LLVM/SPIR-V converter:<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">1.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->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.<o:p class=""></o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">2.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->llvm/lib/SPIRV containing the main functionality of bi-way translation between LLVM IR and SPIR-V, llvm/lib/Target/SPIRV containing a thin wrapper as a target machine to allow Clang targeting SPIR-V. The advantage compared with 1 is
that it allows a more conventional way of using Clang to produce SPIR-V. However it is subject to the same issue as 1 about not reflecting the requirement on the LLVM IR which can be translated to SPIR-V.<o:p class=""></o:p></p><p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><!--[if !supportLists]--><span style="mso-list:Ignore" class="">3.<span style="font:7.0pt "Times New Roman"" class="">
</span></span><!--[endif]-->llvm/lib/Target/SPIRV only. The advantage is that it reflects the requirement on the target triple and data layout for LLVM IR which can be translated to SPIR-V. However putting the SPIR-V to LLVM converter in the same directory is unconventional.
Leaving the SPIR-V to LLVM converter out of LLVM source tree is also not desirable since OpenCL vendors need this functionality.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">Our proposal is to take approach 3 and keep the bi-way converter in llvm/lib/Target/SPIRV. The functionality of the bi-way converter is exposed through llvm/include/Support/SPIRV.h. </p></div></div></div></blockquote><div><br class=""></div><div>If the bi-way converter logic is in llvm/lib/Target/SPIRV (libLLVMSPIRV) and there are APIs for it in llvm/include/Support/SPIRV.h (libLLVMSupport), you make Support depend on a target which is a layering violation.</div><div><br class=""></div><div>Can you please explain how you see this working?</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><p class="MsoNormal">A thin wrapper as a target machine is also provided to
allow Clang targeting SPIR-V. The rationale is that this directory structure better reflects the nature of SPIR-V. SPIR-V is not an alternative representation for arbitrary LLVM IR. Instead, it is an alternative representation for LLVM IR targeting generic
OpenCL or Vulkan platforms. It has its own specific target triple and data layout. Therefore it makes sense for the functionality to be put under llvm/lib/Target. Also, as an alternative representation of LLVM IR, it makes sense to have a bi-way convertor.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Implementation<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">About the implementation of the converter, although there are suggestions to take the SelectionDAG/MC approach, it seems not a major concern in general. The current implementation uses a shared in-memory representation of SPIR-V, which
facilitates supporting bi-way translation. The round-trip translated LLVM IR by the current implementation has passed OpenCL SPIR 1.2 conformance test, which proves the current implementation works. On the other hand, the SelectionDAG/MC approach would require
significant tweaking compared to a conventional backend, since SPIR-V is not a low level machine ISA but a high level generic IR. Also, the SelectionDAG/MC approach only supports one-way translation from LLVM to SPIR-V. Therefore unless major concern arises,
we will keep the current implementation approach.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Maintenance<o:p class=""></o:p></p><p class="MsoNormal" align="center" style="text-align:center"><o:p class=""> </o:p></p><p class="MsoNormal">The current implementation works by breaking down LLVM IR to instructions and re-constructing them in SPIR-V, and vice versa. Therefore the dependence of the current implementation on LLVM is mainly the C++ API in llvm/include/IR. As such,
its dependence on LLVM is similar to typical module passes. Our experience with porting it among LLVM 3.2/3.4/3.6 is that the porting effort is moderate.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Milestones<o:p class=""></o:p></p><p class="MsoNormal" align="center" style="text-align:center"><o:p class=""> </o:p></p><p class="MsoNormal">Currently Clang can compile OpenCL 1.2/2.0 C kernel source to LLVM IR with spir/spir64 target triple, which is compatible with SPIR-V for the supported instructions, data types and builtin functions. Therefore the first milestone of the
converter is to support compiling OpenCL 1.2/2.0 kernel to SPIR-V. This is also to lay the foundation for the upcoming OpenCL 2.1 C++ frontend development in Clang. The next milestone would be supporting OpenCL 2.1 C++, which hopefully would be in synch with
the frontend development work. In the meantime, as the SPIR-V target becomes stable and is able to support the instructions common to OpenCL and GLSL, hopefully the GLSL frontend work and support for GLSL specific instructions would pick up and finally we
would have a SPIR-V target supporting the complete SPIR-V spec.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Testing<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">We will add lit tests for SPIR-V. Also the converter would be tested by different OpenCL vendors for production quality through comprehensive conformance tests, since SPIR-V is required by OpenCL 2.1.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal" align="center" style="text-align:center">Logistics<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">AMD, Intel and some other SPIR WG members would join force for the development of the bi-way converter. Since supporting of SPIR-V is required by OpenCL 2.1, it is expected that OpenCL vendors would continue the maintenance efforts for
supporting SPIRV target in LLVM.<o:p class=""></o:p></p><p class="MsoNormal"><o:p class=""> </o:p></p><p class="MsoNormal">Yaxun Liu<o:p class=""></o:p></p><p class="MsoNormal">AMD<o:p class=""></o:p></p><p class="MsoNormal"><span style="color:#1F497D" class=""> </span></p>
</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>