卤化物函数重塑

Halide Func reshape

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

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

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