4

I started learning some basics about OpenCL a while ago and decided to give the "Basic programming sample" from Apple a go. I runs OK on CPU, but when I select GPU as the target device I get err = -45 from

err = gclExecKernelAPPLE(k, ndrange, &kargs);

This error code translates to CL_INVALID_PROGRAM_EXECUTABLE. Any idea how can I correct the sample code?

Automatically generated kernel.cl.c code looks like this (+ includes on top):

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;
}
4

1 回答 1

1

我在 10.7.3 下运行时看到了同样的问题,而 10.7.5 上的机器运行良好。我注意到CVMCompiler每次调用我的应用程序后该进程都崩溃了。

检查堆栈跟踪,我注意到它在尝试解析位码以编译为本机代码时崩溃。由于位码解析失败,因此没有生成的编译程序可供gclExecKernelAPPLE()执行,因此出现错误。

尝试升级到 10.7.5,或者确实是 10.8,问题应该会消失。(我刚刚对此进行了测试,它确实解决了问题。)

于 2013-02-21T05:42:59.617 回答