1

我是 OpenCL 编程的新手。我的第一个程序让我很难过。我想查询每个平台中每个设备的设备名称和供应商名称。我的系统有两个平台,第一个是AMD平台,第二个是NVIDIA CUDA平台。我编写了以下代码来获取所需的信息。

 int main(int argc, char **argv) {

    try {
            vector<cl::Platform>platforms;
            cl::Platform::get(&platforms);

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

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

            string dName(devices[0].getInfo<CL_DEVICE_NAME>());
            string vendor(devices[0].getInfo<CL_DEVICE_VENDOR>());

            cout<<"\tDevice Name:"<<dName<<endl;
            cout<<"\tDevice Vendor: "<<vendor<<endl;    
    }catch(cl::Error  err) {
            cerr<<err.what()<<" error: "<<printErrorString(err.err())<<endl;

            return 0;
    }

}

当我将平台索引更改为 1 时

    cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; 

我的程序因“分段错误”而崩溃。

我真的很感谢你的帮助。谢谢!

4

1 回答 1

1

我怀疑您使用的是 AMD APP SDK 中的 cl.hpp 头文件?如果是这种情况,那么问题在于头文件调用了 OpenCL 1.2 函数(不记得是哪个函数),该函数由系统中的 AMD 设备提供,而不是由 Nvidia GPU 提供。您的 Nvidia GPU 仅支持 OpenCL 1.1。我知道的最佳解决方案是使用来自 Khronos 网站的 OpenCL 1.1 的头文件。

于 2013-06-17T15:43:12.967 回答