<?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 Incorrect kernel execution with barrier(CLK_LOCAL_MEM_FENCE)  in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976435#M2464</link>
    <description>&lt;P&gt;Consider the following kernel:&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;__kernel void test(__global float2 *output, __global float2 *input)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __local float lmem[8];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float2 a;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const size_t tid = get_global_id(0);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(tid / 8 == 0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = input[tid];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lmem[tid] = -a.x;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; barrier(CLK_LOCAL_MEM_FENCE);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.x = lmem[tid];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; barrier(CLK_LOCAL_MEM_FENCE);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output[tid] = a;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;If I execute it with global size == local_size == 16 and pass an array of 16 float2 elements as input:&lt;/P&gt;
&lt;P&gt;[plain]input = [&amp;nbsp; 0.+0.j&amp;nbsp;&amp;nbsp; 1.+0.j&amp;nbsp;&amp;nbsp; 2.+0.j&amp;nbsp;&amp;nbsp; 3.+0.j&amp;nbsp;&amp;nbsp; 4.+0.j&amp;nbsp;&amp;nbsp; 5.+0.j&amp;nbsp;&amp;nbsp; 6.+0.j&amp;nbsp;&amp;nbsp; 7.+0.j&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 8.+0.j&amp;nbsp;&amp;nbsp; 9.+0.j&amp;nbsp; 10.+0.j&amp;nbsp; 11.+0.j&amp;nbsp; 12.+0.j&amp;nbsp; 13.+0.j&amp;nbsp; 14.+0.j&amp;nbsp; 15.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;and a zero-filled buffer as output, I expect the first 8 elements of the output to have their real parts negated in the output array, while the rest of it remaining untouched:&lt;/P&gt;
&lt;P&gt;[plain]output = [-0.+0.j -1.+0.j -2.+0.j -3.+0.j -4.+0.j -5.+0.j -6.+0.j -7.+0.j 0.+0.j&lt;BR /&gt;&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;This is what happens on Ubuntu 12.04 x64, nVidia CUDA 5 platform, Tesla C2050 device. But on the same operating system, Intel OpenCL XE SDK 2013 3.0.67279, and Intel Xeon E5620 the whole resulting buffer remains untouched:&lt;/P&gt;
&lt;P&gt;[plain]output = [ 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&lt;BR /&gt;&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;The output coincides with the reference CUDA output if I do any of the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Comment out the barriers;&lt;/LI&gt;
&lt;LI&gt;Use float arrays instead of float2&lt;/LI&gt;
&lt;LI&gt;Initialize "a" inside the kernel instead of reading it from input (i.e. as "a = (float2)(tid, 0)").&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Has anyone encountered such behavior? Is it a bug, or am I making incorrect assumptions about how barriers work?&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2013 05:24:28 GMT</pubDate>
    <dc:creator>vladimirsson</dc:creator>
    <dc:date>2013-08-15T05:24:28Z</dc:date>
    <item>
      <title>Incorrect kernel execution with barrier(CLK_LOCAL_MEM_FENCE)</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976435#M2464</link>
      <description>&lt;P&gt;Consider the following kernel:&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;__kernel void test(__global float2 *output, __global float2 *input)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __local float lmem[8];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float2 a;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const size_t tid = get_global_id(0);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(tid / 8 == 0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = input[tid];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lmem[tid] = -a.x;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; barrier(CLK_LOCAL_MEM_FENCE);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.x = lmem[tid];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; barrier(CLK_LOCAL_MEM_FENCE);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output[tid] = a;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;If I execute it with global size == local_size == 16 and pass an array of 16 float2 elements as input:&lt;/P&gt;
&lt;P&gt;[plain]input = [&amp;nbsp; 0.+0.j&amp;nbsp;&amp;nbsp; 1.+0.j&amp;nbsp;&amp;nbsp; 2.+0.j&amp;nbsp;&amp;nbsp; 3.+0.j&amp;nbsp;&amp;nbsp; 4.+0.j&amp;nbsp;&amp;nbsp; 5.+0.j&amp;nbsp;&amp;nbsp; 6.+0.j&amp;nbsp;&amp;nbsp; 7.+0.j&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 8.+0.j&amp;nbsp;&amp;nbsp; 9.+0.j&amp;nbsp; 10.+0.j&amp;nbsp; 11.+0.j&amp;nbsp; 12.+0.j&amp;nbsp; 13.+0.j&amp;nbsp; 14.+0.j&amp;nbsp; 15.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;and a zero-filled buffer as output, I expect the first 8 elements of the output to have their real parts negated in the output array, while the rest of it remaining untouched:&lt;/P&gt;
&lt;P&gt;[plain]output = [-0.+0.j -1.+0.j -2.+0.j -3.+0.j -4.+0.j -5.+0.j -6.+0.j -7.+0.j 0.+0.j&lt;BR /&gt;&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;This is what happens on Ubuntu 12.04 x64, nVidia CUDA 5 platform, Tesla C2050 device. But on the same operating system, Intel OpenCL XE SDK 2013 3.0.67279, and Intel Xeon E5620 the whole resulting buffer remains untouched:&lt;/P&gt;
&lt;P&gt;[plain]output = [ 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&lt;BR /&gt;&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j&amp;nbsp; 0.+0.j][/plain]&lt;/P&gt;
&lt;P&gt;The output coincides with the reference CUDA output if I do any of the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Comment out the barriers;&lt;/LI&gt;
&lt;LI&gt;Use float arrays instead of float2&lt;/LI&gt;
&lt;LI&gt;Initialize "a" inside the kernel instead of reading it from input (i.e. as "a = (float2)(tid, 0)").&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Has anyone encountered such behavior? Is it a bug, or am I making incorrect assumptions about how barriers work?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2013 05:24:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976435#M2464</guid>
      <dc:creator>vladimirsson</dc:creator>
      <dc:date>2013-08-15T05:24:28Z</dc:date>
    </item>
    <item>
      <title>Hello vladimirsson!</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976436#M2465</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;A href="http://software.intel.com/en-us/user/542464" style="font-family: Arial, Helvetica, sans-serif; font-size: 11.199999809265137px; line-height: 13.199999809265137px; background-color: rgb(238, 238, 238);"&gt;vladimirsson&lt;/A&gt;!&lt;/P&gt;

&lt;P&gt;According to OpenCL specification and common sense&amp;nbsp;barrier()&amp;nbsp;must be&amp;nbsp;encountered by all work-items in a work-group executing the kernel or not encountered at all.&amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;From OpenCL specification:&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;This function must be&amp;nbsp;encountered by all work-items in a work-group&amp;nbsp;executing the kernel.&amp;nbsp;If barrier is inside a conditional statement, then&amp;nbsp;all work-items must enter the conditional if any&amp;nbsp;work-item enters the conditional statement and&amp;nbsp;executes the barrier.&amp;nbsp;If barrier is inside a loop, all work-items must&amp;nbsp;execute the barrier for each iteration of the loop&amp;nbsp;before any are allowed to continue execution&amp;nbsp;beyond the barrier.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;In your kernel only part of work-items in work-group call&amp;nbsp;barrier(), because remaining work-items finish execution inside if statement. So behavior is undefined.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2014 11:39:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976436#M2465</guid>
      <dc:creator>EvgeniyPeshkov</dc:creator>
      <dc:date>2014-02-03T11:39:25Z</dc:date>
    </item>
    <item>
      <title>Thank you, I must have missed</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976437#M2466</link>
      <description>&lt;P&gt;Thank you, I must have missed that part in the specs. Something to look out for in other kernels too.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2014 05:01:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Incorrect-kernel-execution-with-barrier-CLK-LOCAL-MEM-FENCE/m-p/976437#M2466</guid>
      <dc:creator>vladimirsson</dc:creator>
      <dc:date>2014-02-13T05:01:46Z</dc:date>
    </item>
  </channel>
</rss>

