From 54bdbcd6ddfe650021a17ab7a768695a359d9d77 Mon Sep 17 00:00:00 2001 From: Alexander Peskov Date: Tue, 29 Jun 2021 16:06:23 +0300 Subject: [PATCH 1/7] Add get_json method to graph_eceutor factory Signed-off-by: Alexander Peskov --- src/runtime/graph_executor/graph_executor_factory.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/graph_executor/graph_executor_factory.cc b/src/runtime/graph_executor/graph_executor_factory.cc index a13fbd860d43..7e66c38223af 100644 --- a/src/runtime/graph_executor/graph_executor_factory.cc +++ b/src/runtime/graph_executor/graph_executor_factory.cc @@ -53,6 +53,10 @@ PackedFunc GraphExecutorFactory::GetFunction( } *rv = this->ExecutorCreate(devices); }); + } else if (name == "get_json") { + return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { + *rv = this->graph_json_; + }); } else if (name == "debug_create") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { ICHECK_GE(args.size(), 2); From bbf33973f73a2d9c6cadd5d5a78f5d61e5834884 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Thu, 19 Aug 2021 12:31:52 +0300 Subject: [PATCH 2/7] Update Debugger runtime documentation for exported libraries --- docs/dev/debugger.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/dev/debugger.rst b/docs/dev/debugger.rst index 38172a2189e0..93d6b36754d8 100644 --- a/docs/dev/debugger.rst +++ b/docs/dev/debugger.rst @@ -123,12 +123,12 @@ Example of loading the parameters How to use Debugger? *************************************** -1. In ``config.cmake`` set the ``USE_GRAPH_EXECUTOR_DEBUG`` flag to ``ON`` +1. In ``config.cmake`` set the ``USE_GRAPH_RUNTIME_DEBUG`` flag to ``ON`` :: # Whether enable additional graph debug functions - set(USE_GRAPH_EXECUTOR_DEBUG ON) + set(USE_GRAPH_RUNTIME_DEBUG ON) 2. Do 'make' tvm, so that it will make the ``libtvm_runtime.so`` @@ -148,6 +148,22 @@ How to use Debugger? m.run() tvm_out = m.get_output(0, tvm.nd.empty(out_shape, dtype)).numpy() +4. If network previously was exported to external libray using ``lib.export_library("network.so")`` + like shared object file/dynamic linked library, the initialization + of debug runtime will be slightly different + +:: + lib = tvm.runtime.load_module("network.so") + m = graph_executor.GraphModuleDebug(lib["debug_create"]("default", dev), + [dev], lib["get_json"](), dump_root="/tmp/tvmdbg") + # set inputs + m.set_input('data', tvm.nd.array(data.astype(dtype))) + m.set_input(**params) + # execute + m.run() + tvm_out = m.get_output(0, tvm.nd.empty(out_shape, dtype)).numpy() + + The outputs are dumped to a temporary folder in ``/tmp`` folder or the folder specified while creating the runtime. From 472684dc2fe7d93a04229e91c0fefd13b818479d Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Thu, 19 Aug 2021 14:08:11 +0300 Subject: [PATCH 3/7] Fix cpplint --- src/runtime/graph_executor/graph_executor_factory.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/runtime/graph_executor/graph_executor_factory.cc b/src/runtime/graph_executor/graph_executor_factory.cc index 7e66c38223af..55cce89c52a3 100644 --- a/src/runtime/graph_executor/graph_executor_factory.cc +++ b/src/runtime/graph_executor/graph_executor_factory.cc @@ -54,9 +54,8 @@ PackedFunc GraphExecutorFactory::GetFunction( *rv = this->ExecutorCreate(devices); }); } else if (name == "get_json") { - return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { - *rv = this->graph_json_; - }); + return PackedFunc( + [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->graph_json_; }); } else if (name == "debug_create") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { ICHECK_GE(args.size(), 2); From 660a8fbc960a811e7d7d6d8309b128762c15299a Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Wed, 25 Aug 2021 13:17:31 +0300 Subject: [PATCH 4/7] Change module get_json to get_graph_json, add test --- docs/dev/debugger.rst | 7 +++---- .../graph_executor/graph_executor_factory.cc | 3 ++- .../test_runtime_module_based_interface.py | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/docs/dev/debugger.rst b/docs/dev/debugger.rst index 93d6b36754d8..e5928db3e328 100644 --- a/docs/dev/debugger.rst +++ b/docs/dev/debugger.rst @@ -123,12 +123,12 @@ Example of loading the parameters How to use Debugger? *************************************** -1. In ``config.cmake`` set the ``USE_GRAPH_RUNTIME_DEBUG`` flag to ``ON`` +1. In ``config.cmake`` set the ``USE_PROFILER`` flag to ``ON`` :: # Whether enable additional graph debug functions - set(USE_GRAPH_RUNTIME_DEBUG ON) + set(USE_PROFILER ON) 2. Do 'make' tvm, so that it will make the ``libtvm_runtime.so`` @@ -154,8 +154,7 @@ How to use Debugger? :: lib = tvm.runtime.load_module("network.so") - m = graph_executor.GraphModuleDebug(lib["debug_create"]("default", dev), - [dev], lib["get_json"](), dump_root="/tmp/tvmdbg") + m = graph_executor.create(lib["get_graph_json"](), lib, dev, dump_root="/tmp/tvmdbg") # set inputs m.set_input('data', tvm.nd.array(data.astype(dtype))) m.set_input(**params) diff --git a/src/runtime/graph_executor/graph_executor_factory.cc b/src/runtime/graph_executor/graph_executor_factory.cc index 55cce89c52a3..42fc28b60df2 100644 --- a/src/runtime/graph_executor/graph_executor_factory.cc +++ b/src/runtime/graph_executor/graph_executor_factory.cc @@ -53,9 +53,10 @@ PackedFunc GraphExecutorFactory::GetFunction( } *rv = this->ExecutorCreate(devices); }); - } else if (name == "get_json") { + } else if (name == "get_graph_json") { return PackedFunc( [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->graph_json_; }); + } else if (name == "debug_create") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { ICHECK_GE(args.size(), 2); diff --git a/tests/python/unittest/test_runtime_module_based_interface.py b/tests/python/unittest/test_runtime_module_based_interface.py index e984979ac14f..9eeea41503be 100644 --- a/tests/python/unittest/test_runtime_module_based_interface.py +++ b/tests/python/unittest/test_runtime_module_based_interface.py @@ -90,6 +90,25 @@ def test_cpu(): tvm.testing.assert_allclose(out, verify(data), atol=1e-5) +def test_cpu_get_graph_json(): + if not tvm.testing.device_enabled("llvm"): + print("Skip because llvm is not enabled") + return + mod, params = relay.testing.synthetic.get_workload() + with relay.build_config(opt_level=3): + complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) + from tvm.contrib import utils + + temp = utils.tempdir() + file_name = "deploy_lib.so" + path_lib = temp.relpath(file_name) + complied_graph_lib.export_library(path_lib) + loaded_lib = tvm.runtime.load_module(path_lib) + json = loaded_lib["get_graph_json"]() + assert isinstance(json, str) == True + assert json.find("tvmgen_default_fused_nn_softmax1") == 6312 + + @tvm.testing.requires_cuda @tvm.testing.requires_gpu def test_gpu(): @@ -619,3 +638,4 @@ def make_module(mod): test_remove_package_params() test_debug_graph_executor() test_multiple_imported_modules() + test_cpu_get_graph_json() From fe97c33b301435edb5f0a702f355eb96021c9914 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Wed, 25 Aug 2021 14:53:47 +0300 Subject: [PATCH 5/7] Fix get_graph_json test --- tests/python/unittest/test_runtime_module_based_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/unittest/test_runtime_module_based_interface.py b/tests/python/unittest/test_runtime_module_based_interface.py index 9eeea41503be..90b8b1b20cd2 100644 --- a/tests/python/unittest/test_runtime_module_based_interface.py +++ b/tests/python/unittest/test_runtime_module_based_interface.py @@ -106,7 +106,7 @@ def test_cpu_get_graph_json(): loaded_lib = tvm.runtime.load_module(path_lib) json = loaded_lib["get_graph_json"]() assert isinstance(json, str) == True - assert json.find("tvmgen_default_fused_nn_softmax1") == 6312 + assert json.find("tvmgen_default_fused_nn_softmax1") > -1 @tvm.testing.requires_cuda From 7b1f3f6f745cceb79a928278697075ce6dfcb72a Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Thu, 26 Aug 2021 06:38:41 +0300 Subject: [PATCH 6/7] Change verificatino of llvm support in tet to decorator --- .../test_runtime_module_based_interface.py | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/tests/python/unittest/test_runtime_module_based_interface.py b/tests/python/unittest/test_runtime_module_based_interface.py index 90b8b1b20cd2..2abbcef29283 100644 --- a/tests/python/unittest/test_runtime_module_based_interface.py +++ b/tests/python/unittest/test_runtime_module_based_interface.py @@ -46,10 +46,8 @@ def verify(data): return out +@tvm.testing.requires_llvm def test_legacy_compatibility(): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): graph, lib, graph_params = relay.build_module.build(mod, "llvm", params=params) @@ -63,10 +61,8 @@ def test_legacy_compatibility(): tvm.testing.assert_allclose(out, verify(data), atol=1e-5) +@tvm.testing.requires_llvm def test_cpu(): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -90,10 +86,8 @@ def test_cpu(): tvm.testing.assert_allclose(out, verify(data), atol=1e-5) +@tvm.testing.requires_llvm def test_cpu_get_graph_json(): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -139,9 +133,6 @@ def test_gpu(): @tvm.testing.uses_gpu def test_mod_export(): def verify_cpu_export(obj_format): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -229,10 +220,8 @@ def setup_gmod(): out = gmod.get_output(0).numpy() tvm.testing.assert_allclose(out, verify(data), atol=1e-5) + @tvm.testing.requires_llvm def verify_rpc_cpu_export(obj_format): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -327,12 +316,10 @@ def check_remote(server): verify_rpc_gpu_export(obj_format) +@tvm.testing.requires_llvm @tvm.testing.uses_gpu def test_remove_package_params(): def verify_cpu_remove_package_params(obj_format): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -423,10 +410,8 @@ def verify_gpu_remove_package_params(obj_format): out = gmod.get_output(0).numpy() tvm.testing.assert_allclose(out, verify(data), atol=1e-5) + @tvm.testing.requires_llvm def verify_rpc_cpu_remove_package_params(obj_format): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) @@ -536,10 +521,8 @@ def verify_rpc_gpu_remove_package_params(obj_format): verify_rpc_gpu_remove_package_params(obj_format) +@tvm.testing.requires_llvm def test_debug_graph_executor(): - if not tvm.testing.device_enabled("llvm"): - print("Skip because llvm is not enabled") - return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) From 3f4f8594a50efcdcf8d2cf8b61b384b6cf1f5af0 Mon Sep 17 00:00:00 2001 From: Andrey Malyshev Date: Mon, 30 Aug 2021 13:19:25 +0300 Subject: [PATCH 7/7] Fix sphinx warning in debugger.rst --- docs/dev/debugger.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/dev/debugger.rst b/docs/dev/debugger.rst index e5928db3e328..4a612cac37be 100644 --- a/docs/dev/debugger.rst +++ b/docs/dev/debugger.rst @@ -153,6 +153,7 @@ How to use Debugger? of debug runtime will be slightly different :: + lib = tvm.runtime.load_module("network.so") m = graph_executor.create(lib["get_graph_json"](), lib, dev, dump_root="/tmp/tvmdbg") # set inputs