OpenCL does not find a platform?

I am trying to use the C ++ API for OpenCL. I installed the NVIDIA drivers, and I verified that I could run a simple vector addition program here . I can compile this program with the next call to gcc, and the program starts without problems.

gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include

However, I would prefer to use the C ++ API rather than the very detailed host files needed by C.

I downloaded the C ++ bindings from Khronos from here and put the file cl.hppin the same place as my other file cl.h. The code uses some C ++ 11, so I can compile the code with:

g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include

but when I try to run the program, I get an error:

clGetPlatformIDs(-1001)

I also tried the example provided here , which gave a more useful error message.

No platforms found. Check OpenCL installation!

The specific code that provides this error is as follows:

std::vector<cl::Platform> all_platforms;
    cl::Platform::get(&all_platforms);
    if(all_platforms.size()==0){
    std::cout<<" No platforms found. Check OpenCL installation!\n";
    exit(1);
    }

It seems so strange that the C implementation runs without a problem. Any ideas would be truly appreciated.

EDIT

The C implementation is actually not working properly. Each add is printed equal to zero. The check ret_num_platformsalso returns 0. For some reason, my installation does not find my GPU. What could i miss? My installation consists of the nvidia-340 and cuda-6.5 drivers installed through apt-getand the .runfile, respectively.

+4
source share
2 answers

@pasternak . , ubuntu apt-get cuda . .

  • nvidia cuda (sudo apt-get purge cuda* nvidia-*)
  • cuda-6.5 CODA-
  • .
  • ttyl (Ctrl-Alt-F1)
  • X- (sudo stop lightdm)
  • cuda (sh cuda_6.5.14_linux_64.run)
  • ""
  • ttyl, X- cuda "" ( ).
  • PATH, /usr/local/cuda-6.5/bin LD_LIBRARY_PATH /usr/local/cuda-6.5/lib64
  • main.c(gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include)
  • ./vectorAddition

API ++

  • cl.hpp Khronos , , 1.1
  • cl.hpp /usr/local/cuda-6.5/include/CL CL.
  • main.cpp(g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include)
  • , (./vectorAddition_cpp)

.

, Ubuntu nvidia, , cuda. , , .

+4

, , , C, , , cl.hpp . , , C :

cl_platform_id platform_id = NULL; 
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);

, 1. , OpenCL , platform_id. , , "ret", , , .

, , cl.hpp, cl:: Platform:: get:

static cl_int get(
    VECTOR_CLASS<Platform>* platforms)
{
    cl_uint n = 0;
    cl_int err = ::clGetPlatformIDs(0, NULL, &n);
    if (err != CL_SUCCESS) {
        return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
    }

    cl_platform_id* ids = (cl_platform_id*) alloca(
        n * sizeof(cl_platform_id));
    err = ::clGetPlatformIDs(n, ids, NULL);
    if (err != CL_SUCCESS) {
        return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
    }

    platforms->assign(&ids[0], &ids[n]);
    return CL_SUCCESS;
}

,

::clGetPlatformIDs(0, NULL, &n);

, 0, OpenCL runtime "n". , "n".

, , C , , , cl.hpp - , , .

, ICD . , :

ERROR: clGetPlatformID -1001 OpenCL (Linux)

, .

+2

All Articles