<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: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=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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: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.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.m4537029536541563720xmsonormal, li.m4537029536541563720xmsonormal, div.m4537029536541563720xmsonormal
        {mso-style-name:m_4537029536541563720x_msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.m4537029536541563720xxmsonormal, li.m4537029536541563720xxmsonormal, div.m4537029536541563720xxmsonormal
        {mso-style-name:m_4537029536541563720x_xmsonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.m4537029536541563720xxxmsonormal, li.m4537029536541563720xxxmsonormal, div.m4537029536541563720xxxmsonormal
        {mso-style-name:m_4537029536541563720x_xxmsonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.m4537029536541563720xxxcurrenthithighlight
        {mso-style-name:m_4537029536541563720x_xxcurrenthithighlight;}
p.m4537029536541563720xxxxmsonormal, li.m4537029536541563720xxxxmsonormal, div.m4537029536541563720xxxxmsonormal
        {mso-style-name:m_4537029536541563720x_xxxmsonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle24
        {mso-style-type:personal-reply;
        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;}
--></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">The workgroup size is usually 64 or 128. The number of workgroups can be quite large if the global size is large. If for each local array we waste 124 bytes, the total waste could be quite large, considering local memory is precious resource
 for GPU.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">On the other hand, passing the alignment info and using it is pretty straight forward.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sam<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> mats.o.petersson@googlemail.com [mailto:mats.o.petersson@googlemail.com]
<b>On Behalf Of </b>mats petersson<br>
<b>Sent:</b> Thursday, January 11, 2018 7:47 AM<br>
<b>To:</b> Anastasia Stulova <Anastasia.Stulova@arm.com><br>
<b>Cc:</b> Sumner, Brian <Brian.Sumner@amd.com>; Liu, Yaxun (Sam) <Yaxun.Liu@amd.com>; cfe-dev (cfe-dev@lists.llvm.org) <cfe-dev@lists.llvm.org>; Bader, Alexey (alexey.bader@intel.com) <alexey.bader@intel.com>; nd <nd@arm.com><br>
<b>Subject:</b> Re: [cfe-dev] [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">I'm still a little bit confused about the background of this. And I understand that the actual usecase here may not be something that can be shared, but perhaps at least some part of the underlying problem can
 be shared to help with the understanding of the issue is here... <o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">The approach I've taken is to allocate every local argument with the "largest alignment requirement" (in other words 128 bytes - this may of course vary depending on the HW available in the GPU).<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">As I see it, this wouldn't lead to THAT much overhead in the allocations, as local storage is per work-group, and the number of llocal arguments is, hopefully, not a very large number.<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Whilst I'm all for saving memory when possible, I'm not sure adding a set of alignment values to the argument list of enqueue_kernel, for calls that have local arguments, and the extra complexity, even if it's
 not large, is worth the saving of local memory allocations. I'd really like to understand why a single large alignment doesn't work in this case.<o:p></o:p></p>
</div>
<p class="MsoNormal">I'm completely aware that this may be my lack of understanding of something - hopefully I will learn something new, if that's the case...
<br>
<br>
--<o:p></o:p></p>
</div>
<p class="MsoNormal">Mats<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 11 January 2018 at 12:02, Anastasia Stulova via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<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">
<div>
<div id="m_4537029536541563720divtagdefaultwrapper">
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Hi Brian,<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Considering the current implementation there is no reason we couldn't generate code with arbitrary pointer types instead of void. This is anyways implemented as a custom
 check. I don't know though if there might be limitations if using different compilation toolchains or so. Although I can imagine this will require custom implementation anywhere. Should we clarify this in spec?<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Cheers,<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Anastasia<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="m_4537029536541563720divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com" target="_blank">Brian.Sumner@amd.com</a>><br>
<b>Sent:</b> 10 January 2018 18:26:44<br>
<b>To:</b> Anastasia Stulova; Liu, Yaxun (Sam); cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>); Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>)<br>
<b>Cc:</b> nd<o:p></o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span style="color:black"><br>
<b>Subject:</b> RE: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<div>
<p class="m4537029536541563720xmsonormal"><span style="color:#1F497D">From my perspective, this restriction is nonsense.  OpenCL kernel local* arguments are not required to point to void.  Why must block local* arguments point to void?  They have to be cast
 to actually be useful; this is an unnecessary extra step.  And unless the actual type is available, the kernel enqueue mechanism has no choice to align the storage to 128 bytes since any local void * could actually be a local ulong16 *.</span><o:p></o:p></p>
<p class="m4537029536541563720xmsonormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
<p class="m4537029536541563720xmsonormal"><span style="color:#1F497D">Thanks,</span><o:p></o:p></p>
<p class="m4537029536541563720xmsonormal"><span style="color:#1F497D">Brian</span><o:p></o:p></p>
<p class="m4537029536541563720xmsonormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="m4537029536541563720xmsonormal"><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"> Anastasia Stulova [mailto:<a href="mailto:Anastasia.Stulova@arm.com" target="_blank">Anastasia.Stulova@arm.com</a>]
<br>
<b>Sent:</b> Wednesday, January 10, 2018 9:55 AM<br>
<b>To:</b> Liu, Yaxun (Sam); cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>); Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>)<br>
<b>Cc:</b> Sumner, Brian; nd<br>
<b>Subject:</b> Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions</span><o:p></o:p></p>
</div>
</div>
<p class="m4537029536541563720xmsonormal"> <o:p></o:p></p>
<div id="m_4537029536541563720x_divtagdefaultwrapper">
<p><span style="color:black">Hi Sam,</span><o:p></o:p></p>
<p><span style="color:black"> </span><o:p></o:p></p>
<p><span style="color:black">There is a restriction in OpenCL spec I have referenced in my previous email - s6.13.17.2, which is implemented by Clang. If you look in the file test/SemaOpenCL/<a href="http://cl20-device-side-enqueue.cl" target="_blank">cl20-device-side-enqueue.cl</a>
 around line 117, you will see that block_B is rejected to be passed into enqueue_kernel because it has a parameter which isn't "local void*". If you think this is wrong perhaps it would make sense to revisit this bit and understand whether the current spec
 should be changed to allow more optimal implementations to exist. But as for the current state, I don't think we can implement what you are suggesting because we can only have one block argument type for a block in enqueue.</span><o:p></o:p></p>
<p><span style="color:black"> </span><o:p></o:p></p>
<p><span style="color:black">Cheer,</span><o:p></o:p></p>
<p><span style="color:black">Anastasia</span><o:p></o:p></p>
<p class="m4537029536541563720xmsonormal" style="margin-bottom:12.0pt"><span style="color:black"> </span><o:p></o:p></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="color:black">
<hr size="2" width="98%" align="center">
</span></div>
<div id="m_4537029536541563720x_divRplyFwdMsg">
<p class="m4537029536541563720xmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>><br>
<b>Sent:</b> 08 January 2018 22:25<br>
<b>To:</b> Anastasia Stulova; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>); Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>)<br>
<b>Cc:</b> Sumner, Brian; nd<br>
<b>Subject:</b> RE: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions
</span><o:p></o:p></p>
<div>
<p class="m4537029536541563720xmsonormal"><span style="color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="m4537029536541563720xxmsonormal"><span style="color:black">My comments are below.</span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="m4537029536541563720xxmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> Anastasia Stulova [<a href="mailto:Anastasia.Stulova@arm.com" target="_blank">mailto:Anastasia.Stulova@arm.com</a>]
<br>
<b>Sent:</b> Tuesday, December 19, 2017 10:21 AM<br>
<b>To:</b> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>>; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>>;
 Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>) <<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>><br>
<b>Cc:</b> Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com" target="_blank">Brian.Sumner@amd.com</a>>; nd <<a href="mailto:nd@arm.com" target="_blank">nd@arm.com</a>><br>
<b>Subject:</b> Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions</span><o:p></o:p></p>
</div>
</div>
<p class="m4537029536541563720xxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<div id="m_4537029536541563720x_x_divtagdefaultwrapper">
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">> For example, if a block kernel has argument local int4*. Its alignment should be 16 bytes. </span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal" style="margin-bottom:12.0pt"><span style="color:black">Perhaps I am missing something but I still don't see anything in the spec that requires pointers themselves to take alignment from the pointee type. In your example
 int4* should be aligned to the pointer size (either 4 or 8 bites) while int4 should be 16 byte aligned. Clang will set the alignment of load and store operations correctly according to their data types specified in the source code (which is mainly inherited
 from C implementation apart from some special data types like vectors). The arguments passed to kernels are allocated elsewhere and OpenCL compiler has no control over this.</span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal" style="margin-bottom:12.0pt"><span style="color:black">  Sam: The spec (v2.0s6.1.5) requires “the pointee is always appropriately aligned as required by the data type”, which means the pointee of the kernel argument
 of int4* type should be aligned at 16 bytes.</span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal" style="margin-bottom:12.0pt"><span style="color:black"><br>
Regarding enqueued kernels as far as I understand you suggest to add block argument alignment info into builtin? Even though it shouldn't be strictly necessary I believe some implementation can indeed be done more efficiently using this. So I don't see any
 problem adding this. However, spec (s6.13.17.2) mandates that the enqueued block function only has void* types as parameters: "Each argument must be declared to be a void pointer to local memory."  So could you elaborate please where exactly do you plan to
 get the optimal alignment from?</span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal" style="margin-bottom:12.0pt"><span style="color:black">  Sam: The block function is passed to the builtin. The argument of the block function has the proper data type instead of void* type. Clang can deduce the alignment
 of the pointee of the kernel argument from the block function type.</span><o:p></o:p></p>
<p class="m4537029536541563720xxmsonormal" style="margin-bottom:12.0pt"><span style="color:black"><br>
Thanks,<br>
Anastasia</span><o:p></o:p></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="color:black">
<hr size="2" width="98%" align="center">
</span></div>
<div id="m_4537029536541563720x_x_divRplyFwdMsg">
<p class="m4537029536541563720xxmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>><br>
<b>Sent:</b> 15 December 2017 19:08<br>
<b>To:</b> Anastasia Stulova; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>); Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>)<br>
<b>Cc:</b> Sumner, Brian; nd<br>
<b>Subject:</b> RE: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions
</span><o:p></o:p></p>
<div>
<p class="m4537029536541563720xxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">Spec reference:</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">OpenCL v2.0 s6.1.5</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">The OpenCL compiler is responsible for aligning data items to the appropriate alignment as required by the data type. For arguments to a __kernel function declared to be a pointer to a data
 type, the OpenCL compiler can assume that the pointee is always appropriately aligned as required by the data type. The behavior of an unaligned load or store is undefined, except for the vloadn, vload_halfn, vstoren, and vstore_halfn functions defined in
 section 6.13.7.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">s6.2.5</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">Casting a pointer to a new type represents an unchecked assertion that the address is correctly aligned.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">The C Standard, 6.3.2.3, paragraph 7 [ISO/IEC 9899:2011], states</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the referenced type,
 the behavior is undefined.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">For example, if a block kernel has argument local int4*. Its alignment should be 16 bytes. Passing a pointer aligned to 1 byte may result in undefined behavior. Most hardware can still load
 from the unaligned memory but will a performance hit. If runtime wants to avoid the performance hit, it has to allocate the buffer at maximum possible alignment e.g. 32 bytes, which will result in wasted memory.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">Sam</span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="m4537029536541563720xxxmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> Anastasia Stulova [<a href="mailto:Anastasia.Stulova@arm.com" target="_blank">mailto:Anastasia.Stulova@arm.com</a>]
<br>
<b>Sent:</b> Friday, December 15, 2017 10:40 AM<br>
<b>To:</b> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>>; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>) <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>>;
 Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>) <<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>><br>
<b>Cc:</b> Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com" target="_blank">Brian.Sumner@amd.com</a>>; nd <<a href="mailto:nd@arm.com" target="_blank">nd@arm.com</a>><br>
<b>Subject:</b> Re: [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions</span><o:p></o:p></p>
</div>
</div>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<div id="m_4537029536541563720x_x_x_divtagdefaultwrapper">
<p><span style="color:black"> </span><o:p></o:p></p>
<p><span style="color:black">><span class="m4537029536541563720xxxcurrenthithighlight"> OpenCL</span> spec requires that a pointer should be aligned to at least the pointee type.</span><o:p></o:p></p>
<p><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black">So a pointer to int16 would be 64 byte aligned? Seems strange though. Can you give me the spec reference?<br>
<br>
> Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates local buffer with extra alignment therefore wasted memory space.<br>
<br>
Can you explain in more details here, please.<br>
<br>
Cheer,<br>
Anastasia</span><o:p></o:p></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="color:black">
<hr size="2" width="98%" align="center">
</span></div>
<div id="m_4537029536541563720x_x_x_divRplyFwdMsg">
<p class="m4537029536541563720xxxmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" target="_blank">Yaxun.Liu@amd.com</a>><br>
<b>Sent:</b> 01 December 2017 19:45<br>
<b>To:</b> Anastasia Stulova; cfe-dev (<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>); Bader, Alexey (<a href="mailto:alexey.bader@intel.com" target="_blank">alexey.bader@intel.com</a>)<br>
<b>Cc:</b> Sumner, Brian<br>
<b>Subject:</b> [RFC][OpenCL] Pass alignment of arguments in local addr space for device-side enqueued kernel to __enqueue_kernel functions
</span><o:p></o:p></p>
<div>
<p class="m4537029536541563720xxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Hi,</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">OpenCL spec requires that a pointer should be aligned to at least the pointee type. Therefore, if a device-side enqueued kernel has a local int* argument, it should be aligned to 4 bytes.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Since these buffers in local addr space are allocated by __enqueue_kernel, it needs to know the alignment of these buffers, not just their sizes.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Although such information is not passed to the original OpenCL builtin function enqueue_kernel, it can be obtained by checking the prototype of the block invoke function at compile time.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">I would like to create a patch to pass this information to  __enqueue_kernel. Otherwise, __enqueue_kernel has to either allocate unaligned local buffer, which degrades performance, or allocates
 local buffer with extra alignment therefore wasted memory space.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Any comments?</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Thanks.</span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="m4537029536541563720xxxxmsonormal"><span style="color:black">Sam</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>