【问题标题】:Halide Func reshape卤化物功能重塑
【发布时间】:2017-11-16 18:12:42
【问题描述】:

我想转换 Halide Func 的尺寸。例如考虑以下内容,
func1(x, y, z) = some operation
我知道函数每个维度的范围。让我们假设他们是
x = [0, 3], y = [0, 3], z = [0, 15] 现在,如果我想将 func 转换为 1 维,类似这样
flatten(z * 16 + y * 4 + x) = func1(x, y, z)
但上述定义无效,因为函数定义没有纯 Var。无论如何我可以在 Halide 中做到这一点吗?

【问题讨论】:

    标签: halide


    【解决方案1】:

    您需要将其表示为一个变量的纯函数,例如:

    flatten(x) = func1(x % 4, (x % 16) / 4, x / 16);
    

    您可以通过适当地安排展平来简化大部分添加的寻址算法,例如:

    // Require the bounds realized to be a multiple of 16.
    flatten.align_bounds(x, 16);
    
    // Split the loops at the "critical points" of the addressing arithmetic.
    flatten
        .unroll(x, 4, TailStrategy::RoundUp)
        .split(x, xo, xi, 4, TailStrategy::RoundUp);
    

    【讨论】:

    • 我正在考虑用缩减域来做这件事。有这种可能吗?
    • 您可以通过缩减来做到这一点,但使用缩减会限制调度选项,并且您将无法将此阶段内联到任何后续阶段,这通常首选用于像这样的重塑步骤。
    • 要认识到的关键是@dsharlet 写的内容与您想写的内容相同,只是重新关联以解决左侧的索引参数。跨度>
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    相关资源
    最近更新 更多