OpenCL找不到平台? [英] OpenCL not finding platforms?

查看:686
本文介绍了OpenCL找不到平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将C ++ API用于OpenCL.我已经安装了NVIDIA驱动程序,并进行了测试,可以运行提供的简单矢量添加程序此处.我可以通过下面的gcc调用来编译该程序,并且程序可以正常运行.

I am trying to utilize the C++ API for OpenCL. I have installed my NVIDIA drivers and I have tested that I can run the simple vector addition program provided here. I can compile this program with following gcc call and the program runs without problem.

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

但是,我非常喜欢使用C ++ API,而不是C所需的非常冗长的宿主文件.

However, I would very much prefer to use the C++ API as opposed the very verbose host files needed for C.

我从此处从Khronos下载了C ++绑定将cl.hpp文件放置在与其他cl.h文件相同的位置.该代码使用一些C ++ 11,因此我可以使用以下代码进行编译:

I downloaded the C++ bindings from Khronos from here and placed the cl.hpp file in the same location as my other cl.h file. 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 the error:

clGetPlatformIDs(-1001)

我还尝试了提供的示例在这里,并且给出了更有用的错误消息.

I also tried the example provided here as well which gave a more helpful error message.

No platforms found. Check OpenCL installation!

提供此错误的特定代码是:

The particular code which provides this error is this:

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);
    }

鉴于C实现可以毫无问题地运行,因此这似乎很奇怪.我们将不胜感激任何见解.

This seems so strange given that the C implementation runs without problem. Any insights would be sincerely appreciated.

编辑

C实现实际上未正确运行.每个加法打印为零.检查ret_num_platforms也会返回0.由于某种原因,我的设置无法找到我的GPU.我可能错过了什么?我的安装包含分别通过apt-get.run文件安装的nvidia-340驱动程序和cuda-6.5.

The C implementation actually isn't running correctly. Each addition is printed to equal zero. Checking the ret_num_platforms also returns 0. For some reason my setup is failing to find my GPU. What could I have missed? My install consists of the nvidia-340 driver and cuda-6.5 installed via apt-get and the .run file respectively.

推荐答案

衷心感谢@pasternak帮助我解决此问题.为了解决这个问题,我最终需要避免基本上所有的ubuntu apt-get调用进行安装,而仅使用cuda运行文件进行完整安装.这是解决问题的方法.

My sincerest thanks to @pasternak for helping me troubleshoot this problem. To solve it however I ended up needing to avoid essentially all ubuntu apt-get calls for install and just use the cuda run file for the full installation. Here is what fixed the problem.

  1. 清除现有的nvidia和cuda实现(sudo apt-get purge cuda* nvidia-*)
  2. CUDA工具包归档文件中下载cuda-6.5工具包
  3. 重新启动计算机
  4. 切换到ttyl(Ctrl-Alt-F1)
  5. 停止X服务器(sudo stop lightdm)
  6. 运行cuda运行文件(sh cuda_6.5.14_linux_64.run)
  7. 选择是"并接受所有默认值
  8. 需要重启
  9. 切换到ttyl,停止X服务器并再次运行cuda运行文件,然后选择是",并为所有内容(包括驱动程序)重新设置为默认值
  10. 更新PATH以包括/usr/local/cuda-6.5/binLD_LIBRARY_PATH 包括/usr/local/cuda-6.5/lib64
  11. 重新启动
  12. 编译main.c程序(gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include)
  13. 验证可与./vectorAddition
  14. 一起使用
  1. Purge existing nvidia and cuda implementations (sudo apt-get purge cuda* nvidia-*)
  2. Download cuda-6.5 toolkit from the CUDA toolkit archive
  3. Reboot computer
  4. Switch to ttyl (Ctrl-Alt-F1)
  5. Stop the X server (sudo stop lightdm)
  6. Run the cuda run file (sh cuda_6.5.14_linux_64.run)
  7. Select 'yes' and accept all defaults
  8. Required reboot
  9. Switch to ttyl, stop X server and run the cuda run file again and select 'yes' and default for everything (including the driver again)
  10. Update PATH to include /usr/local/cuda-6.5/bin and LD_LIBRARY_PATH to include /usr/local/cuda-6.5/lib64
  11. Reboot again
  12. Compile main.c program (gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include)
  13. Verify works with ./vectorAddition

C ++ API

  1. 从Khronos 此处下载cl.hpp文件,请注意它是1.1版
  2. 将cl.hpp文件和其他cl标头放置在/usr/local/cuda-6.5/include/CL中.
  3. 编译main.cpp(g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include)
  4. 验证它是否有效(./vectorAddition_cpp)
  1. Download cl.hpp file from Khronos here noting that it is version 1.1
  2. Place cl.hpp file in /usr/local/cuda-6.5/include/CL with other cl headers.
  3. Compile main.cpp (g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include)
  4. Verify it works (./vectorAddition_cpp)

两个程序的所有输出均显示正确的输出,以实现向量之间的加法.

All output from both programs show the correct output for addition between vectors.

我个人觉得很有趣,Ubuntu的nvidia驱动程序似乎不能与cuda工具包配合使用.可能仅适用于旧版本,但仍然非常意外.

I personally find it interesting the Ubuntu's nvidia drivers don't seem to play well with the cuda toolkits. Possibly just for the older versions but still very unexpected.

这篇关于OpenCL找不到平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆