在 Halide AoT 编译中使用 Tuple

Using Tuple with Halide AoT compilation

我将 Halide 用于 C++ 代码库的某些部分。我有一个带有 AoT 编译的函数,它计算一个元组值 Func,所以它被编译为 buffer_t 结构作为函数的输入(现在它被编译为 halide_buffer_t)。在我称为库的 .cpp 文件中,我将这些 buffer_t 值定义如下:

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

我有这部分代码将缓冲区映射到我想要存储结果的 c++ 数组,而且我还需要 min 和 extent 的值来让函数实现数组的一部分而不是整个数组。 这适用于旧版本的 Halide,但不适用于新的 halide 缓冲区。用新的缓冲区实现做同样的事情的最好方法是什么?

你应该使用 Halide::Runtime::Buffer 除非你有充分的理由不这样做(比如有限或没有 C++ 支持。)由于你的数据不是紧密打包的,你必须向 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();