【问题标题】:Halide - sort buffer/function in one dimension卤化物 - 一维排序缓冲区/函数
【发布时间】:2021-07-17 12:38:09
【问题描述】:

我目前正在使用带有生成器和提前编译的 Halide。

在管道的某个地方,我有一个 3D 缓冲区,其中一个维度的范围有限(通常为 3-6 个值)。 我想对该维度中的值进行排序。 当我跳过管道开头的处理时, 它看起来有点像这样:

Input <  Buffer<uint16_t>> input  { "input" , 2}; // Dimensions: (y, x)
Input <  uint8_t>        > sizeZ  { "sizeZ"    }; // Size in Z-dimension
Output<  Buffer<uint16_t>> output { "output", 3}; // Dimensions: (z, y, x)

Var x,y,z;

Func input3D(z,y,x) = input(y,z+x*sizeZ);

output = 'sort input3D on Z dimension'.

如果 Halide 中已经提供了一些排序功能(是这样吗?),我会得到最大的帮助。 另一种方法是调用外部 C 实现对该维度中的所有值进行排序并将它们分配给输出缓冲区。 那将是这样的:

output(:, y, x) = external_sort(input(:, y, x))

其中我使用 Python 表示法来表示 Z 维度中的所有元素。 在 Halide 中是否有可能发生这样的事情?

【问题讨论】:

    标签: halide


    【解决方案1】:

    这里有一个调用外部 C 函数对 Halide 函数进行排序的示例:https://github.com/halide/Halide/blob/master/test/correctness/extern_sort.cpp

    通用排序算法不能用 Halide 表示。然而,小向量的排序网络可以。有关双音排序的示例,请参见此处:https://github.com/halide/Halide/blob/master/test/correctness/sort_exprs.cpp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 2023-03-28
      相关资源
      最近更新 更多