Search code examples
halide

Using Tuple with Halide AoT compilation


I'm using Halide for some parts of a C++ code base. I have a function with AoT compilation that evaluates a Tuple-valued Func so it was compiled to buffer_t structs as an input to the function before (now it's compiled to halide_buffer_t). In the .cpp file that I call the library, I'd define these buffer_t values as follows:

  result1.host = (uint8_t*)result_cpp_array;
  result1.elem_size = sizeof(float);
  result1.stride[0] = 1;
  result1.min[0] = 2;
  result1.min[1] = 2;
  result1.min[2] = 2;
  result1.stride[1] = size_x + 1;
  result1.stride[2] = (size_y + 1) * (size_x + 1);
  result1.extent[0] = size_x - 3;
  result1.extent[1] = size_y - 3;
  result1.extent[2] = size_z - 3;

  int error = function_aot_halide(/*list of inputs*/, &result1, /*other results similar to result1*/);

I had this part of the code to map the buffer to the c++ array where I want to store the result, and also I need the values of min and extent to have the function realize over part of the array and not the entire array. This worked correctly with old versions of Halide but it doesn't work with the new halide buffer. What would be the best way to do the same thing with the new buffer implementations?


Solution

  • You should use Halide::Runtime::Buffer unless you have a good reason not to (like limited or no C++ support.) Since your data is not tightly packed, you'll have to explain that to Buffer.

    halide_dimension_t result_shape[3] =
        { { 2, size_x - 3, 1 }
        , { 2, size_y - 3, size_x + 1 }
        , { 2, size_z - 3, (size_y + 1) * (size_x + 1) }
        };
    Halide::Runtime::Buffer< float > result_buffer( result_cpp_array, 3, result_shape );
    result_buffer.set_host_dirty();