From e0d26352443bf8ab94d7a1b1444cd2913b70b07b Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Wed, 20 Oct 2021 23:15:33 -0700 Subject: [PATCH 1/6] Use custom lookup_linked_params function in app/hexagon_launcher. --- apps/hexagon_launcher/launcher_core.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/hexagon_launcher/launcher_core.cc b/apps/hexagon_launcher/launcher_core.cc index 6a5704d3888a..be71baaee0a5 100644 --- a/apps/hexagon_launcher/launcher_core.cc +++ b/apps/hexagon_launcher/launcher_core.cc @@ -169,7 +169,10 @@ tvm::runtime::Module create_graph_executor(const std::string& graph_json, uint64_t device_type = device.device_type; uint64_t device_id = device.device_id; + std::string linked_params = "tvm.runtime.hexagon.lookup_linked_params"; + const tvm::runtime::PackedFunc lookup_linked_params = get_runtime_func(linked_params); // Use default param lookup function (linked into the module). - tvm::runtime::TVMRetValue rv = create_executor(graph_json, graph_module, device_type, device_id); + tvm::runtime::TVMRetValue rv = create_executor(graph_json, graph_module, + lookup_linked_params, device_type, device_id); return rv.operator tvm::runtime::Module(); } From 90589d953260d04a9fabcf06a40ed7b2733fbc30 Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Mon, 20 Sep 2021 13:53:17 -0700 Subject: [PATCH 2/6] Use new device api in hexagon launcher. --- apps/hexagon_launcher/launcher_core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/hexagon_launcher/launcher_core.cc b/apps/hexagon_launcher/launcher_core.cc index be71baaee0a5..6da1de01fc00 100644 --- a/apps/hexagon_launcher/launcher_core.cc +++ b/apps/hexagon_launcher/launcher_core.cc @@ -148,7 +148,7 @@ const tvm::runtime::PackedFunc get_module_func(tvm::runtime::Module module, } void reset_device_api() { - const tvm::runtime::PackedFunc api = get_runtime_func("device_api.cpu"); + const tvm::runtime::PackedFunc api = get_runtime_func("device_api.hexagon.v2"); tvm::runtime::Registry::Register("device_api.hexagon", true).set_body(api); } From 2814d9e81e297287d67ae556bfa73746bdfa6ba8 Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Wed, 20 Oct 2021 22:30:14 -0700 Subject: [PATCH 3/6] Ensure app/hexagon_launcher uses kDLCPU for external allocations so that CopyDataFromTo knows how to handle the provided memory. --- apps/hexagon_launcher/launcher_core.h | 2 ++ apps/hexagon_launcher/launcher_hexagon.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/hexagon_launcher/launcher_core.h b/apps/hexagon_launcher/launcher_core.h index f2aa8f10d0a6..91384133ab7b 100644 --- a/apps/hexagon_launcher/launcher_core.h +++ b/apps/hexagon_launcher/launcher_core.h @@ -89,6 +89,8 @@ struct Model { static tvm::Device device() { return tvm::Device{static_cast(kDLHexagon), 0}; } + static tvm::Device external() { return tvm::Device{static_cast(kDLCPU), 0}; } + tvm::runtime::PackedFunc run; }; diff --git a/apps/hexagon_launcher/launcher_hexagon.cc b/apps/hexagon_launcher/launcher_hexagon.cc index 0a5d1f55e0c2..a157f7b9b9fe 100644 --- a/apps/hexagon_launcher/launcher_hexagon.cc +++ b/apps/hexagon_launcher/launcher_hexagon.cc @@ -106,7 +106,7 @@ AEEResult __QAIC_HEADER(launcher_rpc_set_input)(remote_handle64 handle, int inpu DLTensor tensor{ const_cast(input_value), - Model::device(), + Model::external(), meta->ndim, meta->dtype, const_cast(meta->shape), From a173c9ebc086a9170f4c2093ec3cd53662f0e8a4 Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Wed, 20 Oct 2021 22:36:46 -0700 Subject: [PATCH 4/6] Use loadfile_hexagon in app/hexagon_launcher. --- apps/hexagon_launcher/launcher_core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/hexagon_launcher/launcher_core.cc b/apps/hexagon_launcher/launcher_core.cc index 6da1de01fc00..b6aed5012f79 100644 --- a/apps/hexagon_launcher/launcher_core.cc +++ b/apps/hexagon_launcher/launcher_core.cc @@ -153,7 +153,7 @@ void reset_device_api() { } tvm::runtime::Module load_module(const std::string& file_name) { - static const tvm::runtime::PackedFunc loader = get_runtime_func("runtime.module.loadfile_so"); + static const tvm::runtime::PackedFunc loader = get_runtime_func("runtime.module.loadfile_hexagon"); tvm::runtime::TVMRetValue rv = loader(file_name); if (rv.type_code() == kTVMModuleHandle) { return rv.operator tvm::runtime::Module(); From 9d57bcff136ba44cb3e2685939ee42e2517ff563 Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Wed, 20 Oct 2021 09:26:55 -0700 Subject: [PATCH 5/6] Update hexagon launcher's get_output method to utilize NDArray's for copying in order to exercise the DeviceAPI. --- apps/hexagon_launcher/launcher_hexagon.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/hexagon_launcher/launcher_hexagon.cc b/apps/hexagon_launcher/launcher_hexagon.cc index a157f7b9b9fe..5db21a49fb75 100644 --- a/apps/hexagon_launcher/launcher_hexagon.cc +++ b/apps/hexagon_launcher/launcher_hexagon.cc @@ -26,6 +26,8 @@ extern "C" { #include } +#include + #include #include #include @@ -153,6 +155,18 @@ AEEResult __QAIC_HEADER(launcher_rpc_get_output)(remote_handle64 handle, int out tvm::runtime::PackedFunc get_output = get_module_func(TheModel->graph_executor, "get_output"); tvm::runtime::NDArray output = get_output(output_idx); + + std::vector shape_vec{output->shape, + output->shape + output->ndim}; + + auto* container = new tvm::runtime::NDArray::Container(static_cast(output_value), shape_vec, + output->dtype, Model::external()); + container->SetDeleter([](tvm::Object* container) { + delete static_cast(container); + }); + + tvm::runtime::NDArray host_output(GetObjectPtr(container)); + if (meta_size != 0) { auto* meta = reinterpret_cast(output_meta); if (meta_size < meta->meta_size(output->ndim)) { @@ -170,8 +184,7 @@ AEEResult __QAIC_HEADER(launcher_rpc_get_output)(remote_handle64 handle, int out return error_too_small(__func__, "value_size", value_size, data_size); } - auto data = reinterpret_cast(output->data); - std::copy(data, data + data_size, output_value); + host_output.CopyFrom(output); } return AEE_SUCCESS; From 76400b5c9797006f815d725c3858a5215693359a Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Fri, 22 Oct 2021 09:22:09 -0700 Subject: [PATCH 6/6] Apply clang formatting --- apps/hexagon_launcher/launcher_core.cc | 7 ++++--- apps/hexagon_launcher/launcher_hexagon.cc | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/hexagon_launcher/launcher_core.cc b/apps/hexagon_launcher/launcher_core.cc index b6aed5012f79..0fe9f9f59e4a 100644 --- a/apps/hexagon_launcher/launcher_core.cc +++ b/apps/hexagon_launcher/launcher_core.cc @@ -153,7 +153,8 @@ void reset_device_api() { } tvm::runtime::Module load_module(const std::string& file_name) { - static const tvm::runtime::PackedFunc loader = get_runtime_func("runtime.module.loadfile_hexagon"); + static const tvm::runtime::PackedFunc loader = + get_runtime_func("runtime.module.loadfile_hexagon"); tvm::runtime::TVMRetValue rv = loader(file_name); if (rv.type_code() == kTVMModuleHandle) { return rv.operator tvm::runtime::Module(); @@ -172,7 +173,7 @@ tvm::runtime::Module create_graph_executor(const std::string& graph_json, std::string linked_params = "tvm.runtime.hexagon.lookup_linked_params"; const tvm::runtime::PackedFunc lookup_linked_params = get_runtime_func(linked_params); // Use default param lookup function (linked into the module). - tvm::runtime::TVMRetValue rv = create_executor(graph_json, graph_module, - lookup_linked_params, device_type, device_id); + tvm::runtime::TVMRetValue rv = + create_executor(graph_json, graph_module, lookup_linked_params, device_type, device_id); return rv.operator tvm::runtime::Module(); } diff --git a/apps/hexagon_launcher/launcher_hexagon.cc b/apps/hexagon_launcher/launcher_hexagon.cc index 5db21a49fb75..6925e1da9bfa 100644 --- a/apps/hexagon_launcher/launcher_hexagon.cc +++ b/apps/hexagon_launcher/launcher_hexagon.cc @@ -155,12 +155,10 @@ AEEResult __QAIC_HEADER(launcher_rpc_get_output)(remote_handle64 handle, int out tvm::runtime::PackedFunc get_output = get_module_func(TheModel->graph_executor, "get_output"); tvm::runtime::NDArray output = get_output(output_idx); + std::vector shape_vec{output->shape, output->shape + output->ndim}; - std::vector shape_vec{output->shape, - output->shape + output->ndim}; - - auto* container = new tvm::runtime::NDArray::Container(static_cast(output_value), shape_vec, - output->dtype, Model::external()); + auto* container = new tvm::runtime::NDArray::Container( + static_cast(output_value), shape_vec, output->dtype, Model::external()); container->SetDeleter([](tvm::Object* container) { delete static_cast(container); });