[Beignet] a question about default optimize option when building
彭席汉
peng_xihan at dahuatech.com
Thu Feb 12 16:47:29 PST 2015
Thanks for your patient reply, I will try.
Åíϯºº
2015-02-13
·¢¼þÈË£º Zhigang Gong
·¢ËÍʱ¼ä£º 2015-02-12 18:26:54
ÊÕ¼þÈË£º 'Åíϯºº'
³ËÍ£º 'å½å¸æ±?peng_xihan at dahuatec'@domain.invalid; beignet at lists.freedesktop.org; 'Song, Ruiling'
Ö÷Ì⣺ RE: [Beignet] a question about default optimize option when building
One correction:
Just checked the C99 standard, the restricted pointer is officially supported.
So if should be safe for you to use this in your opencl kernel.
> -----Original Message-----
> From: Zhigang Gong [mailto:zhigang.gong at linux.intel.com]
> Sent: Thursday, February 12, 2015 6:21 PM
> To: 'Åíϯºº'
> Cc: 'å½å¸æ±?peng_xihan at dahuatec'; 'beignet at lists.freedesktop.org'; 'Song,
> Ruiling'
> Subject: RE: [Beignet] a question about default optimize option when building
>
> I just found a non-standard performance hint keyword __restrict__ is
> supported by CLANG.
> You could try it this way
>
> __global unsigned char __restrict__ *p;
> int a, b, c, d;
>
> res1 = *p * (a*b + c*d);
> <some code here >
> res2 = *p * (a*b + c*d + 1);
>
>
> Then the compiler will treat pointer p pointing to an unique chunk of memory
> which could only be accessed by p. Then if there is no storing to pointer p
> between the res1 and res2 assignment, the res2 will not generate an extra
> load.
>
> Please have a try at your kernel and check the difference by enable the LLVM
> output as below:
>
> export OCL_OUTPUT_LLVM_AFTER_GEN=1
>
> Please be warned, this is not a portable way even it works for beignet, may not
> work with other OpenCL library.
>
> > -----Original Message-----
> > From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf
> > Of Zhigang Gong
> > Sent: Thursday, February 12, 2015 4:57 PM
> > To: Åíϯºº
> > Cc: å½å¸æ±?peng_xihan at dahuatec; beignet at lists.freedesktop.org; Song,
> > Ruiling
> > Subject: Re: [Beignet] a question about default optimize option when
> > building
> >
> > Athough theoretically this is doable for OpenCL, if user could
> > guarantee all the buffers are not overlapped, then the compiler could
> > do more aggresive optimization to merge duplicate loads.
> >
> > But you can check the OpenCL C spec or C99 spec, there are no such
> > type of attribute qualifiers defined, so there is no safe/portable way
> > to do this type of optimization from compiler side currently.
> >
> > On Thu, Feb 12, 2015 at 05:32:08PM +0800, Åíϯºº wrote:
> > > Any way to tell compiler I have no side effect for memory pointer p
> > > and I don't
> > want to load it again?
> > >
> > >
> > >
> > >
> > > Åíϯºº
> > > 2015-02-12
> > >
> > >
> > >
> > > ·¢¼þÈË£º Zhigang Gong
> > > ·¢ËÍʱ¼ä£º 2015-02-12 17:14:36
> > > ÊÕ¼þÈË£º Song, Ruiling
> > > ³ËÍ£º beignet at lists.freedesktop.org; ÅíϯT
> > peng_xihan at dahuatech.com >
> > > Ö÷Ì⣺ Re: [Beignet] a question about default optimize option when
> > > building
> > >
> > > Some additional analysis based on ruiling's comment.
> > >
> > > The second load from p(to calculate res2) may or may not be issued.
> > > It depends on whether there are some side effect instructions
> > > between
> > > res1 and res2's assignment. For example, if there is a store
> > > instruction or there is a barrier, the second load will be issued
> > > and you will see two loads for the same pointer in the final instruction
> stream.
> > >
> > > As to the a * b + c*d, it will always be optimized and be reused
> > > when calculate for res2 which means at the res2 assignment it will
> > > only generate one add instruction to add the 1 to the previous
> > > calculated value.
> > >
> > > On Thu, Feb 12, 2015 at 08:56:57AM +0000, Song, Ruiling wrote:
> > > > It should not read global memory again. We already enable such
> > > > kind of
> > optimization pass in LLVM.
> > > > And (a*b+c*d) should not calculate again. This is common-subexpression.
> > Clang should do it easily. But I am not quite sure whether clang is
> > affected by
> > -O2 or -O0. Anyone know details?
> > > >
> > > > To check specific kernel. You may need to ¡®export
> > OCL_OUTPUT_LLVM_AFTER_GEN=1¡¯ and build your program again to get
> the
> > LLVM IR.
> > > >
> > > > From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On
> > > > Behalf Of Åíϯºº
> > > > Sent: Thursday, February 12, 2015 4:40 PM
> > > > To: beignet at lists.freedesktop.org
> > > > Subject: [Beignet] a question about default optimize option when
> > > > building
> > > >
> > > > Hi:
> > > >
> > > > My CL kernel program looks like as follow:
> > > >
> > > > __global unsigned char *p;
> > > > int a, b, c, d;
> > > >
> > > > res1 = *p * (a*b + c*d);
> > > >
> > > > <some code here >
> > > >
> > > > res2 = *p * (a*b + c*d + 1);
> > > >
> > > >
> > > > If I use default build option, for res2, what will EU do? read
> > > > global memory
> > for pointer p again and do computing of "a*b + c*d" again?
> > >
> > > > _______________________________________________
> > > > Beignet mailing list
> > > > Beignet at lists.freedesktop.org
> > > > http://lists.freedesktop.org/mailman/listinfo/beignet
> > >
> > > _______________________________________________
> > > Beignet mailing list
> > > Beignet at lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/beignet
> > > = = = = = = = = = = = = = = = = = = = =
> > >
> > > ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
> > > Àñ£¡
> > >
> > >
> > >
> > > ¡¡2015-02-12
> > >
> >
> ****************************************************************
> > ******
> > > ******************
> > >
> > > ¹«Ë¾Ãû³Æ£ºÕ㽴󻪼¼Êõ¹É·ÝÓÐÏÞ¹«Ë¾
> > > ZheJiang Dahua Technology CO.,LTD.
> > > µØÖ·£ºº¼Öݱõ½Çø±õ°²Â·1199ºÅ
> > > ²¿ÃÅ£º´æ´¢²úÆ·Ïß-NVR²úÆ·Ïß
> > > ÊÖ»ú£º18969076807
> > > ÓÊÕþ±àÂ룺310053
> > > E-mail: peng_xihan at dahuatech.com
> > > Http: //www.dahuatech.com
> > >
> > >
> >
> ****************************************************************
> > ******
> > > ********************
> >
> >
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/beignet
= = = = = = = = = = = = = = = = = = = =
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
Àñ£¡
¡¡¡¡¡¡¡¡¡¡¡¡
¡¡2015-02-13
****************************************************************************************
¹«Ë¾Ãû³Æ£ºÕ㽴󻪼¼Êõ¹É·ÝÓÐÏÞ¹«Ë¾
ZheJiang Dahua Technology CO.,LTD.
µØÖ·£ºº¼Öݱõ½Çø±õ°²Â·1199ºÅ
²¿ÃÅ£º´æ´¢²úÆ·Ïß-NVR²úÆ·Ïß
ÊÖ»ú£º18969076807
ÓÊÕþ±àÂ룺310053
E-mail: peng_xihan at dahuatech.com
Http: //www.dahuatech.com
******************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/beignet/attachments/20150213/ddd9ba0c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NVRÐû´«.png
Type: application/octet-stream
Size: 188177 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/beignet/attachments/20150213/ddd9ba0c/attachment-0001.obj>
More information about the Beignet
mailing list