web_runtime.cc 1.78 KB
Newer Older
1 2 3 4
/*!
 *  Copyright (c) 2017 by Contributors
 * \file web_runtime.cc
 */
5 6 7
#include <sys/stat.h>
#include <fstream>

8 9 10 11 12 13 14 15
#include "../src/runtime/c_runtime_api.cc"
#include "../src/runtime/cpu_device_api.cc"
#include "../src/runtime/workspace_pool.cc"
#include "../src/runtime/module_util.cc"
#include "../src/runtime/system_lib_module.cc"
#include "../src/runtime/module.cc"
#include "../src/runtime/registry.cc"
#include "../src/runtime/file_util.cc"
16 17 18 19
#include "../src/runtime/dso_module.cc"
#include "../src/runtime/rpc/rpc_session.cc"
#include "../src/runtime/rpc/rpc_event_impl.cc"
#include "../src/runtime/rpc/rpc_server_env.cc"
20
#include "../src/runtime/graph/graph_runtime.cc"
21 22
#include "../src/runtime/opengl/opengl_device_api.cc"
#include "../src/runtime/opengl/opengl_module.cc"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

namespace tvm {
namespace contrib {

struct RPCEnv {
 public:
  RPCEnv() {
    base_ = "/rpc";
    mkdir(&base_[0], 0777);
  }
  // Get Path.
  std::string GetPath(const std::string& file_name) {
    return base_ + "/" + file_name;
  }

 private:
  std::string base_;
};

42
TVM_REGISTER_GLOBAL("tvm.rpc.server.workpath")
43 44 45 46
.set_body([](TVMArgs args, TVMRetValue* rv) {
    static RPCEnv env;
    *rv = env.GetPath(args[0]);
  });
Tianqi Chen committed
47

48
TVM_REGISTER_GLOBAL("tvm.rpc.server.load_module")
Tianqi Chen committed
49 50 51 52 53
.set_body([](TVMArgs args, TVMRetValue *rv) {
    std::string file_name = "/rpc/" + args[0].operator std::string();
    *rv = Module::LoadFromFile(file_name, "");
    LOG(INFO) << "Load module from " << file_name << " ...";
  });
54 55
}  // namespace contrib
}  // namespace tvm
56 57 58 59 60 61 62 63 64 65 66 67 68

// dummy parallel runtime
int TVMBackendParallelLaunch(
    FTVMParallelLambda flambda,
    void* cdata,
    int num_task) {
  TVMAPISetLastError("Parallel is not supported in Web runtime");
  return -1;
}

int TVMBackendParallelBarrier(int task_id, TVMParallelGroupEnv* penv) {
  return 0;
}