<?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 BenR, in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182702#M6736</link>
    <description>&lt;P&gt;Hi BenR,&lt;/P&gt;&lt;P&gt;Thanks for the clear example&amp;nbsp;and the interest.&lt;/P&gt;&lt;P&gt;Can you confirm some platform details?&lt;/P&gt;&lt;P&gt;Are you on Linux* OS or Windows* OS?&lt;/P&gt;&lt;P&gt;For Intel Graphics Technology, which OpenCL runtime are you using? Which version?&lt;/P&gt;&lt;P&gt;If you're on a recent NEO Linux Debian/Ubuntu build, can you provide the versions of intel-gmmlib_X.X.X.X, intel-igc-core_X.X.X intel-igc-opencl_X.X.X, and intel-opencl_X.X.X packages? Or perhaps at least the Device Driver Version as reported from clGetDeviceInfo(...) or a platform interrogation tool like clinfo?&lt;/P&gt;&lt;P&gt;If it's Windows* OS can you provide the Device Driver Version as reported from clGetDeviceInfo(...) or a platform interrogation tool like clinfo?&amp;nbsp;The driver revision for the package can be good as well. Reference for Windows* OS:&amp;nbsp;https://downloadcenter.intel.com/product/80939/Graphics-Drivers.&lt;/P&gt;&lt;P&gt;Any deployment details that can be provided for enabling Intel Graphics Technology/Intel(R) UHD Graphics 630&amp;nbsp;are useful... thanks.&lt;/P&gt;&lt;P&gt;-MichaelC&lt;/P&gt;</description>
    <pubDate>Sat, 29 Dec 2018 00:41:14 GMT</pubDate>
    <dc:creator>Michael_C_Intel1</dc:creator>
    <dc:date>2018-12-29T00:41:14Z</dc:date>
    <item>
      <title>OpenCL bug: 64-bit integer multiply produces incorrect result</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182701#M6735</link>
      <description>&lt;P&gt;I am running into an issue on my Intel GPU where the high 32&amp;nbsp;bits of a 64-bit product are all 0's. In particular it happens when:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. One of the operands is an immediate value&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;2. The other operand is a 64-bit long less than 2^32-1, but large enough that the product should&amp;nbsp;overflow into the higher 32 bits of the 64-bit result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have provided code to demonstrate the bug.&amp;nbsp;It copies 0xfefefefe to the device (as a 64-bit long), and multiplies it by 0x1234 and copies back the result.&lt;/P&gt;&lt;P&gt;It produces this output on my machine:&lt;/P&gt;
&lt;PRE class="brush:plain; class-name:dark;"&gt;Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Expected: 1221b9b9a798
  Actual:   1221b9b9a798
&lt;STRONG&gt;Intel(R) UHD Graphics 630
  Expected: 1221b9b9a798
  Actual:   b9b9a798&lt;/STRONG&gt;
AMD Radeon Pro 560X Compute Engine
  Expected: 1221b9b9a798
  Actual:   1221b9b9a798&lt;/PRE&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;

#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;

#ifdef __APPLE__
#define CL_SILENCE_DEPRECATION
#include &amp;lt;OpenCL/opencl.h&amp;gt;
#else
#include &amp;lt;CL/cl.h&amp;gt;
#endif

const char *_kernelSource =
"__kernel void testKernel(__global long *ptr)\
{\
    if(get_global_id(0) == 0) {\
        ptr[0] *= 0x1234;\
    }\
}";


void run_test(cl_device_id device_id)
{
    cl_context ctx;
    cl_command_queue cmd;
    cl_program prog;
    cl_kernel kernel;
    cl_int err = 0;

    ctx = clCreateContext(0, 1, &amp;amp;device_id, NULL, NULL, &amp;amp;err);
    if (!ctx)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to create a compute context!" &amp;lt;&amp;lt; std::endl;
        return;
    }

    cmd = clCreateCommandQueue(ctx, device_id, 0, &amp;amp;err);
    if (!cmd)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to create a command commands!" &amp;lt;&amp;lt; std::endl;
        return;
    }

    size_t len = strlen(_kernelSource);
    prog = clCreateProgramWithSource(ctx, 1, &amp;amp;_kernelSource, &amp;amp;len, &amp;amp;err);
    if (!prog)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to create compute program!" &amp;lt;&amp;lt; std::endl;
        return;
    }

    err = clBuildProgram(prog, 0, NULL, NULL, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        size_t len;
        char buffer[2048] = {0};

        std::cout &amp;lt;&amp;lt; "Error: Failed to build program executable! error code " &amp;lt;&amp;lt; err &amp;lt;&amp;lt; std::endl;
        clGetProgramBuildInfo(prog, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &amp;amp;len);
        std::cout &amp;lt;&amp;lt; "error: " &amp;lt;&amp;lt; buffer &amp;lt;&amp;lt; std::endl;
        return;
    }

    kernel = clCreateKernel(prog, "testKernel", &amp;amp;err);
    if (!kernel || err != CL_SUCCESS)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to create compute kernel!" &amp;lt;&amp;lt; std::endl;
        return;
    }

    size_t global = 1;
    size_t local = 0;

    err = clGetKernelWorkGroupInfo(kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &amp;amp;local, NULL);
    if (err != CL_SUCCESS)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to retrieve kernel work group info!" &amp;lt;&amp;lt; std::endl;
        return;
    }
    global = local;

    // Copy test value over to device
    uint64_t test_value = 0xfefefefe;

    cl_mem dev_ptr = clCreateBuffer(ctx, 0, sizeof(uint64_t), NULL, &amp;amp;err);
    clEnqueueWriteBuffer(cmd, dev_ptr, CL_TRUE, 0, sizeof(uint64_t), &amp;amp;test_value, 0, NULL, NULL);

    // Call the kernel
    clSetKernelArg(kernel, 0, sizeof(cl_mem), &amp;amp;dev_ptr);
    err = clEnqueueNDRangeKernel(cmd, kernel, 1, NULL, &amp;amp;global, &amp;amp;local, 0, NULL, NULL);
    if (err)
    {
        std::cout &amp;lt;&amp;lt; "Error: Failed to execute kernel! Error code " &amp;lt;&amp;lt; err &amp;lt;&amp;lt; std::endl;
        return;
    }

    clFinish(cmd);

    // Copy result back from device
    std::cout &amp;lt;&amp;lt; "  Expected: " &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; (test_value * 0x1234)  &amp;lt;&amp;lt; std::endl;
    uint64_t result;
    clEnqueueReadBuffer(cmd, dev_ptr, CL_TRUE, 0, sizeof(uint64_t), &amp;amp;result, 0, NULL, NULL);
    std::cout &amp;lt;&amp;lt; "  Actual:   " &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; result &amp;lt;&amp;lt; std::endl;
    clFinish(cmd);


    // Cleanup
    clReleaseMemObject(dev_ptr);
    clReleaseProgram(prog);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(cmd);
    clReleaseContext(ctx);

}

int main(int argc, char** argv)
{
    int err = 0;
      
    unsigned int num_platforms = 0;
   
    cl_platform_id platform_ids[10];
    std::vector&amp;lt;cl_device_id&amp;gt; device_ids;
    std::vector&amp;lt;std::string&amp;gt; device_names;

    err = clGetPlatformIDs(0, NULL, &amp;amp;num_platforms);

    if(num_platforms == 0) {
      std::cout &amp;lt;&amp;lt; "No OpenCL platforms found" &amp;lt;&amp;lt; std::endl;
      return 0; 
    }

    clGetPlatformIDs(num_platforms, platform_ids, NULL);

    // Get device ID's and names
    for(int i = 0; i &amp;lt; num_platforms; i++) {
      unsigned int num_devices = 0;
      cl_device_id ids[10];

      clGetDeviceIDs(platform_ids&lt;I&gt;, CL_DEVICE_TYPE_ALL, 0, NULL, &amp;amp;num_devices);

      if(num_devices == 0) {
        continue;
      }

      clGetDeviceIDs(platform_ids&lt;I&gt;, CL_DEVICE_TYPE_ALL, num_devices, ids, NULL);

      for(int j = 0; j &amp;lt; num_devices; j++) {
        char buf[256] = {0};
        size_t name_size;

        clGetDeviceInfo(ids&lt;J&gt;, CL_DEVICE_NAME, sizeof(buf), buf, &amp;amp;name_size);
        device_ids.push_back(ids&lt;J&gt;);
        device_names.push_back(std::string(buf));
      }
    }

    // Run the test on each device
    for(int i = 0; i &amp;lt; device_ids.size(); i++) {
      std::cout &amp;lt;&amp;lt; device_names&lt;I&gt; &amp;lt;&amp;lt; std::endl;
      run_test(device_ids&lt;I&gt;); 
    }

    return 0;
}&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 00:30:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182701#M6735</guid>
      <dc:creator>Ben_R</dc:creator>
      <dc:date>2018-12-28T00:30:25Z</dc:date>
    </item>
    <item>
      <title>Hi BenR,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182702#M6736</link>
      <description>&lt;P&gt;Hi BenR,&lt;/P&gt;&lt;P&gt;Thanks for the clear example&amp;nbsp;and the interest.&lt;/P&gt;&lt;P&gt;Can you confirm some platform details?&lt;/P&gt;&lt;P&gt;Are you on Linux* OS or Windows* OS?&lt;/P&gt;&lt;P&gt;For Intel Graphics Technology, which OpenCL runtime are you using? Which version?&lt;/P&gt;&lt;P&gt;If you're on a recent NEO Linux Debian/Ubuntu build, can you provide the versions of intel-gmmlib_X.X.X.X, intel-igc-core_X.X.X intel-igc-opencl_X.X.X, and intel-opencl_X.X.X packages? Or perhaps at least the Device Driver Version as reported from clGetDeviceInfo(...) or a platform interrogation tool like clinfo?&lt;/P&gt;&lt;P&gt;If it's Windows* OS can you provide the Device Driver Version as reported from clGetDeviceInfo(...) or a platform interrogation tool like clinfo?&amp;nbsp;The driver revision for the package can be good as well. Reference for Windows* OS:&amp;nbsp;https://downloadcenter.intel.com/product/80939/Graphics-Drivers.&lt;/P&gt;&lt;P&gt;Any deployment details that can be provided for enabling Intel Graphics Technology/Intel(R) UHD Graphics 630&amp;nbsp;are useful... thanks.&lt;/P&gt;&lt;P&gt;-MichaelC&lt;/P&gt;</description>
      <pubDate>Sat, 29 Dec 2018 00:41:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182702#M6736</guid>
      <dc:creator>Michael_C_Intel1</dc:creator>
      <dc:date>2018-12-29T00:41:14Z</dc:date>
    </item>
    <item>
      <title>Hi Michael,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182703#M6737</link>
      <description>&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I originally discovered it on MacOS, but I have reproduced it on a Windows 10 laptop with an Intel HD Graphics 530.&lt;/P&gt;&lt;P&gt;This is the version information from clinfo.exe on the Windows machine:&lt;/P&gt;
&lt;PRE class="brush:plain; class-name:dark;"&gt;  Device Name                                     Intel(R) HD Graphics 530
  Device Vendor                                   Intel(R) Corporation
  Device Vendor ID                                0x8086
  Device Version                                  OpenCL 2.0 
  Driver Version                                  21.20.16.4664
  Device OpenCL C Version                         OpenCL C 2.0 &lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 12:58:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182703#M6737</guid>
      <dc:creator>Ben_R</dc:creator>
      <dc:date>2018-12-31T12:58:00Z</dc:date>
    </item>
    <item>
      <title>BenR,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182704#M6738</link>
      <description>&lt;P&gt;BenR,&lt;/P&gt;&lt;P&gt;Thanks again for the clear example&amp;nbsp;and for following up on the version information. I've passed this sighting on to the dev team.&amp;nbsp; We'll post any issue updates to this thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-MichaelC&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 01:49:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182704#M6738</guid>
      <dc:creator>Michael_C_Intel1</dc:creator>
      <dc:date>2019-01-03T01:49:09Z</dc:date>
    </item>
    <item>
      <title>For tracking... a source code</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182705#M6739</link>
      <description>&lt;P&gt;For tracking... a source code change made it into March 2019 releases and newer:&amp;nbsp;&lt;A href="https://github.com/intel/intel-graphics-compiler/commit/fc424fc1ca78ca20b0a043da8533f6da874534f6#diff-63ce5df4a6b95d049b47c7d6b67e7c4b"&gt;Reference&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-MichaelC&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 14:42:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-bug-64-bit-integer-multiply-produces-incorrect-result/m-p/1182705#M6739</guid>
      <dc:creator>Michael_C_Intel1</dc:creator>
      <dc:date>2020-04-09T14:42:55Z</dc:date>
    </item>
  </channel>
</rss>

