OpenCL 1.2 C++;包装器-对clReleaseDevice的未定义引用
我尝试使用OpenCL C++包装器API来执行以下程序:OpenCL 1.2 C++;包装器-对clReleaseDevice的未定义引用,opencl,nvidia,Opencl,Nvidia,我尝试使用OpenCL C++包装器API来执行以下程序: #define __CL_ENABLE_EXCEPTIONS #include <CL/cl.hpp> #include <cstdio> #include <cstdlib> #include <iostream> const char helloStr [] = "__kernel void " "hello(void) "
#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;
}
我得到以下错误消息:
/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
/tmp/ccbUf7dB.o:在函数'cl::detail::ReferenceHandler::release(\u cl\u device\u id*)中:
示例.cpp:(.text._ZN2cl6detail16ReferenceHandlerIP13\u cl\u device\u idE7releaseES3\uzn2cl6detail16referencehandlerip13\u cl\u device\u idE7releaseES3\u14):未定义对“clReleaseDevice”的引用
collect2:错误:ld返回了1个退出状态
我读过一些关于clReleaseDevice不适用于传统设备的文章(例如,请参阅),但我的图形卡是最近开发的(NVidia GTX 660 Ti,支持OpenCL 1.2)。从那里我可以去哪里
我在Ubuntu13.04 x64上运行这个程序,并从UbuntuRepositories安装了nvidia opencl dev和opencl头。根本原因是什么
问题是您所链接的OpenCL库不支持OpenCL 1.2。一般说来,在支持您想要使用的版本的OpenCL实现可用于特定平台之前,在与提供的OpenCL共享库进行链接时,您将遇到此问题。有两种解决方案:
- 从Khronos下载与所选硬件提供的OpenCL版本相匹配的cl.hpp版本,并继续使用设备制造商提供的库
- 链接到实现最新OpenCL标准的OpenCL共享库,但编写多个代码路径-每个OpenCL版本一个,确保每个代码路径仅使用该版本支持的OpenCL函数<强>这个路由比较难,我不知道如何使用C++包装。< /强>如果你在不支持OpenCL 1.2的平台上调用OpenCL 1.2函数,你会得到一个Sebug,这就是为什么需要不同的代码路径。
2015年5月底,Nvidia发布了支持OpenCL 1.2的驱动程序,请参见下面Z Boson的评论。更新驱动程序应该可以解决链接器错误。GeForce GTX 6xx和更高版本的卡(早期品牌的更名除外)支持OpenCL 1.2。您可以在Khronos OpenCL站点上查看以确保。GTX 660 Ti已上市,因此您很幸运。是的。我从未在Nvidia设备上见过OpenCL1.2。在您的系统上编译此文件,并查看“OpenCLC版本”:
#包括
#包括
#包括
int main(){
//拿到平台
向量平台;
cl::平台::获取(&platforms);
//在平台的数量上循环
对于(size_t i=0;i std::无法尝试将-DCL\u USE\u DEPRECATED\u OPENCL\u 1\u api
添加到您的makefile中。不做任何更改..我浏览了CL/CL.hpp文件,与此define捆绑的代码似乎与此函数调用无关。如果您将\define CL\u USE\u DEPRECATED\u OPENCL\u 1\u 1\u api;#包括“CL/CL.h”怎么办##未定义CL#U版本#1#2#定义#CL#U启用#例外#包括“CL-1.2.hpp”
这行得通吗?我在亚马逊AWS nvidia上用ubuntu 14.04试用过,似乎还可以?我通过谷歌搜索得到了OpenCL 1.2支持,但似乎我错了!谢谢。谢谢你-刚刚遇到了同样的问题!nvidia现在在Linux和Windows上支持OpenCL 1.2“最近,NVIDIA还最终向其专有的Linux驱动程序添加了OpenCL 1.2支持。”以及“是的,NVIDIA 352.84和352.63的最新Win10驱动程序包括OpenCL 1.2支持。”
/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
#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;
}