web_runtime.cc 2.57 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * 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
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12 13 14 15 16 17 18 19
 * 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.
 */

20 21 22
/*!
 * \file web_runtime.cc
 */
23 24 25
#include <sys/stat.h>
#include <fstream>

26 27 28
#include "../src/runtime/c_runtime_api.cc"
#include "../src/runtime/cpu_device_api.cc"
#include "../src/runtime/workspace_pool.cc"
29 30
#include "../src/runtime/library_module.cc"
#include "../src/runtime/system_library.cc"
31
#include "../src/runtime/module.cc"
32
#include "../src/runtime/ndarray.cc"
33
#include "../src/runtime/object.cc"
34 35
#include "../src/runtime/registry.cc"
#include "../src/runtime/file_util.cc"
36
#include "../src/runtime/dso_library.cc"
37 38 39
#include "../src/runtime/rpc/rpc_session.cc"
#include "../src/runtime/rpc/rpc_event_impl.cc"
#include "../src/runtime/rpc/rpc_server_env.cc"
40
#include "../src/runtime/graph/graph_runtime.cc"
41 42
#include "../src/runtime/opengl/opengl_device_api.cc"
#include "../src/runtime/opengl/opengl_module.cc"
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

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_;
};

62
TVM_REGISTER_GLOBAL("tvm.rpc.server.workpath")
63
.set_body_typed([](std::string path) {
64
    static RPCEnv env;
65
    return env.GetPath(path);
66
  });
Tianqi Chen committed
67

68
TVM_REGISTER_GLOBAL("tvm.rpc.server.load_module")
69
.set_body_typed([](std::string path) {
70
    std::string file_name = "/rpc/" + path;
Tianqi Chen committed
71
    LOG(INFO) << "Load module from " << file_name << " ...";
72
    return Module::LoadFromFile(file_name, "");
Tianqi Chen committed
73
  });
74 75
}  // namespace contrib
}  // namespace tvm
76 77 78 79 80 81 82 83 84 85 86 87 88

// 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;
}