<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 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.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@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]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It is my view that this is an implementation detail and not an issue with the SPIR spec.  As SPIR is just a representation of a program in a portable manner,
 it is up to the consumer of SPIR to correctly set up the kernels based on the devices calling convention/ABI when the SPIR binary is loaded for that specific device.<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"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<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""> mankeyrabbit@gmail.com [mailto:mankeyrabbit@gmail.com]
<b>On Behalf Of </b>James Molloy<br>
<b>Sent:</b> Wednesday, September 26, 2012 1:06 AM<br>
<b>To:</b> Pekka Jääskeläinen<br>
<b>Cc:</b> Villmow, Micah; Ouriel, Boaz; cfe-dev@cs.uiuc.edu; llvmdev@cs.uiuc.edu; pocl-devel@lists.sourceforge.net<br>
<b>Subject:</b> Re: [cfe-dev] [LLVMdev] SPIR provisional specification is now available in the Khronos website<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Micah, Boaz,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Do you guys have any ideas about how to fix this issue?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">James<o:p></o:p></p>
<div>
<p class="MsoNormal">On 24 September 2012 16:04, James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>> wrote:<o:p></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">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222">For the record, I just workarounded it in pocl by borrowing the<br>
BreakConstantGEPs code from SAFECode. But for SPIR specs, IMHO, this should<br>
be reconsidered.</span><o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#222222">Yes, I agree.</span><o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 24 September 2012 15:08, Pekka Jääskeläinen <<a href="mailto:pekka.jaaskelainen@tut.fi" target="_blank">pekka.jaaskelainen@tut.fi</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Well,<br>
<br>
To be honest I'm not very comfortable with the whole constant GEP<br>
idea. It's a new thing to me and I do not fully understand its<br>
point in LLVM IR, so I probably wasn't very clear ;)<br>
<br>
Anyways, me bringing it up was meant as an example of what can happen<br>
if one (mis)uses the C function static variable semantics for something that<br>
really is a thread local variable (in usual thread parallel implementations).<br>
<br>
For the record, I just workarounded it in pocl by borrowing the<br>
BreakConstantGEPs code from SAFECode. But for SPIR specs, IMHO, this should<br>
be reconsidered.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
On 09/24/2012 05:00 PM, James Molloy wrote:<o:p></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">
<div>
<p class="MsoNormal">Hi,<br>
<br>
Sorry, With a prod from Silviu (cc'd) I now understand - I was interpreting<br>
your use of "constant GEP" as "GEP with constant operand" as opposed to<br>
"ConstantGEP node" which of course can only take a Constant* operand, not a<br>
Value* operand.<br>
<br>
I now fully see the problem and realise that my solution is also prone to<br>
that problem :)<br>
<br>
Cheers,<br>
<br>
James<br>
<br>
On 24 September 2012 14:41, James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><mailto:<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>>> wrote:<br>
<br>
Hi,<br>
<br>
I don't fully understand your problem description.<br>
<br>
...is caused by LLVM/Clang thinking<br>
<br>
they are buffers with a constant base which they eventually won't be in a<br>
parallel WG implementation. This triggers an issue I'm currently working on<br>
pocl: <a href="https://bugs.launchpad.net/pocl/+bug/1032203" target="_blank">https://bugs.launchpad.net/pocl/+bug/1032203</a> because Clang generates<br>
constant GEPs for the local buffer accesses (even though in a parallel<br>
thread-safe implementation the local variables cannot be stored to constant<br>
locations).<br>
<br>
<br>
Surely if you're passing in pointers to the kernel function that differ<br>
depending on workgroup, then a GEP from those pointers of a constant amount<br>
is perfectly safe. Why would a constant GEP from a per-workgroup base be a<br>
problem?<br>
<br>
<br>
I'm sure there's something I've misunderstood about your solution...<br>
<br>
Cheers,<br>
<br>
James<br>
<br>
On 24 September 2012 12:41, Pekka Jääskeläinen <<a href="mailto:pekka.jaaskelainen@tut.fi" target="_blank">pekka.jaaskelainen@tut.fi</a><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><mailto:<a href="mailto:pekka.jaaskelainen@tut.fi" target="_blank">pekka.jaaskelainen@tut.fi</a>>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Hi all,<br>
<br>
Another OpenCL C implementation issue I'm currently fighting with<o:p></o:p></p>
<p class="MsoNormal">is how<o:p></o:p></p>
<p class="MsoNormal">to best implement the automatic __local variables. Seems SPIR<o:p></o:p></p>
<p class="MsoNormal">enforces<o:p></o:p></p>
<p class="MsoNormal">the current Clang implementation of them that converts the automatic<br>
locals to C function static variables (thus, in practice global<o:p></o:p></p>
<p class="MsoNormal">variables).<o:p></o:p></p>
<p class="MsoNormal"><br>
Clearly, this is not a thread safe "final implementation", thus<o:p></o:p></p>
<p class="MsoNormal">works as is<o:p></o:p></p>
<p class="MsoNormal">only when multiple work groups of the same kernel are not executed in<br>
parallel. Therefore, some other compiler pass is assumed to<o:p></o:p></p>
<p class="MsoNormal">convert those<o:p></o:p></p>
<p class="MsoNormal">function static (module global variables) to some other storage<o:p></o:p></p>
<p class="MsoNormal">where the<o:p></o:p></p>
<p class="MsoNormal">local buffers are allocated per work group thread.<br>
<br>
The pocl implementation is what was suggested some time ago in<o:p></o:p></p>
<p class="MsoNormal">this list:<o:p></o:p></p>
<p class="MsoNormal">the locals are converted to local arguments to the kernel<o:p></o:p></p>
<p class="MsoNormal">function which<o:p></o:p></p>
<p class="MsoNormal">are then passed per-thread buffers when the work group is<o:p></o:p></p>
<p class="MsoNormal">executed. Thus,<o:p></o:p></p>
<p class="MsoNormal">pocl needs to convert the references to these dummy globals to local<br>
buffer pointers at the end of the kernel function argument list.<br>
<br>
The problem from the use of the "semantically inadequate" 'function<br>
static' variables for the local buffers is caused by LLVM/Clang<o:p></o:p></p>
<p class="MsoNormal">thinking<o:p></o:p></p>
<p class="MsoNormal">they are buffers with a constant base which they eventually won't<o:p></o:p></p>
<p class="MsoNormal">be in<o:p></o:p></p>
<p class="MsoNormal">a parallel WG implementation. This triggers an issue I'm<o:p></o:p></p>
<p class="MsoNormal">currently working<o:p></o:p></p>
<p class="MsoNormal">on pocl: <a href="https://bugs.launchpad.net/pocl/+bug/1032203" target="_blank">
https://bugs.launchpad.net/pocl/+bug/1032203</a> because Clang<br>
generates constant GEPs for the local buffer accesses (even though in a<o:p></o:p></p>
<p class="MsoNormal">parallel<o:p></o:p></p>
<p class="MsoNormal">thread-safe implementation the local variables cannot be stored to<br>
constant locations).<br>
<br>
So, I wonder if this piece of SPIR specs might cause other similar<br>
problems (LLVM optimizing incorrectly due to the slightly wrong<o:p></o:p></p>
<p class="MsoNormal">semantics)<o:p></o:p></p>
<p class="MsoNormal">in the future and should be improved. The minimal fix would be to add<br>
some kind of attribute to the function static global that<o:p></o:p></p>
<p class="MsoNormal">prevents<o:p></o:p></p>
<p class="MsoNormal">Clang/LLVM thinking the address is constant and apply<o:p></o:p></p>
<p class="MsoNormal">optimizations that<o:p></o:p></p>
<p class="MsoNormal">rely on that. Semantically the local buffer is actually a thread-local<o:p></o:p></p>
<p class="MsoNormal">variable.<o:p></o:p></p>
<p class="MsoNormal">Are thread locals somehow supported in LLVM IR?<br>
<br>
<br>
On 09/13/2012 12:19 PM, Pekka Jääskeläinen wrote:<o:p></o:p></p>
<p class="MsoNormal"><br>
For what it's worth, this issue manifests itself in an unsolved pocl<br>
bug: <a href="https://bugs.launchpad.net/pocl/+bug/987905" target="_blank">https://bugs.launchpad.net/pocl/+bug/987905</a><br>
<br>
It would be simpler to implement a portable implementation for<o:p></o:p></p>
<p class="MsoNormal">calling the<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">kernel from the host if we could assume the kernel calling<o:p></o:p></p>
</blockquote>
<p class="MsoNormal">convention<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">mapped each OpenCL setArg arg to a single kernel function arg (and<o:p></o:p></p>
</blockquote>
<p class="MsoNormal">preferably all<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">arg data in memory). For the non-kernel functions it should not<o:p></o:p></p>
</blockquote>
<p class="MsoNormal">matter and<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-bottom:12.0pt">could be target-specific.<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
<br>
-- Pekka<o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
</div>
</div>
</blockquote>
<p class="MsoNormal"><span style="color:#888888"><br>
<br>
-- <br>
Pekka</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>