1

Halide 言語での split() の動作について質問があります。

split() を使用すると、計算領域が分割係数の倍数でない場合、エッジで要素が 2 回計算されます。たとえば、計算領域が 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
4

1 に答える 1

1

可能ですが、醜いです。Halide は通常、 Func 内のポイントを任意に再評価できること、および入力が出力とエイリアシングされないことを前提としているため、エッジ近くのいくつかの値を再計算することは常に安全です。

これが問題であるという事実は、悪い兆候です。あなたがやろうとしていることを達成するための他の方法があるかもしれません。

とにかく、回避策は、明示的な RDom を使用して、Halide に何を繰り返し処理するかを正確に伝えることです。

// No pure definition
f(x) = undef<int>(); 

// An update stage that does the vectorized part:
Expr w = (input.width()/4)*4;
RDom r(0, w);
f(r) = something;
f.update(0).vectorize(r, 4);

// An update stage that does the tail end:
RDom r2(input.width(), input.width() - w);
f(r2) = something;
f.update(1); // Don't vectorize the tail end
于 2015-10-21T21:27:08.857 に答える