4

Is it possible in Halide to produce a file which contains generated OpenCL code? I have tried to produce a c file from a Halide program which target would be opencl, but I don't see any opencl specfic code there.

Edit 1:

I would like to see especially how kernels are created in Halide. Something like this:

static char kernelSourceCode[] = kernel void test_kernel(int a, int b, __global int *out) { out[0] = a + b; }

Edit 2:

Ok, I put HL_DEBUG_CODEGEN=1 to env variable and set in the code set_target(Target::Debug). I got bunch of code on the screen, which some of were OpenCL code but I still can't see any kernel spesific code.

There are two lines on the screen which indicates about kernels. Should there be something?

OpenCL kernel: /*OpenCL C*/

Then there is also a line:

kernel void _at_least_one_kernel(int x) { }

In example if I have a function like this:

gradient(x, y) = x + y;

Is the function inside a kernel if I want to target to OpenCL?

jussijii
  • 41
  • 4

1 Answers1

1

Here is what I managed to spot from documentation

CUDA or OpenCL are not enabled by default. You have to construct a Target object, enable one of them, and then pass that target object to compile_jit.

Target target = get_host_target();
target.set_feature(Target::OpenCL);
curved.compile_jit(target);

Or similarely you can use compile_to method, by providing the correct target.

EXPORT void Halide::Func::compile_to(const Outputs & output_files,
                                     std::vector<Argument> args,
                                     const std::string& fn_name,
                                     const Target& target = get_target_from_environment() 
)   
deimus
  • 9,565
  • 12
  • 63
  • 107
  • I am using "compile_to_c" function to produce a c source file from Halide code. I would like to get somehow similar file or output to see what opencl code Halide produces. Or to know if it is even possible. – jussijii Jan 20 '15 at 14:05
  • Check the updated answer, there is also `compile_to` method which might be more suitable for you – deimus Jan 21 '15 at 14:34