<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
So we have been in discussions within the Khronos SPIR-V work group
on our push to get our SPIR-V code into tip LLVM and have drawn the
following conclusions;<br>
<ul>
<li>We absolutely must create a fully fledged backend that uses
all the machinery that target backends are expected to use.</li>
<li>We probably have to split out the SPIR-V -> LLVM IR into a
separate project from LLVM ala Clang et al.</li>
</ul>
<p>As we want to allow developers to use the SPIR-V
production/consumption code now, and the time sink doing the above
approach would incur, we are going to open source the current work
on the Khronos GitHub page as a first step.<br>
</p>
<p>We intend to revisit introducing a SPIR-V backend to LLVM in the
future.<br>
</p>
<p>Cheers,<br>
-Neil.<br>
</p>
<div class="moz-cite-prefix">On 18/06/15 20:25, Liu, Yaxun (Sam)
wrote:<br>
</div>
<blockquote
cite="mid:8CBAA9728E0B304BAD56DCC6F40C931B18AE9B91@storexdag03.amd.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* Font Definitions */
@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;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.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 class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
Eli Bendersky [<a class="moz-txt-link-freetext" href="mailto:eliben@google.com">mailto:eliben@google.com</a>]
<br>
<b>Sent:</b> Thursday, June 18, 2015 1:43 PM<br>
<b>To:</b> Mehdi Amini<br>
<b>Cc:</b> Liu, Yaxun (Sam); <a class="moz-txt-link-abbreviated" href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
<b>Subject:</b> Re: [LLVMdev] [RFC] Proposal for Adding
SPIRV Target<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Jun 18, 2015 at 10:26 AM,
Mehdi Amini <<a moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>>
wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<blockquote
style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Jun 18, 2015, at 9:31
AM, Liu, Yaxun (Sam) <<a
moz-do-not-send="true"
href="mailto:Yaxun.Liu@amd.com"
target="_blank">Yaxun.Liu@amd.com</a>>
wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<div style="border:none;border-top:solid
#B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<div>
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Mehdi
Amini [<a moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com"
target="_blank"><span
style="color:purple">mailto:mehdi.amini@apple.com</span></a>] <br>
<b>Sent:</b> Thursday, June 18,
2015 11:24 AM<br>
<b>To:</b> Liu, Yaxun (Sam)<br>
<b>Cc:</b> <a
moz-do-not-send="true"
href="mailto:llvmdev@cs.uiuc.edu"
target="_blank"><span
style="color:purple">llvmdev@cs.uiuc.edu</span></a><br>
<b>Subject:</b> Re: [LLVMdev]
[RFC] Proposal for Adding SPIRV
Target</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<blockquote
style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">On Jun 18,
2015, at 6:23 AM, Liu, Yaxun (Sam)
<<a moz-do-not-send="true"
href="mailto:Yaxun.Liu@amd.com"
target="_blank"><span
style="color:purple">Yaxun.Liu@amd.com</span></a>>
wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi
Mehdi,</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thank
you for your comments. My
comments are below.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sam</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div
style="border:none;border-top:solid
#B5C4DF 1.0pt;padding:3.0pt 0in
0in 0in">
<div>
<div>
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Mehdi
Amini [<a
moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com"
target="_blank"><span
style="color:purple">mailto:mehdi.amini@apple.com</span></a>] <br>
<b>Sent:</b> Wednesday,
June 17, 2015 12:43 PM<br>
<b>To:</b> Liu, Yaxun
(Sam)<br>
<b>Cc:</b> <a
moz-do-not-send="true"
href="mailto:llvmdev@cs.uiuc.edu"
target="_blank"><span
style="color:purple">llvmdev@cs.uiuc.edu</span></a><br>
<b>Subject:</b> Re:
[LLVMdev] [RFC] Proposal
for Adding SPIRV Target</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Hi Liu,<o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Thanks for
the detailed proposal.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote
style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal">On
Jun 17, 2015, at 5:44
AM, Liu, Yaxun (Sam)
<<a
moz-do-not-send="true"
href="mailto:Yaxun.Liu@amd.com" target="_blank"><span
style="color:purple">Yaxun.Liu@amd.com</span></a>>
wrote:<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Here
is the revised
proposal for the
LLVM/SPIR-V
converter. Please
comment. Thanks.</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"
style="text-align:center"
align="center"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Proposal
of Adding SPIRV Target</span><o:p></o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"
style="text-align:center"
align="center"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Background</span><o:p></o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div style="margin-left:.5in">
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">1.</span><span
style="font-size:7.0pt"> </span><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
<div style="margin-left:.5in">
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">2.</span><span
style="font-size:7.0pt"> </span><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">The
application
developer ships the
application
containing the
SPIR-V binary to
customers.</span><o:p></o:p></p>
</div>
</div>
</div>
<div style="margin-left:.5in">
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">3.</span><span
style="font-size:7.0pt"> </span><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
<div style="margin-left:.5in">
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">4.</span><span
style="font-size:7.0pt"> </span><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><span
style="color:#1F497D">+
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>
<o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"
style="text-align:center"
align="center"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Location</span><o:p></o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""> </span><o:p></o:p></p>
</div>
</div>
</div>
<div style="margin-left:.5in">
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">1.</span><span
style="font-size:7.0pt"> </span><span
style="font-size:11.0pt;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><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">How
important is it to
“reflect it”? <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">The
SPIR-V emitter could just
assert on the data layout
matching what is expected.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="color:#1F497D">+
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><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">I don’t know how
the discussion about SelectionDAG
impact your plan. <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">However it is not
clear to me why the SPIR-V -> IR
path would benefit in any way to be
there as well?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="color:#1F497D">+ 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><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal">It doesn’t not seem “natural”
to me that a “target” backend would operate as a
“source”. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">It is not clear also what piece
of the target infrastructure would be helpful to
convert from SPIR-V to IR.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">At some point there was a C
target backend, it still would seem silly to
implement clang as a target. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">+1 <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">It's highly unusual for lib/Target
to implement X-to-LLVM-IR conversions.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Eli<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">OK
how about let’s keep the original location. Keep the
converter in lib/SPIRV and add a thin wrapper in
lib/Target/SPIRV for now. As refactoring work goes
on and lib/Target/SPIRV becomes full-fledged, phase
out the SPIRV writer in lib/SPIRV. This also helps
keep the SelectionDAG/MC implementation cleaner.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sam
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
</body>
</html>