问题描述
我正在尝试将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.
- 清除现有的nvidia和cuda实现(
sudo apt-get purge cuda* nvidia-*
) - 从 CUDA工具包归档文件中下载cuda-6.5工具包
- 重新启动计算机
- 切换到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
一起使用
- Purge existing nvidia and cuda implementations (
sudo apt-get purge cuda* nvidia-*
) - Download cuda-6.5 toolkit from the CUDA toolkit archive
- Reboot computer
- Switch to ttyl (Ctrl-Alt-F1)
- Stop the X server (sudo stop lightdm)
- Run the cuda run file (
sh cuda_6.5.14_linux_64.run
) - Select 'yes' and accept all defaults
- Required reboot
- Switch to ttyl, stop X server and run the cuda run file again and select 'yes' and default for everything (including the driver again)
- Update
PATH
to include/usr/local/cuda-6.5/bin
andLD_LIBRARY_PATH
to include/usr/local/cuda-6.5/lib64
- Reboot again
- Compile main.c program (
gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include
) - Verify works with
./vectorAddition
C ++ API
- 从Khronos 此处下载
cl.hpp
文件,请注意它是1.1版 - 将cl.hpp文件和其他cl标头放置在
/usr/local/cuda-6.5/include/CL
中. - 编译main.cpp(
g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include
) - 验证它是否有效(
./vectorAddition_cpp
)
- Download
cl.hpp
file from Khronos here noting that it is version 1.1 - Place cl.hpp file in
/usr/local/cuda-6.5/include/CL
with other cl headers. - Compile main.cpp (
g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include
) - 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找不到平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!