From e4ff001f9fa56f5222805c6689c77d5297636a80 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Mon, 30 Jan 2023 21:45:20 +0200 Subject: [PATCH 1/5] [TOPHUB] use keys as a keyword for searching of existing statistics In case of ARM we might not specify -device and in this case llvm will be used while even in this case we can determin proper filename with stat since keys have architecture defined. The same situatin must with with x86 --- python/tvm/autotvm/tophub.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/tvm/autotvm/tophub.py b/python/tvm/autotvm/tophub.py index f705d591e6ee..32b73e4dd5e2 100644 --- a/python/tvm/autotvm/tophub.py +++ b/python/tvm/autotvm/tophub.py @@ -110,6 +110,8 @@ def context(target, extra_files=None): device = tgt.attrs.get("device", "") if device != "": possible_names.append(_alias(device)) + for k in tgt.keys: + possible_names.append(k) possible_names.append(tgt.kind.name) all_packages = list(PACKAGE_VERSION.keys()) From 3fde8b30a1a4d3dcd0532a591b3ddb4e70d00645 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Tue, 31 Jan 2023 10:59:34 +0200 Subject: [PATCH 2/5] Add test on target not having arm_cpu device --- .../unittest/test_autotvm_dispatch_context.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/python/unittest/test_autotvm_dispatch_context.py b/tests/python/unittest/test_autotvm_dispatch_context.py index 6ca062047fd7..eba0c954198b 100644 --- a/tests/python/unittest/test_autotvm_dispatch_context.py +++ b/tests/python/unittest/test_autotvm_dispatch_context.py @@ -19,6 +19,7 @@ to the parameters of workload""" from tvm import autotvm +import tvm @autotvm.template("testing/dispatch_fallback") @@ -31,5 +32,19 @@ def test_fallback(): simple_template(2, 3) +def test_tophub_kinds_match(): + def verify_arm_cpu(target): + best_by_targetkey = autotvm.tophub.context(target).best_by_targetkey + assert(len(best_by_targetkey)) + found_arm_cpu = False + for a, _ in best_by_targetkey: + if "arm_cpu" in a: + found_arm_cpu = True + break + assert(found_arm_cpu) + + verify_arm_cpu("llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon,+v8.2a,+dotprod") + verify_arm_cpu("llvm -model=snapdragon835 -mtriple=arm64-linux-android -mattr=+neon") + if __name__ == "__main__": test_fallback() From 8b84b43865000c94b8617f82eda89616acdffb20 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Tue, 31 Jan 2023 11:07:27 +0200 Subject: [PATCH 3/5] minor fix, add comment --- python/tvm/autotvm/tophub.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/tvm/autotvm/tophub.py b/python/tvm/autotvm/tophub.py index 32b73e4dd5e2..8b86ab39b154 100644 --- a/python/tvm/autotvm/tophub.py +++ b/python/tvm/autotvm/tophub.py @@ -110,8 +110,10 @@ def context(target, extra_files=None): device = tgt.attrs.get("device", "") if device != "": possible_names.append(_alias(device)) - for k in tgt.keys: - possible_names.append(k) + # for cases when we do have explicitly defined -device in the target, + # we still might have information about it stored in keys container + # in other case we will load statistics for definitely irrelative stat + possible_names.extend(tgt.keys) possible_names.append(tgt.kind.name) all_packages = list(PACKAGE_VERSION.keys()) From 4a7345ca24833b28d4fd02317e6c2c700eb722c8 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Tue, 31 Jan 2023 12:05:56 +0200 Subject: [PATCH 4/5] Fix pylint --- tests/python/unittest/test_autotvm_dispatch_context.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/python/unittest/test_autotvm_dispatch_context.py b/tests/python/unittest/test_autotvm_dispatch_context.py index eba0c954198b..ba75992128a8 100644 --- a/tests/python/unittest/test_autotvm_dispatch_context.py +++ b/tests/python/unittest/test_autotvm_dispatch_context.py @@ -35,16 +35,17 @@ def test_fallback(): def test_tophub_kinds_match(): def verify_arm_cpu(target): best_by_targetkey = autotvm.tophub.context(target).best_by_targetkey - assert(len(best_by_targetkey)) + assert len(best_by_targetkey) found_arm_cpu = False for a, _ in best_by_targetkey: if "arm_cpu" in a: found_arm_cpu = True break - assert(found_arm_cpu) + assert found_arm_cpu verify_arm_cpu("llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon,+v8.2a,+dotprod") verify_arm_cpu("llvm -model=snapdragon835 -mtriple=arm64-linux-android -mattr=+neon") + if __name__ == "__main__": test_fallback() From 812c36cc5c51c8dda92be2913e1e0d91163e1e39 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Thu, 2 Feb 2023 12:31:15 +0200 Subject: [PATCH 5/5] Fix comment --- python/tvm/autotvm/tophub.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/tvm/autotvm/tophub.py b/python/tvm/autotvm/tophub.py index 8b86ab39b154..99dd312d870a 100644 --- a/python/tvm/autotvm/tophub.py +++ b/python/tvm/autotvm/tophub.py @@ -106,13 +106,19 @@ def context(target, extra_files=None): if isinstance(tgt, str): tgt = Target(tgt) + # The TOPHUB file names rely on Target's device or kind. Both these types of + # information exist in Target.keys, but rules of filling this filed is not explicitly + # defined, we are afraid to rely only on Target.keys. At the same time Target.device + # is filled only if device was pointed explicitly in target string, that is not mandatory + # and in some cases we need to get information about device from Target.keys + # In priority order we verify: + # 1) Target.device + # 2) Target.keys + # 3) Target.kind possible_names = [] device = tgt.attrs.get("device", "") if device != "": possible_names.append(_alias(device)) - # for cases when we do have explicitly defined -device in the target, - # we still might have information about it stored in keys container - # in other case we will load statistics for definitely irrelative stat possible_names.extend(tgt.keys) possible_names.append(tgt.kind.name)