kparzysz-quic commented on a change in pull request #8986:
URL: https://github.com/apache/tvm/pull/8986#discussion_r709342341



##########
File path: src/runtime/hexagon/launcher/README.md
##########
@@ -0,0 +1,142 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+# Hexagon Graph Launcher
+
+## Compilation
+
+The launcher consists of two parts: part running on Hexagon, and part running
+on Android. They need to be compiled separately. Since some source files are
+shared between these two parts, make sure to delete all object files beteween

Review comment:
       Fixed.

##########
File path: src/runtime/hexagon/launcher/README.md
##########
@@ -0,0 +1,142 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+# Hexagon Graph Launcher
+
+## Compilation
+
+The launcher consists of two parts: part running on Hexagon, and part running
+on Android. They need to be compiled separately. Since some source files are
+shared between these two parts, make sure to delete all object files beteween
+compilations. Compile the Hexagon code first.
+
+### Prerequisites
+
+1. Android NDK version r19c or later.
+2. Hexagon SDK version 4.0.0 or later.
+
+Android NDK can be downloaded from https://developer.android.com/ndk.
+Hexagon SDK is available at //developer.qualcomm.com/software/hexagon-dsp-sdk.
+
+### Compilation of the Hexagon part
+
+1. Build the static version of TVM runtime for Hexagon: this step is the same
+   as building the shared version, except at the cmake step, add
+   `-DBUILD_STATIC_RUNTIME=ON`. The compilation step should create
+   `libtvm_runtime.a`.
+
+2. Create a subdirectory for the build files, and run `cmake` with the
+   following variables set:
+   - `FASTRPC_LIBS=SKEL`
+   - `HEXAGON_SDK_ROOT` to the path to the Hexagon SDK
+   - `CMAKE_C_COMPILER=hexagon-clang`
+   - `CMAKE_CXX_COMPILER=hexagon-clang++`
+   - `HEXAGON_ARCH` to one of v65, v66, v68
+   - `TVM_RUNTIME_HEXAGON=/path/to/libtvm_runtime.a` _statically_ linked
+     TVM runtime
+   Make sure to provide the path to launcher's `CMakeLists.txt` directory
+   in `cmake` invocation.
+
+3. Run `make`. This will create `liblauncher_rpc_skel.so`.
+
+### Compilation of the Android part
+
+1. Build TVM runtime for Android. Unlike in the Hexagon case, this should be
+   the dynamic library (which is the default), i.e. `libtvm_runtime.so`.
+
+2. Create a subdirectory for the build files (different from the one used for
+   Hexagon files), and run `cmake` with the following variables set:
+   - `FASTRPC_LIBS=STUB`
+   - `HEXAGON_SDK_ROOT` to the path to the Hexagon SDK
+   - `CMAKE_C_COMPILER=aarch64-linux-android28-clang` (or later)
+   - `CMAKE_CXX_COMPILER=aarch64-linux-android28-clang++` (or later)
+   - `HEXAGON_ARCH` to one of v65, v66, v68 (same as for the Hexagon part)
+   - `TVM_RUNTIME_ANDROID=/path/to/libtvm_runtime.so` dynamically or
+     statically linked TVM runtime
+
+3. Run `make`. This will create `launcher_android`.
+
+## Execution
+
+From the Android shell, do
+```
+./launcher_android --in_config input.json --out_config output.json
+```
+
+You may need to add the location of `libtvm_runtime.so` to `LD_LIBRARY_PATH`.
+See below for more information about the setup and launcher's inputs.
+
+### Preparation steps
+
+Copy the set of binaries created in the compilation step to the device:
+- `liblauncher_rpc_skel.so`,
+- `libgcc.so` (this one should come from the Hexagon toolchain),
+- `launcher_android`,
+- `libtvm_runtime.so` (for Android).

Review comment:
       I think I addressed it, let me know if that's what you meant.

##########
File path: src/runtime/hexagon/launcher/launcher_hexagon.cc
##########
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+extern "C" {
+#include <AEEStdDef.h>
+#include <AEEStdErr.h>
+#include <HAP_farf.h>
+#include <HAP_perf.h>
+#include <qurt_error.h>
+#include <qurt_hvx.h>
+}
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "launcher_core.h"
+#include "launcher_rpc.h"
+
+static std::unique_ptr<Model> TheModel;
+
+static AEEResult error_too_small(const std::string& func_name, const 
std::string& value_name,
+                                 int given, int needed) {
+  FARF(ERROR, "%s: %s value too small (%d), need at least %d", 
func_name.c_str(),
+       value_name.c_str(), given, needed);
+  return AEE_EBADPARM;
+}
+
+int __QAIC_HEADER(launcher_rpc_open)(const char* uri, remote_handle64* handle) 
{
+  *handle = 0;  // Just use any value.
+  reset_device_api();
+  return AEE_SUCCESS;
+}
+
+int __QAIC_HEADER(launcher_rpc_close)(remote_handle64 handle) {
+  // Comment to stop clang-format from single-lining this function.
+  return AEE_SUCCESS;
+}
+
+AEEResult __QAIC_HEADER(launcher_rpc_load)(remote_handle64 handle, const char* 
module_path,
+                                           const char* graph_json) {
+  if (TheModel) {
+    // Need to unload first.
+    FARF(ERROR, "%s: model already loaded, unload first", __func__);
+    return AEE_EUNABLETOLOAD;
+  }
+
+  tvm::runtime::Module module = load_module(module_path);
+  tvm::runtime::Module executor = create_graph_executor(graph_json, module, 
Model::device());
+
+  TheModel = std::make_unique<Model>(executor, module, graph_json);
+  return AEE_SUCCESS;
+}
+
+AEEResult __QAIC_HEADER(launcher_rpc_unload)(remote_handle64 handle) {
+  if (TheModel) {
+    TheModel.reset();
+  }
+  return AEE_SUCCESS;
+}
+
+AEEResult __QAIC_HEADER(launcher_rpc_get_num_inputs)(remote_handle64 handle, 
int* num_inputs) {
+  if (!TheModel) {
+    // No model created.
+    return AEE_EBADSTATE;
+  }
+
+  tvm::runtime::PackedFunc get_num_inputs =
+      get_module_func(TheModel->graph_executor, "get_num_inputs");
+  *num_inputs = get_num_inputs();
+  return AEE_SUCCESS;
+}
+
+AEEResult __QAIC_HEADER(launcher_rpc_set_input)(remote_handle64 handle, int 
input_idx,
+                                                const unsigned char* 
input_meta, int meta_size,
+                                                const unsigned char* 
input_value, int value_size) {
+  if (!TheModel) {
+    // No model created.
+    FARF(ERROR, "%s: no model created", __func__);
+    return AEE_EBADSTATE;
+  }
+
+  const auto* meta = reinterpret_cast<const tensor_meta*>(input_meta);
+  if (meta_size < meta->meta_size()) {
+    return error_too_small(__func__, "meta_size", meta_size, 
meta->meta_size());
+  }
+  if (value_size < meta->data_size()) {
+    return error_too_small(__func__, "value_size", value_size, 
meta->data_size());
+  }
+
+  DLTensor tensor{
+      const_cast<unsigned char*>(input_value),
+      Model::device(),
+      meta->ndim,
+      meta->dtype,
+      const_cast<int64_t*>(meta->shape),
+      /*strides*/ nullptr,
+      /*byte_offset*/ 0,
+  };
+  DLManagedTensor managed{tensor, /*manager_ctx*/ nullptr, /*deleter*/ 
nullptr};
+
+  auto input = tvm::runtime::NDArray::FromDLPack(&managed);
+
+  tvm::runtime::PackedFunc set_input = 
get_module_func(TheModel->graph_executor, "set_input");
+  set_input(input_idx, input);

Review comment:
       `set_input_zero_copy` might work, but I haven't tested it.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to