text
stringlengths
1
2.05k
.Select(r_b % 6 == 3 and nu % 6 == 2, T.float32(2.5), T.Select(r_b % 6 == 3 and nu % 6 == 1, T.float32(0.5), T.Select(r_b % 6 == 3 and nu % 6 == 0, T.float32(1.5), T.Select(r_b % 6 == 2 and nu % 6 == 5, T.float32(-1.5), T.Select(r_b % 6 == 2 and nu % 6 == 4, T.float32(-1), T.Select(r_b % 6 == 2 and nu % 6 == 3, T.float32(-1), T.Select(r_b % 6 == 2 and nu % 6 == 2, T.float32(0.5), T.Select(r_b % 6 == 2 and nu % 6 == 1, T.float32(-2.5), T.Select(r_b % 6 == 2 and nu % 6 == 0, T.float32(-2), T.Select(r_b % 6 == 1 and nu % 6 == 5, T.float32(1), T.Select(r_b % 6 == 1 and nu % 6 == 4, T.float32(0.5), T.Select(r_b % 6 == 1 and nu % 6 == 3, T.float32(-2), T.Select(r_b % 6 == 1 and nu % 6 == 2, T.float32(-1), T.Select(r_b % 6 == 1 and nu % 6 == 1, T.float32(1), T.Select(r_b % 6 == 1 and nu % 6 == 0, T.float32(-1.5), T.Select(r_b % 6 == 0 and nu % 6 == 5, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 4, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 3, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 2, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 1, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))))))))))))))) for ax0, ax1, ax2, ax3 in T.grid(6, 6, 1, 1): with T.block("data_pack_local"): T.where(i2_i3_fused_0 * 512 + i2_i3_fused_1 < 12544) v0, v1 = T.axis.remap("SS", [ax0, ax1]) v2 = T.axis.spatial(64, (i2_i3_fused_0 * 512 + i2_i3_fused_1) v3 = T.axis.spatial(196, (i2_i3_fused_0 * 120 + i2_i3_fused_1) % 196 + ax3) T.reads(data_pack_local[v0, v1, v2, v3]) T.writes(data_pack[v0, v1, v2, v3]) data_pack[v0, v1, v2, v3] = data_pack_local[v0, v1, v2, v3] for i0_0_i1_0_i2_0_i3_0_fused in T.thread_binding(14, thread="blockIdx.x"): for i0_1_i1_1_i2_1_i3_1_fused in T.thread_binding(224, thread="vthread.
x"): for i0_2_i1_2_i2_2_i3_2_fused in T.thread_binding(2, thread="threadIdx.x"): for i4_0 in T.serial(2): for ax0_ax1_ax2_ax3_fused in T.serial(32256): with T.block("data_pack_shared"): v0 = T.axis.spatial(6, ax0_ax1_ax2_ax3_fused v1 = T.axis.spatial(6, ax0_ax1_ax2_ax3_fused % 5376 v2 = T.axis.spatial(64, i4_0 * 32 + ax0_ax1_ax2_ax3_fused % 896 v3 = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 7 * 28 + ax0_ax1_ax2_ax3_fused % 28) T.reads(data_pack[v0, v1, v2, v3]) T.writes(data_pack_shared[v0, v1, v2, v3]) T.block_attr({"meta_schedule.cooperative_fetch":4}) data_pack_shared[v0, v1, v2, v3] = data_pack[v0, v1, v2, v3] for ax0_ax1_ax2_ax3_fused in T.serial(36864): with T.block("weight_shared"): v0 = T.axis.spatial(6, ax0_ax1_ax2_ax3_fused v1 = T.axis.spatial(6, ax0_ax1_ax2_ax3_fused % 6144 v2 = T.axis.spatial(64, i4_0 * 32 + ax0_ax1_ax2_ax3_fused % 1024 v3 = T.axis.spatial(64, i0_0_i1_0_i2_0_i3_0_fused T.reads(weight[v0, v1, v2, v3]) T.writes(weight_shared[v0, v1, v2, v3]) T.block_attr({"meta_schedule.cooperative_fetch":3}) weight_shared[v0, v1, v2, v3] = weight[v0, v1, v2, v3] for i4_1, i0_3, i1_3, i2_3, i3_3, i4_2, i0_4, i1_4, i2_4, i3_4 in T.grid(16, 2, 3, 1, 4, 2, 3, 1, 1, 1): with T.block("bgemm"):
eps = T.axis.spatial(6, i0_3 * 3 + i0_4) nu = T.axis.spatial(6, i1_4 + i0_1_i1_1_i2_1_i3_1_fused co = T.axis.spatial(64, i0_0_i1_0_i2_0_i3_0_fused p = T.axis.spatial(196, i3_4 + i0_0_i1_0_i2_0_i3_0_fused % 7 * 28 + i0_1_i1_1_i2_1_i3_1_fused % 7 * 4 + i3_3) ci = T.axis.reduce(64, i4_0 * 32 + i4_1 * 2 + i4_2) T.reads(data_pack_shared[eps, nu, ci, p], weight_shared[eps, nu, ci, co]) T.writes(bgemm_local[eps, nu, co, p]) T.block_attr({"meta_schedule.thread_extent_high_inclusive":1024, "meta_schedule.thread_extent_low_inclusive":32, "meta_schedule.tiling_structure":"SSSRRSRS"}) with T.init(): bgemm_local[eps, nu, co, p] = T.float32(0) bgemm_local[eps, nu, co, p] = bgemm_local[eps, nu, co, p] + data_pack_shared[eps, nu, ci, p] * weight_shared[eps, nu, ci, co] for ax0, ax1, ax2, ax3 in T.grid(6, 3, 1, 4): with T.block("bgemm_local"): v0 = T.axis.spatial(6, ax0) v1 = T.axis.spatial(6, i0_1_i1_1_i2_1_i3_1_fused v2 = T.axis.spatial(64, i0_0_i1_0_i2_0_i3_0_fused v3 = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 7 * 28 + i0_1_i1_1_i2_1_i3_1_fused % 7 * 4 + ax3) T.reads(bgemm_local[v0, v1, v2, v3]) T.writes(bgemm[v0, v1, v2, v3]) bgemm[v0, v1, v2, v3] = bgemm_local[v0, v1, v2, v3] for i0_i1_i2_0_i3_0_fused_0 in T.thread_binding(196, thread="blockIdx.x"): for i0_i1_i2_0_i3_0_fused_1 in T.thread_binding(64, thread="threadIdx.x"):
for ax0, ax1 in T.grid(1, 1): for ax2 in T.unroll(4): for ax3 in T.unroll(4): for ax4 in T.unroll(6): for ax5 in T.unroll(6): with T.block("inverse"): co = T.axis.spatial(64, (i0_i1_i2_0_i3_0_fused_0 * 64 + i0_i1_i2_0_i3_0_fused_1) p = T.axis.spatial(196, (i0_i1_i2_0_i3_0_fused_0 * 64 + i0_i1_i2_0_i3_0_fused_1) % 196 vh, vw, r_a, r_b = T.axis.remap("SSRR", [ax2, ax3, ax4, ax5]) T.reads(bgemm[r_a, r_b, co, p]) T.writes(inverse_local[co, p, vh, vw]) T.block_attr({"schedule_rule":"conv2d_nchw_winograd_inverse"}) with T.init(): inverse_local[co, p, vh, vw] = T.float32(0) inverse_local[co, p, vh, vw] = inverse_local[co, p, vh, vw] + bgemm[r_a, r_b, co, p] * T.Select(r_a % 6 == 5 and vh % 4 == 3, T.float32(1), T.Select(r_a % 6 == 5 and vh % 4 == 2, T.float32(0), T.Select(r_a % 6 == 5 and vh % 4 == 1, T.float32(0), T.Select(r_a % 6 == 5 and vh % 4 == 0, T.float32(0), T.Select(r_a % 6 == 4 and vh % 4 == 3, T.float32(-8), T.Select(r_a % 6 == 4 and vh % 4 == 2, T.float32(4), T.Select(r_a % 6 == 4 and vh % 4 == 1, T.float32(-2), T.Select(r_a % 6 == 4 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 3 and vh % 4 == 3, T.float32(0.125), T.Select(r_a % 6 == 3 and vh % 4 == 2, T.float32(0.25), T.Select(r_a % 6 == 3 and vh % 4 == 1, T.float32(0.5), T.Select(r_a % 6 == 3 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 3, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 2, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 1, T.float32(1), T.Select(r_a % 6
== 2 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 1 and vh % 4 == 3, T.float32(-1), T.Select(r_a % 6 == 1 and vh % 4 == 2, T.float32(1), T.Select(r_a % 6 == 1 and vh % 4 == 1, T.float32(-1), T.Select(r_a % 6 == 1 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 0 and vh % 4 == 3, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 2, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 1, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))) * T.Select(r_b % 6 == 5 and vw % 4 == 3, T.float32(1), T.Select(r_b % 6 == 5 and vw % 4 == 2, T.float32(0), T.Select(r_b % 6 == 5 and vw % 4 == 1, T.float32(0), T.Select(r_b % 6 == 5 and vw % 4 == 0, T.float32(0), T.Select(r_b % 6 == 4 and vw % 4 == 3, T.float32(-8), T.Select(r_b % 6 == 4 and vw % 4 == 2, T.float32(4), T.Select(r_b % 6 == 4 and vw % 4 == 1, T.float32(-2), T.Select(r_b % 6 == 4 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 3 and vw % 4 == 3, T.float32(0.125), T.Select(r_b % 6 == 3 and vw % 4 == 2, T.float32(0.25), T.Select(r_b % 6 == 3 and vw % 4 == 1, T.float32(0.5), T.Select(r_b % 6 == 3 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 3, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 2, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 1, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 1 and vw % 4 == 3, T.float32(-1), T.Select(r_b % 6 == 1 and vw % 4 == 2, T.float32(1), T.Select(r_b % 6 == 1 and vw % 4 == 1, T.float32(-1), T.Select(r_b % 6 == 1 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 0 and vw % 4 == 3, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 2, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 1, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))) for i2_1, i3_1 in T.grid(4, 4): with T.block("conv2d_winograd"): n = T.axis.spatial(1, 0) co = T.axis.spatial(64, (i0_i1_i2_
0_i3_0_fused_0 * 64 + i0_i1_i2_0_i3_0_fused_1) h = T.axis.spatial(56, (i0_i1_i2_0_i3_0_fused_0 * 64 + i0_i1_i2_0_i3_0_fused_1) % 196 w = T.axis.spatial(56, (i0_i1_i2_0_i3_0_fused_0 * 64 + i0_i1_i2_0_i3_0_fused_1) % 14 * 4 + i3_1) T.reads(inverse_local[co, n * 196 + h T.writes(conv2d_winograd[n, co, h, w]) conv2d_winograd[n, co, h, w] = inverse_local[co, n * 196 + h decision_0 = [ ("SampleCategorical", 4), ("SamplePerfectTile", [1, 1, 1, 2, 3]), ("SamplePerfectTile", [1, 2, 1, 3, 1]), ("SamplePerfectTile", [2, 16, 2, 1, 1]), ("SamplePerfectTile", [7, 7, 1, 4, 1]), ("SamplePerfectTile", [2, 16, 2]), ("SampleCategorical", 3), ("SampleCategorical", 2), ("SampleCategorical", 1), ("SampleCategorical", 1), ] with _target(): mod = create_te_workload("C2D_WIN_NCHW", 0) actual = _design_space(mod) check_sketches( mod, sketches=actual, expected_mods=[cuda_nchw_0], expected_decisions=[decision_0], debug_mask=0, ) if __name__ == "__main__": test_cuda_nhwc() test_cuda_nchw()
""" Test Meta Schedule SpaceGenerator """
import math
import pytest
import tvm
import tvm.testing from tvm._ffi.base
import TVMError from tvm.meta_schedule.space_generator
import ( PySpaceGenerator, ScheduleFn, SpaceGeneratorUnion, ) from tvm.meta_schedule.tune_context
import TuneContext from tvm.meta_schedule.utils
import derived_object from tvm.script
import tir as T from tvm.tir.schedule
import Schedule @tvm.script.ir_module class Matmul: @T.prim_func def main(a: T.handle, b: T.handle, c: T.handle) -> None: T.func_attr({"global_symbol": "main"}) A = T.match_buffer(a, (1024, 1024), "float32") B = T.match_buffer(b, (1024, 1024), "float32") C = T.match_buffer(c, (1024, 1024), "float32") for i, j, k in T.grid(1024, 1024, 1024): with T.block("matmul"): vi, vj, vk = T.axis.remap("SSR", [i, j, k]) with T.init(): C[vi, vj] = 0.0 C[vi, vj] = C[vi, vj] + A[vi, vk] * B[vk, vj] def schedule_matmul(sch: Schedule): block = sch.get_block("matmul") i, j, k = sch.get_loops(block=block) i_0, i_1, i_2, i_3 = sch.split(loop=i, factors=[2, 4, 64, 2]) j_0, j_1, j_2, j_3 = sch.split(loop=j, factors=[4, 64, 2, 2]) k_0, k_1 = sch.split(loop=k, factors=[32, 32]) sch.reorder(i_0, j_0, i_1, j_1, k_0, i_2, j_2, k_1, i_3, j_3) def _check_correct(schedule: Schedule): trace = schedule.trace for inst in trace.decisions: assert math.prod(trace.decisions[inst]) == 1024 def test_meta_schedule_space_generator_schedule_fn(): mod = Matmul space_generator = ScheduleFn(sch_fn=schedule_matmul) design_spaces = space_generator.generate_design_space(mod) assert len(design_spaces) == 1 (schedule,) = design_spaces _check_correct(schedule) def test_meta_schedule_design_space_generator_union(): mod = Matmul space_generator = ScheduleFn(sch_fn=schedule_matmul) space_generator_union = SpaceGeneratorUnion([space_generator, space_generator]) design_spaces = space_generator_union.generate_design_space(mod) assert len(design_spaces) == 2 for design_space in design_spaces: _check_correct(design_space) def test_meta_schedule_design_space_generator_NIE(): @derived_object
class TestPySpaceGenerator(PySpaceGenerator): def __init__(self): super().__init__() self.sch_rules = [] self.postprocs = [] self.mutator_probs = {} with pytest.raises( TVMError, match="PySpaceGenerator's InitializeWithTuneContext method not implemented!" ): generator = TestPySpaceGenerator() generator._initialize_with_tune_context(TuneContext()) if __name__ == "__main__": tvm.testing.main()
""" Test Meta Schedule Task Scheduler """
import random
import weakref from typing
import Set
import pytest
import tvm
import tvm.testing from tvm
import meta_schedule as ms from tvm.meta_schedule.testing.dummy_object
import DummyBuilder, DummyRunner from tvm.script
import tir as T from tvm.tir
import Schedule @tvm.script.ir_module class MatmulModule: @T.prim_func def main( a: T.handle, b: T.handle, c: T.handle, ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) A = T.match_buffer(a, (1024, 1024), "float32") B = T.match_buffer(b, (1024, 1024), "float32") C = T.match_buffer(c, (1024, 1024), "float32") for i, j, k in T.grid(1024, 1024, 1024): with T.block("matmul"): vi, vj, vk = T.axis.remap("SSR", [i, j, k]) with T.init(): C[vi, vj] = 0.0 C[vi, vj] = C[vi, vj] + A[vi, vk] * B[vk, vj] @tvm.script.ir_module class MatmulReluModule: @T.prim_func def main( a: T.handle, b: T.handle, d: T.handle, ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) A = T.match_buffer(a, (1024, 1024), "float32") B = T.match_buffer(b, (1024, 1024), "float32") D = T.match_buffer(d, (1024, 1024), "float32") C = T.alloc_buffer((1024, 1024), "float32") for i, j, k in T.grid(1024, 1024, 1024): with T.block("matmul"): vi, vj, vk = T.axis.remap("SSR", [i, j, k]) with T.init(): C[vi, vj] = 0.0 C[vi, vj] = C[vi, vj] + A[vi, vk] * B[vk, vj] for i, j in T.grid(1024, 1024): with T.block("relu"): vi, vj = T.axis.remap("SS", [i, j]) D[vi, vj] = T.max(C[vi, vj], 0.0) @tvm.script.ir_module class BatchMatmulModule: @T.prim_func def main( a: T.handle, b: T.handle, c: T.handle, ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) A = T.match_buffer(a, [16, 128, 128]) B = T.match_buffer(b, [16, 128, 128]) C = T.match_buffer(c, [16, 128, 128]) for n, i, j, k in T.grid(16, 128, 128, 128): with T.block("matmul"):
vn, vi, vj, vk = T.axis.remap("SSSR", [n, i, j, k]) with T.init(): C[vn, vi, vj] = 0.0 C[vn, vi, vj] = C[vn, vi, vj] + A[vn, vi, vk] * B[vn, vj, vk] def _schedule_matmul(sch: Schedule): block = sch.get_block("matmul") i, j, k = sch.get_loops(block=block) i_0, i_1, i_2, i_3 = sch.split(loop=i, factors=[2, 4, 64, 2]) j_0, j_1, j_2, j_3 = sch.split(loop=j, factors=[4, 64, 2, 2]) k_0, k_1 = sch.split(loop=k, factors=[32, 32]) sch.reorder(i_0, j_0, i_1, j_1, k_0, i_2, j_2, k_1, i_3, j_3) def _schedule_batch_matmul(sch: Schedule): block = sch.get_block("matmul") i, j, k, t = sch.get_loops(block=block) i_0, i_1, i_2, i_3 = sch.split(loop=i, factors=[2, 2, 2, 2]) j_0, j_1, j_2, j_3 = sch.split(loop=j, factors=[2, 4, 64, 2]) k_0, k_1 = sch.split(loop=k, factors=[32, 32]) t_0, t_1 = sch.split(loop=t, factors=[2, 512]) sch.reorder(i_0, j_0, i_1, j_1, k_0, i_2, j_2, k_1, i_3, j_3, t_0, t_1) @ms.derived_object
class MyTaskScheduler(ms.task_scheduler.PyTaskScheduler): done: Set = set() def next_task_id(self) -> int: tasks = self._outer().tasks_ while len(self.done) != len(tasks): x = random.randint(0, len(tasks) - 1) task = tasks[x] if not task.is_terminated: """Calling base func via following route: Python side: PyTaskScheduler does not have `_touch_task` Call TaskScheduler's `touch_task`, which calls ffi C++ side: The ffi calls TaskScheduler's `touch_task` But it is overridden in PyTaskScheduler PyTaskScheduler checks if the function is overridden in python If not, it returns the TaskScheduler's vtable, calling TaskScheduler::TouchTask """ if task.runner_futures is not None: self.join_running_task(x) return x self.done.add(x) return -1 def test_meta_schedule_task_scheduler_single(): num_trials_per_iter = 3 max_trials_per_task = 10 database = ms.database.MemoryDatabase() round_robin = ms.task_scheduler.RoundRobin() round_robin.tune( [ ms.TuneContext( MatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="Test", rand_state=42, ) ], [1.0], max_trials_global=num_trials_per_iter, max_trials_per_task=max_trials_per_task, num_trials_per_iter=64, builder=DummyBuilder(), runner=DummyRunner(), database=database, measure_callbacks=[ms.measure_callback.AddToDatabase()], cost_model=None, ) assert len(database) == max_trials_per_task def test_meta_schedule_task_scheduler_mult
iple(): num_trials_per_iter = 6 max_trials_per_task = 101 tasks = [ ms.TuneContext( MatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="Matmul", rand_state=42, ), ms.TuneContext( MatmulReluModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="MatmulRelu", rand_state=0xDEADBEEF, ), ms.TuneContext( BatchMatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_batch_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="BatchMatmul", rand_state=0x114514, ), ] database = ms.database.MemoryDatabase() round_robin = ms.task_scheduler.RoundRobin() round_robin.tune( tasks, [1.0, 1.0, 1.0], builder=DummyBuilder(), runner=DummyRunner(), database=database, measure_callbacks=[ms.measure_callback.AddToDatabase()], max_trials_global=max_trials_per_task * len(tasks), max_trials_per_task=max_trials_per_task, num_trials_per_iter=num_trials_per_iter, cost_model=None, ) assert len(database) == max_trials_per_task * len(tasks) for task in tasks: assert ( len( database.get_top_k( database.commit_workload(task.mod), 100000, ) ) == max_trials_per_task ) def test_meta_schedule_task_scheduler_NIE(): @ms.derived_object
class NIETaskScheduler(ms.task_scheduler.PyTaskScheduler): pass with pytest.raises(ValueError, match="next_task_id is not defined"): scheduler = NIETaskScheduler() scheduler.next_task_id() def test_meta_schedule_task_scheduler_avoid_cyclic(): scheduler = MyTaskScheduler() test = weakref.ref(scheduler) del scheduler assert test() is None def test_meta_schedule_task_scheduler_override_next_task_id_only(): max_trials_per_task = 101 tasks = [ ms.TuneContext( MatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="Matmul", rand_state=42, ), ms.TuneContext( MatmulReluModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="MatmulRelu", rand_state=0xDEADBEEF, ), ms.TuneContext( BatchMatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_batch_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="BatchMatmul", rand_state=0x114514, ), ] database = ms.database.MemoryDatabase() scheduler = MyTaskScheduler() scheduler.tune( tasks, task_weights=[1.0] * len(tasks), builder=DummyBuilder(), runner=DummyRunner(), database=database, measure_callbacks=[ms.measure_callback.AddToDatabase()], max_trials_global=max_trials_per_task * len(tasks), max_trials_per_task=max_trials_per_task, num_trials_per_iter=6, cost_model=None, ) assert len(database) == max_trials_per_task * len(tasks) for task in tasks: assert ( len( database.get_top_k( database.commit_workloa
d(task.mod), 100000, ) ) == max_trials_per_task ) def test_meta_schedule_task_scheduler_multiple_gradient_based(): max_trials_per_task = 101 tasks = [ ms.TuneContext( MatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="Matmul", rand_state=42, ), ms.TuneContext( MatmulReluModule, target=tvm.target.Target("llvm"), space_generator=_schedule_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="MatmulRelu", rand_state=0xDEADBEEF, ), ms.TuneContext( BatchMatmulModule, target=tvm.target.Target("llvm"), space_generator=_schedule_batch_matmul, search_strategy=ms.search_strategy.ReplayTrace(), task_name="BatchMatmul", rand_state=0x114514, ), ] database = ms.database.MemoryDatabase() gradient_based = ms.task_scheduler.GradientBased() gradient_based.tune( tasks, task_weights=[1.0, 1.0, 1.0], builder=DummyBuilder(), runner=DummyRunner(), database=database, measure_callbacks=[ms.measure_callback.AddToDatabase()], max_trials_global=max_trials_per_task * len(tasks), max_trials_per_task=max_trials_per_task, num_trials_per_iter=6, cost_model=None, ) assert len(database) == max_trials_per_task * len(tasks) for task in tasks: assert ( len(database.get_top_k(database.commit_workload(task.mod), 10000)) == max_trials_per_task ) if __name__ == "__main__": test_meta_schedule_task_scheduler_single() test_meta_schedule_task_scheduler_multiple() test_meta_schedule_task_scheduler_NIE() test_meta_schedule_task_scheduler_avoid_cyclic()
test_meta_schedule_task_scheduler_override_next_task_id_only() test_meta_schedule_task_scheduler_multiple_gradient_based()
import pytest
import tvm
import tvm.testing
import tvm.meta_schedule as ms from tvm.script
import tir as T from tvm.tir
import Schedule, floormod, floordiv from tvm.tir.tensor_intrin.cuda
import * from tvm.target
import Target from tvm.target.codegen
import llvm_lookup_intrinsic_id @tvm.script.ir_module class Dense: @T.prim_func def main( p0: T.Buffer[(128, 128), "float32"], p1: T.Buffer[(128, 128), "float32"], T_matmul_NT: T.Buffer[(128, 128), "float32"], ) -> None: T.func_attr({"layout_free_buffers": [1], "tir.noalias": True, "global_symbol": "main"}) for i0, i1, i2 in T.grid(128, 128, 128): with T.block("T_matmul_NT"): i, j, k = T.axis.remap("SSR", [i0, i1, i2]) T.reads(p0[i, k], p1[j, k]) T.writes(T_matmul_NT[i, j]) T.block_attr({"layout_free_placeholders": []}) with T.init(): T_matmul_NT[i, j] = T.float32(0) T_matmul_NT[i, j] = T_matmul_NT[i, j] + p0[i, k] * p1[j, k] @tvm.script.ir_module class DenseAdd: @T.prim_func def main( p0: T.Buffer[(128, 128), "float32"], p1: T.Buffer[(128, 128), "float32"], T_add: T.Buffer[(128, 128), "float32"], ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) T_matmul_NT = T.alloc_buffer([128, 128], dtype="float32") compile_engine_const = T.alloc_buffer([], dtype="float32") for i0, i1, i2 in T.grid(128, 128, 128): with T.block("T_matmul_NT"): i, j, k = T.axis.remap("SSR", [i0, i1, i2]) T.reads(p0[i, k], p1[j, k]) T.writes(T_matmul_NT[i, j]) T.block_attr({"layout_free_placeholders": []}) with T.init(): T_matmul_NT[i, j] = T.float32(0) T_matmul_NT[i, j] = T_matmul_NT[i, j] + p0[i, k] * p1[j, k] with T.block("compile_engine_const"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const[()]) compile_engine_const[()] = T.float32(1) for i0, i1 in T.grid(128, 128): with T
.block("T_add"): ax0, ax1 = T.axis.remap("SS", [i0, i1]) T.reads(T_matmul_NT[ax0, ax1], compile_engine_const[()]) T.writes(T_add[ax0, ax1]) T_add[ax0, ax1] = T_matmul_NT[ax0, ax1] + compile_engine_const[()] @tvm.script.ir_module class DenseAdd_scheduled_cpu: @T.prim_func def main( p0: T.Buffer[(128, 128), "float32"], p1: T.Buffer[(128, 128), "float32"], T_add: T.Buffer[(128, 128), "float32"], ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) T_matmul_NT_global = T.alloc_buffer([128, 128], dtype="float32") p1_global = T.alloc_buffer([2, 128, 64], dtype="float32") for ax0, ax1 in T.grid(128, 128): with T.block("p1_global"): v0, v1 = T.axis.remap("SS", [ax0, ax1]) T.reads(p1[v0, v1]) T.writes(p1_global[v0 T.block_attr({"meta_schedule.layout_rewrite_preproc": 1}) p1_global[v0 for i0_0_i1_0_fused_fused in T.parallel(4): for i0_1, i1_1 in T.grid(8, 1): for i0_2_init, i1_2_init, i0_3_init in T.grid(4, 1, 2): for i1_3_fused_init in T.vectorized(64): with T.block("T_matmul_NT_init"): i = T.axis.spatial( 128, i0_0_i1_0_fused_fused + i0_1 * 8 + i0_2_init * 2 + i0_3_init, ) j = T.axis.spatial( 128, i0_0_i1_0_fused_fused % 2 * 64 + i1_1 * 64 + i1_2_init * 64 + i1_3_fused_init, ) T.reads()
T.writes(T_matmul_NT_global[i, j]) T.block_attr( { "layout_free_placeholders": [], "meta_schedule.tiling_structure": "SSRSRS", } ) T_matmul_NT_global[i, j] = T.float32(0) for i2_0, i0_2, i1_2, i2_1, i0_3 in T.grid(128, 4, 1, 1, 2): for i1_3_fused in T.vectorized(64): with T.block("T_matmul_NT_update"): i = T.axis.spatial( 128, i0_0_i1_0_fused_fused ) j = T.axis.spatial( 128, i0_0_i1_0_fused_fused % 2 * 64 + i1_1 * 64 + i1_2 * 64 + i1_3_fused, ) k = T.axis.reduce(128, i2_0 + i2_1) T.reads( T_matmul_NT_global[i, j], p0[i, k], p1_global[j ) T.writes(T_matmul_NT_global[i, j]) T.block_attr( { "layout_free_placeholders": [], "meta_schedule.tiling_structure": "SSRSRS", } ) T_matmul_NT_global[i, j] = ( T_matmul_NT_global[i, j] + p0[i, k] * p1_global[j ) for ax0 in T.serial(64): for ax1_fused in T.vectorized(64): with T.block("T_matmul_NT_global"): v0 = T.axis.spatial(128, i0_0_i1_0_fused_fused v1 = T.axis.spatial(128, i0_0_i1_0_fused_fused % 2 * 64 + ax1_fused) T.reads(T_matmul_NT_glob
al[v0, v1]) T.writes(T_add[v0, v1]) T_add[v0, v1] = T_matmul_NT_global[v0, v1] + T.float32(1) @tvm.script.ir_module class DenseAdd_cpu_no_write_cache: @T.prim_func def main(p0: T.Buffer[(128, 128), "float32"], p1: T.Buffer[(128, 128), "float32"], T_add: T.Buffer[(128, 128), "float32"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) T_matmul_NT = T.alloc_buffer([128, 128], dtype="float32") p1_global = T.alloc_buffer([8, 4, 16, 32], dtype="float32") for ax0, ax1 in T.grid(128, 128): with T.block("p1_global"): v0, v1 = T.axis.remap("SS", [ax0, ax1]) T.reads(p1[v0, v1]) T.writes(p1_global[v1 T.block_attr({"meta_schedule.layout_rewrite_preproc":1}) p1_global[v1 for i0_0_i1_0_i0_1_i1_1_fused in T.parallel(16, annotations={"pragma_auto_unroll_max_step":16, "pragma_unroll_explicit":1}): for i0_2_init, i1_2_init, i0_3_init in T.grid(4, 4, 2): for i1_3_fused_init in T.vectorized(32): with T.block("T_matmul_NT_init"): i = T.axis.spatial(128, i0_0_i1_0_i0_1_i1_1_fused j = T.axis.spatial(128, i1_2_init * 32 + i1_3_fused_init) T.reads() T.writes(T_matmul_NT[i, j]) T.block_attr({"layout_free_placeholders":[], "meta_schedule.tiling_structure":"SSRSRS"}) T_matmul_NT[i, j] = T.float32(0) for i2_0, i0_2, i1_2, i2_1, i0_3 in T.grid(8, 4, 4, 16, 2): for i1_3_fused in T.vectorized(32): with T.block("T_matmul_NT_update"): i = T.axis.spatial(128, i0_0_i1_0_i0_1_i1_1_fused j = T.axis.spatial(128, i1_2 * 32 + i1_3_fused) k = T.axis.reduce(128, i2_0 * 16 + i2_1)
T.reads(T_matmul_NT[i, j], p0[i, k], p1_global[k T.writes(T_matmul_NT[i, j]) T.block_attr({"layout_free_placeholders":[], "meta_schedule.tiling_structure":"SSRSRS"}) T_matmul_NT[i, j] = T_matmul_NT[i, j] + p0[i, k] * p1_global[k for i0_i1_fused in T.parallel(16384): with T.block("T_add"): ax0 = T.axis.spatial(128, i0_i1_fused ax1 = T.axis.spatial(128, i0_i1_fused % 128) T.reads(T_matmul_NT[ax0, ax1]) T.writes(T_add[ax0, ax1]) T_add[ax0, ax1] = T_matmul_NT[ax0, ax1] + T.float32(1) @tvm.script.ir_module class DenseAdd_scheduled_gpu: @T.prim_func def main( p0: T.Buffer[(128, 128), "float32"], p1: T.Buffer[(128, 128), "float32"], T_add: T.Buffer[(128, 128), "float32"], ) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) T_matmul_NT_local = T.alloc_buffer([128, 128], dtype="float32", scope="local") p0_shared = T.alloc_buffer([128, 128], dtype="float32", scope="shared") p1_shared = T.alloc_buffer([128, 128], dtype="float32", scope="shared") for i0_0_i1_0_fused in T.thread_binding( 32, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step": 64, "pragma_unroll_explicit": 1}, ): for i0_1_i1_1_fused in T.thread_binding(1, thread="vthread.x"): for i0_2_i1_2_fused in T.thread_binding(128, thread="threadIdx.x"): for i0_3_init, i1_3_init, i0_4_init, i1_4_init in T.grid(1, 4, 1, 1): with T.block("T_matmul_NT_init"): i = T.axis.spatial( 128, i0_0_i1_0_fused + i0_2_i1_2_fused + i0_3_init
+ i0_4_init, ) j = T.axis.spatial( 128, i1_4_init + i0_0_i1_0_fused % 4 * 32 + i0_2_i1_2_fused % 8 * 4 + i1_3_init, ) T.reads() T.writes(T_matmul_NT_local[i, j]) T.block_attr( { "layout_free_placeholders": [], "meta_schedule.thread_extent_high_inclusive": 256, "meta_schedule.thread_extent_low_inclusive": 16, "meta_schedule.tiling_structure": "SSSRRSRS", } ) T_matmul_NT_local[i, j] = T.float32(0) for i2_0 in T.serial(32): for ax0_ax1_fused_0 in T.serial(1): for ax0_ax1_fused_1 in T.thread_binding(128, thread="threadIdx.x"): for ax0_ax1_fused_2 in T.vectorized(2): with T.block("p0_shared"): T.where( (ax0_ax1_fused_0 * 128 + ax0_ax1_fused_1) * 2 + ax0_ax1_fused_2 < 64 ) v0 = T.axis.spatial( 128, i0_0_i1_0_fused + ( ax0_ax1_fused_0 * 256 + ax0_ax1_fused_1 * 2 + ax0_ax1_fuse
d_2 ) ) v1 = T.axis.spatial( 128, i2_0 * 4 + ( ax0_ax1_fused_0 * 256 + ax0_ax1_fused_1 * 2 + ax0_ax1_fused_2 ) % 4, ) T.reads(p0[v0, v1]) T.writes(p0_shared[v0, v1]) p0_shared[v0, v1] = p0[v0, v1] for ax0_ax1_fused_0 in T.serial(1): for ax0_ax1_fused_1 in T.thread_binding(128, thread="threadIdx.x"): for ax0_ax1_fused_2 in T.vectorized(4): with T.block("p1_shared"): T.where( (ax0_ax1_fused_0 * 128 + ax0_ax1_fused_1) * 4 + ax0_ax1_fused_2 < 128 ) v0 = T.axis.spatial( 128, i0_0_i1_0_fused % 4 * 32 + ( ax0_ax1_fused_0 * 512 + ax0_ax1_fused_1 * 4 + ax0_ax1_fused_2 ) )
v1 = T.axis.spatial( 128, i2_0 * 4 + ( ax0_ax1_fused_0 * 512 + ax0_ax1_fused_1 * 4 + ax0_ax1_fused_2 ) % 4, ) T.reads(p1[v0, v1]) T.writes(p1_shared[v0, v1]) p1_shared[v0, v1] = p1[v0, v1] for i2_1, i0_3, i1_3, i2_2, i0_4, i1_4 in T.grid(1, 1, 4, 4, 1, 1): with T.block("T_matmul_NT_update"): i = T.axis.spatial( 128, i0_0_i1_0_fused ) j = T.axis.spatial( 128, i1_4 + i0_0_i1_0_fused % 4 * 32 + i0_2_i1_2_fused % 8 * 4 + i1_3, ) k = T.axis.reduce(128, i2_0 * 4 + i2_1 * 4 + i2_2) T.reads(T_matmul_NT_local[i, j], p0_shared[i, k], p1_shared[j, k]) T.writes(T_matmul_NT_local[i, j]) T.block_attr( { "layout_free_placeholders": [], "meta_schedule.thread_extent_high_inclusive": 256, "meta_schedule.thread_extent_low_inclusive": 16, "meta_
schedule.tiling_structure": "SSSRRSRS", } ) T_matmul_NT_local[i, j] = ( T_matmul_NT_local[i, j] + p0_shared[i, k] * p1_shared[j, k] ) for ax0, ax1 in T.grid(1, 4): with T.block("T_matmul_NT_local"): v0 = T.axis.spatial( 128, i0_0_i1_0_fused ) v1 = T.axis.spatial( 128, i0_0_i1_0_fused % 4 * 32 + i0_2_i1_2_fused % 8 * 4 + ax1 ) T.reads(T_matmul_NT_local[v0, v1]) T.writes(T_add[v0, v1]) T_add[v0, v1] = T_matmul_NT_local[v0, v1] + T.float32(1) @tvm.script.ir_module class Conv2dInt8: @T.prim_func def main(p0: T.Buffer[(16, 56, 56, 64), "int8"], p1: T.Buffer[(256, 1, 1, 64), "int8"], p2: T.Buffer[(1, 1, 1, 256), "int32"], p3: T.Buffer[(1, 1, 1, 256), "int32"], p4: T.Buffer[(1, 1, 1, 256), "int64"], p5: T.Buffer[(1, 1, 1, 256), "int64"], p6: T.Buffer[(1, 1, 1, 256), "int64"], p7: T.Buffer[(), "int32"], p8: T.Buffer[1, "int32"], compute: T.Buffer[(16, 56, 56, 256), "int32"]) -> None: T.func_attr({"tir.noalias": True, "global_symbol": "main"}) pad_temp = T.alloc_buffer([16, 56, 56, 64], dtype="int8") conv2d_nhwc = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_subtract = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_add = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_cast = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_multiply = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_add_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_right_shift = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_cast_1 = T.alloc_buffer
([16, 56, 56, 256], dtype="int32") T_add_2 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") compute_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_cast_2 = T.alloc_buffer([16, 56, 56, 256], dtype="uint8") T_cast_3 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_subtract_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") for i0, i1, i2, i3 in T.grid(16, 56, 56, 64): with T.block("pad_temp"): i0_1, i1_1, i2_1, i3_1 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p0[i0_1, i1_1, i2_1, i3_1]) T.writes(pad_temp[i0_1, i1_1, i2_1, i3_1]) pad_temp[i0_1, i1_1, i2_1, i3_1] = p0[i0_1, i1_1, i2_1, i3_1] for i0, i1, i2, i3, i4, i5, i6 in T.grid(16, 56, 56, 256, 1, 1, 64): with T.block("conv2d_nhwc"): nn, yy, xx, ff, ry, rx, rc = T.axis.remap("SSSSRRR", [i0, i1, i2, i3, i4, i5, i6]) T.reads(pad_temp[nn, yy + ry, xx + rx, rc], p1[ff, ry, rx, rc]) T.writes(conv2d_nhwc[nn, yy, xx, ff]) with T.init(): conv2d_nhwc[nn, yy, xx, ff] = 0 conv2d_nhwc[nn, yy, xx, ff] = conv2d_nhwc[nn, yy, xx, ff] + T.cast(pad_temp[nn, yy + ry, xx + rx, rc], "int32") * T.cast(p1[ff, ry, rx, rc], "int32") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_subtract"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(conv2d_nhwc[ax0, ax1, ax2, ax3], p2[0, 0, 0, ax3]) T.writes(T_subtract[ax0, ax1, ax2, ax3]) T_subtract[ax0, ax1, ax2, ax3] = conv2d_nhwc[ax0, ax1, ax2, ax3] - p2[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_subtract[ax0, ax1, ax2, ax3], p3[0, 0, 0, ax3]) T.writes(T_add[ax0, ax1, ax2, ax3])
T_add[ax0, ax1, ax2, ax3] = T_subtract[ax0, ax1, ax2, ax3] + p3[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_cast"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add[ax0, ax1, ax2, ax3]) T.writes(T_cast[ax0, ax1, ax2, ax3]) T_cast[ax0, ax1, ax2, ax3] = T.cast(T_add[ax0, ax1, ax2, ax3], "int64") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_multiply"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_cast[ax0, ax1, ax2, ax3], p4[0, 0, 0, ax3]) T.writes(T_multiply[ax0, ax1, ax2, ax3]) T_multiply[ax0, ax1, ax2, ax3] = T_cast[ax0, ax1, ax2, ax3] * p4[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_multiply[ax0, ax1, ax2, ax3], p5[0, 0, 0, ax3]) T.writes(T_add_1[ax0, ax1, ax2, ax3]) T_add_1[ax0, ax1, ax2, ax3] = T_multiply[ax0, ax1, ax2, ax3] + p5[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_right_shift"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add_1[ax0, ax1, ax2, ax3], p6[0, 0, 0, ax3]) T.writes(T_right_shift[ax0, ax1, ax2, ax3]) T_right_shift[ax0, ax1, ax2, ax3] = T.shift_right(T_add_1[ax0, ax1, ax2, ax3], p6[0, 0, 0, ax3], dtype="int64") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_cast_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_right_shift[ax0, ax1, ax2, ax3]) T.writes(T_cast_1[ax0, ax1, ax2, ax3]) T_cast_1[ax0, ax1, ax2, ax3] = T.cast(T_right_shift[ax0, ax1, ax2, ax3], "int32") f
or i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add_2"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p7[()], T_cast_1[ax0, ax1, ax2, ax3]) T.writes(T_add_2[ax0, ax1, ax2, ax3]) T_add_2[ax0, ax1, ax2, ax3] = p7[()] + T_cast_1[ax0, ax1, ax2, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("compute"): i0_2, i1_2, i2_2, i3_2 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add_2[i0_2, i1_2, i2_2, i3_2]) T.writes(compute_1[i0_2, i1_2, i2_2, i3_2]) compute_1[i0_2, i1_2, i2_2, i3_2] = T.max(T.min(T_add_2[i0_2, i1_2, i2_2, i3_2], 255), 0) for i0_3, i1_3, i2_3, i3_3 in T.grid(16, 56, 56, 256): with T.block("T_cast_2"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_3, i1_3, i2_3, i3_3]) T.reads(compute_1[ax0, ax1, ax2, ax3]) T.writes(T_cast_2[ax0, ax1, ax2, ax3]) T_cast_2[ax0, ax1, ax2, ax3] = T.cast(compute_1[ax0, ax1, ax2, ax3], "uint8") for i0_4, i1_4, i2_4, i3_4 in T.grid(16, 56, 56, 256): with T.block("T_cast_3"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_4, i1_4, i2_4, i3_4]) T.reads(T_cast_2[ax0, ax1, ax2, ax3]) T.writes(T_cast_3[ax0, ax1, ax2, ax3]) T_cast_3[ax0, ax1, ax2, ax3] = T.cast(T_cast_2[ax0, ax1, ax2, ax3], "int32") for i0_5, i1_5, i2_5, i3_5 in T.grid(16, 56, 56, 256): with T.block("T_subtract_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_5, i1_5, i2_5, i3_5]) T.reads(T_cast_3[ax0, ax1, ax2, ax3], p8[0]) T.writes(T_subtract_1[ax0, ax1, ax2, ax3]) T_subtract_1[ax0, ax1, ax2, ax3] = T_cast_3[ax0, ax1, ax2, ax3] - p8[0] for i0_6, i1_6, i2_6, i3_6 in T.grid(16, 56, 56, 256): with T.block("compute_1"): i0_
7, i1_7, i2_7, i3_7 = T.axis.remap("SSSS", [i0_6, i1_6, i2_6, i3_6]) T.reads(T_subtract_1[i0_7, i1_7, i2_7, i3_7]) T.writes(compute[i0_7, i1_7, i2_7, i3_7]) compute[i0_7, i1_7, i2_7, i3_7] = T.q_multiply_shift(T_subtract_1[i0_7, i1_7, i2_7, i3_7], 1963325822, 31, 1, dtype="int32") @tvm.script.ir_module class Conv2dInt8_target: @T.prim_func def main(p0: T.Buffer[(16, 56, 56, 64), "int8"], p1: T.Buffer[(256, 1, 1, 64), "int8"], p2: T.Buffer[(1, 1, 1, 256), "int32"], p3: T.Buffer[(1, 1, 1, 256), "int32"], p4: T.Buffer[(1, 1, 1, 256), "int64"], p5: T.Buffer[(1, 1, 1, 256), "int64"], p6: T.Buffer[(1, 1, 1, 256), "int64"], p7: T.Buffer[(), "int32"], p8: T.Buffer[1, "int32"], p9: T.Buffer[(16, 56, 56, 256), "int32"], compute: T.Buffer[(16, 56, 56, 256), "uint8"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) pad_temp = T.alloc_buffer([16, 56, 56, 64], dtype="int8") conv2d_nhwc = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_subtract = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_add = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_cast = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_multiply = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_add_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_right_shift = T.alloc_buffer([16, 56, 56, 256], dtype="int64") T_cast_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_add_2 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") compute_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_cast_2 = T.alloc_buffer([16, 56, 56, 256], dtype="uint8") T_cast_3 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_subtract_1 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") compute_2 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") T_add_3 = T.alloc_buffer([16, 56, 56, 256], dtype="int32") compute_3 = T.a
lloc_buffer([16, 56, 56, 256], dtype="int32") T_cast_4 = T.alloc_buffer([16, 56, 56, 256], dtype="uint8") for i0, i1, i2, i3 in T.grid(16, 56, 56, 64): with T.block("pad_temp"): i0_1, i1_1, i2_1, i3_1 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p0[i0_1, i1_1, i2_1, i3_1]) T.writes(pad_temp[i0_1, i1_1, i2_1, i3_1]) pad_temp[i0_1, i1_1, i2_1, i3_1] = p0[i0_1, i1_1, i2_1, i3_1] for i0, i1, i2, i3, i4, i5, i6 in T.grid(16, 56, 56, 256, 1, 1, 64): with T.block("conv2d_nhwc"): nn, yy, xx, ff, ry, rx, rc = T.axis.remap("SSSSRRR", [i0, i1, i2, i3, i4, i5, i6]) T.reads(pad_temp[nn, yy + ry, xx + rx, rc], p1[ff, ry, rx, rc]) T.writes(conv2d_nhwc[nn, yy, xx, ff]) with T.init(): conv2d_nhwc[nn, yy, xx, ff] = 0 conv2d_nhwc[nn, yy, xx, ff] = conv2d_nhwc[nn, yy, xx, ff] + T.cast(pad_temp[nn, yy + ry, xx + rx, rc], "int32") * T.cast(p1[ff, ry, rx, rc], "int32") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_subtract"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(conv2d_nhwc[ax0, ax1, ax2, ax3], p2[0, 0, 0, ax3]) T.writes(T_subtract[ax0, ax1, ax2, ax3]) T_subtract[ax0, ax1, ax2, ax3] = conv2d_nhwc[ax0, ax1, ax2, ax3] - p2[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_subtract[ax0, ax1, ax2, ax3], p3[0, 0, 0, ax3]) T.writes(T_add[ax0, ax1, ax2, ax3]) T_add[ax0, ax1, ax2, ax3] = T_subtract[ax0, ax1, ax2, ax3] + p3[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_cast"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T
.reads(T_add[ax0, ax1, ax2, ax3]) T.writes(T_cast[ax0, ax1, ax2, ax3]) T_cast[ax0, ax1, ax2, ax3] = T.cast(T_add[ax0, ax1, ax2, ax3], "int64") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_multiply"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_cast[ax0, ax1, ax2, ax3], p4[0, 0, 0, ax3]) T.writes(T_multiply[ax0, ax1, ax2, ax3]) T_multiply[ax0, ax1, ax2, ax3] = T_cast[ax0, ax1, ax2, ax3] * p4[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_multiply[ax0, ax1, ax2, ax3], p5[0, 0, 0, ax3]) T.writes(T_add_1[ax0, ax1, ax2, ax3]) T_add_1[ax0, ax1, ax2, ax3] = T_multiply[ax0, ax1, ax2, ax3] + p5[0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_right_shift"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add_1[ax0, ax1, ax2, ax3], p6[0, 0, 0, ax3]) T.writes(T_right_shift[ax0, ax1, ax2, ax3]) T_right_shift[ax0, ax1, ax2, ax3] = T.shift_right(T_add_1[ax0, ax1, ax2, ax3], p6[0, 0, 0, ax3], dtype="int64") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_cast_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_right_shift[ax0, ax1, ax2, ax3]) T.writes(T_cast_1[ax0, ax1, ax2, ax3]) T_cast_1[ax0, ax1, ax2, ax3] = T.cast(T_right_shift[ax0, ax1, ax2, ax3], "int32") for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("T_add_2"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p7[()], T_cast_1[ax0, ax1, ax2, ax3]) T.writes(T_add_2[ax0, ax1, a
x2, ax3]) T_add_2[ax0, ax1, ax2, ax3] = p7[()] + T_cast_1[ax0, ax1, ax2, ax3] for i0, i1, i2, i3 in T.grid(16, 56, 56, 256): with T.block("compute"): i0_2, i1_2, i2_2, i3_2 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add_2[i0_2, i1_2, i2_2, i3_2]) T.writes(compute_1[i0_2, i1_2, i2_2, i3_2]) compute_1[i0_2, i1_2, i2_2, i3_2] = T.max(T.min(T_add_2[i0_2, i1_2, i2_2, i3_2], 255), 0) for i0_3, i1_3, i2_3, i3_3 in T.grid(16, 56, 56, 256): with T.block("T_cast_2"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_3, i1_3, i2_3, i3_3]) T.reads(compute_1[ax0, ax1, ax2, ax3]) T.writes(T_cast_2[ax0, ax1, ax2, ax3]) T_cast_2[ax0, ax1, ax2, ax3] = T.cast(compute_1[ax0, ax1, ax2, ax3], "uint8") for i0_4, i1_4, i2_4, i3_4 in T.grid(16, 56, 56, 256): with T.block("T_cast_3"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_4, i1_4, i2_4, i3_4]) T.reads(T_cast_2[ax0, ax1, ax2, ax3]) T.writes(T_cast_3[ax0, ax1, ax2, ax3]) T_cast_3[ax0, ax1, ax2, ax3] = T.cast(T_cast_2[ax0, ax1, ax2, ax3], "int32") for i0_5, i1_5, i2_5, i3_5 in T.grid(16, 56, 56, 256): with T.block("T_subtract_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_5, i1_5, i2_5, i3_5]) T.reads(T_cast_3[ax0, ax1, ax2, ax3], p8[0]) T.writes(T_subtract_1[ax0, ax1, ax2, ax3]) T_subtract_1[ax0, ax1, ax2, ax3] = T_cast_3[ax0, ax1, ax2, ax3] - p8[0] for i0_6, i1_6, i2_6, i3_6 in T.grid(16, 56, 56, 256): with T.block("compute_1"): i0_7, i1_7, i2_7, i3_7 = T.axis.remap("SSSS", [i0_6, i1_6, i2_6, i3_6]) T.reads(T_subtract_1[i0_7, i1_7, i2_7, i3_7]) T.writes(compute_2[i0_7, i1_7, i2_7, i3_7]) compute_2[i0_7, i1_7, i2_7, i3_7] = T.q_multiply_shift(T_s
ubtract_1[i0_7, i1_7, i2_7, i3_7], 1098990753, 31, 1, dtype="int32") for i0_8, i1_8, i2_8, i3_8 in T.grid(16, 56, 56, 256): with T.block("T_add_3"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_8, i1_8, i2_8, i3_8]) T.reads(compute_2[ax0, ax1, ax2, ax3], p9[ax0, ax1, ax2, ax3]) T.writes(T_add_3[ax0, ax1, ax2, ax3]) T_add_3[ax0, ax1, ax2, ax3] = compute_2[ax0, ax1, ax2, ax3] + p9[ax0, ax1, ax2, ax3] for i0_9, i1_9, i2_9, i3_9 in T.grid(16, 56, 56, 256): with T.block("compute_2"): i0_10, i1_10, i2_10, i3_10 = T.axis.remap("SSSS", [i0_9, i1_9, i2_9, i3_9]) T.reads(T_add_3[i0_10, i1_10, i2_10, i3_10]) T.writes(compute_3[i0_10, i1_10, i2_10, i3_10]) compute_3[i0_10, i1_10, i2_10, i3_10] = T.max(T.min(T_add_3[i0_10, i1_10, i2_10, i3_10], 255), 0) for i0_11, i1_11, i2_11, i3_11 in T.grid(16, 56, 56, 256): with T.block("T_cast_4"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0_11, i1_11, i2_11, i3_11]) T.reads(compute_3[ax0, ax1, ax2, ax3]) T.writes(T_cast_4[ax0, ax1, ax2, ax3]) T_cast_4[ax0, ax1, ax2, ax3] = T.cast(compute_3[ax0, ax1, ax2, ax3], "uint8") for i0_12, i1_12, i2_12, i3_12 in T.grid(16, 56, 56, 256): with T.block("compute_3"): i0_13, i1_13, i2_13, i3_13 = T.axis.remap("SSSS", [i0_12, i1_12, i2_12, i3_12]) T.reads(T_cast_4[i0_13, i1_13, i2_13, i3_13]) T.writes(compute[i0_13, i1_13, i2_13, i3_13]) compute[i0_13, i1_13, i2_13, i3_13] = T.max(T.min(T_cast_4[i0_13, i1_13, i2_13, i3_13], T.uint8(255)), T.uint8(0)) @tvm.script.ir_module class Conv2dInt8_tensorcore_scheduled: @T.prim_func def main(p0: T.Buffer[(16, 56, 56, 64), "int8"], p1: T.Buffer[(256, 1, 1, 64), "int8"], p2: T.Buffer[(1, 1, 1, 256), "int32"], p3: T.Buffer[(1, 1, 1, 256), "int32"], p4: T.Buffer[(1, 1, 1, 2
56), "int64"], p5: T.Buffer[(1, 1, 1, 256), "int64"], p6: T.Buffer[(1, 1, 1, 256), "int64"], p7: T.Buffer[(), "int32"], p8: T.Buffer[1, "int32"], p9: T.Buffer[(16, 56, 56, 256), "int32"], compute: T.Buffer[(16, 56, 56, 256), "uint8"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) a0 = T.var("int32") a1 = T.var("int32") b0 = T.var("int32") b1 = T.var("int32") c0 = T.var("int32") c1 = T.var("int32") d0 = T.var("int32") d0_1 = T.var("int32") d0_2 = T.var("int32") d0_3 = T.var("int32") d1 = T.var("int32") d1_1 = T.var("int32") d1_2 = T.var("int32") d1_3 = T.var("int32") s0 = T.var("int32") s0_1 = T.var("int32") s0_2 = T.var("int32") s1 = T.var("int32") s1_1 = T.var("int32") s1_2 = T.var("int32") conv2d_nhwc_reindex_shared = T.alloc_buffer([50176, 256], dtype="int32", scope="shared") conv2d_nhwc_reindex_shared_wmma_accumulator = T.alloc_buffer([50176, 256], dtype="int32", scope="wmma.accumulator") pad_temp_reindex_shared = T.alloc_buffer([50176, 64], dtype="int8", scope="shared") p1_reindex_shared = T.alloc_buffer([1, 1, 256, 64], dtype="int8", scope="shared") pad_temp_reindex_shared_wmma_matrix_a = T.alloc_buffer([50176, 64], dtype="int8", scope="wmma.matrix_a") p1_reindex_shared_wmma_matrix_b = T.alloc_buffer([1, 1, 256, 64], dtype="int8", scope="wmma.matrix_b") for ax2_0_0_ax3_0_0_fused in T.thread_binding(3136, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step":512, "pragma_unroll_explicit":1}): for ax2_0_1_ax3_0_1_fused in T.thread_binding(1, thread="vthread.x"): for ax2_0_2_ax3_0_2_fused in T.thread_binding(16, thread="threadIdx.x"): for ax0_0, ax1_0 in T.grid(1, 1): for ax2_0_3_init, ax3_0_3_init, ax2_0_4_init, ax3_0_4_init in T.grid(1, 1, 1, 1):
with T.block("conv2d_nhwc_o_init"): v2_o = T.axis.spatial(3136, ax2_0_0_ax3_0_0_fused v3_o = T.axis.spatial(16, ax3_0_4_init + ax2_0_0_ax3_0_0_fused % 8 * 2 + ax2_0_2_ax3_0_2_fused % 2 + ax3_0_3_init) T.reads() T.writes(conv2d_nhwc_reindex_shared_wmma_accumulator[v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16]) T.block_attr({"meta_schedule.thread_extent_high_inclusive":1024, "meta_schedule.thread_extent_low_inclusive":32, "warp_execution":1}) C = T.match_buffer(conv2d_nhwc_reindex_shared_wmma_accumulator[v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16], [16, 16], dtype="int32", strides=[d1, d0], scope="wmma.accumulator", offset_factor=16) T.evaluate(T.tvm_fill_fragment(C.data, 16, 16, 16, C.elem_offset for ax4_0_0 in T.serial(2): for ax0_ax1_fused_0 in T.serial(16): for ax0_ax1_fused_1 in T.thread_binding(16, thread="threadIdx.x"): for ax0_ax1_fused_2 in T.vectorized(16): with T.block("pad_temp_reindex_shared"): v0 = T.axis.spatial(50176, ax2_0_0_ax3_0_0_fused v1 = T.axis.spatial(64, ax4_0_0 * 32 + (ax0_ax1_fused_0 * 256 + ax0_ax1_fused_1 * 16 + ax0_ax1_fused_2) % 32) T.reads(p0[v0 T.writes(pad_temp_reindex_shared[v0, v1]) T.block_attr({"buffer_dim_align":[[0, 0, 32, 16]]}) pad_temp_reindex_shared[v0, v1] = p0[v0 for ax0_ax1_ax2_ax3_fused_0 in T.serial(8): for ax0_ax1_ax2_ax3_fused_1
in T.thread_binding(16, thread="threadIdx.x"): for ax0_ax1_ax2_ax3_fused_2 in T.vectorized(8): with T.block("p1_reindex_shared"): v0 = T.axis.spatial(1, 0) v1 = T.axis.spatial(1, 0) v2 = T.axis.spatial(256, ax2_0_0_ax3_0_0_fused % 8 * 32 + (ax0_ax1_ax2_ax3_fused_0 * 128 + ax0_ax1_ax2_ax3_fused_1 * 8 + ax0_ax1_ax2_ax3_fused_2) v3 = T.axis.spatial(64, ax4_0_0 * 32 + (ax0_ax1_ax2_ax3_fused_0 * 128 + ax0_ax1_ax2_ax3_fused_1 * 8 + ax0_ax1_ax2_ax3_fused_2) % 32) T.reads(p1[v2, v0, v1, v3]) T.writes(p1_reindex_shared[v0, v1, v2, v3]) T.block_attr({"buffer_dim_align":[[0, 2, 32, 16]]}) p1_reindex_shared[v0, v1, v2, v3] = p1[v2, v0, v1, v3] for ax0_1, ax1_1, ax4_0_1 in T.grid(1, 1, 1): for ax0_0_1, ax1_0_1 in T.grid(1, 2): with T.block("pad_temp_reindex_shared_wmma.matrix_a_o"): v0_o = T.axis.spatial(3136, ax2_0_0_ax3_0_0_fused v1_o = T.axis.spatial(4, ax4_0_0 * 2 + ax1_0_1) T.reads(pad_temp_reindex_shared[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16]) T.writes(pad_temp_reindex_shared_wmma_matrix_a[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16]) A = T.match_buffer(pad_temp_reindex_shared[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16], [16, 16], dtype="int8", strides=[s1, s0], scope="shared", offset_factor=16) C_1 = T.match_buffer(pad_temp_rei
ndex_shared_wmma_matrix_a[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16], [16, 16], dtype="int8", strides=[d1_1, d0_1], scope="wmma.matrix_a", offset_factor=16) T.evaluate(T.tvm_load_matrix_sync(C_1.data, 16, 16, 16, C_1.elem_offset for ax0, ax1, ax2_0, ax3_0 in T.grid(1, 1, 1, 2): with T.block("p1_reindex_shared_wmma.matrix_b_o"): v0 = T.axis.spatial(1, 0) v1 = T.axis.spatial(1, 0) v2_o = T.axis.spatial(16, ax2_0_0_ax3_0_0_fused % 8 * 2 + ax2_0_2_ax3_0_2_fused % 2) v3_o = T.axis.spatial(4, ax4_0_0 * 2 + ax3_0) T.reads(p1_reindex_shared[v0, v1, v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16]) T.writes(p1_reindex_shared_wmma_matrix_b[v0, v1, v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16]) A_1 = T.match_buffer(p1_reindex_shared[v0, v1, v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16], [16, 16], dtype="int8", strides=[s1_1, s0_1], scope="shared", offset_factor=16) C_2 = T.match_buffer(p1_reindex_shared_wmma_matrix_b[v0, v1, v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16], [16, 16], dtype="int8", strides=[d1_2, d0_2], scope="wmma.matrix_b", offset_factor=16) T.evaluate(T.tvm_load_matrix_sync(C_2.data, 16, 16, 16, C_2.elem_offset for ax2_0_3, ax3_0_3, ax0_2, ax1_2, ax4_0_2, ax2_0_4, ax3_0_4 in T.grid(1, 1, 1, 1, 2, 1, 1): with T.block("conv2d_nhwc_o_update"): v0 = T.axis.reduce(1, 0) v1 = T.axis.reduce(1, 0) v2_o = T.axis.spatial(31
36, ax2_0_0_ax3_0_0_fused v3_o = T.axis.spatial(16, ax3_0_4 + ax2_0_0_ax3_0_0_fused % 8 * 2 + ax2_0_2_ax3_0_2_fused % 2 + ax3_0_3) v4_o = T.axis.reduce(4, ax4_0_0 * 2 + ax4_0_1 * 2 + ax4_0_2) T.reads(conv2d_nhwc_reindex_shared_wmma_accumulator[v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16], pad_temp_reindex_shared_wmma_matrix_a[v2_o * 16 : v2_o * 16 + 16, v4_o * 16 : v4_o * 16 + 16], p1_reindex_shared_wmma_matrix_b[v0, v1, v3_o * 16 : v3_o * 16 + 16, v4_o * 16 : v4_o * 16 + 16]) T.writes(conv2d_nhwc_reindex_shared_wmma_accumulator[v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16]) T.block_attr({"meta_schedule.thread_extent_high_inclusive":1024, "meta_schedule.thread_extent_low_inclusive":32, "warp_execution":1}) A_2 = T.match_buffer(pad_temp_reindex_shared_wmma_matrix_a[v2_o * 16 : v2_o * 16 + 16, v4_o * 16 : v4_o * 16 + 16], [16, 16], dtype="int8", strides=[a1, a0], scope="wmma.matrix_a", offset_factor=16) B = T.match_buffer(p1_reindex_shared_wmma_matrix_b[v0, v1, v3_o * 16 : v3_o * 16 + 16, v4_o * 16 : v4_o * 16 + 16], [16, 16], dtype="int8", strides=[b1, b0], scope="wmma.matrix_b", offset_factor=16) C_3 = T.match_buffer(conv2d_nhwc_reindex_shared_wmma_accumulator[v2_o * 16 : v2_o * 16 + 16, v3_o * 16 : v3_o * 16 + 16], [16, 16], dtype="int32", strides=[c1, c0], scope="wmma.accumulator", offset_factor=16) T.evaluate(T.tvm_mma_sync(C_3.data, C_3.elem_offset for ax0_0, ax1_0 in T.grid(1, 1): with T.block("conv2d_nhwc_reindex_shared_wmma.accumulator_o"): v0_o = T.axis.spatial(3136, ax2_0_0_ax3_0_0_fused v1_o = T.axis.spatial(16, ax2_0_0_ax3_0_0_
fused % 8 * 2 + ax2_0_2_ax3_0_2_fused % 2) T.reads(conv2d_nhwc_reindex_shared_wmma_accumulator[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16]) T.writes(conv2d_nhwc_reindex_shared[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16]) A_3 = T.match_buffer(conv2d_nhwc_reindex_shared_wmma_accumulator[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16], [16, 16], dtype="int32", strides=[d1_3, d0_3], scope="wmma.accumulator", offset_factor=16) C_4 = T.match_buffer(conv2d_nhwc_reindex_shared[v0_o * 16 : v0_o * 16 + 16, v1_o * 16 : v1_o * 16 + 16], [16, 16], dtype="int32", strides=[s1_2, s0_2], scope="shared", offset_factor=16) T.evaluate(T.tvm_store_matrix_sync(A_3.data, 16, 16, 16, A_3.elem_offset for ax0, ax1_0 in T.grid(128, 2): for ax1_1 in T.thread_binding(16, thread="threadIdx.x"): with T.block("conv2d_nhwc_reindex_shared"): v0 = T.axis.spatial(50176, ax2_0_0_ax3_0_0_fused v1 = T.axis.spatial(256, ax2_0_0_ax3_0_0_fused % 8 * 32 + ax1_0 * 16 + ax1_1) T.reads(p7[()], conv2d_nhwc_reindex_shared[v0, v1], p2[0, 0, 0, v1], p3[0, 0, 0, v1], p4[0, 0, 0, v1], p5[0, 0, 0, v1], p6[0, 0, 0, v1], p8[0], p9[v0 T.writes(compute[v0 compute[v0 @tvm.script.ir_module class Conv2dInt8_NCHWc: @T.prim_func def main(p0: T.Buffer[(1, 32, 7, 7, 16), "uint8"], p1: T.Buffer[(128, 32, 1, 1, 4, 16, 4), "int8"], p2: T.Buffer[(1, 128, 1, 1, 16), "int32"], p3: T.Buffer[(1, 128, 1, 1, 16), "float32"], p4: T.Buffer[1, "float32"], p5: T.Buffer[(1, 128, 7, 7, 16), "int32"], compute: T.Buffer[(1, 128, 7, 7, 16), "uint8"]) -> None: T.func_attr({"tir.noalias": True, "global_symbol": "main"}) compile_engine_const = T.alloc_buffer([], dtype="float3
2") conv2d_NCHWc_int8 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_add = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_multiply = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") compile_engine_const_1 = T.alloc_buffer([], dtype="float32") T_add_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_floor = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_cast_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") compute_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="uint8") T_cast_3 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_subtract = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_multiply_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") compile_engine_const_2 = T.alloc_buffer([], dtype="float32") T_add_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_floor_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_cast_4 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_add_3 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") compute_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast_5 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="uint8") with T.block("compile_engine_const"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const[()]) compile_engine_const[()] = T.float32(0.94537687301635742) for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in T.grid(1, 128, 7, 7, 16, 1, 1, 32, 4, 4): with T.block("conv2d_NCHWc_int8"): n, oc_chunk, oh, ow, oc_block, kh, kw, ic_outer, ic_f_inner, ic_s_inner = T.axis.remap("SSSSSRRRRR", [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]) T.reads(p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 + ic_s_inner], p1[oc_chunk, ic_outer,
kh, kw, ic_f_inner, oc_block, ic_s_inner]) T.writes(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block]) T.block_attr({"schedule_rule":"meta_schedule.conv2d_NCHWc_int8", "workload":["conv2d_NCHWc_int8.x86", ["TENSOR", [1, 32, 7, 7, 16], "uint8"], ["TENSOR", [128, 32, 1, 1, 4, 16, 4], "int8"], [1, 1], [0, 0, 0, 0], [1, 1], "NCHW16c", "NCHW16c", "int32"]}) with T.init(): conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] = 0 conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] = conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] + T.cast(p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 + ic_s_inner], "int32") * T.cast(p1[oc_chunk, ic_outer, kh, kw, ic_f_inner, oc_block, ic_s_inner], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(conv2d_NCHWc_int8[ax0, ax1, ax2, ax3, ax4], p2[ax0, ax1, 0, 0, ax4]) T.writes(T_add[ax0, ax1, ax2, ax3, ax4]) T_add[ax0, ax1, ax2, ax3, ax4] = conv2d_NCHWc_int8[ax0, ax1, ax2, ax3, ax4] + p2[ax0, ax1, 0, 0, ax4] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast[ax0, ax1, ax2, ax3, ax4]) T_cast[ax0, ax1, ax2, ax3, ax4] = T.cast(T_add[ax0, ax1, ax2, ax3, ax4], "float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_multiply"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast[ax0, ax1, ax2, ax3, ax4], p3[ax0, ax1, 0, 0, ax4]) T.writes(T_multiply[ax0, ax1, ax2, ax3, ax4]) T_multiply[ax0, ax1, ax2, ax3, ax4] = T_cast[ax0, ax1, ax2, ax3, ax4] * p3[ax0, ax1,
0, 0, ax4] with T.block("compile_engine_const_1"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_1[()]) compile_engine_const_1[()] = T.float32(54.5) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_multiply[ax0, ax1, ax2, ax3, ax4], compile_engine_const_1[()]) T.writes(T_add_1[ax0, ax1, ax2, ax3, ax4]) T_add_1[ax0, ax1, ax2, ax3, ax4] = T_multiply[ax0, ax1, ax2, ax3, ax4] + compile_engine_const_1[()] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_floor"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_floor[ax0, ax1, ax2, ax3, ax4]) T_floor[ax0, ax1, ax2, ax3, ax4] = T.floor(T_add_1[ax0, ax1, ax2, ax3, ax4], dtype="float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_floor[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_1[ax0, ax1, ax2, ax3, ax4]) T_cast_1[ax0, ax1, ax2, ax3, ax4] = T.cast(T_floor[ax0, ax1, ax2, ax3, ax4], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("compute"): i0_1, i1_1, i2_1, i3_1, i4_1 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_1[i0_1, i1_1, i2_1, i3_1, i4_1]) T.writes(compute_1[i0_1, i1_1, i2_1, i3_1, i4_1]) compute_1[i0_1, i1_1, i2_1, i3_1, i4_1] = T.max(T.min(T_cast_1[i0_1, i1_1, i2_1, i3_1, i4_1], 255), 0) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_2"): ax0, ax1,
ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(compute_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_2[ax0, ax1, ax2, ax3, ax4]) T_cast_2[ax0, ax1, ax2, ax3, ax4] = T.cast(compute_1[ax0, ax1, ax2, ax3, ax4], "uint8") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_3"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_3[ax0, ax1, ax2, ax3, ax4]) T_cast_3[ax0, ax1, ax2, ax3, ax4] = T.cast(T_cast_2[ax0, ax1, ax2, ax3, ax4], "float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_subtract"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_3[ax0, ax1, ax2, ax3, ax4], p4[0]) T.writes(T_subtract[ax0, ax1, ax2, ax3, ax4]) T_subtract[ax0, ax1, ax2, ax3, ax4] = T_cast_3[ax0, ax1, ax2, ax3, ax4] - p4[0] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_multiply_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(compile_engine_const[()], T_subtract[ax0, ax1, ax2, ax3, ax4]) T.writes(T_multiply_1[ax0, ax1, ax2, ax3, ax4]) T_multiply_1[ax0, ax1, ax2, ax3, ax4] = compile_engine_const[()] * T_subtract[ax0, ax1, ax2, ax3, ax4] with T.block("compile_engine_const_2"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_2[()]) compile_engine_const_2[()] = T.float32(0.5) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_2"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_multiply_1[ax0, ax1, ax2, ax3, ax4], compile_engine_const_2[()])
T.writes(T_add_2[ax0, ax1, ax2, ax3, ax4]) T_add_2[ax0, ax1, ax2, ax3, ax4] = T_multiply_1[ax0, ax1, ax2, ax3, ax4] + compile_engine_const_2[()] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_floor_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_floor_1[ax0, ax1, ax2, ax3, ax4]) T_floor_1[ax0, ax1, ax2, ax3, ax4] = T.floor(T_add_2[ax0, ax1, ax2, ax3, ax4], dtype="float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_4"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_floor_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_4[ax0, ax1, ax2, ax3, ax4]) T_cast_4[ax0, ax1, ax2, ax3, ax4] = T.cast(T_floor_1[ax0, ax1, ax2, ax3, ax4], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_3"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_4[ax0, ax1, ax2, ax3, ax4], p5[ax0, ax1, ax2, ax3, ax4]) T.writes(T_add_3[ax0, ax1, ax2, ax3, ax4]) T_add_3[ax0, ax1, ax2, ax3, ax4] = T_cast_4[ax0, ax1, ax2, ax3, ax4] + p5[ax0, ax1, ax2, ax3, ax4] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("compute_1"): i0_2, i1_2, i2_2, i3_2, i4_2 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_3[i0_2, i1_2, i2_2, i3_2, i4_2]) T.writes(compute_2[i0_2, i1_2, i2_2, i3_2, i4_2]) compute_2[i0_2, i1_2, i2_2, i3_2, i4_2] = T.max(T.min(T_add_3[i0_2, i1_2, i2_2, i3_2, i4_2], 255), 0) for i0_3, i1_3, i2_3, i3_3, i4_3 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_5"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SS
SSS", [i0_3, i1_3, i2_3, i3_3, i4_3]) T.reads(compute_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_5[ax0, ax1, ax2, ax3, ax4]) T_cast_5[ax0, ax1, ax2, ax3, ax4] = T.cast(compute_2[ax0, ax1, ax2, ax3, ax4], "uint8") for i0_4, i1_4, i2_4, i3_4, i4_4 in T.grid(1, 128, 7, 7, 16): with T.block("compute_2"): i0_5, i1_5, i2_5, i3_5, i4_5 = T.axis.remap("SSSSS", [i0_4, i1_4, i2_4, i3_4, i4_4]) T.reads(T_cast_5[i0_5, i1_5, i2_5, i3_5, i4_5]) T.writes(compute[i0_5, i1_5, i2_5, i3_5, i4_5]) compute[i0_5, i1_5, i2_5, i3_5, i4_5] = T.max(T.min(T_cast_5[i0_5, i1_5, i2_5, i3_5, i4_5], T.uint8(255)), T.uint8(0)) @tvm.script.ir_module class Conv2dInt8_NCHWc_target: @T.prim_func def main(p0: T.Buffer[(1, 32, 7, 7, 16), "uint8"], p1: T.Buffer[(128, 32, 1, 1, 4, 16, 4), "int8"], p2: T.Buffer[(1, 128, 1, 1, 16), "int32"], p3: T.Buffer[(1, 128, 1, 1, 16), "float32"], p4: T.Buffer[1, "float32"], p5: T.Buffer[(1, 128, 7, 7, 16), "uint8"], T_cast: T.Buffer[(1, 128, 7, 7, 16), "int32"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True}) compile_engine_const = T.alloc_buffer([], dtype="float32") conv2d_NCHWc_int8 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_add = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_multiply = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") compile_engine_const_1 = T.alloc_buffer([], dtype="float32") T_add_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_floor = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_cast_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") compute = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast_3 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="uint8") T_cast_4 = T.alloc_buffer([1, 128, 7, 7, 16], dty
pe="float32") T_subtract = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_multiply_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") compile_engine_const_2 = T.alloc_buffer([], dtype="float32") T_add_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_floor_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_cast_5 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") compile_engine_const_3 = T.alloc_buffer([], dtype="float32") T_cast_6 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_multiply_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") compile_engine_const_4 = T.alloc_buffer([], dtype="float32") T_add_3 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_floor_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="float32") T_cast_7 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_add_4 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") compute_1 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") T_cast_8 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="uint8") compute_2 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="uint8") with T.block("compile_engine_const"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const[()]) compile_engine_const[()] = T.float32(0.95489668846130371) for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in T.grid(1, 128, 7, 7, 16, 1, 1, 32, 4, 4): with T.block("conv2d_NCHWc_int8"): n, oc_chunk, oh, ow, oc_block, kh, kw, ic_outer, ic_f_inner, ic_s_inner = T.axis.remap("SSSSSRRRRR", [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]) T.reads(p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 + ic_s_inner], p1[oc_chunk, ic_outer, kh, kw, ic_f_inner, oc_block, ic_s_inner]) T.writes(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block]) T.block_attr({"schedule_rule":"meta_schedule.conv2d_NCHWc_int8",
"workload":["conv2d_NCHWc_int8.x86", ["TENSOR", [1, 32, 7, 7, 16], "uint8"], ["TENSOR", [128, 32, 1, 1, 4, 16, 4], "int8"], [1, 1], [0, 0, 0, 0], [1, 1], "NCHW16c", "NCHW16c", "int32"]}) with T.init(): conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] = 0 conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] = conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block] + T.cast(p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 + ic_s_inner], "int32") * T.cast(p1[oc_chunk, ic_outer, kh, kw, ic_f_inner, oc_block, ic_s_inner], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(conv2d_NCHWc_int8[ax0, ax1, ax2, ax3, ax4], p2[ax0, ax1, 0, 0, ax4]) T.writes(T_add[ax0, ax1, ax2, ax3, ax4]) T_add[ax0, ax1, ax2, ax3, ax4] = conv2d_NCHWc_int8[ax0, ax1, ax2, ax3, ax4] + p2[ax0, ax1, 0, 0, ax4] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_1[ax0, ax1, ax2, ax3, ax4]) T_cast_1[ax0, ax1, ax2, ax3, ax4] = T.cast(T_add[ax0, ax1, ax2, ax3, ax4], "float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_multiply"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_1[ax0, ax1, ax2, ax3, ax4], p3[ax0, ax1, 0, 0, ax4]) T.writes(T_multiply[ax0, ax1, ax2, ax3, ax4]) T_multiply[ax0, ax1, ax2, ax3, ax4] = T_cast_1[ax0, ax1, ax2, ax3, ax4] * p3[ax0, ax1, 0, 0, ax4] with T.block("compile_engine_const_1"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_1[()]) compile_en
gine_const_1[()] = T.float32(65.5) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_multiply[ax0, ax1, ax2, ax3, ax4], compile_engine_const_1[()]) T.writes(T_add_1[ax0, ax1, ax2, ax3, ax4]) T_add_1[ax0, ax1, ax2, ax3, ax4] = T_multiply[ax0, ax1, ax2, ax3, ax4] + compile_engine_const_1[()] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_floor"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_floor[ax0, ax1, ax2, ax3, ax4]) T_floor[ax0, ax1, ax2, ax3, ax4] = T.floor(T_add_1[ax0, ax1, ax2, ax3, ax4], dtype="float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_floor[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_2[ax0, ax1, ax2, ax3, ax4]) T_cast_2[ax0, ax1, ax2, ax3, ax4] = T.cast(T_floor[ax0, ax1, ax2, ax3, ax4], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("compute"): i0_1, i1_1, i2_1, i3_1, i4_1 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_2[i0_1, i1_1, i2_1, i3_1, i4_1]) T.writes(compute[i0_1, i1_1, i2_1, i3_1, i4_1]) compute[i0_1, i1_1, i2_1, i3_1, i4_1] = T.max(T.min(T_cast_2[i0_1, i1_1, i2_1, i3_1, i4_1], 255), 0) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_2"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(compute[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_3[ax0, ax1, ax2, ax3, ax4]) T
_cast_3[ax0, ax1, ax2, ax3, ax4] = T.cast(compute[ax0, ax1, ax2, ax3, ax4], "uint8") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_3"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_3[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_4[ax0, ax1, ax2, ax3, ax4]) T_cast_4[ax0, ax1, ax2, ax3, ax4] = T.cast(T_cast_3[ax0, ax1, ax2, ax3, ax4], "float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_subtract"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_4[ax0, ax1, ax2, ax3, ax4], p4[0]) T.writes(T_subtract[ax0, ax1, ax2, ax3, ax4]) T_subtract[ax0, ax1, ax2, ax3, ax4] = T_cast_4[ax0, ax1, ax2, ax3, ax4] - p4[0] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_multiply_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(compile_engine_const[()], T_subtract[ax0, ax1, ax2, ax3, ax4]) T.writes(T_multiply_1[ax0, ax1, ax2, ax3, ax4]) T_multiply_1[ax0, ax1, ax2, ax3, ax4] = compile_engine_const[()] * T_subtract[ax0, ax1, ax2, ax3, ax4] with T.block("compile_engine_const_2"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_2[()]) compile_engine_const_2[()] = T.float32(0.5) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_2"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_multiply_1[ax0, ax1, ax2, ax3, ax4], compile_engine_const_2[()]) T.writes(T_add_2[ax0, ax1, ax2, ax3, ax4]) T_add_2[ax0, ax1, ax2, ax3, ax4] = T_multiply_1[ax0, ax1, ax2, ax3, ax4] + compile_engine_const_2[()] for i0, i1, i2,
i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_floor_1"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_floor_1[ax0, ax1, ax2, ax3, ax4]) T_floor_1[ax0, ax1, ax2, ax3, ax4] = T.floor(T_add_2[ax0, ax1, ax2, ax3, ax4], dtype="float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_4"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_floor_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_5[ax0, ax1, ax2, ax3, ax4]) T_cast_5[ax0, ax1, ax2, ax3, ax4] = T.cast(T_floor_1[ax0, ax1, ax2, ax3, ax4], "int32") with T.block("compile_engine_const_3"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_3[()]) compile_engine_const_3[()] = T.float32(0.71245479583740234) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_5"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(p5[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_6[ax0, ax1, ax2, ax3, ax4]) T_cast_6[ax0, ax1, ax2, ax3, ax4] = T.cast(p5[ax0, ax1, ax2, ax3, ax4], "float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_multiply_2"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(compile_engine_const_3[()], T_cast_6[ax0, ax1, ax2, ax3, ax4]) T.writes(T_multiply_2[ax0, ax1, ax2, ax3, ax4]) T_multiply_2[ax0, ax1, ax2, ax3, ax4] = compile_engine_const_3[()] * T_cast_6[ax0, ax1, ax2, ax3, ax4] with T.block("compile_engine_const_4"): vi = T.axis.spatial(1, 0) T.reads() T.writes(compile_engine_const_4[()])
compile_engine_const_4[()] = T.float32(0.5) for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_3"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_multiply_2[ax0, ax1, ax2, ax3, ax4], compile_engine_const_4[()]) T.writes(T_add_3[ax0, ax1, ax2, ax3, ax4]) T_add_3[ax0, ax1, ax2, ax3, ax4] = T_multiply_2[ax0, ax1, ax2, ax3, ax4] + compile_engine_const_4[()] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_floor_2"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_3[ax0, ax1, ax2, ax3, ax4]) T.writes(T_floor_2[ax0, ax1, ax2, ax3, ax4]) T_floor_2[ax0, ax1, ax2, ax3, ax4] = T.floor(T_add_3[ax0, ax1, ax2, ax3, ax4], dtype="float32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_6"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_floor_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_7[ax0, ax1, ax2, ax3, ax4]) T_cast_7[ax0, ax1, ax2, ax3, ax4] = T.cast(T_floor_2[ax0, ax1, ax2, ax3, ax4], "int32") for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("T_add_4"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_cast_5[ax0, ax1, ax2, ax3, ax4], T_cast_7[ax0, ax1, ax2, ax3, ax4]) T.writes(T_add_4[ax0, ax1, ax2, ax3, ax4]) T_add_4[ax0, ax1, ax2, ax3, ax4] = T_cast_5[ax0, ax1, ax2, ax3, ax4] + T_cast_7[ax0, ax1, ax2, ax3, ax4] for i0, i1, i2, i3, i4 in T.grid(1, 128, 7, 7, 16): with T.block("compute_1"): i0_2, i1_2, i2_2, i3_2, i4_2 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4]) T.reads(T_add_4[i0_2, i1_2, i2_2, i3_2, i4_2])
T.writes(compute_1[i0_2, i1_2, i2_2, i3_2, i4_2]) compute_1[i0_2, i1_2, i2_2, i3_2, i4_2] = T.max(T.min(T_add_4[i0_2, i1_2, i2_2, i3_2, i4_2], 255), 0) for i0_3, i1_3, i2_3, i3_3, i4_3 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_7"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0_3, i1_3, i2_3, i3_3, i4_3]) T.reads(compute_1[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast_8[ax0, ax1, ax2, ax3, ax4]) T_cast_8[ax0, ax1, ax2, ax3, ax4] = T.cast(compute_1[ax0, ax1, ax2, ax3, ax4], "uint8") for i0_4, i1_4, i2_4, i3_4, i4_4 in T.grid(1, 128, 7, 7, 16): with T.block("compute_2"): i0_5, i1_5, i2_5, i3_5, i4_5 = T.axis.remap("SSSSS", [i0_4, i1_4, i2_4, i3_4, i4_4]) T.reads(T_cast_8[i0_5, i1_5, i2_5, i3_5, i4_5]) T.writes(compute_2[i0_5, i1_5, i2_5, i3_5, i4_5]) compute_2[i0_5, i1_5, i2_5, i3_5, i4_5] = T.max(T.min(T_cast_8[i0_5, i1_5, i2_5, i3_5, i4_5], T.uint8(255)), T.uint8(0)) for i0_6, i1_6, i2_6, i3_6, i4_6 in T.grid(1, 128, 7, 7, 16): with T.block("T_cast_8"): ax0, ax1, ax2, ax3, ax4 = T.axis.remap("SSSSS", [i0_6, i1_6, i2_6, i3_6, i4_6]) T.reads(compute_2[ax0, ax1, ax2, ax3, ax4]) T.writes(T_cast[ax0, ax1, ax2, ax3, ax4]) T_cast[ax0, ax1, ax2, ax3, ax4] = T.cast(compute_2[ax0, ax1, ax2, ax3, ax4], "int32") def get_conv2d_vnni_mod(intrin_id): @tvm.script.ir_module class Conv2dInt8_NCHWc_scheduled: @T.prim_func def main(p0: T.Buffer[(1, 32, 7, 7, 16), "uint8"], p1: T.Buffer[(128, 32, 1, 1, 4, 16, 4), "int8"], p2: T.Buffer[(1, 128, 1, 1, 16), "int32"], p3: T.Buffer[(1, 128, 1, 1, 16), "float32"], p4: T.Buffer[1, "float32"], p5: T.Buffer[(1, 128, 7, 7, 16), "uint8"], T_cast: T.Buffer[(1, 128, 7, 7, 16), "int32"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True})
conv2d_NCHWc_int8 = T.alloc_buffer([1, 128, 7, 7, 16], dtype="int32") for i0_0_i1_0_i2_0_i3_0_i4_0_0_i0_1_i1_1_fused in T.parallel(128, annotations={"pragma_auto_unroll_max_step":64, "pragma_unroll_explicit":1}): for i2_1, i3_1, i4_0_1 in T.grid(7, 1, 1): for i5_0, i6_0 in T.grid(1, 1): for i1_2_init, i2_2_init, i3_2_init, i1_3_init, i2_3_init, i3_3_init in T.grid(1, 1, 1, 1, 1, 7): with T.block("conv2d_NCHWc_int8_o_init"): n = T.axis.spatial(1, 0) oc_chunk = T.axis.spatial(128, i1_2_init + i1_3_init + i0_0_i1_0_i2_0_i3_0_i4_0_0_i0_1_i1_1_fused oh = T.axis.spatial(7, i2_1 + i2_2_init + i2_3_init) ow = T.axis.spatial(7, i3_1 * 7 + i3_2_init * 7 + i3_3_init) oc_block_o = T.axis.spatial(1, 0) T.reads() T.writes(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, 0 : 16]) for i4_1 in T.vectorized(16): with T.block("conv2d_NCHWc_int8_init"): oc_block_i_init = T.axis.spatial(16, i4_1) T.reads() T.writes(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block_i_init]) conv2d_NCHWc_int8[n, oc_chunk, oh, ow, oc_block_i_init] = 0 for i7_0, i8_0, i9_0_0, i0_2, i1_2, i2_2, i3_2, i4_0_2, i5_1, i6_1, i7_1, i8_1, i9_0_1, i0_3, i1_3, i2_3, i3_3, i4_0_3 in T.grid(4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 7, 1): with T.block("conv2d_NCHWc_int8_o_update"): n = T.axis.spatial(1, 0) oc_chunk = T.axis.spatial(128, i1_2 + i1_3 + i0_0_i1_0_i2_0_i3_0_i4_0_0_i0_1_i1_1_fused
oh = T.axis.spatial(7, i2_1 + i2_2 + i2_3) ow = T.axis.spatial(7, i3_1 * 7 + i3_2 * 7 + i3_3) oc_block_o = T.axis.spatial(1, 0) kh = T.axis.reduce(1, 0) kw = T.axis.reduce(1, 0) ic_outer = T.axis.reduce(32, i7_0 * 8 + i7_1) ic_f_inner = T.axis.reduce(4, i8_1 + i8_0) ic_s_inner_o = T.axis.reduce(1, 0) T.reads(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, 0 : 16], p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 : ic_f_inner * 4 + 4], p1[oc_chunk, ic_outer, kh, kw, ic_f_inner, 0 : 16, 0 : 4]) T.writes(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, 0 : 16]) A = T.match_buffer(p0[n, ic_outer, oh + kh, ow + kw, ic_f_inner * 4 : ic_f_inner * 4 + 4], [4], dtype="uint8", offset_factor=1) B = T.match_buffer(p1[oc_chunk, ic_outer, kh, kw, ic_f_inner, 0 : 16, 0 : 4], [16, 4], dtype="int8", offset_factor=1) C = T.match_buffer(conv2d_NCHWc_int8[n, oc_chunk, oh, ow, 0 : 16], [16], dtype="int32", offset_factor=1) A_u8x4: T.uint8x4 = A[0:4] A_i32: T.int32 = T.reinterpret(A_u8x4, dtype="int32") B_i8x64: T.int8x64 = B[0, 0:64] B_i32x16: T.int32x16 = T.reinterpret(B_i8x64, dtype="int32x16") C_i32x16: T.int32x16 = C[0:16] C[0:16] = T.call_llvm_pure_intrin(intrin_id, T.uint32(0), C_i32x16, T.broadcast(A_i32, 16), B_i32x16, dtype="int32x16") for ax0, ax1, ax2, ax3 in T.grid(1, 1, 1, 7): for ax4_fused in T.vectorized(16): with T.block("T_cast_8"): ax0_1
= T.axis.spatial(1, ax0) ax1_1 = T.axis.spatial(128, i0_0_i1_0_i2_0_i3_0_i4_0_0_i0_1_i1_1_fused ax2_1 = T.axis.spatial(7, i2_1 + ax2) ax3_1, ax4 = T.axis.remap("SS", [ax3, ax4_fused]) T.reads(conv2d_NCHWc_int8[ax0_1, ax1_1, ax2_1, ax3_1, ax4], p2[ax0_1, ax1_1, 0, 0, ax4], p3[ax0_1, ax1_1, 0, 0, ax4], p4[0], p5[ax0_1, ax1_1, ax2_1, ax3_1, ax4]) T.writes(T_cast[ax0_1, ax1_1, ax2_1, ax3_1, ax4]) T_cast[ax0_1, ax1_1, ax2_1, ax3_1, ax4] = T.cast(T.max(T.min(T.cast(T.max(T.min(T.cast(T.floor(T.float32(0.95489668846130371) * (T.cast(T.cast(T.max(T.min(T.cast(T.floor(T.cast(conv2d_NCHWc_int8[ax0_1, ax1_1, ax2_1, ax3_1, ax4] + p2[ax0_1, ax1_1, 0, 0, ax4], "float32") * p3[ax0_1, ax1_1, 0, 0, ax4] + T.float32(65.5), dtype="float32"), "int32"), 255), 0), "uint8"), "float32") - p4[0]) + T.float32(0.5), dtype="float32"), "int32") + T.cast(T.floor(T.float32(0.71245479583740234) * T.cast(p5[ax0_1, ax1_1, ax2_1, ax3_1, ax4], "float32") + T.float32(0.5), dtype="float32"), "int32"), 255), 0), "uint8"), T.uint8(255)), T.uint8(0)), "int32") return Conv2dInt8_NCHWc_scheduled @tvm.script.ir_module class Conv2dWinogradAddRelu: @T.prim_func def main(p0: T.Buffer[(1, 56, 56, 64), "float32"], p1: T.Buffer[(6, 6, 64, 64), "float32"], p2: T.Buffer[(1, 1, 1, 64), "float32"], T_relu: T.Buffer[(1, 56, 56, 64), "float32"]) -> None: T.func_attr({"layout_free_buffers": [1], "tir.noalias": True, "global_symbol": "main"}) data_pad = T.alloc_buffer([1, 58, 58, 64], dtype="float32") input_tile = T.alloc_buffer([6, 6, 196, 64], dtype="float32") B = T.alloc_buffer([6, 6], dtype="float32") data_pack = T.alloc_buffer([6, 6, 196, 64], dtype="float32") bgemm = T.alloc_buffer([6, 6, 196, 64], dtype="float32") A = T.alloc_buffer([6, 4], dtype="float32") inverse = T.
alloc_buffer([4, 4, 196, 64], dtype="float32") conv2d_winograd = T.alloc_buffer([1, 56, 56, 64], dtype="float32") T_add = T.alloc_buffer([1, 56, 56, 64], dtype="float32") for i0, i1, i2, i3 in T.grid(1, 58, 58, 64): with T.block("data_pad"): i0_1, i1_1, i2_1, i3_1 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p0[i0_1, i1_1 - 1, i2_1 - 1, i3_1]) T.writes(data_pad[i0_1, i1_1, i2_1, i3_1]) T.block_attr({"schedule_rule":"None"}) data_pad[i0_1, i1_1, i2_1, i3_1] = T.if_then_else(1 <= i1_1 and i1_1 < 57 and 1 <= i2_1 and i2_1 < 57, p0[i0_1, i1_1 - 1, i2_1 - 1, i3_1], T.float32(0), dtype="float32") for i0, i1, i2, i3 in T.grid(6, 6, 196, 64): with T.block("input_tile"): eps, nu, p, ci = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(data_pad[p T.writes(input_tile[eps, nu, p, ci]) T.block_attr({"schedule_rule":"None"}) input_tile[eps, nu, p, ci] = data_pad[p for i0, i1 in T.grid(6, 6): with T.block("B"): i, j = T.axis.remap("SS", [i0, i1]) T.reads() T.writes(B[i, j]) T.block_attr({"const_matrix":True, "schedule_rule":"meta_schedule.compute_inline"}) B[i, j] = T.Select(i % 6 == 5 and j % 6 == 5, T.float32(1), T.Select(i % 6 == 5 and j % 6 == 4, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 3, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 2, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 1, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 0, T.float32(0), T.Select(i % 6 == 4 and j % 6 == 5, T.float32(1.5), T.Select(i % 6 == 4 and j % 6 == 4, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 3, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 2, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 1, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 0, T.float32(1), T.Select(i % 6 == 3 and j % 6 == 5, T.float32(-2), T.Sele
ct(i % 6 == 3 and j % 6 == 4, T.float32(-0.5), T.Select(i % 6 == 3 and j % 6 == 3, T.float32(2), T.Select(i % 6 == 3 and j % 6 == 2, T.float32(2.5), T.Select(i % 6 == 3 and j % 6 == 1, T.float32(0.5), T.Select(i % 6 == 3 and j % 6 == 0, T.float32(1.5), T.Select(i % 6 == 2 and j % 6 == 5, T.float32(-1.5), T.Select(i % 6 == 2 and j % 6 == 4, T.float32(-1), T.Select(i % 6 == 2 and j % 6 == 3, T.float32(-1), T.Select(i % 6 == 2 and j % 6 == 2, T.float32(0.5), T.Select(i % 6 == 2 and j % 6 == 1, T.float32(-2.5), T.Select(i % 6 == 2 and j % 6 == 0, T.float32(-2), T.Select(i % 6 == 1 and j % 6 == 5, T.float32(1), T.Select(i % 6 == 1 and j % 6 == 4, T.float32(0.5), T.Select(i % 6 == 1 and j % 6 == 3, T.float32(-2), T.Select(i % 6 == 1 and j % 6 == 2, T.float32(-1), T.Select(i % 6 == 1 and j % 6 == 1, T.float32(1), T.Select(i % 6 == 1 and j % 6 == 0, T.float32(-1.5), T.Select(i % 6 == 0 and j % 6 == 5, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 4, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 3, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 2, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 1, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))))))))))))))) for i0, i1, i2, i3, i4, i5 in T.grid(6, 6, 196, 64, 6, 6): with T.block("data_pack"): eps, nu, p, ci, r_a, r_b = T.axis.remap("SSSSRR", [i0, i1, i2, i3, i4, i5]) T.reads(input_tile[r_a, r_b, p, ci], B[T.min(r_a, r_b) : T.max(r_a, r_b) + 1, T.min(eps, nu) : T.max(eps, nu) + 1]) T.writes(data_pack[eps, nu, p, ci]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["eps", "nu", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_data_pack.cuda"}) with T.init(): data_pack[eps, nu, p, ci] = T.float32(0) data_pack[eps, nu, p, ci] = data_pack[eps, nu, p, ci] + input_tile[r_a, r_b, p, ci] * B[r_a, eps] * B[r_b, nu] for i0, i1, i2, i3, i4 in T.grid(6, 6, 196, 64, 64):
with T.block("bgemm"): eps, nu, p, co, ci = T.axis.remap("SSSSR", [i0, i1, i2, i3, i4]) T.reads(data_pack[eps, nu, p, ci], p1[eps, nu, co, ci]) T.writes(bgemm[eps, nu, p, co]) T.block_attr({"layout_free_placeholders":[]}) with T.init(): bgemm[eps, nu, p, co] = T.float32(0) bgemm[eps, nu, p, co] = bgemm[eps, nu, p, co] + data_pack[eps, nu, p, ci] * p1[eps, nu, co, ci] for i0, i1 in T.grid(6, 4): with T.block("A"): i, j = T.axis.remap("SS", [i0, i1]) T.reads() T.writes(A[i, j]) T.block_attr({"const_matrix":True, "schedule_rule":"meta_schedule.compute_inline"}) A[i, j] = T.Select(i % 6 == 5 and j % 4 == 3, T.float32(1), T.Select(i % 6 == 5 and j % 4 == 2, T.float32(0), T.Select(i % 6 == 5 and j % 4 == 1, T.float32(0), T.Select(i % 6 == 5 and j % 4 == 0, T.float32(0), T.Select(i % 6 == 4 and j % 4 == 3, T.float32(-8), T.Select(i % 6 == 4 and j % 4 == 2, T.float32(4), T.Select(i % 6 == 4 and j % 4 == 1, T.float32(-2), T.Select(i % 6 == 4 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 3 and j % 4 == 3, T.float32(0.125), T.Select(i % 6 == 3 and j % 4 == 2, T.float32(0.25), T.Select(i % 6 == 3 and j % 4 == 1, T.float32(0.5), T.Select(i % 6 == 3 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 3, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 2, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 1, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 1 and j % 4 == 3, T.float32(-1), T.Select(i % 6 == 1 and j % 4 == 2, T.float32(1), T.Select(i % 6 == 1 and j % 4 == 1, T.float32(-1), T.Select(i % 6 == 1 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 0 and j % 4 == 3, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 2, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 1, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 0, T.float32(1), T.float32(0)))))))))))))))))))))))
)) for i0, i1, i2, i3, i4, i5 in T.grid(4, 4, 196, 64, 6, 6): with T.block("inverse"): vh, vw, p, co, r_a, r_b = T.axis.remap("SSSSRR", [i0, i1, i2, i3, i4, i5]) T.reads(bgemm[r_a, r_b, p, co], A[T.min(r_a, r_b) : T.max(r_a, r_b) + 1, T.min(vh, vw) : T.max(vh, vw) + 1]) T.writes(inverse[vh, vw, p, co]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["vh", "vw", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_inverse.cuda"}) with T.init(): inverse[vh, vw, p, co] = T.float32(0) inverse[vh, vw, p, co] = inverse[vh, vw, p, co] + bgemm[r_a, r_b, p, co] * A[r_a, vh] * A[r_b, vw] for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("conv2d_winograd"): n, h, w, co = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(inverse[h % 4, w % 4, n * 196 + h T.writes(conv2d_winograd[n, h, w, co]) conv2d_winograd[n, h, w, co] = inverse[h % 4, w % 4, n * 196 + h for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("T_add"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(conv2d_winograd[ax0, ax1, ax2, ax3], p2[ax0, 0, 0, ax3]) T.writes(T_add[ax0, ax1, ax2, ax3]) T_add[ax0, ax1, ax2, ax3] = conv2d_winograd[ax0, ax1, ax2, ax3] + p2[ax0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("T_relu"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add[ax0, ax1, ax2, ax3]) T.writes(T_relu[ax0, ax1, ax2, ax3]) T_relu[ax0, ax1, ax2, ax3] = T.max(T_add[ax0, ax1, ax2, ax3], T.float32(0)) @tvm.script.ir_module class Conv2dWinogradAddResidualRelu: @T.prim_func def main(p0: T.Buffer[(1, 56, 56, 64), "float32"], p1: T.Buffer[(6, 6, 64, 64), "float32"], p2: T.Buffer[(1
, 1, 1, 64), "float32"], p3: T.Buffer[(1, 56, 56, 64), "float32"], T_relu: T.Buffer[(1, 56, 56, 64), "float32"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) data_pad = T.alloc_buffer([1, 58, 58, 64], dtype="float32") input_tile = T.alloc_buffer([6, 6, 196, 64], dtype="float32") B = T.alloc_buffer([6, 6], dtype="float32") data_pack = T.alloc_buffer([6, 6, 196, 64], dtype="float32") bgemm = T.alloc_buffer([6, 6, 196, 64], dtype="float32") A = T.alloc_buffer([6, 4], dtype="float32") inverse = T.alloc_buffer([4, 4, 196, 64], dtype="float32") conv2d_winograd = T.alloc_buffer([1, 56, 56, 64], dtype="float32") T_add = T.alloc_buffer([1, 56, 56, 64], dtype="float32") T_add_1 = T.alloc_buffer([1, 56, 56, 64], dtype="float32") for i0, i1, i2, i3 in T.grid(1, 58, 58, 64): with T.block("data_pad"): i0_1, i1_1, i2_1, i3_1 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(p0[i0_1, i1_1 - 1, i2_1 - 1, i3_1]) T.writes(data_pad[i0_1, i1_1, i2_1, i3_1]) T.block_attr({"schedule_rule":"None"}) data_pad[i0_1, i1_1, i2_1, i3_1] = T.if_then_else(1 <= i1_1 and i1_1 < 57 and 1 <= i2_1 and i2_1 < 57, p0[i0_1, i1_1 - 1, i2_1 - 1, i3_1], T.float32(0), dtype="float32") for i0, i1, i2, i3 in T.grid(6, 6, 196, 64): with T.block("input_tile"): eps, nu, p, ci = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(data_pad[p T.writes(input_tile[eps, nu, p, ci]) T.block_attr({"schedule_rule":"None"}) input_tile[eps, nu, p, ci] = data_pad[p for i0, i1 in T.grid(6, 6): with T.block("B"): i, j = T.axis.remap("SS", [i0, i1]) T.reads() T.writes(B[i, j]) T.block_attr({"const_matrix":True, "schedule_rule":"meta_sche
dule.compute_inline"}) B[i, j] = T.Select(i % 6 == 5 and j % 6 == 5, T.float32(1), T.Select(i % 6 == 5 and j % 6 == 4, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 3, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 2, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 1, T.float32(0), T.Select(i % 6 == 5 and j % 6 == 0, T.float32(0), T.Select(i % 6 == 4 and j % 6 == 5, T.float32(1.5), T.Select(i % 6 == 4 and j % 6 == 4, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 3, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 2, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 1, T.float32(1), T.Select(i % 6 == 4 and j % 6 == 0, T.float32(1), T.Select(i % 6 == 3 and j % 6 == 5, T.float32(-2), T.Select(i % 6 == 3 and j % 6 == 4, T.float32(-0.5), T.Select(i % 6 == 3 and j % 6 == 3, T.float32(2), T.Select(i % 6 == 3 and j % 6 == 2, T.float32(2.5), T.Select(i % 6 == 3 and j % 6 == 1, T.float32(0.5), T.Select(i % 6 == 3 and j % 6 == 0, T.float32(1.5), T.Select(i % 6 == 2 and j % 6 == 5, T.float32(-1.5), T.Select(i % 6 == 2 and j % 6 == 4, T.float32(-1), T.Select(i % 6 == 2 and j % 6 == 3, T.float32(-1), T.Select(i % 6 == 2 and j % 6 == 2, T.float32(0.5), T.Select(i % 6 == 2 and j % 6 == 1, T.float32(-2.5), T.Select(i % 6 == 2 and j % 6 == 0, T.float32(-2), T.Select(i % 6 == 1 and j % 6 == 5, T.float32(1), T.Select(i % 6 == 1 and j % 6 == 4, T.float32(0.5), T.Select(i % 6 == 1 and j % 6 == 3, T.float32(-2), T.Select(i % 6 == 1 and j % 6 == 2, T.float32(-1), T.Select(i % 6 == 1 and j % 6 == 1, T.float32(1), T.Select(i % 6 == 1 and j % 6 == 0, T.float32(-1.5), T.Select(i % 6 == 0 and j % 6 == 5, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 4, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 3, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 2, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 1, T.float32(0), T.Select(i % 6 == 0 and j % 6 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))))))))))))))) for i0, i1, i2, i3, i4, i5 in T.grid(6, 6, 196, 64, 6, 6): with T.block("data_pack"):
eps, nu, p, ci, r_a, r_b = T.axis.remap("SSSSRR", [i0, i1, i2, i3, i4, i5]) T.reads(input_tile[r_a, r_b, p, ci], B[T.min(r_a, r_b) : T.max(r_a, r_b) + 1, T.min(eps, nu) : T.max(eps, nu) + 1]) T.writes(data_pack[eps, nu, p, ci]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["eps", "nu", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_data_pack.cuda"}) with T.init(): data_pack[eps, nu, p, ci] = T.float32(0) data_pack[eps, nu, p, ci] = data_pack[eps, nu, p, ci] + input_tile[r_a, r_b, p, ci] * B[r_a, eps] * B[r_b, nu] for i0, i1, i2, i3, i4 in T.grid(6, 6, 196, 64, 64): with T.block("bgemm"): eps, nu, p, co, ci = T.axis.remap("SSSSR", [i0, i1, i2, i3, i4]) T.reads(data_pack[eps, nu, p, ci], p1[eps, nu, co, ci]) T.writes(bgemm[eps, nu, p, co]) T.block_attr({"layout_free_placeholders":[]}) with T.init(): bgemm[eps, nu, p, co] = T.float32(0) bgemm[eps, nu, p, co] = bgemm[eps, nu, p, co] + data_pack[eps, nu, p, ci] * p1[eps, nu, co, ci] for i0, i1 in T.grid(6, 4): with T.block("A"): i, j = T.axis.remap("SS", [i0, i1]) T.reads() T.writes(A[i, j]) T.block_attr({"const_matrix":True, "schedule_rule":"meta_schedule.compute_inline"}) A[i, j] = T.Select(i % 6 == 5 and j % 4 == 3, T.float32(1), T.Select(i % 6 == 5 and j % 4 == 2, T.float32(0), T.Select(i % 6 == 5 and j % 4 == 1, T.float32(0), T.Select(i % 6 == 5 and j % 4 == 0, T.float32(0), T.Select(i % 6 == 4 and j % 4 == 3, T.float32(-8), T.Select(i % 6 == 4 and j % 4 == 2, T.float32(4), T.Select(i % 6 == 4 and j % 4 == 1, T.float32(-2), T.Select(i % 6 == 4 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 3 and j % 4 == 3, T.float32(0.125), T.Select(i % 6 == 3 and j % 4 == 2, T.float32(0.25), T.Select(i % 6 == 3 and j % 4
== 1, T.float32(0.5), T.Select(i % 6 == 3 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 3, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 2, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 1, T.float32(1), T.Select(i % 6 == 2 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 1 and j % 4 == 3, T.float32(-1), T.Select(i % 6 == 1 and j % 4 == 2, T.float32(1), T.Select(i % 6 == 1 and j % 4 == 1, T.float32(-1), T.Select(i % 6 == 1 and j % 4 == 0, T.float32(1), T.Select(i % 6 == 0 and j % 4 == 3, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 2, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 1, T.float32(0), T.Select(i % 6 == 0 and j % 4 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))) for i0, i1, i2, i3, i4, i5 in T.grid(4, 4, 196, 64, 6, 6): with T.block("inverse"): vh, vw, p, co, r_a, r_b = T.axis.remap("SSSSRR", [i0, i1, i2, i3, i4, i5]) T.reads(bgemm[r_a, r_b, p, co], A[T.min(r_a, r_b) : T.max(r_a, r_b) + 1, T.min(vh, vw) : T.max(vh, vw) + 1]) T.writes(inverse[vh, vw, p, co]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["vh", "vw", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_inverse.cuda"}) with T.init(): inverse[vh, vw, p, co] = T.float32(0) inverse[vh, vw, p, co] = inverse[vh, vw, p, co] + bgemm[r_a, r_b, p, co] * A[r_a, vh] * A[r_b, vw] for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("conv2d_winograd"): n, h, w, co = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(inverse[h % 4, w % 4, n * 196 + h T.writes(conv2d_winograd[n, h, w, co]) conv2d_winograd[n, h, w, co] = inverse[h % 4, w % 4, n * 196 + h for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("T_add"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(conv2d_winograd[ax0, ax1, ax2, ax3], p2[ax0, 0, 0, a
x3]) T.writes(T_add[ax0, ax1, ax2, ax3]) T_add[ax0, ax1, ax2, ax3] = conv2d_winograd[ax0, ax1, ax2, ax3] + p2[ax0, 0, 0, ax3] for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("T_add_1"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add[ax0, ax1, ax2, ax3], p3[ax0, ax1, ax2, ax3]) T.writes(T_add_1[ax0, ax1, ax2, ax3]) T_add_1[ax0, ax1, ax2, ax3] = T_add[ax0, ax1, ax2, ax3] + p3[ax0, ax1, ax2, ax3] for i0, i1, i2, i3 in T.grid(1, 56, 56, 64): with T.block("T_relu"): ax0, ax1, ax2, ax3 = T.axis.remap("SSSS", [i0, i1, i2, i3]) T.reads(T_add_1[ax0, ax1, ax2, ax3]) T.writes(T_relu[ax0, ax1, ax2, ax3]) T_relu[ax0, ax1, ax2, ax3] = T.max(T_add_1[ax0, ax1, ax2, ax3], T.float32(0)) @tvm.script.ir_module class Conv2dWinogradAddResidualRelu_scheduled: @T.prim_func def main(p0: T.Buffer[(1, 56, 56, 64), "float32"], p1: T.Buffer[(6, 6, 64, 64), "float32"], p2: T.Buffer[(1, 1, 1, 64), "float32"], p3: T.Buffer[(1, 56, 56, 64), "float32"], T_relu: T.Buffer[(1, 56, 56, 64), "float32"]) -> None: T.func_attr({"global_symbol": "main", "tir.noalias": True, "layout_free_buffers": [1]}) input_tile_local = T.alloc_buffer([6, 6, 196, 64], dtype="float32", scope="local") data_pack = T.alloc_buffer([6, 6, 196, 64], dtype="float32") bgemm = T.alloc_buffer([6, 6, 196, 64], dtype="float32") inverse = T.alloc_buffer([4, 4, 196, 64], dtype="float32") bgemm_local = T.alloc_buffer([6, 6, 196, 64], dtype="float32", scope="local") data_pack_shared = T.alloc_buffer([6, 6, 196, 64], dtype="float32", scope="shared") p1_shared = T.alloc_buffer([6, 6, 64, 64], dtype="float32", scope="shared") for i2_0_i3_0_i2_1_i3_1_fused_0 in T.thread_binding(98, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step":1024, "
pragma_unroll_explicit":1}): for i2_0_i3_0_i2_1_i3_1_fused_1 in T.thread_binding(128, thread="threadIdx.x"): for ax0, ax1, ax2, ax3 in T.grid(6, 6, 1, 1): with T.block("input_tile"): eps, nu = T.axis.remap("SS", [ax0, ax1]) p = T.axis.spatial(196, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i2_0_i3_0_i2_1_i3_1_fused_1) ci = T.axis.spatial(64, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i2_0_i3_0_i2_1_i3_1_fused_1) % 896 T.reads(p0[p T.writes(input_tile_local[eps, nu, p, ci]) T.block_attr({"schedule_rule":"None"}) input_tile_local[eps, nu, p, ci] = T.if_then_else(1 <= p % 196 for i0 in T.unroll(6): for i1 in T.unroll(6): with T.block("data_pack_init"): eps, nu = T.axis.remap("SS", [i0, i1]) p = T.axis.spatial(196, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i2_0_i3_0_i2_1_i3_1_fused_1) ci = T.axis.spatial(64, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i2_0_i3_0_i2_1_i3_1_fused_1) % 896 T.reads() T.writes(data_pack[eps, nu, p, ci]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["eps", "nu", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_data_pack.cuda"}) data_pack[eps, nu, p, ci] = T.float32(0) for i4 in T.unroll(6): for i5 in T.unroll(6): with T.block("data_pack_update"): eps, nu = T.axis.remap("SS", [i0, i1]) p = T.axis.spatial(196, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i2_0_i3_0_i2_1_i3_1_fused_1) ci = T.axis.spatial(64, (i2_0_i3_0_i2_1_i3_1_fused_0 * 128 + i
2_0_i3_0_i2_1_i3_1_fused_1) % 896 r_a, r_b = T.axis.remap("RR", [i4, i5]) T.reads(data_pack[eps, nu, p, ci], input_tile_local[r_a, r_b, p, ci]) T.writes(data_pack[eps, nu, p, ci]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["eps", "nu", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_data_pack.cuda"}) data_pack[eps, nu, p, ci] = data_pack[eps, nu, p, ci] + input_tile_local[r_a, r_b, p, ci] * T.Select(r_a % 6 == 5 and eps % 6 == 5, T.float32(1), T.Select(r_a % 6 == 5 and eps % 6 == 4, T.float32(0), T.Select(r_a % 6 == 5 and eps % 6 == 3, T.float32(0), T.Select(r_a % 6 == 5 and eps % 6 == 2, T.float32(0), T.Select(r_a % 6 == 5 and eps % 6 == 1, T.float32(0), T.Select(r_a % 6 == 5 and eps % 6 == 0, T.float32(0), T.Select(r_a % 6 == 4 and eps % 6 == 5, T.float32(1.5), T.Select(r_a % 6 == 4 and eps % 6 == 4, T.float32(1), T.Select(r_a % 6 == 4 and eps % 6 == 3, T.float32(1), T.Select(r_a % 6 == 4 and eps % 6 == 2, T.float32(1), T.Select(r_a % 6 == 4 and eps % 6 == 1, T.float32(1), T.Select(r_a % 6 == 4 and eps % 6 == 0, T.float32(1), T.Select(r_a % 6 == 3 and eps % 6 == 5, T.float32(-2), T.Select(r_a % 6 == 3 and eps % 6 == 4, T.float32(-0.5), T.Select(r_a % 6 == 3 and eps % 6 == 3, T.float32(2), T.Select(r_a % 6 == 3 and eps % 6 == 2, T.float32(2.5), T.Select(r_a % 6 == 3 and eps % 6 == 1, T.float32(0.5), T.Select(r_a % 6 == 3 and eps % 6 == 0, T.float32(1.5), T.Select(r_a % 6 == 2 and eps % 6 == 5, T.float32(-1.5), T.Select(r_a % 6 == 2 and eps % 6 == 4, T.float32(-1), T.Select(r_a % 6 == 2 and eps % 6 == 3, T.float32(-1), T.Select(r_a % 6 == 2 and eps % 6 == 2, T.float32(0.5), T.Select(r_a % 6 == 2 and eps % 6 == 1, T.float32(-2.5), T.Select(r_a % 6 == 2 and eps % 6 == 0, T.float32(-2), T.Select(r_a % 6 == 1 and eps % 6 == 5, T.float32(1), T.Select(r_a % 6 == 1 and eps % 6 == 4, T.float32(0.5), T.Select(r_a % 6 =
= 1 and eps % 6 == 3, T.float32(-2), T.Select(r_a % 6 == 1 and eps % 6 == 2, T.float32(-1), T.Select(r_a % 6 == 1 and eps % 6 == 1, T.float32(1), T.Select(r_a % 6 == 1 and eps % 6 == 0, T.float32(-1.5), T.Select(r_a % 6 == 0 and eps % 6 == 5, T.float32(0), T.Select(r_a % 6 == 0 and eps % 6 == 4, T.float32(0), T.Select(r_a % 6 == 0 and eps % 6 == 3, T.float32(0), T.Select(r_a % 6 == 0 and eps % 6 == 2, T.float32(0), T.Select(r_a % 6 == 0 and eps % 6 == 1, T.float32(0), T.Select(r_a % 6 == 0 and eps % 6 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))))))))))))))) * T.Select(r_b % 6 == 5 and nu % 6 == 5, T.float32(1), T.Select(r_b % 6 == 5 and nu % 6 == 4, T.float32(0), T.Select(r_b % 6 == 5 and nu % 6 == 3, T.float32(0), T.Select(r_b % 6 == 5 and nu % 6 == 2, T.float32(0), T.Select(r_b % 6 == 5 and nu % 6 == 1, T.float32(0), T.Select(r_b % 6 == 5 and nu % 6 == 0, T.float32(0), T.Select(r_b % 6 == 4 and nu % 6 == 5, T.float32(1.5), T.Select(r_b % 6 == 4 and nu % 6 == 4, T.float32(1), T.Select(r_b % 6 == 4 and nu % 6 == 3, T.float32(1), T.Select(r_b % 6 == 4 and nu % 6 == 2, T.float32(1), T.Select(r_b % 6 == 4 and nu % 6 == 1, T.float32(1), T.Select(r_b % 6 == 4 and nu % 6 == 0, T.float32(1), T.Select(r_b % 6 == 3 and nu % 6 == 5, T.float32(-2), T.Select(r_b % 6 == 3 and nu % 6 == 4, T.float32(-0.5), T.Select(r_b % 6 == 3 and nu % 6 == 3, T.float32(2), T.Select(r_b % 6 == 3 and nu % 6 == 2, T.float32(2.5), T.Select(r_b % 6 == 3 and nu % 6 == 1, T.float32(0.5), T.Select(r_b % 6 == 3 and nu % 6 == 0, T.float32(1.5), T.Select(r_b % 6 == 2 and nu % 6 == 5, T.float32(-1.5), T.Select(r_b % 6 == 2 and nu % 6 == 4, T.float32(-1), T.Select(r_b % 6 == 2 and nu % 6 == 3, T.float32(-1), T.Select(r_b % 6 == 2 and nu % 6 == 2, T.float32(0.5), T.Select(r_b % 6 == 2 and nu % 6 == 1, T.float32(-2.5), T.Select(r_b % 6 == 2 and nu % 6 == 0, T.float32(-2), T.Select(r_b % 6 == 1 and nu % 6 == 5, T.float32(1), T.Select(r_b % 6 == 1 and nu % 6 == 4, T.float32(0.5), T.Select(r_b % 6 == 1 and nu % 6 == 3, T.float32(-2), T.Select(r_b
% 6 == 1 and nu % 6 == 2, T.float32(-1), T.Select(r_b % 6 == 1 and nu % 6 == 1, T.float32(1), T.Select(r_b % 6 == 1 and nu % 6 == 0, T.float32(-1.5), T.Select(r_b % 6 == 0 and nu % 6 == 5, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 4, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 3, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 2, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 1, T.float32(0), T.Select(r_b % 6 == 0 and nu % 6 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))))))))))))))) for i0_0_i1_0_i2_0_i3_0_fused in T.thread_binding(168, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step":1024, "pragma_unroll_explicit":1}): for i0_1_i1_1_i2_1_i3_1_fused in T.thread_binding(4, thread="vthread.x"): for i0_2_i1_2_i2_2_i3_2_fused in T.thread_binding(48, thread="threadIdx.x"): for i0_3_init, i1_3_init, i2_3_init, i3_3_init, i0_4_init, i1_4_init, i2_4_init, i3_4_init in T.grid(1, 1, 14, 1, 1, 1, 1, 1): with T.block("bgemm_init"): eps = T.axis.spatial(6, i0_4_init + i0_1_i1_1_i2_1_i3_1_fused nu = T.axis.spatial(6, i1_4_init + i0_0_i1_0_i2_0_i3_0_fused p = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 28 co = T.axis.spatial(64, i3_4_init + i0_0_i1_0_i2_0_i3_0_fused % 4 * 16 + i0_2_i1_2_i2_2_i3_2_fused % 16 + i3_3_init) T.reads() T.writes(bgemm_local[eps, nu, p, co]) T.block_attr({"layout_free_placeholders":[], "meta_schedule.thread_extent_high_inclusive":1024, "meta_schedule.thread_extent_low_inclusive":32, "meta_schedule.tiling_structure":"SSSRRSRS"}) bgemm_local[eps, nu, p, co] = T.float32(0) for i4_0 in T.serial(2): for ax0_ax1_ax2_ax3_fused_0 in T.serial(28): for ax0_ax1_ax2_ax3_fused_1 in T.thread_bindi
ng(48, thread="threadIdx.x"): for ax0_ax1_ax2_ax3_fused_2 in T.vectorized(4): with T.block("data_pack_shared"): v0 = T.axis.spatial(6, (ax0_ax1_ax2_ax3_fused_0 * 192 + ax0_ax1_ax2_ax3_fused_1 * 4 + ax0_ax1_ax2_ax3_fused_2) v1 = T.axis.spatial(6, i0_0_i1_0_i2_0_i3_0_fused v2 = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 28 v3 = T.axis.spatial(64, i4_0 * 32 + (ax0_ax1_ax2_ax3_fused_0 * 192 + ax0_ax1_ax2_ax3_fused_1 * 4 + ax0_ax1_ax2_ax3_fused_2) % 32) T.reads(data_pack[v0, v1, v2, v3]) T.writes(data_pack_shared[v0, v1, v2, v3]) data_pack_shared[v0, v1, v2, v3] = data_pack[v0, v1, v2, v3] for ax0_ax1_ax2_ax3_fused_0 in T.serial(16): for ax0_ax1_ax2_ax3_fused_1 in T.thread_binding(48, thread="threadIdx.x"): for ax0_ax1_ax2_ax3_fused_2 in T.vectorized(4): with T.block("p1_shared"): v0 = T.axis.spatial(6, (ax0_ax1_ax2_ax3_fused_0 * 192 + ax0_ax1_ax2_ax3_fused_1 * 4 + ax0_ax1_ax2_ax3_fused_2) v1 = T.axis.spatial(6, i0_0_i1_0_i2_0_i3_0_fused v2 = T.axis.spatial(64, i0_0_i1_0_i2_0_i3_0_fused % 4 * 16 + (ax0_ax1_ax2_ax3_fused_0 * 192 + ax0_ax1_ax2_ax3_fused_1 * 4 + ax0_ax1_ax2_ax3_fused_2) % 512 v3 = T.axis.spatial(64, i4_0 * 32 + (ax0_ax1_ax2_ax3_fused_0 * 192 + ax0_ax1_ax2_ax3_fused_1 * 4 + ax0_ax1_ax2_ax3_fused_2) % 32) T.reads(p1[v0, v1, v2, v3]) T.writes(p1_shared[v0, v1, v2, v3])
p1_shared[v0, v1, v2, v3] = p1[v0, v1, v2, v3] for i4_1, i0_3, i1_3, i2_3, i3_3, i4_2, i0_4, i1_4, i2_4, i3_4 in T.grid(2, 1, 1, 14, 1, 16, 1, 1, 1, 1): with T.block("bgemm_update"): eps = T.axis.spatial(6, i0_4 + i0_1_i1_1_i2_1_i3_1_fused nu = T.axis.spatial(6, i1_4 + i0_0_i1_0_i2_0_i3_0_fused p = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 28 co = T.axis.spatial(64, i3_4 + i0_0_i1_0_i2_0_i3_0_fused % 4 * 16 + i0_2_i1_2_i2_2_i3_2_fused % 16 + i3_3) ci = T.axis.reduce(64, i4_0 * 32 + i4_1 * 16 + i4_2) T.reads(bgemm_local[eps, nu, p, co], data_pack_shared[eps, nu, p, ci], p1_shared[eps, nu, co, ci]) T.writes(bgemm_local[eps, nu, p, co]) T.block_attr({"layout_free_placeholders":[], "meta_schedule.thread_extent_high_inclusive":1024, "meta_schedule.thread_extent_low_inclusive":32, "meta_schedule.tiling_structure":"SSSRRSRS"}) bgemm_local[eps, nu, p, co] = bgemm_local[eps, nu, p, co] + data_pack_shared[eps, nu, p, ci] * p1_shared[eps, nu, co, ci] for ax0, ax1, ax2, ax3 in T.grid(1, 1, 14, 1): with T.block("bgemm_local"): v0 = T.axis.spatial(6, i0_1_i1_1_i2_1_i3_1_fused v1 = T.axis.spatial(6, i0_0_i1_0_i2_0_i3_0_fused v2 = T.axis.spatial(196, i0_0_i1_0_i2_0_i3_0_fused % 28 v3 = T.axis.spatial(64, i0_0_i1_0_i2_0_i3_0_fused % 4 * 16 + i0_2_i1_2_i2_2_i3_2_fused % 16 + ax3) T.reads(bgemm_local[v0, v1, v2, v3]) T.writes(bgemm[v0, v1, v2, v3]) bgemm[v0, v1, v2, v3] = bgemm_local[v0, v1, v2, v3] for i2_0_i3_0_i2_1_i3_1_fused_0 in T.
thread_binding(25, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step":1024, "pragma_unroll_explicit":1}): for i2_0_i3_0_i2_1_i3_1_fused_1 in T.thread_binding(512, thread="threadIdx.x"): for i0 in T.unroll(4): for i1 in T.unroll(4): with T.block("inverse_init"): T.where(i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1 < 12544) vh, vw = T.axis.remap("SS", [i0, i1]) p = T.axis.spatial(196, (i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1) co = T.axis.spatial(64, (i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1) % 448 T.reads() T.writes(inverse[vh, vw, p, co]) T.block_attr({"auto_scheduler_simplify_const_tensor_indices":["vh", "vw", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_inverse.cuda"}) inverse[vh, vw, p, co] = T.float32(0) for i4 in T.unroll(6): for i5 in T.unroll(6): with T.block("inverse_update"): T.where(i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1 < 12544) vh, vw = T.axis.remap("SS", [i0, i1]) p = T.axis.spatial(196, (i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1) co = T.axis.spatial(64, (i2_0_i3_0_i2_1_i3_1_fused_0 * 512 + i2_0_i3_0_i2_1_i3_1_fused_1) % 448 r_a, r_b = T.axis.remap("RR", [i4, i5]) T.reads(inverse[vh, vw, p, co], bgemm[r_a, r_b, p, co]) T.writes(inverse[vh, vw, p, co]) T.block_attr({"auto_scheduler_simplify_const_tensor_indice
s":["vh", "vw", "r_a", "r_b"], "schedule_rule":"meta_schedule.winograd_inverse.cuda"}) inverse[vh, vw, p, co] = inverse[vh, vw, p, co] + bgemm[r_a, r_b, p, co] * T.Select(r_a % 6 == 5 and vh % 4 == 3, T.float32(1), T.Select(r_a % 6 == 5 and vh % 4 == 2, T.float32(0), T.Select(r_a % 6 == 5 and vh % 4 == 1, T.float32(0), T.Select(r_a % 6 == 5 and vh % 4 == 0, T.float32(0), T.Select(r_a % 6 == 4 and vh % 4 == 3, T.float32(-8), T.Select(r_a % 6 == 4 and vh % 4 == 2, T.float32(4), T.Select(r_a % 6 == 4 and vh % 4 == 1, T.float32(-2), T.Select(r_a % 6 == 4 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 3 and vh % 4 == 3, T.float32(0.125), T.Select(r_a % 6 == 3 and vh % 4 == 2, T.float32(0.25), T.Select(r_a % 6 == 3 and vh % 4 == 1, T.float32(0.5), T.Select(r_a % 6 == 3 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 3, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 2, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 1, T.float32(1), T.Select(r_a % 6 == 2 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 1 and vh % 4 == 3, T.float32(-1), T.Select(r_a % 6 == 1 and vh % 4 == 2, T.float32(1), T.Select(r_a % 6 == 1 and vh % 4 == 1, T.float32(-1), T.Select(r_a % 6 == 1 and vh % 4 == 0, T.float32(1), T.Select(r_a % 6 == 0 and vh % 4 == 3, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 2, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 1, T.float32(0), T.Select(r_a % 6 == 0 and vh % 4 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))) * T.Select(r_b % 6 == 5 and vw % 4 == 3, T.float32(1), T.Select(r_b % 6 == 5 and vw % 4 == 2, T.float32(0), T.Select(r_b % 6 == 5 and vw % 4 == 1, T.float32(0), T.Select(r_b % 6 == 5 and vw % 4 == 0, T.float32(0), T.Select(r_b % 6 == 4 and vw % 4 == 3, T.float32(-8), T.Select(r_b % 6 == 4 and vw % 4 == 2, T.float32(4), T.Select(r_b % 6 == 4 and vw % 4 == 1, T.float32(-2), T.Select(r_b % 6 == 4 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 3 and vw % 4 == 3, T.float32(0.125), T.Select(r_b % 6 == 3 and vw % 4 == 2, T.fl
oat32(0.25), T.Select(r_b % 6 == 3 and vw % 4 == 1, T.float32(0.5), T.Select(r_b % 6 == 3 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 3, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 2, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 1, T.float32(1), T.Select(r_b % 6 == 2 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 1 and vw % 4 == 3, T.float32(-1), T.Select(r_b % 6 == 1 and vw % 4 == 2, T.float32(1), T.Select(r_b % 6 == 1 and vw % 4 == 1, T.float32(-1), T.Select(r_b % 6 == 1 and vw % 4 == 0, T.float32(1), T.Select(r_b % 6 == 0 and vw % 4 == 3, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 2, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 1, T.float32(0), T.Select(r_b % 6 == 0 and vw % 4 == 0, T.float32(1), T.float32(0))))))))))))))))))))))))) for i0_i1_i2_i3_fused_0 in T.thread_binding(1568, thread="blockIdx.x", annotations={"pragma_auto_unroll_max_step":1024, "pragma_unroll_explicit":1}): for i0_i1_i2_i3_fused_1 in T.thread_binding(128, thread="threadIdx.x"): with T.block("conv2d_winograd"): n = T.axis.spatial(1, 0) h = T.axis.spatial(56, (i0_i1_i2_i3_fused_0 * 128 + i0_i1_i2_i3_fused_1) w = T.axis.spatial(56, (i0_i1_i2_i3_fused_0 * 128 + i0_i1_i2_i3_fused_1) % 3584 co = T.axis.spatial(64, (i0_i1_i2_i3_fused_0 * 128 + i0_i1_i2_i3_fused_1) % 64) T.reads(inverse[h % 4, w % 4, n * 196 + h T.writes(T_relu[n, h, w, co]) T_relu[n, h, w, co] = T.max(inverse[h % 4, w % 4, n * 196 + h @tvm.script.ir_module class Conv2dInt8_with_predicate: @T.prim_func def main(p0: T.Buffer[(16, 56, 56, 64), "int8"], p1: T.Buffer[(256, 1, 1, 64), "int8"], p2: T.Buffer[(1, 1, 1, 256), "int32"], p3: T.Buffer[(1, 1, 1, 256), "int32"], p4: T.Buffer[256, "int32"], p5: T.Buffer[256, "int32"], p6: T.Buffer[256, "int32"], p7: T.Buffer[(), "int32"], p8: T.Buffer[1, "int32"], compute: T.Buffer[(16, 56, 56, 256), "int32"