<?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 Thanks for your reply. in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122579#M5542</link>
    <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jan 2017 02:49:28 GMT</pubDate>
    <dc:creator>tooguni</dc:creator>
    <dc:date>2017-01-11T02:49:28Z</dc:date>
    <item>
      <title>Why do small changes make in kernel code wrong results?</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122577#M5540</link>
      <description>&lt;P&gt;The following kernel (my_kernel()) which is written based on my_function() calculates wrong results on Intel GPU.&lt;BR /&gt;
	The same code works well on Intel CPU and AMD GPU platform.&lt;BR /&gt;
	If you change the type of array index (idx) from unsigned long to unsigned int, the kernel calculates correct results, but I think that both should calculate correct results.&lt;BR /&gt;
	&lt;SPAN style="font-size: 13.008px;"&gt;Which is caused this problem? By my code or Intel OpenCL SDK?&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;const char* kernel_str =
"__kernel \n"
"void my_kernel(__global const unsigned char* src, \n"
"               __global unsigned char*       dst, \n"
"               const unsigned long           elements) \n"
"{ \n"
"  const unsigned long gid = get_global_id(0); \n"
"  const unsigned long idx = 3 * gid; // NG\n"
"  //const unsigned int idx = 3 * gid; // OK\n"
"  if (! (gid &amp;lt; elements)) { \n"
"    return; \n"
"  } \n"
"  float r = ((float)src[idx] + (1.5f * (float)src[idx + 2])) - 18.0f;\n"
"  float g = (((float)src[idx] - (0.4f * (float)src[idx + 1])) - (0.7f * (float)src[idx + 2])) + 14.0f;\n"
"  float b = ((float)src[idx] + (1.8f * (float)src[idx + 1])) - 23.0f;\n"
"  r = clamp(r, 0.0f, 255.0f); \n"
"  g = clamp(g, 0.0f, 255.0f); \n"
"  b = clamp(b, 0.0f, 255.0f); \n"
"  dst[idx + 0] = convert_uchar(r); \n"
"  dst[idx + 1] = convert_uchar(g); \n"
"  dst[idx + 2] = convert_uchar(b); \n"
"}";


void my_function(const cl_uchar*     src,
                 cl_uchar*           dst,
                 const unsigned long elements)
{
  for (unsigned long gid = 0; gid &amp;lt; elements; ++gid) {
    const unsigned long idx = 3 * gid;
    float r = ((float)src[idx] + (1.5f * (float)src[idx + 2])) - 18.0f;
    float g = (((float)src[idx] - (0.4f * (float)src[idx + 1])) - (0.7f * (float)src[idx + 2])) + 14.0f;
    float b = ((float)src[idx] + (1.8f * (float)src[idx + 1])) - 23.0f;
    r = std::min(std::max(0.0f, r), 255.0f); // clamp
    g = std::min(std::max(0.0f, g), 255.0f);
    b = std::min(std::max(0.0f, b), 255.0f);
    dst[idx + 0] = (cl_uchar)r;
    dst[idx + 1] = (cl_uchar)g;
    dst[idx + 2] = (cl_uchar)b;
  }
}&lt;/PRE&gt;

&lt;P&gt;I am using these environments.&lt;BR /&gt;
	OS : Windows 10 Pro 64bit&lt;BR /&gt;
	Device Name : Intel(R) Iris(TM) Pro Graphics 580&lt;BR /&gt;
	Device Driver Version : 21.20.16.4542&lt;BR /&gt;
	Intel OpenCL SDK : 2016 R3&lt;/P&gt;

&lt;P&gt;OS : Windows 10 Pro 64bit&lt;BR /&gt;
	Device Name : Intel(R) HD Graphics 530&lt;BR /&gt;
	Device Driver Version : 20.19.15.4501&lt;BR /&gt;
	Intel OpenCL SDK : 2016 R2&lt;/P&gt;

&lt;P&gt;I attach a source code and VC project.&lt;/P&gt;

&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 08:43:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122577#M5540</guid>
      <dc:creator>tooguni</dc:creator>
      <dc:date>2016-12-26T08:43:20Z</dc:date>
    </item>
    <item>
      <title>Thanks for your great</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122578#M5541</link>
      <description>&lt;P&gt;Thanks for your great reproducer!&amp;nbsp; We're processing this as a bug.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2016 01:51:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122578#M5541</guid>
      <dc:creator>Jeffrey_M_Intel1</dc:creator>
      <dc:date>2016-12-31T01:51:56Z</dc:date>
    </item>
    <item>
      <title>Thanks for your reply.</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122579#M5542</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 02:49:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Why-do-small-changes-make-in-kernel-code-wrong-results/m-p/1122579#M5542</guid>
      <dc:creator>tooguni</dc:creator>
      <dc:date>2017-01-11T02:49:28Z</dc:date>
    </item>
  </channel>
</rss>

