From: Haichen Shen Date: Wed, 18 Dec 2019 21:17:18 +0000 (-0800) Subject: [TOPI] Allow batch matmul to be fused into injective ops (#4537) X-Git-Tag: upstream/0.7.0~1505 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ba9e8bc75f3c4bc869792a8e7873bb975199100;p=platform%2Fupstream%2Ftvm.git [TOPI] Allow batch matmul to be fused into injective ops (#4537) --- diff --git a/topi/python/topi/x86/batch_matmul.py b/topi/python/topi/x86/batch_matmul.py index b505cbf..25b49d1 100644 --- a/topi/python/topi/x86/batch_matmul.py +++ b/topi/python/topi/x86/batch_matmul.py @@ -92,33 +92,40 @@ def schedule_batch_matmul(cfg, outs): def _callback(op): if "batch_matmul" in op.tag: C = op.output(0) - A, B = s[C].op.input_tensors + A, B = op.input_tensors _, M, K = get_const_tuple(A.shape) _, _, N = get_const_tuple(C.shape) + if op not in s.outputs: + s[C].compute_inline() + O = outs[0] + else: + O = C + + CC = s.cache_write(C, "global") + # create tuning space cfg.define_split("tile_y", M, num_outputs=2) cfg.define_split("tile_x", N, num_outputs=2) cfg.define_split("tile_k", K, num_outputs=2) - k, = s[C].op.reduce_axis - - ko, ki = cfg["tile_k"].apply(s, C, k) - CC = s.rfactor(C, ki) - - b, y, x = s[C].op.axis - yo, yi = cfg["tile_y"].apply(s, C, y) - xo, xi = cfg["tile_x"].apply(s, C, x) - s[C].reorder(b, yo, xo, yi, xi) - bxyo = s[C].fuse(b, yo, xo) - s[C].parallel(bxyo) - s[C].fuse(yi, xi) - - s[CC].compute_at(s[C], bxyo) - _, _, y, x = s[CC].op.axis - s[CC].fuse(y, x) - s[CC].vectorize(s[CC].op.axis[0]) - s[C].pragma(bxyo, 'auto_unroll_max_step', 16) + b, y, x = s[O].op.axis + yo, yi = cfg["tile_y"].apply(s, O, y) + xo, xi = cfg["tile_x"].apply(s, O, x) + s[O].reorder(b, yo, xo, yi, xi) + bxyo = s[O].fuse(b, yo, xo) + s[O].parallel(bxyo) + + s[CC].compute_at(s[O], bxyo) + k, = s[CC].op.reduce_axis + ko, ki = cfg["tile_k"].apply(s, CC, k) + + Crf = s.rfactor(CC, ki) + s[Crf].compute_at(s[CC], s[CC].op.axis[0]) + _, _, y, x = s[Crf].op.axis + s[Crf].fuse(y, x) + s[Crf].vectorize(s[Crf].op.axis[0]) + s[O].pragma(bxyo, 'auto_unroll_max_step', 16) traverse_inline(s, outs[0].op, _callback) return s