<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hi Jeffrey, in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110732#M5294</link>
    <description>&lt;P&gt;Hi Jeffrey,&lt;/P&gt;

&lt;P&gt;I think it would be a good idea to see my presentations on Optimizing Simple OpenCL Kernels here &lt;A href="https://software.intel.com/en-us/articles/optimizing-simple-opencl-kernels"&gt;https://software.intel.com/en-us/articles/optimizing-simple-opencl-kernels&lt;/A&gt; - there is also code there that you can download and play with. Basically, what you are doing is not very optimal. You are better off switching to float4 datatype.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2016 23:55:33 GMT</pubDate>
    <dc:creator>Robert_I_Intel</dc:creator>
    <dc:date>2016-03-15T23:55:33Z</dc:date>
    <item>
      <title>optimize kernel for vector addition</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110731#M5293</link>
      <description>&lt;P&gt;I have 2 vectors (float) with size of 1024*1024*8. &amp;nbsp;I want to do vector addition. My first kernel &lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;vec_add_1()&amp;nbsp;&lt;/SPAN&gt;has Gx=&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;1024*1024*8 and Lx=0&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;__kernel void vec_add_1(__global const float* in1, __global const float* in2, __global float* out)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int i=get_global_id(0);&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp; &amp;nbsp; out&lt;I&gt;=in1&lt;I&gt;+in2&lt;I&gt;;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Kernel&amp;nbsp;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;vec_add_1() takes about 10msec.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 11.1497px;"&gt;To reduce schedule time, &amp;nbsp;I created second kernel&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;vec_add_2().&amp;nbsp;vec_add_1() has Gx=1024*1024*8 /4, Lx=0.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;__kernel void vec_add_2(__global const float* in1, __global const float* in2, __global float* out)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int i=get_global_id(0);&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp; &amp;nbsp; int j=(i&amp;lt;&amp;lt;2);&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;out&lt;J&gt;=in1&lt;J&gt;+in2&lt;J&gt;;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; out[j+1]=in1[j+1]+in2[j+1];&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; out[j+2]=in1[j+2]+in2[j+2];&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; out[j+3]=in1[j+3]+in2[j+3];&lt;BR /&gt;
	}&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/P&gt;

&lt;P&gt;However, &amp;nbsp;I got 2 quite different results&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;- Running vec_add_2() in code builder session,&amp;nbsp;vec_add_2() takes ~13msec, which is slower than&amp;nbsp;vec_add_1()&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;-&amp;nbsp;Running vec_add_2() with host code together,&amp;nbsp;vec_add_2() takes ~7msec,&amp;nbsp;which is faster than&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;vec_add_1()&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;So my questions are&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;- why running vec_add_2() with and without code builder session give quite different results?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;- is&amp;nbsp;vec_add_2() an optimized version than&amp;nbsp;vec_add_1()?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;thanks,&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 11.1497px;"&gt;Jeffrey&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 21:06:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110731#M5293</guid>
      <dc:creator>Fu_J_Intel</dc:creator>
      <dc:date>2016-03-14T21:06:59Z</dc:date>
    </item>
    <item>
      <title>Hi Jeffrey,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110732#M5294</link>
      <description>&lt;P&gt;Hi Jeffrey,&lt;/P&gt;

&lt;P&gt;I think it would be a good idea to see my presentations on Optimizing Simple OpenCL Kernels here &lt;A href="https://software.intel.com/en-us/articles/optimizing-simple-opencl-kernels"&gt;https://software.intel.com/en-us/articles/optimizing-simple-opencl-kernels&lt;/A&gt; - there is also code there that you can download and play with. Basically, what you are doing is not very optimal. You are better off switching to float4 datatype.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 23:55:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110732#M5294</guid>
      <dc:creator>Robert_I_Intel</dc:creator>
      <dc:date>2016-03-15T23:55:33Z</dc:date>
    </item>
    <item>
      <title>Hi Robert,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110733#M5295</link>
      <description>&lt;P&gt;Hi Robert,&lt;/P&gt;

&lt;P&gt;I changed my kernel to use float4 as below&lt;/P&gt;

&lt;P&gt;__kernel void vec_add_3(__global const float4* in1, __global const float4* in2, __global float4* out)&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;int i=get_global_id(0);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;out&lt;I&gt;=in1&lt;I&gt;+in2&lt;I&gt;;&lt;BR /&gt;
	}&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;Gx is correspondingly changed to be 1/4 of original vector size (&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;original vector size&amp;nbsp;&lt;/SPAN&gt;is 1024*1024*8. &amp;nbsp;Gx for&amp;nbsp;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;vec_add_3() is&amp;nbsp;1024*1024*8 / 4). &amp;nbsp;Then I did "run analysis" in code-builder session. Surprisingly, &amp;nbsp;I execution time is still ~10ms, &amp;nbsp;almost no improvement.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 05:06:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110733#M5295</guid>
      <dc:creator>Fu_J_Intel</dc:creator>
      <dc:date>2016-03-16T05:06:20Z</dc:date>
    </item>
    <item>
      <title>Hi Jeffrey,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110734#M5296</link>
      <description>&lt;P&gt;Hi Jeffrey,&lt;/P&gt;

&lt;P&gt;Couple of more things two try:&lt;/P&gt;

&lt;P&gt;1. try to combine what you are doing in vec_add_2 with float4&lt;/P&gt;

&lt;P&gt;2. try using float8 or even float16&lt;/P&gt;

&lt;P&gt;3. try a combination of vec_add_2 and float4 and/or float8.&lt;/P&gt;

&lt;P&gt;The basic problem is that for the simple kernels you need to pack much more compute onto a hardware thread.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 16:12:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/optimize-kernel-for-vector-addition/m-p/1110734#M5296</guid>
      <dc:creator>Robert_I_Intel</dc:creator>
      <dc:date>2016-03-18T16:12:43Z</dc:date>
    </item>
  </channel>
</rss>

