<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:v = "urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:st2 =
"urn:schemas-microsoft-com:office:smarttags" xmlns:st1 = "Tencent"><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7601.18487"></HEAD>
<BODY>
<DIV><FONT size=2>
<DIV><FONT color=#0000ff size=2 face=Verdana>Thanks for your patient reply, I
will try.</FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV align=left>
<DIV align=left><FONT size=2 face=Verdana>
<HR style="WIDTH: 122px; HEIGHT: 2px" SIZE=2>
</FONT></DIV>
<DIV><FONT color=#c0c0c0><FONT size=2 face=Verdana>彭席汉</FONT></DIV>
<DIV><FONT size=2 face=Verdana>2015-02-13</FONT></FONT></DIV></DIV>
<DIV><FONT size=2 face=Verdana>
<HR>
</FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>发件人:</STRONG> Zhigang
Gong</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>发送时间:</STRONG>
2015-02-12 18:26:54</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>收件人:</STRONG>
'彭席汉'</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>抄送:</STRONG>
'褰腑姹?peng_xihan@dahuatec'@domain.invalid; beignet@lists.freedesktop.org; 'Song,
Ruiling'</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2><STRONG>主题:</STRONG> RE: [Beignet] a
question about default optimize option when building</FONT></FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><FONT size=2 face=Verdana>
<DIV>One correction:</DIV>
<DIV>Just checked the C99 standard, the restricted pointer is officially supported.</DIV>
<DIV>So if should be safe for you to use this in your opencl kernel.</DIV>
<DIV> </DIV>
<DIV>> -----Original Message-----</DIV>
<DIV>> From: Zhigang Gong [mailto:zhigang.gong@linux.intel.com]</DIV>
<DIV>> Sent: Thursday, February 12, 2015 6:21 PM</DIV>
<DIV>> To: '彭席汉'</DIV>
<DIV>> Cc: '褰腑姹?peng_xihan@dahuatec'; 'beignet@lists.freedesktop.org'; 'Song,</DIV>
<DIV>> Ruiling'</DIV>
<DIV>> Subject: RE: [Beignet] a question about default optimize option when building</DIV>
<DIV>> </DIV>
<DIV>> I just found a non-standard performance hint keyword __restrict__ is</DIV>
<DIV>> supported by CLANG.</DIV>
<DIV>> You could try it this way</DIV>
<DIV>> </DIV>
<DIV>> __global unsigned char __restrict__ *p;</DIV>
<DIV>> int a, b, c, d;</DIV>
<DIV>> </DIV>
<DIV>> res1 = *p * (a*b + c*d);</DIV>
<DIV>> <some code here ></DIV>
<DIV>> res2 = *p * (a*b + c*d + 1);</DIV>
<DIV>> </DIV>
<DIV>> </DIV>
<DIV>> Then the compiler will treat pointer p pointing to an unique chunk of memory</DIV>
<DIV>> which could only be accessed by p. Then if there is no storing to pointer p</DIV>
<DIV>> between the res1 and res2 assignment, the res2 will not generate an extra</DIV>
<DIV>> load.</DIV>
<DIV>> </DIV>
<DIV>> Please have a try at your kernel and check the difference by enable the LLVM</DIV>
<DIV>> output as below:</DIV>
<DIV>> </DIV>
<DIV>> export OCL_OUTPUT_LLVM_AFTER_GEN=1</DIV>
<DIV>> </DIV>
<DIV>> Please be warned, this is not a portable way even it works for beignet, may not</DIV>
<DIV>> work with other OpenCL library.</DIV>
<DIV>> </DIV>
<DIV>> > -----Original Message-----</DIV>
<DIV>>
> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf</DIV>
<DIV>> > Of Zhigang Gong</DIV>
<DIV>>
> Sent: Thursday, February 12, 2015 4:57 PM</DIV>
<DIV>> > To: 彭席汉</DIV>
<DIV>>
> Cc: 褰腑姹?peng_xihan@dahuatec; beignet@lists.freedesktop.org; Song,</DIV>
<DIV>> > Ruiling</DIV>
<DIV>>
> Subject: Re: [Beignet] a question about default optimize option when</DIV>
<DIV>> > building</DIV>
<DIV>> ></DIV>
<DIV>>
> Athough theoretically this is doable for OpenCL, if user could</DIV>
<DIV>>
> guarantee all the buffers are not overlapped, then the compiler could</DIV>
<DIV>>
> do more aggresive optimization to merge duplicate loads.</DIV>
<DIV>> ></DIV>
<DIV>>
> But you can check the OpenCL C spec or C99 spec, there are no such</DIV>
<DIV>>
> type of attribute qualifiers defined, so there is no safe/portable way</DIV>
<DIV>>
> to do this type of optimization from compiler side currently.</DIV>
<DIV>> ></DIV>
<DIV>>
> On Thu, Feb 12, 2015 at 05:32:08PM +0800, 彭席汉 wrote:</DIV>
<DIV>> >
> Any way to tell compiler I have no side effect for memory pointer p</DIV>
<DIV>> > > and I don't</DIV>
<DIV>> > want to load it again?</DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > > 彭席汉</DIV>
<DIV>> > > 2015-02-12</DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > > 发件人: Zhigang Gong</DIV>
<DIV>> > > 发送时间: 2015-02-12 17:14:36</DIV>
<DIV>> > > 收件人: Song, Ruiling</DIV>
<DIV>> >
> 抄送: beignet@lists.freedesktop.org; 彭席汿</DIV>
<DIV>> > peng_xihan@dahuatech.com ></DIV>
<DIV>> >
> 主题: Re: [Beignet] a question about default optimize option when</DIV>
<DIV>> > > building</DIV>
<DIV>> > ></DIV>
<DIV>> >
> Some additional analysis based on ruiling's comment.</DIV>
<DIV>> > ></DIV>
<DIV>> >
> The second load from p(to calculate res2) may or may not be issued.</DIV>
<DIV>> >
> It depends on whether there are some side effect instructions</DIV>
<DIV>> > > between</DIV>
<DIV>> >
> res1 and res2's assignment. For example, if there is a store</DIV>
<DIV>> >
> instruction or there is a barrier, the second load will be issued</DIV>
<DIV>> >
> and you will see two loads for the same pointer in the final instruction</DIV>
<DIV>> stream.</DIV>
<DIV>> > ></DIV>
<DIV>> >
> As to the a * b + c*d, it will always be optimized and be reused</DIV>
<DIV>> >
> when calculate for res2 which means at the res2 assignment it will</DIV>
<DIV>> >
> only generate one add instruction to add the 1 to the previous</DIV>
<DIV>> > > calculated value.</DIV>
<DIV>> > ></DIV>
<DIV>> >
> On Thu, Feb 12, 2015 at 08:56:57AM +0000, Song, Ruiling wrote:</DIV>
<DIV>> > >
> It should not read global memory again. We already enable such</DIV>
<DIV>> > > > kind of</DIV>
<DIV>> > optimization pass in LLVM.</DIV>
<DIV>> > >
> And (a*b+c*d) should not calculate again. This is common-subexpression.</DIV>
<DIV>>
> Clang should do it easily. But I am not quite sure whether clang is</DIV>
<DIV>> > affected by</DIV>
<DIV>>
> -O2 or -O0. Anyone know details?</DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> To check specific kernel. You may need to ‘export</DIV>
<DIV>>
> OCL_OUTPUT_LLVM_AFTER_GEN=1’ and build your program again to get</DIV>
<DIV>> the</DIV>
<DIV>> > LLVM IR.</DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On</DIV>
<DIV>> > > > Behalf Of 彭席汉</DIV>
<DIV>> > >
> Sent: Thursday, February 12, 2015 4:40 PM</DIV>
<DIV>> > >
> To: beignet@lists.freedesktop.org</DIV>
<DIV>> > >
> Subject: [Beignet] a question about default optimize option when</DIV>
<DIV>> > > > building</DIV>
<DIV>> > > ></DIV>
<DIV>> > > > Hi:</DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> My CL kernel program looks like as follow:</DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> __global unsigned char *p;</DIV>
<DIV>> > >
> int a, b, c, d;</DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> res1 = *p * (a*b + c*d);</DIV>
<DIV>> > > ></DIV>
<DIV>> > > >
<some code here ></DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> res2 = *p * (a*b + c*d + 1);</DIV>
<DIV>> > > ></DIV>
<DIV>> > > ></DIV>
<DIV>> > >
> If I use default build option, for res2, what will EU do? read</DIV>
<DIV>> > > > global memory</DIV>
<DIV>>
> for pointer p again and do computing of "a*b + c*d" again?</DIV>
<DIV>> > ></DIV>
<DIV>> > >
> _______________________________________________</DIV>
<DIV>> > >
> Beignet mailing list</DIV>
<DIV>> > >
> Beignet@lists.freedesktop.org</DIV>
<DIV>> > > > <A
href="http://lists.freedesktop.org/mailman/listinfo/beignet">http://lists.freedesktop.org/mailman/listinfo/beignet</A></DIV>
<DIV>> > ></DIV>
<DIV>> >
> _______________________________________________</DIV>
<DIV>> > > Beignet mailing list</DIV>
<DIV>> > > Beignet@lists.freedesktop.org</DIV>
<DIV>> > > <A
href="http://lists.freedesktop.org/mailman/listinfo/beignet">http://lists.freedesktop.org/mailman/listinfo/beignet</A></DIV>
<DIV>> >
> = = = = = = = = = = = = = = = = = = = =</DIV>
<DIV>> > ></DIV>
<DIV>> > > 致</DIV>
<DIV>> > > 礼!</DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> >
> 2015-02-12</DIV>
<DIV>> > ></DIV>
<DIV>> ></DIV>
<DIV>> ****************************************************************</DIV>
<DIV>> > ******</DIV>
<DIV>> > > ******************</DIV>
<DIV>> > ></DIV>
<DIV>> > > 公司名称:浙江大华技术股份有限公司</DIV>
<DIV>> >
> ZheJiang Dahua Technology CO.,LTD.</DIV>
<DIV>> > > 地址:杭州滨江区滨安路1199号</DIV>
<DIV>> > > 部门:存储产品线-NVR产品线</DIV>
<DIV>> > > 手机:18969076807</DIV>
<DIV>> > > 邮政编码:310053</DIV>
<DIV>> >
> E-mail: peng_xihan@dahuatech.com</DIV>
<DIV>> >
> Http: //www.dahuatech.com</DIV>
<DIV>> > ></DIV>
<DIV>> > ></DIV>
<DIV>> ></DIV>
<DIV>> ****************************************************************</DIV>
<DIV>> > ******</DIV>
<DIV>> > > ********************</DIV>
<DIV>> ></DIV>
<DIV>> ></DIV>
<DIV>> > _______________________________________________</DIV>
<DIV>> > Beignet mailing list</DIV>
<DIV>> > Beignet@lists.freedesktop.org</DIV>
<DIV>> > <A
href="http://lists.freedesktop.org/mailman/listinfo/beignet">http://lists.freedesktop.org/mailman/listinfo/beignet</A></DIV></FONT></DIV></FONT></DIV>
<DIV>= = = = = = = = = = = = = = = = = = = =</DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2> 致<BR>礼!<BR> </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>
<BR>
2015-02-13</FONT></DIV>
<DIV><FONT
size=2>****************************************************************************************<BR> </FONT><v:shape
style="Z-INDEX: 1; POSITION: absolute; TEXT-ALIGN: left; MARGIN-TOP: 26.85pt; WIDTH: 54.4pt; HEIGHT: 15.95pt; MARGIN-LEFT: 63.4pt; LEFT: 0px"
id=_x0000_s1027 type="#_x0000_t75"><v:imagedata o:title="logo"
src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"></v:imagedata></v:shape><v:shape
style="Z-INDEX: 1; POSITION: absolute; TEXT-ALIGN: left; MARGIN-TOP: 26.85pt; WIDTH: 54.4pt; HEIGHT: 15.95pt; MARGIN-LEFT: 63.4pt; LEFT: 0px"
id=_x0000_s1026 type="#_x0000_t75"><v:imagedata o:title="logo"
src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"><FONT
size=2></FONT></v:imagedata></v:shape><FONT size=2></FONT><FONT size=2><IMG
border=0 hspace=0 alt="" align=baseline src="cid:__0@Foxmail.net"> </DIV>
<DIV><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
<DIV><FONT size=2><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
公司名称:浙江大华技术股份有限公司<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"
lang=EN-US> ZheJiang Dahua Technology CO.,LTD.<o:p></o:p></SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
地址:杭州滨江区滨安路<st1:RTX w:st="on"><SPAN lang=EN-US>1199</SPAN></st1:RTX>号</SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
部门:存储产品线-NVR产品线</SPAN></P>
<DIV>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">
手机:18969076807</SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"> </SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">邮政编码:<st1:RTX
w:st="on"><SPAN lang=EN-US>3100</SPAN></st1:RTX><SPAN
lang=EN-US>53<o:p></o:p></SPAN></SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"
lang=EN-US> E-mail: <A
href="mailto:peng_xihan@dahuatech.com">peng_xihan@dahuatech.com</A></SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"
lang=EN-US></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"
lang=EN-US> Http: //www.dahuatech.com</SPAN><FONT
size=2><BR></FONT></P></DIV>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan"
class=MsoNormal align=left></SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"
lang=EN-US></SPAN></FONT></SPAN></FONT><FONT
size=2>******************************************************************************************</FONT></P></DIV></DIV></BODY></HTML>