You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/09/21 07:42:25 UTC
[GitHub] [tvm] masahi opened a new pull request, #12854: [Hexagon] Support template-free meta schedule tuning
masahi opened a new pull request, #12854:
URL: https://github.com/apache/tvm/pull/12854
Adds test cases for
* Auto-scheduler style, template free tuning for fp16 conv2d in NHWC layout.
* `vrmpy` auto tensorization for TE int8 `dense`, achieving 440 GFLOPs on SD888.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
masahi commented on code in PR #12854:
URL: https://github.com/apache/tvm/pull/12854#discussion_r984903021
##########
tests/python/contrib/test_hexagon/test_meta_schedule.py:
##########
@@ -209,3 +213,207 @@ def schedule_dense_for_tune(sch):
with hexagon_launcher.start_session() as session:
verify_dense(sch, target, M, N, K, session)
+
+
+# This is an example of a schedule found by vrmpy auto tensorization.
+# It gets 440 GFLOPS on SD888.
+@tvm.script.ir_module
+class Module_vrmpy_auto_tensorize:
+ @T.prim_func
+ def main(
+ X: T.Buffer[(128, 768), "uint8"],
+ packedW: T.Buffer[(24, 192, 32, 4), "uint8"],
+ compute: T.Buffer[(128, 768), "int32"],
+ ) -> None:
+ T.func_attr({"global_symbol": "main", "tir.noalias": True})
+ for i0_0_i1_0_0_fused in T.parallel(
+ 512, annotations={"pragma_auto_unroll_max_step": 64, "pragma_unroll_explicit": 1}
+ ):
+ for i0_1_init, i1_0_1_init, i0_2_init, i1_0_2_init in T.grid(2, 3, 1, 1):
+ with T.block("compute_o_init"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1_init + i0_2_init)
+ j_o = T.axis.spatial(24, i1_0_2_init + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1_init)
+ T.reads()
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ for i1_1 in T.vectorized(32):
+ with T.block("compute_init"):
+ j_i_init = T.axis.spatial(32, i1_1)
+ T.reads()
+ T.writes(compute[i, j_o * 32 + j_i_init])
+ compute[i, j_o * 32 + j_i_init] = 0
+ for i2_0_0, i0_1, i1_0_1, i2_0_1, i0_2, i1_0_2 in T.grid(32, 2, 3, 6, 1, 1):
+ with T.block("compute_o_update"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1 + i0_2)
+ j_o = T.axis.spatial(24, i1_0_2 + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1)
+ k_o = T.axis.reduce(192, i2_0_0 * 6 + i2_0_1)
+ T.reads(
+ compute[i, j_o * 32 : j_o * 32 + 32],
+ X[i, k_o * 4 : k_o * 4 + 4],
+ packedW[j_o, k_o, 0:32, 0:4],
+ )
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ A = T.match_buffer(
+ X[i, k_o * 4 : k_o * 4 + 4], [4], dtype="uint8", offset_factor=1
+ )
+ B = T.match_buffer(
+ packedW[j_o, k_o, 0:32, 0:4], [32, 4], dtype="uint8", offset_factor=1
+ )
+ C = T.match_buffer(
+ compute[i, j_o * 32 : j_o * 32 + 32], [32], dtype="int32", offset_factor=1
+ )
+ A_u8x4: T.uint8x4 = A[0:4]
+ A_i32: T.int32 = T.reinterpret(A_u8x4, dtype="int32")
+ B_i32x32: T.int32x32 = T.reinterpret(B[0, 0:128], dtype="int32x32")
+ C[0:32] = T.call_llvm_pure_intrin(
+ 4390, T.uint32(3), C[0:32], B_i32x32, A_i32, dtype="int32x32"
+ )
+
+
+@tvm.testing.requires_hexagon
+def test_vrmpy_dense_auto_tensorize(hexagon_launcher):
+ if hexagon_launcher._serial_number == "simulator":
+ pytest.skip(msg="Tuning on simulator not supported.")
+
+ target_hexagon = tvm.target.hexagon("v68")
+ target = tvm.target.Target(target_hexagon, host=target_hexagon)
+
+ M, N, K = 128, 768, 768
+ workload = te.create_prim_func(dense(M, N, K))
+
+ sch_rules = [
+ schedule_rule.MultiLevelTilingWithIntrin(
+ VRMPY_u8u8i32_INTRIN,
+ structure="SRSRS",
+ tile_binds=None,
+ max_innermost_factor=64,
+ vector_load_lens=None,
+ reuse_read=None,
+ reuse_write=schedule_rule.ReuseType(
+ req="may",
+ levels=[1, 2],
+ scope="global",
+ ),
+ ),
+ schedule_rule.ParallelizeVectorizeUnroll(
+ max_jobs_per_core=16,
+ max_vectorize_extent=128,
+ unroll_max_steps=[0, 16, 64, 512],
+ unroll_explicit=True,
+ ),
+ ]
+
+ postprocs = [
+ postproc.RewriteParallelVectorizeUnroll(),
+ postproc.RewriteReductionBlock(),
+ postproc.RewriteTensorize(vectorize_init_loop=True),
+ ]
+
+ if True:
Review Comment:
I intentionally left it so that people can use both then and else paths. The else path just compiles and runs the best schedule found in my experiment, which reproduces 440 GOPs performance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
masahi commented on code in PR #12854:
URL: https://github.com/apache/tvm/pull/12854#discussion_r976170836
##########
python/tvm/meta_schedule/tune.py:
##########
@@ -596,8 +600,23 @@ def tune_relay(
target = default_config.target(target)
# pylint: enable=protected-access,
# parse the tuning contexts
+
+ if executor is None:
+ executor = relay.backend.Executor("graph")
+
+ if "link-params" in executor.attrs:
+ link_params = executor.attrs["link-params"]
+ else:
+ link_params = False
+
with Profiler.timeit("TaskExtraction"):
- extracted_tasks = extract_task_from_relay(mod, target, params)
+ pass_config = {
+ "relay.FuseOps.link_params": link_params,
+ "relay.backend.use_meta_schedule": True,
+ "relay.backend.tir_converter": "default",
+ }
Review Comment:
See https://github.com/apache/tvm/blob/370abe69d24519a5453cead846d328a1c378957f/python/tvm/meta_schedule/relay_integration.py#L87-L91 for why this change is necessary. We only need to pass `relay.FuseOps.link_params` config, others are for compatibility with the existing code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tmoreau89 merged pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
tmoreau89 merged PR #12854:
URL: https://github.com/apache/tvm/pull/12854
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
masahi commented on code in PR #12854:
URL: https://github.com/apache/tvm/pull/12854#discussion_r984903021
##########
tests/python/contrib/test_hexagon/test_meta_schedule.py:
##########
@@ -209,3 +213,207 @@ def schedule_dense_for_tune(sch):
with hexagon_launcher.start_session() as session:
verify_dense(sch, target, M, N, K, session)
+
+
+# This is an example of a schedule found by vrmpy auto tensorization.
+# It gets 440 GFLOPS on SD888.
+@tvm.script.ir_module
+class Module_vrmpy_auto_tensorize:
+ @T.prim_func
+ def main(
+ X: T.Buffer[(128, 768), "uint8"],
+ packedW: T.Buffer[(24, 192, 32, 4), "uint8"],
+ compute: T.Buffer[(128, 768), "int32"],
+ ) -> None:
+ T.func_attr({"global_symbol": "main", "tir.noalias": True})
+ for i0_0_i1_0_0_fused in T.parallel(
+ 512, annotations={"pragma_auto_unroll_max_step": 64, "pragma_unroll_explicit": 1}
+ ):
+ for i0_1_init, i1_0_1_init, i0_2_init, i1_0_2_init in T.grid(2, 3, 1, 1):
+ with T.block("compute_o_init"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1_init + i0_2_init)
+ j_o = T.axis.spatial(24, i1_0_2_init + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1_init)
+ T.reads()
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ for i1_1 in T.vectorized(32):
+ with T.block("compute_init"):
+ j_i_init = T.axis.spatial(32, i1_1)
+ T.reads()
+ T.writes(compute[i, j_o * 32 + j_i_init])
+ compute[i, j_o * 32 + j_i_init] = 0
+ for i2_0_0, i0_1, i1_0_1, i2_0_1, i0_2, i1_0_2 in T.grid(32, 2, 3, 6, 1, 1):
+ with T.block("compute_o_update"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1 + i0_2)
+ j_o = T.axis.spatial(24, i1_0_2 + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1)
+ k_o = T.axis.reduce(192, i2_0_0 * 6 + i2_0_1)
+ T.reads(
+ compute[i, j_o * 32 : j_o * 32 + 32],
+ X[i, k_o * 4 : k_o * 4 + 4],
+ packedW[j_o, k_o, 0:32, 0:4],
+ )
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ A = T.match_buffer(
+ X[i, k_o * 4 : k_o * 4 + 4], [4], dtype="uint8", offset_factor=1
+ )
+ B = T.match_buffer(
+ packedW[j_o, k_o, 0:32, 0:4], [32, 4], dtype="uint8", offset_factor=1
+ )
+ C = T.match_buffer(
+ compute[i, j_o * 32 : j_o * 32 + 32], [32], dtype="int32", offset_factor=1
+ )
+ A_u8x4: T.uint8x4 = A[0:4]
+ A_i32: T.int32 = T.reinterpret(A_u8x4, dtype="int32")
+ B_i32x32: T.int32x32 = T.reinterpret(B[0, 0:128], dtype="int32x32")
+ C[0:32] = T.call_llvm_pure_intrin(
+ 4390, T.uint32(3), C[0:32], B_i32x32, A_i32, dtype="int32x32"
+ )
+
+
+@tvm.testing.requires_hexagon
+def test_vrmpy_dense_auto_tensorize(hexagon_launcher):
+ if hexagon_launcher._serial_number == "simulator":
+ pytest.skip(msg="Tuning on simulator not supported.")
+
+ target_hexagon = tvm.target.hexagon("v68")
+ target = tvm.target.Target(target_hexagon, host=target_hexagon)
+
+ M, N, K = 128, 768, 768
+ workload = te.create_prim_func(dense(M, N, K))
+
+ sch_rules = [
+ schedule_rule.MultiLevelTilingWithIntrin(
+ VRMPY_u8u8i32_INTRIN,
+ structure="SRSRS",
+ tile_binds=None,
+ max_innermost_factor=64,
+ vector_load_lens=None,
+ reuse_read=None,
+ reuse_write=schedule_rule.ReuseType(
+ req="may",
+ levels=[1, 2],
+ scope="global",
+ ),
+ ),
+ schedule_rule.ParallelizeVectorizeUnroll(
+ max_jobs_per_core=16,
+ max_vectorize_extent=128,
+ unroll_max_steps=[0, 16, 64, 512],
+ unroll_explicit=True,
+ ),
+ ]
+
+ postprocs = [
+ postproc.RewriteParallelVectorizeUnroll(),
+ postproc.RewriteReductionBlock(),
+ postproc.RewriteTensorize(vectorize_init_loop=True),
+ ]
+
+ if True:
Review Comment:
I intentionally left it so that people can experiment with both `then` and `else` paths. The `else` path just compiles and runs the best schedule found in my experiment, which reproduces 440 GOPs performance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] kparzysz-quic commented on a diff in pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
kparzysz-quic commented on code in PR #12854:
URL: https://github.com/apache/tvm/pull/12854#discussion_r984890169
##########
tests/python/contrib/test_hexagon/test_meta_schedule.py:
##########
@@ -209,3 +213,207 @@ def schedule_dense_for_tune(sch):
with hexagon_launcher.start_session() as session:
verify_dense(sch, target, M, N, K, session)
+
+
+# This is an example of a schedule found by vrmpy auto tensorization.
+# It gets 440 GFLOPS on SD888.
+@tvm.script.ir_module
+class Module_vrmpy_auto_tensorize:
+ @T.prim_func
+ def main(
+ X: T.Buffer[(128, 768), "uint8"],
+ packedW: T.Buffer[(24, 192, 32, 4), "uint8"],
+ compute: T.Buffer[(128, 768), "int32"],
+ ) -> None:
+ T.func_attr({"global_symbol": "main", "tir.noalias": True})
+ for i0_0_i1_0_0_fused in T.parallel(
+ 512, annotations={"pragma_auto_unroll_max_step": 64, "pragma_unroll_explicit": 1}
+ ):
+ for i0_1_init, i1_0_1_init, i0_2_init, i1_0_2_init in T.grid(2, 3, 1, 1):
+ with T.block("compute_o_init"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1_init + i0_2_init)
+ j_o = T.axis.spatial(24, i1_0_2_init + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1_init)
+ T.reads()
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ for i1_1 in T.vectorized(32):
+ with T.block("compute_init"):
+ j_i_init = T.axis.spatial(32, i1_1)
+ T.reads()
+ T.writes(compute[i, j_o * 32 + j_i_init])
+ compute[i, j_o * 32 + j_i_init] = 0
+ for i2_0_0, i0_1, i1_0_1, i2_0_1, i0_2, i1_0_2 in T.grid(32, 2, 3, 6, 1, 1):
+ with T.block("compute_o_update"):
+ i = T.axis.spatial(128, i0_0_i1_0_0_fused // 8 * 2 + i0_1 + i0_2)
+ j_o = T.axis.spatial(24, i1_0_2 + i0_0_i1_0_0_fused % 8 * 3 + i1_0_1)
+ k_o = T.axis.reduce(192, i2_0_0 * 6 + i2_0_1)
+ T.reads(
+ compute[i, j_o * 32 : j_o * 32 + 32],
+ X[i, k_o * 4 : k_o * 4 + 4],
+ packedW[j_o, k_o, 0:32, 0:4],
+ )
+ T.writes(compute[i, j_o * 32 : j_o * 32 + 32])
+ A = T.match_buffer(
+ X[i, k_o * 4 : k_o * 4 + 4], [4], dtype="uint8", offset_factor=1
+ )
+ B = T.match_buffer(
+ packedW[j_o, k_o, 0:32, 0:4], [32, 4], dtype="uint8", offset_factor=1
+ )
+ C = T.match_buffer(
+ compute[i, j_o * 32 : j_o * 32 + 32], [32], dtype="int32", offset_factor=1
+ )
+ A_u8x4: T.uint8x4 = A[0:4]
+ A_i32: T.int32 = T.reinterpret(A_u8x4, dtype="int32")
+ B_i32x32: T.int32x32 = T.reinterpret(B[0, 0:128], dtype="int32x32")
+ C[0:32] = T.call_llvm_pure_intrin(
+ 4390, T.uint32(3), C[0:32], B_i32x32, A_i32, dtype="int32x32"
+ )
+
+
+@tvm.testing.requires_hexagon
+def test_vrmpy_dense_auto_tensorize(hexagon_launcher):
+ if hexagon_launcher._serial_number == "simulator":
+ pytest.skip(msg="Tuning on simulator not supported.")
+
+ target_hexagon = tvm.target.hexagon("v68")
+ target = tvm.target.Target(target_hexagon, host=target_hexagon)
+
+ M, N, K = 128, 768, 768
+ workload = te.create_prim_func(dense(M, N, K))
+
+ sch_rules = [
+ schedule_rule.MultiLevelTilingWithIntrin(
+ VRMPY_u8u8i32_INTRIN,
+ structure="SRSRS",
+ tile_binds=None,
+ max_innermost_factor=64,
+ vector_load_lens=None,
+ reuse_read=None,
+ reuse_write=schedule_rule.ReuseType(
+ req="may",
+ levels=[1, 2],
+ scope="global",
+ ),
+ ),
+ schedule_rule.ParallelizeVectorizeUnroll(
+ max_jobs_per_core=16,
+ max_vectorize_extent=128,
+ unroll_max_steps=[0, 16, 64, 512],
+ unroll_explicit=True,
+ ),
+ ]
+
+ postprocs = [
+ postproc.RewriteParallelVectorizeUnroll(),
+ postproc.RewriteReductionBlock(),
+ postproc.RewriteTensorize(vectorize_init_loop=True),
+ ]
+
+ if True:
Review Comment:
Is this a leftover from something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tmoreau89 commented on pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
tmoreau89 commented on PR #12854:
URL: https://github.com/apache/tvm/pull/12854#issuecomment-1265449228
Thanks @masahi @kparzysz-quic, the PR has been merged!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on pull request #12854: [Hexagon] Support template-free meta schedule tuning
Posted by GitBox <gi...@apache.org>.
masahi commented on PR #12854:
URL: https://github.com/apache/tvm/pull/12854#issuecomment-1253544832
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org