【发布时间】:2012-08-27 23:27:48
【问题描述】:
不久前我开始学习一些有关 OpenCL 的基础知识,并决定试试 Apple 的 "Basic programming sample"。我在 CPU 上运行正常,但是当我选择 GPU 作为目标设备时,我得到 err = -45 from
err = gclExecKernelAPPLE(k, ndrange, &kargs);
此错误代码转换为CL_INVALID_PROGRAM_EXECUTABLE。知道如何更正示例代码吗?
自动生成的kernel.cl.c 代码如下所示(+ 包含在顶部):
static void initBlocks(void);
// Initialize static data structures
static block_kernel_pair pair_map[1] = {
{ NULL, NULL }
};
static block_kernel_map bmap = { 0, 1, initBlocks, pair_map };
// Block function
void (^square_kernel)(const cl_ndrange *ndrange, cl_float* input, cl_float* output) =
^(const cl_ndrange *ndrange, cl_float* input, cl_float* output) {
int err = 0;
cl_kernel k = bmap.map[0].kernel;
if (!k) {
initBlocks();
k = bmap.map[0].kernel;
}
if (!k)
gcl_log_fatal("kernel square does not exist for device");
kargs_struct kargs;
gclCreateArgsAPPLE(k, &kargs);
err |= gclSetKernelArgMemAPPLE(k, 0, input, &kargs);
err |= gclSetKernelArgMemAPPLE(k, 1, output, &kargs);
gcl_log_cl_fatal(err, "setting argument for square failed");
err = gclExecKernelAPPLE(k, ndrange, &kargs);
gcl_log_cl_fatal(err, "Executing square failed");
gclDeleteArgsAPPLE(k, &kargs);
};
// Initialization functions
static void initBlocks(void) {
const char* build_opts = " -cl-std=CL1.1";
static dispatch_once_t once;
dispatch_once(&once,
^{ int err = gclBuildProgramBinaryAPPLE("OpenCL/kernel.cl", "", &bmap, build_opts);
if (!err) {
assert(bmap.map[0].block_ptr == square_kernel && "mismatch block");
bmap.map[0].kernel = clCreateKernel(bmap.program, "square", &err);
}
});
}
__attribute__((constructor))
static void RegisterMap(void) {
gclRegisterBlockKernelMap(&bmap);
bmap.map[0].block_ptr = square_kernel;
}
【问题讨论】:
-
我假设您正在使用 GPU 创建队列,但是这个 GPU 是否支持 openCL?
-
是的,使用 gpu 创建队列,是的,gpu 支持 opencl (ati HD6750M)。事实上,它在使用非苹果方法时运行正常。我只想知道为什么“官方”的方式会失败?
-
如果您不通过构建选项会发生什么行为,即 build_opts = "-cl-std=CL1.1"... ?你还有这个错误吗?
-
@ocluser 我不能跳过这个特定的选项,xcode 会自动包含它。但是,我可以更改一个选项。是架构。默认情况下,它是一个字符串“i386 x86_64 gpu_32”。无论我在这里进行什么更改,它在 CPU 上运行正常,但在 GPU 上以 -45 失败。即使我只放了“gpu_32”,它也可以在 CPU 上运行,但不能在 GPU 上运行。这几乎就像选项没有传递给 opencl 编译器一样。
标签: xcode macos osx-lion opencl