You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/01/27 22:02:41 UTC

[GitHub] [tvm] kparzysz-quic commented on a change in pull request #9631: [Hexagon] Add RPC Mechanism for Hexagon

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



##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}
+
+  void MessageStart(size_t message_size_bytes) {}
+
+  ssize_t PosixWrite(const uint8_t* buf, size_t write_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixWrite called, write_len_bytes: %d",
+                  write_len_bytes);
+    size_t written_size = static_cast<size_t>(
+        write_buffer_.sputn(reinterpret_cast<const char*>(buf), write_len_bytes));
+    if (written_size != write_len_bytes) {
+      HEXAGON_PRINT(ALWAYS, "HexagonIOHandler written_size failed");
+    }
+    return (ssize_t)written_size;
+  }
+
+  void MessageDone() {}
+
+  ssize_t PosixRead(uint8_t* buf, size_t read_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixRead called, %d, %d", read_len_bytes,
+                  read_buffer_index_);
+
+    uint32_t bytes_to_read = 0;
+    if ((read_buffer_index_ - read_len_bytes) < 0) {
+      bytes_to_read = read_buffer_index_;
+    } else {
+      bytes_to_read = read_len_bytes;
+    }
+
+    std::memcpy(buf, read_buffer_, bytes_to_read);
+    read_buffer_ += bytes_to_read;
+    read_buffer_index_ -= bytes_to_read;
+    if (bytes_to_read != read_len_bytes) {
+      HEXAGON_PRINT(ERROR, "Error bytes_to_read (%d) < read_len_bytes (%d).", bytes_to_read,
+                    read_len_bytes);
+    }
+    return (ssize_t)bytes_to_read;
+  }
+
+  /*!
+   * \brief Set read buffer in IOHandler to data pointer.
+   * \param data The data pointer.
+   * \param data_size_bytes The size of data in bytes.
+   *
+   * \return The status
+   */
+  AEEResult SetReadBuffer(const uint8_t* data, size_t data_size_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler SetReadBuffer called: %d, prev read_buffer_index_: ",
+                  data_size_bytes, read_buffer_index_);
+    if (data_size_bytes > read_buffer_size_bytes_) {
+      return AEE_EFAILED;
+    }
+    read_buffer_ = data;
+    read_buffer_index_ = data_size_bytes;
+    return AEE_SUCCESS;
+  }
+
+  /*!
+   * \brief Get pointer to the buffer that a packet has been written to.

Review comment:
       This function doesn't "get any pointers", it copies (part of) the write buffer to the specified address.

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}
+
+  void MessageStart(size_t message_size_bytes) {}
+
+  ssize_t PosixWrite(const uint8_t* buf, size_t write_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixWrite called, write_len_bytes: %d",
+                  write_len_bytes);
+    size_t written_size = static_cast<size_t>(
+        write_buffer_.sputn(reinterpret_cast<const char*>(buf), write_len_bytes));
+    if (written_size != write_len_bytes) {
+      HEXAGON_PRINT(ALWAYS, "HexagonIOHandler written_size failed");
+    }
+    return (ssize_t)written_size;
+  }
+
+  void MessageDone() {}
+
+  ssize_t PosixRead(uint8_t* buf, size_t read_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixRead called, %d, %d", read_len_bytes,
+                  read_buffer_index_);
+
+    uint32_t bytes_to_read = 0;
+    if ((read_buffer_index_ - read_len_bytes) < 0) {

Review comment:
       This shouldn't be subtracting unsigned numbers, just comparing them.

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}
+
+  void MessageStart(size_t message_size_bytes) {}
+
+  ssize_t PosixWrite(const uint8_t* buf, size_t write_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixWrite called, write_len_bytes: %d",
+                  write_len_bytes);
+    size_t written_size = static_cast<size_t>(
+        write_buffer_.sputn(reinterpret_cast<const char*>(buf), write_len_bytes));
+    if (written_size != write_len_bytes) {
+      HEXAGON_PRINT(ALWAYS, "HexagonIOHandler written_size failed");
+    }
+    return (ssize_t)written_size;
+  }
+
+  void MessageDone() {}
+
+  ssize_t PosixRead(uint8_t* buf, size_t read_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixRead called, %d, %d", read_len_bytes,
+                  read_buffer_index_);
+
+    uint32_t bytes_to_read = 0;
+    if ((read_buffer_index_ - read_len_bytes) < 0) {
+      bytes_to_read = read_buffer_index_;
+    } else {
+      bytes_to_read = read_len_bytes;
+    }
+
+    std::memcpy(buf, read_buffer_, bytes_to_read);
+    read_buffer_ += bytes_to_read;
+    read_buffer_index_ -= bytes_to_read;
+    if (bytes_to_read != read_len_bytes) {
+      HEXAGON_PRINT(ERROR, "Error bytes_to_read (%d) < read_len_bytes (%d).", bytes_to_read,
+                    read_len_bytes);
+    }
+    return (ssize_t)bytes_to_read;
+  }
+
+  /*!
+   * \brief Set read buffer in IOHandler to data pointer.
+   * \param data The data pointer.
+   * \param data_size_bytes The size of data in bytes.
+   *
+   * \return The status
+   */
+  AEEResult SetReadBuffer(const uint8_t* data, size_t data_size_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler SetReadBuffer called: %d, prev read_buffer_index_: ",
+                  data_size_bytes, read_buffer_index_);
+    if (data_size_bytes > read_buffer_size_bytes_) {
+      return AEE_EFAILED;
+    }
+    read_buffer_ = data;
+    read_buffer_index_ = data_size_bytes;
+    return AEE_SUCCESS;
+  }
+
+  /*!
+   * \brief Get pointer to the buffer that a packet has been written to.
+   * \param buf The data pointer.
+   * \param read_size_bytes The size of read in bytes.
+   *
+   * \return The size of data that is read in bytes.
+   */
+  int64_t GetWriteBuffer(uint8_t* buf, size_t read_size_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler GetWriteBuffer called, read_len_bytes: %d",
+                  read_size_bytes);
+    return write_buffer_.sgetn(reinterpret_cast<char*>(buf), read_size_bytes);
+  }
+
+  void Close() { HEXAGON_PRINT(ALWAYS, "HexagonIOHandler Close called"); }
+
+  void Exit(int code) { exit(code); }
+
+ private:
+  const uint8_t* read_buffer_;
+  uint32_t read_buffer_index_;
+  size_t read_buffer_size_bytes_;
+
+  std::stringbuf write_buffer_;
+};
+
+class HexagonRPCServer {
+ public:
+  explicit HexagonRPCServer(uint8_t* receive_buffer, size_t receive_buffer_size_bytes)
+      : io_{receive_buffer, receive_buffer_size_bytes}, rpc_server_{&io_} {};
+
+  /*!
+   * \brief Wrtie to IOHandler.
+   * \param data The data pointer
+   * \param data_size_bytes The data size in bytes.
+   *
+   * \return The size of data written to IOHandler.
+   */
+  int64_t Write(const uint8_t* data, size_t data_size_bytes) {
+    if (io_.SetReadBuffer(data, data_size_bytes) != AEE_SUCCESS) {
+      return -1;
+    }
+    rpc_server_.ProcessOnePacket();
+    return (int64_t)data_size_bytes;
+  }
+
+  /*!
+   * \brief Read from IOHandler.
+   * \param buf The buffer pointer
+   * \param read_size_bytes Read request size in bytes.
+   *
+   * \return The size of data that is read in bytes.
+   */
+  int64_t Read(uint8_t* buf, size_t read_size_bytes) {
+    return io_.GetWriteBuffer(buf, read_size_bytes);
+  }
+
+ private:
+  HexagonIOHandler io_;
+  MinRPCServer<HexagonIOHandler> rpc_server_;
+};
+
+}  // namespace hexagon
+}  // namespace runtime
+}  // namespace tvm
+
+namespace {
+tvm::runtime::hexagon::HexagonRPCServer* get_hexagon_rpc_server() {
+  static tvm::runtime::hexagon::HexagonRPCServer g_hexagon_rpc_server(
+      new uint8_t[TVM_HEXAGON_RPC_BUFF_SIZE_BYTES], TVM_HEXAGON_RPC_BUFF_SIZE_BYTES);

Review comment:
       This allocation is lost the first time the server tries to read something (see `SetReadBuffer`).

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}
+
+  void MessageStart(size_t message_size_bytes) {}
+
+  ssize_t PosixWrite(const uint8_t* buf, size_t write_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixWrite called, write_len_bytes: %d",
+                  write_len_bytes);
+    size_t written_size = static_cast<size_t>(
+        write_buffer_.sputn(reinterpret_cast<const char*>(buf), write_len_bytes));
+    if (written_size != write_len_bytes) {
+      HEXAGON_PRINT(ALWAYS, "HexagonIOHandler written_size failed");
+    }
+    return (ssize_t)written_size;
+  }
+
+  void MessageDone() {}
+
+  ssize_t PosixRead(uint8_t* buf, size_t read_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixRead called, %d, %d", read_len_bytes,
+                  read_buffer_index_);
+
+    uint32_t bytes_to_read = 0;
+    if ((read_buffer_index_ - read_len_bytes) < 0) {
+      bytes_to_read = read_buffer_index_;
+    } else {
+      bytes_to_read = read_len_bytes;
+    }
+
+    std::memcpy(buf, read_buffer_, bytes_to_read);
+    read_buffer_ += bytes_to_read;
+    read_buffer_index_ -= bytes_to_read;
+    if (bytes_to_read != read_len_bytes) {
+      HEXAGON_PRINT(ERROR, "Error bytes_to_read (%d) < read_len_bytes (%d).", bytes_to_read,
+                    read_len_bytes);
+    }
+    return (ssize_t)bytes_to_read;
+  }
+
+  /*!
+   * \brief Set read buffer in IOHandler to data pointer.
+   * \param data The data pointer.
+   * \param data_size_bytes The size of data in bytes.
+   *
+   * \return The status
+   */
+  AEEResult SetReadBuffer(const uint8_t* data, size_t data_size_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler SetReadBuffer called: %d, prev read_buffer_index_: ",
+                  data_size_bytes, read_buffer_index_);
+    if (data_size_bytes > read_buffer_size_bytes_) {
+      return AEE_EFAILED;
+    }
+    read_buffer_ = data;

Review comment:
       This loses the initial read buffer, which is never deallocated.

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}

Review comment:
       The order here should follow the order of declarations below.

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)
+      : read_buffer_{read_buffer},
+        read_buffer_size_bytes_{read_buffer_size_bytes},
+        read_buffer_index_{0} {}
+
+  void MessageStart(size_t message_size_bytes) {}
+
+  ssize_t PosixWrite(const uint8_t* buf, size_t write_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixWrite called, write_len_bytes: %d",
+                  write_len_bytes);
+    size_t written_size = static_cast<size_t>(
+        write_buffer_.sputn(reinterpret_cast<const char*>(buf), write_len_bytes));
+    if (written_size != write_len_bytes) {
+      HEXAGON_PRINT(ALWAYS, "HexagonIOHandler written_size failed");
+    }
+    return (ssize_t)written_size;
+  }
+
+  void MessageDone() {}
+
+  ssize_t PosixRead(uint8_t* buf, size_t read_len_bytes) {
+    HEXAGON_PRINT(ALWAYS, "HexagonIOHandler PosixRead called, %d, %d", read_len_bytes,
+                  read_buffer_index_);
+
+    uint32_t bytes_to_read = 0;
+    if ((read_buffer_index_ - read_len_bytes) < 0) {
+      bytes_to_read = read_buffer_index_;
+    } else {
+      bytes_to_read = read_len_bytes;
+    }
+
+    std::memcpy(buf, read_buffer_, bytes_to_read);
+    read_buffer_ += bytes_to_read;
+    read_buffer_index_ -= bytes_to_read;
+    if (bytes_to_read != read_len_bytes) {
+      HEXAGON_PRINT(ERROR, "Error bytes_to_read (%d) < read_len_bytes (%d).", bytes_to_read,
+                    read_len_bytes);

Review comment:
       If it's an error to read less than `read_len_bytes`, then why is the code above trying to handle this?

##########
File path: src/runtime/hexagon/rpc/hexagon/rpc_server.cc
##########
@@ -0,0 +1,271 @@
+/*
+ * 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 <dlfcn.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+#include "../../../library_module.h"
+#include "../../../minrpc/minrpc_server.h"
+#include "../../hexagon/hexagon_common.h"
+#include "hexagon_rpc.h"
+
+// TODO(mehrdadh): make this configurable.
+#define TVM_HEXAGON_RPC_BUFF_SIZE_BYTES 2 * 1024 * 1024
+
+#define TVM_LOG_CUSTOMIZE 1
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+/*!
+ * \brief Hexagon IO Handler used in HexagonRPCServer(MinRPCServer).
+ *
+ * \param read_buffer The pointer to read buffer.
+ * \param read_buffer_size_bytes The read buffer size in bytes.
+ */
+class HexagonIOHandler {
+ public:
+  explicit HexagonIOHandler(uint8_t* read_buffer, size_t read_buffer_size_bytes)

Review comment:
       The `read_buffer` is not used for anything.




-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org