diff --git a/apps/hexagon_launcher/launcher_core.cc b/apps/hexagon_launcher/launcher_core.cc index 6a5704d3888a..0fe9f9f59e4a 100644 --- a/apps/hexagon_launcher/launcher_core.cc +++ b/apps/hexagon_launcher/launcher_core.cc @@ -148,12 +148,13 @@ 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); } 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(); @@ -169,7 +170,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(); } 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..6925e1da9bfa 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 @@ -106,7 +108,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), @@ -153,6 +155,16 @@ 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 +182,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;