我对 Halide 语言中 split() 的行为有疑问。
当我使用 split() 时,当计算区域不是拆分因子的倍数时,它会在边缘计算两次元素。例如,当计算区域为 10 且分割因子为 4 时,Halide 将计算元素 [0,1,2,3]、[4,5,6,7] 和 [6,7,8,9],如下所示下面是 trace_stores() 的结果。
有没有办法在 split() 的内部循环的最后一步只计算元素 [8,9]?
示例代码:
#include "Halide.h"
using namespace Halide;
#define INPUT_SIZE 10
int main(int argc, char** argv) {
Func f("f");
Var x("x");
f(x) = x;
Var xi("xi");
f.split(x, x, xi, 4);
f.trace_stores();
Image<int32_t> out = f.realize(INPUT_SIZE);
return 0;
}
trace_stores() 结果:
Store f.0(0) = 0
Store f.0(1) = 1
Store f.0(2) = 2
Store f.0(3) = 3
Store f.0(4) = 4
Store f.0(5) = 5
Store f.0(6) = 6
Store f.0(7) = 7
Store f.0(6) = 6
Store f.0(7) = 7
Store f.0(8) = 8
Store f.0(9) = 9