1

我正在尝试使用 OpenCL 作为我提前编译的目标。在我的 Halide 内核中,我有一个名为 Func 的函数norm,我编译如下:

...

 // Start with a default target
Target target = get_host_target();

// Set opencl
target.set_feature(Target::OpenCL);

// Compile
std::vector<Argument> args1(2);
args1[0] = input;
args1[1] = n;
norm.compile_to_file("norm", args1, target);

然后我编译(并执行以获取norm.onorm.h)没有错误使用

g++ -o mavg kernel.cpp -I /opt/intel/intel-opencl-1.2-5.0.0.43/opencl-1.2-sdk-5.0.0.43/include -I Halide/include -L Halide/lib -lHalide -lOpenCL

然后我有一个自动生成的(在 Python 中)库包装器,它调用我编译的内核:

#include <stdio.h>
#include <CL/cl.h>
#include <stdlib.h>
#include "norm.h"

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
    #define LIBRARY_API extern "C" __declspec(dllexport)
#else
    #define LIBRARY_API extern "C"
#endif

// Compiled with the following values
// float* arg0 (float32) arg0 = <numpy.core._internal._ctypes object at 0x7f8b5e54a790>
// int arg1 (<type 'int'>) arg1 = c_int(5)
// float* arg2 (float32) arg2 = <numpy.core._internal._ctypes object at 0x7f8b5e54a690>
// int arg0_h (<type 'int'>) arg0_h = c_int(768)
// int arg0_w (<type 'int'>) arg0_w = c_int(1024)
// int arg0_nd (<type 'int'>) arg0_nd = c_int(3)
// int arg0_n (<type 'int'>) arg0_n = c_int(1)
// int arg2_h (<type 'int'>) arg2_h = c_int(768)
// int arg2_w (<type 'int'>) arg2_w = c_int(1024)
// int arg2_nd (<type 'int'>) arg2_nd = c_int(3)
// int arg2_n (<type 'int'>) arg2_n = c_int(1)
LIBRARY_API int run(float* arg0, int arg1, 
                    float* arg2, int arg0_h, int arg0_w, int arg0_nd, int arg0_n, int arg2_h, int arg2_w, int arg2_nd, int arg2_n)
{
    buffer_t buf_arg0 = {0};
    buf_arg0.extent[0] = arg0_w; // buffer width
    buf_arg0.extent[1] = arg0_h; // buffer height
    buf_arg0.extent[2] = 3; // buffer depth
    buf_arg0.stride[0] = 1;  // spacing in memory between adjacent values of x
    buf_arg0.stride[1] = arg0_w; // spacing in memory between adjacent values of y
    buf_arg0.stride[2] = arg0_w*arg0_h; // buffer depth
    buf_arg0.elem_size = arg0_n * sizeof(float); // bytes per element
    buf_arg0.host = (uint8_t*) arg0; // host buffer

    buffer_t buf_arg2 = {0};
    buf_arg2.extent[0] = arg2_w; // buffer width
    buf_arg2.extent[1] = arg2_h; // buffer height
    buf_arg2.extent[2] = 3; // buffer depth
    buf_arg2.stride[0] = 1;  // spacing in memory between adjacent values of x
    buf_arg2.stride[1] = arg2_w; // spacing in memory between adjacent values of y
    buf_arg2.stride[2] = arg2_w*arg2_h; // buffer depth
    buf_arg2.elem_size = arg2_n * sizeof(float); // bytes per element
    buf_arg2.host = (uint8_t*) arg2; // host buffer

    norm(&buf_arg0, arg1, &buf_arg2);
    return 0;
}

然后我得到一个

undefined symbol: clBuildProgram

当我尝试使用ctypesPython 调用我的库时。是否支持 OpenCL AOT 编译,如果支持,知道问题可能是什么吗?

谢谢。

4

2 回答 2

1

我使用的卤化物版本已经过时了……我清理了它,获取了当前的版本,它现在可以工作了:https ://github.com/halide/Halide/tree/release_2015_09_11

对于那些感兴趣的人,我不必添加 OpenCL 包含或链接器标志。

于 2015-09-22T19:39:23.080 回答
0

我们将 Halide 更改为自动搜索和动态加载 GPU API 库。这发生在 4 月,但到 6 月左右有一些错误修复。不再需要使用 Halide 将 OpenCL 支持库链接到可执行文件中,但如果可以在当前进程中找到符号而无需加载任何库,Halide 将使用这些符号。因此链接到库是一种避免路径搜索的方法。

于 2015-09-23T07:55:13.203 回答