如何运行Apple的OpenCL"Hello World" XCode中的示例 [英] How to run Apple's OpenCL "Hello World" example in XCode
问题描述
Apple提供了一个OpenCL"Hello World"示例,可以从以下页面将其作为.zip
文件下载:
Apple provides an OpenCL "Hello World" example, which can be downloaded as a .zip
file from the following page:
我下载了它,在Xcode中打开了项目,然后单击了Run
.构建成功,但是出现以下错误消息: Error: Failed to create a device group!
I downloaded it, opened the project in Xcode, and clicked Run
. The build succeeded, but I got the following error message: Error: Failed to create a device group!
对于在Mac上运行一个简单的OpenCL示例的任何建议,我将不胜感激.如果它在诊断上是相关的:我在2011年初的MacBook Pro上运行Mac OS 10.7.5,并且安装了Xcode 4.2.
I would appreciate any advice on how to get a simple OpenCL example running on my Mac. In case it is diagnostically relevant: I'm running Mac OS 10.7.5 on an early 2011 MacBook Pro, and I have Xcode version 4.2 installed.
推荐答案
万岁,我自己解决了这个问题. Apple提供的hello.c
文件包含以下代码行:
Hooray, I worked it out myself. The hello.c
file that Apple provides contains the following lines of code:
114 // Connect to a compute device
115 //
116 int gpu = 1;
117 err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);
118 if (err != CL_SUCCESS)
119 {
120 printf("Error: Failed to create a device group!\n");
121 return EXIT_FAILURE;
122 }
代码正在尝试获取支持OpenCL的GPU设备的ID.问题是我的机器(MacBook Pro,2011年初)没有支持OpenCL的GPU.如果改为设置CL_DEVICE_TYPE_CPU
标志,则找到CPU,并且此确实支持OpenCL.如果文件修改如下:
The code is trying to get the id of a GPU device that supports OpenCL. The problem is that my machine (MacBook Pro, Early 2011) doesn't have a GPU that supports OpenCL. If the CL_DEVICE_TYPE_CPU
flag is set instead, then the CPU is found, and this does support OpenCL. If the file is modified as follows:
116 int gpu = 0;
然后我得到输出: Computed '1024/1024' correct values!
then I get the output: Computed '1024/1024' correct values!
这篇关于如何运行Apple的OpenCL"Hello World" XCode中的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!