tqchen commented on a change in pull request #4281: [RUTNIME] Support C++ RPC
URL: https://github.com/apache/incubator-tvm/pull/4281#discussion_r344293873
 
 

 ##########
 File path: apps/cpp_rpc/rpc_env.cc
 ##########
 @@ -0,0 +1,248 @@
+/*
+ * 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.
+ */
+
+/*!
+ *  Copyright (c) 2019 by Contributors
+ * \file rpc_env.cc
+ * \brief Server environment of the RPC.
+ */
+#include <tvm/runtime/registry.h>
+#include <errno.h>
+#ifndef _MSC_VER
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#else
+#include <Windows.h>
+#endif
+#include <fstream>
+#include <vector>
+#include <iostream>
+#include <string>
+#include <cstring>
+
+#include "rpc_env.h"
+#include "../../src/common/util.h"
+#include "../../src/runtime/file_util.h"
+
+namespace tvm {
+namespace runtime {
+
+RPCEnv::RPCEnv() {
+  #if defined(__linux__) || defined(__ANDROID__)
+    base_ = "./rpc";
+    mkdir(&base_[0], 0777);
+
+    TVM_REGISTER_GLOBAL("tvm.rpc.server.workpath")
+    .set_body([](TVMArgs args, TVMRetValue* rv) {
+        static RPCEnv env;
+        *rv = env.GetPath(args[0]);
+      });
+
+    TVM_REGISTER_GLOBAL("tvm.rpc.server.load_module")
+    .set_body([](TVMArgs args, TVMRetValue *rv) {
+        static RPCEnv env;
+        std::string file_name = env.GetPath(args[0]);
+        *rv = Load(&file_name, "");
+        LOG(INFO) << "Load module from " << file_name << " ...";
+      });
+  #else
+    LOG(FATAL) << "Only support RPC in linux environment";
+  #endif
+}
+/*!
+ * \brief GetPath To get the workpath from packed function
+ * \param name The file name
+ * \return The full path of file.
+ */
+std::string RPCEnv::GetPath(const std::string& file_name) {
 
 Review comment:
   in the case of when we will have to copy file_name anyway, it is better to 
make the argument
   
   ```std::string file_name``` (no reference), so sometimes the compiler can do 
a move or directly elide copy if we pass a std::string that is not being used 
else-where

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


With regards,
Apache Git Services

Reply via email to