<?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 This looks a lot like an in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-clGetPlatformIDs-gives-26-valgrind-memcheck-errors/m-p/1174916#M6629</link>
    <description>&lt;P&gt;This looks a lot like an issue that was discussed on the Khronos github:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/13" target="_blank"&gt;https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/13&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In the end, it was closed because there was no clean de-initialization or exit point to free platform information allocated in the OpenCL ICD loader.&amp;nbsp; Could this be the same issue?&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2017 20:45:45 GMT</pubDate>
    <dc:creator>Ben_A_Intel</dc:creator>
    <dc:date>2017-12-19T20:45:45Z</dc:date>
    <item>
      <title>OpenCL clGetPlatformIDs gives 26 valgrind memcheck errors</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-clGetPlatformIDs-gives-26-valgrind-memcheck-errors/m-p/1174915#M6628</link>
      <description>&lt;P&gt;The code:&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;// g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query
// valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query N

#include &amp;lt;CL/cl.h&amp;gt;
#include &amp;lt;CL/cl.hpp&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;memory&amp;gt;

using namespace std;

#define CL_CHECK_ERROR(error)                                    \
  if ((error) != CL_SUCCESS){ cout &amp;lt;&amp;lt; "ERROR in " &amp;lt;&amp;lt; __FILE__ &amp;lt;&amp;lt; ":" &amp;lt;&amp;lt; __LINE__ &amp;lt;&amp;lt; "\n"; }

int main(int, char * argv[])
{
  int type = stoi(argv[1]);

  string info_buffer;
  int info_buffer_size = 1024;
  info_buffer.reserve(info_buffer_size);

  if (type == 0){

    vector&amp;lt;cl_platform_id&amp;gt; platforms;
    cl_uint num_platforms;

    CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &amp;amp;num_platforms));
    cout &amp;lt;&amp;lt; "num_platforms: " &amp;lt;&amp;lt; num_platforms &amp;lt;&amp;lt; "\n";
    platforms.reserve(num_platforms);
    platforms.resize(num_platforms);
    CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.data(), NULL));
    cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms.data()[0] &amp;lt;&amp;lt; "\n";
    // cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms.data()[1] &amp;lt;&amp;lt; "\n";
    // cout &amp;lt;&amp;lt; platforms.size() &amp;lt;&amp;lt; "\n";
    for (auto&amp;amp; platform : platforms){
      cout &amp;lt;&amp;lt; platform &amp;lt;&amp;lt; "\n";
      size_t size;
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &amp;amp;size));
      info_buffer.resize(size); // works also with size - 1
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
      cout &amp;lt;&amp;lt; "platform: '" &amp;lt;&amp;lt; info_buffer &amp;lt;&amp;lt; "'\n";
    }

  }else if (type == 1){

    cl_uint num_platforms;

    CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &amp;amp;num_platforms));
    cout &amp;lt;&amp;lt; "num_platforms: " &amp;lt;&amp;lt; num_platforms &amp;lt;&amp;lt; "\n";
    unique_ptr&amp;lt;cl_platform_id[]&amp;gt; platforms(new cl_platform_id[num_platforms]);

    CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.get(), NULL));
    cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms[0] &amp;lt;&amp;lt; "\n";
    // cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms[1] &amp;lt;&amp;lt; "\n";
    for (uint i=0; i&amp;lt;num_platforms; i++){
      cl_platform_id platform = platforms&lt;I&gt;;
      cout &amp;lt;&amp;lt; platforms&lt;I&gt; &amp;lt;&amp;lt; "\n";
      size_t size;
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &amp;amp;size));
      info_buffer.resize(size); // works also with size - 1
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
      cout &amp;lt;&amp;lt; "platform: '" &amp;lt;&amp;lt; info_buffer &amp;lt;&amp;lt; "'\n";
    }

  } else {
    vector&amp;lt;cl::Platform&amp;gt; platforms;
    cl::Platform::get(&amp;amp;platforms);
    cout &amp;lt;&amp;lt; "num_platforms: " &amp;lt;&amp;lt; platforms.size() &amp;lt;&amp;lt; "\n";
    cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms.at(0)() &amp;lt;&amp;lt; "\n";
    // cout &amp;lt;&amp;lt; "- " &amp;lt;&amp;lt; platforms[1] &amp;lt;&amp;lt; "\n";
    for (auto&amp;amp; platform : platforms) {
      CL_CHECK_ERROR(platform.getInfo(CL_PLATFORM_NAME, &amp;amp;info_buffer));
      cout &amp;lt;&amp;lt; "platform: " &amp;lt;&amp;lt; info_buffer &amp;lt;&amp;lt; "\n";
    }
  }

  return 0;
}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	The compilation:&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;PRE class="brush:;"&gt;g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query
&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Valgrind:&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;PRE class="brush:;"&gt;valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 0 2&amp;gt;query_t0.memcheck

valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 1 2&amp;gt;query_t1.memcheck

valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 2 2&amp;gt;query_t2.memcheck&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;/P&gt;

&lt;P&gt;In all cases (t0, t1 with .h, t2 with .hpp):&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;PRE class="brush:;"&gt;==2208== LEAK SUMMARY:
==2208==    definitely lost: 1,072 bytes in 5 blocks
==2208==    indirectly lost: 76 bytes in 2 blocks
==2208==      possibly lost: 368 bytes in 1 blocks
==2208==    still reachable: 60,016 bytes in 209 blocks
==2208==         suppressed: 0 bytes in 0 blocks
==2208== Reachable blocks (those to which a pointer was found) are not shown.
==2208== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2208==
==2208== For counts of detected and suppressed errors, rerun with: -v
==2208== ERROR SUMMARY: 26 errors from 20 contexts (suppressed: 0 from 0)&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;/P&gt;

&lt;P&gt;Some errors (from the t2):&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;PRE class="brush:;"&gt;==2304== Conditional jump or move depends on uninitialised value(s)
==2304==    at 0x7B2B183: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7B0DEA2: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7AF90AA: clIcdGetPlatformIDsKHR (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304==  Uninitialised value was created by a heap allocation
==2304==    at 0x4C2D7FF: operator new(unsigned long, std::nothrow_t const&amp;amp;) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x7B0DE8A: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7AF90AA: clIcdGetPlatformIDsKHR (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304== Conditional jump or move depends on uninitialised value(s)
==2304==    at 0x7B0DED7: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7AF90AA: clIcdGetPlatformIDsKHR (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304==  Uninitialised value was created by a heap allocation
==2304==    at 0x4C2D7FF: operator new(unsigned long, std::nothrow_t const&amp;amp;) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x7B0DE8A: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7AF90AA: clIcdGetPlatformIDsKHR (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304== Conditional jump or move depends on uninitialised value(s)
==2304==    at 0x7B0C988: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7B0CE6C: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7B61D9F: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x400FB92: _dl_fini (in /usr/lib/ld-2.26.so)
==2304==    by 0x5962487: __run_exit_handlers (in /usr/lib/libc-2.26.so)
==2304==    by 0x59624D9: exit (in /usr/lib/libc-2.26.so)
==2304==    by 0x594BF70: (below main) (in /usr/lib/libc-2.26.so)
==2304==  Uninitialised value was created by a heap allocation
==2304==    at 0x4C2D7FF: operator new(unsigned long, std::nothrow_t const&amp;amp;) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x7B0DE8A: ??? (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x7AF90AA: clIcdGetPlatformIDsKHR (in /opt/intel/opencl/libigdrcl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304== 8 bytes in 1 blocks are definitely lost in loss record 5 of 171
==2304==    at 0x4C2CEFF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x4E3B7C8: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
==2304==    by 0x10B143: main (query.cpp:69)
==2304==
==2304== 64 bytes in 1 blocks are definitely lost in loss record 136 of 171
==2304==    at 0x4C2CEFF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x4014015: dl_open_worker (in /usr/lib/ld-2.26.so)
==2304==    by 0x5A5D143: _dl_catch_error (in /usr/lib/libc-2.26.so)
==2304==    by 0x4013319: _dl_open (in /usr/lib/ld-2.26.so)
==2304==    by 0x5F01E85: ??? (in /usr/lib/libdl-2.26.so)
==2304==    by 0x5A5D143: _dl_catch_error (in /usr/lib/libc-2.26.so)
==2304==    by 0x5F02586: ??? (in /usr/lib/libdl-2.26.so)
==2304==    by 0x5F01F21: dlopen (in /usr/lib/libdl-2.26.so)
==2304==    by 0x758EDE1: ??? (in /opt/intel/opencl/libtbbmalloc.so.2)
==2304==    by 0x400F519: call_init.part.0 (in /usr/lib/ld-2.26.so)
==2304==    by 0x400F625: _dl_init (in /usr/lib/ld-2.26.so)
==2304==    by 0x4013AFD: dl_open_worker (in /usr/lib/ld-2.26.so)
==2304==
==2304== 278 (240 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 149 of 171
==2304==    at 0x4C2D56F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x69FE787: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x69750C0: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x6975911: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x698B734: clGetPlatformIDs (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
===2304== 286 (248 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 150 of 171
==2304==    at 0x4C2D56F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2304==    by 0x69FE8B9: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x69750C0: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x6975911: ??? (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x698B734: clGetPlatformIDs (in /opt/intel/opencl/libintelocl.so)
==2304==    by 0x65284E3: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x6508F1F: ??? (in /opt/intel/opencl/libIntelOpenCL.so)
==2304==    by 0x4E3B77D: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x4E3D6CE: ??? (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x5CF1DBE: __pthread_once_slow (in /usr/lib/libpthread-2.26.so)
==2304==    by 0x4E3BD20: clGetPlatformIDs (in /opt/intel/opencl/libOpenCL.so.1)
==2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)
=2304==    by 0x10B77C: cl::Platform::get(std::vector&amp;lt;cl::Platform, std::allocator&amp;lt;cl::Platform&amp;gt; &amp;gt;*) (cl.hpp:2338)&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;/P&gt;

&lt;P&gt;As you can see, I have tried three different ways to query the platforms (t0, t1 using the C API, t2 using the C++ API). How can I remove the memory leaks in my code? Am I doing something wrong?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 13:30:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-clGetPlatformIDs-gives-26-valgrind-memcheck-errors/m-p/1174915#M6628</guid>
      <dc:creator>RN1</dc:creator>
      <dc:date>2017-12-18T13:30:28Z</dc:date>
    </item>
    <item>
      <title>This looks a lot like an</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-clGetPlatformIDs-gives-26-valgrind-memcheck-errors/m-p/1174916#M6629</link>
      <description>&lt;P&gt;This looks a lot like an issue that was discussed on the Khronos github:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/13" target="_blank"&gt;https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/13&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In the end, it was closed because there was no clean de-initialization or exit point to free platform information allocated in the OpenCL ICD loader.&amp;nbsp; Could this be the same issue?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:45:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-clGetPlatformIDs-gives-26-valgrind-memcheck-errors/m-p/1174916#M6629</guid>
      <dc:creator>Ben_A_Intel</dc:creator>
      <dc:date>2017-12-19T20:45:45Z</dc:date>
    </item>
  </channel>
</rss>

