OpenCL 1.2 C ++ Wrapper - undefined link to clReleaseDevice

I am trying to use the OpenCL C ++ shell API for the following program:

#define __CL_ENABLE_EXCEPTIONS


#include <CL/cl.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>

 const char helloStr []  = "__kernel void "
                          "hello(void) "
                          "{ "
                          "  "
                          "} ";

 int
 main(void)
 {
    cl_int err = CL_SUCCESS;
    try {

      std::vector<cl::Platform> platforms;
      cl::Platform::get(&platforms);
      if (platforms.size() == 0) {
          std::cout << "Platform size 0\n";
          return -1;
      }

      cl_context_properties properties[] =
         { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
      cl::Context context(CL_DEVICE_TYPE_CPU, properties);

      std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();

      cl::Program::Sources source(1,
          std::make_pair(helloStr,strlen(helloStr)));
      cl::Program program_ = cl::Program(context, source);
      program_.build(devices);

      cl::Kernel kernel(program_, "hello", &err);

      cl::Event event;
      cl::CommandQueue queue(context, devices[0], 0, &err);
      queue.enqueueNDRangeKernel(
          kernel,
          cl::NullRange,
          cl::NDRange(4,4),
          cl::NullRange,
          NULL,
          &event);

      event.wait();
    }
    catch (cl::Error err) {
       std::cerr
          << "ERROR: "
          << err.what()
          << "("
          << err.err()
          << ")"
          << std::endl;
    }

   return EXIT_SUCCESS;
 }

I use the same kernel file from this blog post, anyway, this is not a problem since I cannot compile.

I compile the program with the following command:

g++ example.cpp -o example -l OpenCL

and I get the following error message:

/tmp/ccbUf7dB.o: In function `cl::detail::ReferenceHandler<_cl_device_id*>::release(_cl_device_id*)':
example.cpp:(.text._ZN2cl6detail16ReferenceHandlerIP13_cl_device_idE7releaseES3_[_ZN2cl6detail16ReferenceHandlerIP13_cl_device_idE7releaseES3_]+0x14): undefined reference to `clReleaseDevice'
collect2: error: ld returned 1 exit status

I read material that clReleaseDevice does not work for legacy devices (see for example this question ), but my graphics card is quite recent (NVidia GTX 660 Ti, supports OpenCL 1.2). Where can I go from there?

I am running this on Ubuntu 13.04 x64 with nvidia-opencl-dev and opencl headers installed from ubuntu repositories.

+5
source share
2

, OpenCL, , OpenCL 1.2. , OpenCL, , , , OpenCL, . :

  • cl.hpp Khronos, OpenCL, , , .
  • OpenCL, OpenCL, - OpenCL, , OpenCL, . , , ++-.. OpenCL 1.2 , OpenCL 1.2, segfault, .

Nvidia

Nvidia , OpenCL 1.2. OpenCL OpenCL 1.2, , .

2015 Nvidia , OpenCL 1.2, . Z Boson . . GeForce GTX 6xx ( ) OpenCL 1.2. Khronos OpenCL, . GTX 660 Ti , .

+10

. OpenCL 1.2 Nvidia. "OpenCL C Version":

#include <iostream>
#include <vector>
#include <CL/cl.hpp>

int main() {

    // Get the platforms
    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    // Loop over the number of platforms
    for ( size_t i = 0; i < platforms.size(); ++i ) {

        // Display the platform information
        std::cout << "Platform " << i+1 << ": "
                            << platforms[i].getInfo<CL_PLATFORM_NAME>()
        << "\n----------------------------------------------"
        << "\nVendor    : " << platforms[i].getInfo<CL_PLATFORM_VENDOR>()
        << "\nVersion   : " << platforms[i].getInfo<CL_PLATFORM_VERSION>();

        // Get the devices on the current platform
        std::vector <cl::Device> devices;
        platforms[i].getDevices( CL_DEVICE_TYPE_ALL , & devices);

        // Loop over the devices
        std::cout << "\n----------------------------------------------\n";
        for ( size_t j = 0; j < devices.size(); ++j ) {

            // Display the device information
            std::cout
            << "\n   Device " << j+1 << ": "
            <<          devices[j].getInfo< CL_DEVICE_NAME >()
            << "\n\t Device Version     : "
            <<          devices[j].getInfo< CL_DEVICE_VERSION >()
            << "\n\t OpenCL C Version   : "
            <<          devices[j].getInfo< CL_DEVICE_OPENCL_C_VERSION >()
            << "\n\t Compute Units      : "
            <<          devices[j].getInfo< CL_DEVICE_MAX_COMPUTE_UNITS >()
            << "\n\t Max Work Group Size: "
            <<          devices[j].getInfo< CL_DEVICE_MAX_WORK_GROUP_SIZE >()
            << "\n\t Clock Frequency    : "
            <<          devices[j].getInfo< CL_DEVICE_MAX_CLOCK_FREQUENCY >()
            << "\n\t Local Memory Size  : "
            <<          devices[j].getInfo< CL_DEVICE_LOCAL_MEM_SIZE >()
            << "\n\t Global Memory Size : "
            <<          devices[j].getInfo< CL_DEVICE_GLOBAL_MEM_SIZE >();

            // Check if the device supports double precision
            std::string str = devices[j].getInfo<CL_DEVICE_EXTENSIONS>();
            size_t found = str.find("cl_khr_fp64");
            std::cout << "\n\t Double Precision   : ";
            if ( found != std::string::npos ){ std::cout << "yes\n"; }
            else {                             std::cout <<  "no\n"; }
        }
        std::cout << "\n----------------------------------------------\n";
    }
//  std::cin.ignore();
    return 0;
}
0

All Articles