tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] tqchen commented on a change in pull request #5484: [REFACTOR][RPC][PROCOTOL-CHANGE] Modularize the RPC infra
Date Mon, 04 May 2020 19:57:45 GMT

tqchen commented on a change in pull request #5484:
URL: https://github.com/apache/incubator-tvm/pull/5484#discussion_r419691019



##########
File path: src/runtime/rpc/rpc_endpoint.cc
##########
@@ -0,0 +1,1059 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file rpc_session.cc
+ * \brief RPC session for remote function call.
+ */
+#include <tvm/runtime/c_runtime_api.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/device_api.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/runtime/serializer.h>
+#include <memory>
+#include <array>
+#include <string>
+#include <chrono>
+#include <vector>
+#include <utility>
+#include <cmath>
+#include <algorithm>
+
+#include "rpc_endpoint.h"
+#include "rpc_local_session.h"
+#include "../object_internal.h"
+#include "../../support/ring_buffer.h"
+#include "../../support/arena.h"
+
+namespace tvm {
+namespace runtime {
+
+/*!
+ * Event-driven state-machine based handlers for RPCEndpoint.
+ *
+ * Key functions:
+ *
+ * - SendPackedSeq: send the arguments over to the peer
+ * - HandleNextEvent: handle the next request from the peer(RPCCode followed by per code
protocol).
+ */
+class RPCEndpoint::EventHandler : public dmlc::Stream {
+ public:
+  EventHandler(support::RingBuffer* reader,
+               support::RingBuffer* writer,
+               std::string name,
+               std::string* remote_key)
+      : reader_(reader),
+        writer_(writer),
+        name_(name),
+        remote_key_(remote_key) {
+    this->Clear();
+
+    if (*remote_key == "%toinit") {
+      state_ = kInitHeader;
+      remote_key_->resize(0);
+      pending_request_bytes_ = sizeof(int32_t);
+    }
+  }
+
+  /*!
+   * \brief Bytes needed to fulfill current request
+   */
+  size_t BytesNeeded() const {
+    if (reader_->bytes_available() < pending_request_bytes_) {
+      return pending_request_bytes_ - reader_->bytes_available();
+    } else {
+      return 0;
+    }
+  }
+
+  /*!
+   * \brief Request number of bytes from the reader.
+   * \param nbytes The number of bytes
+   */
+  void RequestBytes(size_t nbytes) {
+    pending_request_bytes_ += nbytes;
+    reader_->Reserve(pending_request_bytes_);
+  }
+
+  /*! \return Whether we are ready to handle next request. */
+  bool Ready() const {
+    return reader_->bytes_available() >= pending_request_bytes_;
+  }
+
+  /*! \return Whether we can perform a clean shutdown */
+  bool CanCleanShutdown() const {
+    return state_ == kRecvPacketNumBytes;
+  }
+
+  /*! \brief Finish the copy ack stage. */
+  void FinishCopyAck() {
+    this->SwitchToState(kRecvPacketNumBytes);
+  }
+
+  /*!
+   * \brief Enter the io loop until the next event.
+   * \param client_mode Whether we are in the client.
+   * \param setreturn The function to set the return value encoding.
+   * \return The function to set return values when there is a return event.
+   */
+  RPCCode HandleNextEvent(bool client_mode, RPCSession::FEncodeReturn setreturn) {
+    std::swap(client_mode_, client_mode);
+
+    while (this->Ready()) {
+      switch (state_) {
+        case kInitHeader: HandleInitHeader(); break;
+        case kRecvPacketNumBytes: {
+          uint64_t packet_nbytes;
+          CHECK(this->Read(&packet_nbytes));
+          if (packet_nbytes != 0) {

Review comment:
       there is no max limit for now.




----------------------------------------------------------------
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.

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



Mime
View raw message