1

I'm trying to use OpenCL as the target to my ahead of time compilation. In my Halide kernel I have a Func called norm which I compile like this:

...

 // 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);

which I then compile (and execute to get norm.o and norm.h) without errors using

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

I then have an automatically generated (in Python) library wrapper that calls my compiled kernel:

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

I then get a

undefined symbol: clBuildProgram

when I try to call my library using ctypes in Python. Is OpenCL AOT compilation supported and if it is, any idea what the problem might be?

Thanks.

3
  • I haven't work with C from Python though, but I don't see the clBuildProgram in your code. So, perhaps the problem is that your python code trying to call this function, but the function is missing?
    – Hi-Angel
    Sep 22, 2015 at 16:21
  • Can you comment on which version of Halide you are using? As of August 5, you shouldn't need to include or link explicitly to any OpenCL headers/OpenCL.lib. It might actually be that linking explicitly is breaking this mechanism somehow, you could try removing the OpenCL related bits from your build command.
    – dsharlet
    Sep 22, 2015 at 16:28
  • The Halide version I was using was outdated... I cleaned it up, fetched the current build, and it's now working. github.com/halide/Halide/tree/release_2015_09_11
    – uzpe
    Sep 22, 2015 at 19:38

2 Answers 2

1

The Halide version I was using was outdated... I cleaned it up, fetched the current build, and it's now working: https://github.com/halide/Halide/tree/release_2015_09_11

For those interested, I did not have to add the OpenCL include or linker flags.

0

We changed Halide to search for and dynamically load GPU API libraries automatically. This happened back in April, but there are a few bug fixes through June or so. It should no longer be necessary to link the OpenCL support libraries into the executable using Halide, though if the symbols can be found in the current process without loading any libraries, Halide will use those. Thus linking to the library is a way to avoid the path searching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.