c++ - 在 cpp 中找不到任何 OpenCL 平台
问题描述
我正在尝试从 opencl 编程指南执行这个 hello world 代码。它显示“找不到任何 OpenCL 平台。”。我正在使用 g++ -std=c++0x HelloWorld.cpp -o main.out -l OpenCL 编译源代码。为什么它显示“无法找到任何 OpenCL 平台。无法创建 OpenCL 上下文。”
cl_context CreateContext()
{
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformId;
cl_context context = NULL;
// First, select an OpenCL platform to run on. For this example, we
// simply choose the first available platform. Normally, you would
// query for all available platforms and select the most appropriate one.
errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
if (errNum != CL_SUCCESS || numPlatforms <= 0)
{
std::cerr << "Failed to find any OpenCL platforms." << std::endl;
return NULL;
}
// Next, create an OpenCL context on the platform. Attempt to
// create a GPU-based context, and if that fails, try to create
// a CPU-based context.
cl_context_properties contextProperties[] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)firstPlatformId,
0
};
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cout << "Could not create GPU context, trying CPU..." << std::endl;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
return NULL;
}
}
return context;
}
解决方案
推荐阅读
- tensorflow - 不生成数据增强
- ios - 无法在 Xcode 中添加推送通知功能
- asp.net-mvc - 我无法创建已发布的网站。我想在已发布的网站上创建 iis 实例
- bash - 如何使用 awk 为新创建的 bash 用户设置密码
- textures - 尝试在 2D 纹理上创建无序访问视图
- android - 在哪里可以找到按 API 级别列出的 Android 权限的完整列表?
- reactjs - 如何将 jsSIP 与 React 一起使用?
- c++ - 这个请求频率限制器线程安全吗?
- java - NoClassDefFoundError-om/google/api/client/googleapis/batch/json/JsonBatchCallback
- java - Java SimpleDateFormat 无法解析“yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSX”格式模式的日期