OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

OpenCL clGetPlatformIDs gives 26 valgrind memcheck errors

RN1
New Contributor I
678 Views

The code:

// 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 <CL/cl.h>
#include <CL/cl.hpp>
#include <vector>
#include <string>
#include <iostream>
#include <memory>

using namespace std;

#define CL_CHECK_ERROR(error)                                    \
  if ((error) != CL_SUCCESS){ cout << "ERROR in " << __FILE__ << ":" << __LINE__ << "\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<cl_platform_id> platforms;
    cl_uint num_platforms;

    CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &num_platforms));
    cout << "num_platforms: " << num_platforms << "\n";
    platforms.reserve(num_platforms);
    platforms.resize(num_platforms);
    CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.data(), NULL));
    cout << "- " << platforms.data()[0] << "\n";
    // cout << "- " << platforms.data()[1] << "\n";
    // cout << platforms.size() << "\n";
    for (auto& platform : platforms){
      cout << platform << "\n";
      size_t size;
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &size));
      info_buffer.resize(size); // works also with size - 1
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
      cout << "platform: '" << info_buffer << "'\n";
    }

  }else if (type == 1){

    cl_uint num_platforms;

    CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &num_platforms));
    cout << "num_platforms: " << num_platforms << "\n";
    unique_ptr<cl_platform_id[]> platforms(new cl_platform_id[num_platforms]);

    CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.get(), NULL));
    cout << "- " << platforms[0] << "\n";
    // cout << "- " << platforms[1] << "\n";
    for (uint i=0; i<num_platforms; i++){
      cl_platform_id platform = platforms;
      cout << platforms << "\n";
      size_t size;
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &size));
      info_buffer.resize(size); // works also with size - 1
      CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
      cout << "platform: '" << info_buffer << "'\n";
    }

  } else {
    vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);
    cout << "num_platforms: " << platforms.size() << "\n";
    cout << "- " << platforms.at(0)() << "\n";
    // cout << "- " << platforms[1] << "\n";
    for (auto& platform : platforms) {
      CL_CHECK_ERROR(platform.getInfo(CL_PLATFORM_NAME, &info_buffer));
      cout << "platform: " << info_buffer << "\n";
    }
  }

  return 0;
}



The compilation:

g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query

Valgrind:

valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 0 2>query_t0.memcheck

valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 1 2>query_t1.memcheck

valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 2 2>query_t2.memcheck


In all cases (t0, t1 with .h, t2 with .hpp):

==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)


Some errors (from the t2):

==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<cl::Platform, std::allocator<cl::Platform> >*) (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&) (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<cl::Platform, std::allocator<cl::Platform> >*) (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<cl::Platform, std::allocator<cl::Platform> >*) (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&) (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<cl::Platform, std::allocator<cl::Platform> >*) (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&) (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<cl::Platform, std::allocator<cl::Platform> >*) (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<cl::Platform, std::allocator<cl::Platform> >*) (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<cl::Platform, std::allocator<cl::Platform> >*) (cl.hpp:2338)
=2304==    by 0x10B77C: cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*) (cl.hpp:2338)


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?

 

0 Kudos
1 Reply
Ben_A_Intel
Employee
678 Views

This looks a lot like an issue that was discussed on the Khronos github:

https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/13

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.  Could this be the same issue?

0 Kudos
Reply