Skip to content

Commit

Permalink
[RUNTIME] Minimum runtime module (apache#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed May 29, 2018
1 parent 343c19a commit d781a57
Show file tree
Hide file tree
Showing 7 changed files with 612 additions and 29 deletions.
4 changes: 3 additions & 1 deletion nnvm/deploy/nnvm_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* All in one runtime
* \file nnvm_runtime.cc
*/
/*
#include "../src/core/graph.cc"
#include "../src/core/node.cc"
#include "../src/core/pass.cc"
#include "../src/core/op.cc"
#include "../src/pass/saveload_json.cc"
#include "../src/runtime/graph_executor.cc"
#include "../src/runtime/graph_executor.cc"*/
#include "../src/runtime/graph_runtime.cc"
3 changes: 2 additions & 1 deletion nnvm/src/compiler/graph_fuse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ nnvm::Graph GraphFuseCompile(nnvm::Graph g) {
for (uint32_t nid = 0; nid < idx.num_nodes(); ++nid) {
const auto& inode = idx[nid];
if (inode.source->is_variable()) {
// only copy over name since that is sufficient.
nnvm::NodePtr np = nnvm::Node::Create();
np->attrs = inode.source->attrs;
np->attrs.name = inode.source->attrs.name;
old_new[nid] = np;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion nnvm/src/compiler/graph_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ size_t GraphHash(const Graph& graph) {
for (uint32_t nid = 0; nid < idx.num_nodes(); ++nid) {
const IndexedGraph::Node& inode = idx[nid];
// Use name instad op address so it is deterministic across runs
key = dmlc::HashCombine(key, inode.source->op()p);
if (inode.source->is_variable()) continue;
key = dmlc::HashCombine(key, inode.source->op()->name);
hash_temp.clear();
for (const auto& kv : GetAttrDict(inode.source->attrs)) {
hash_temp.push_back(dmlc::HashCombine(str_hash(kv.first), kv.second));
Expand Down
5 changes: 2 additions & 3 deletions nnvm/src/runtime/graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ inline void TVMOpParamParser(nnvm::NodeAttrs* attrs) {
attrs->parsed = std::move(param);
}

DMLC_REGISTER_PARAMETER(TVMOpParam);

NNVM_REGISTER_OP(tvm_op)
.set_attr_parser(TVMOpParamParser)
Expand Down Expand Up @@ -328,12 +327,12 @@ tvm::runtime::Module RuntimeCreate(std::string sym_json,
return tvm::runtime::Module(exec);
}

TVM_REGISTER_GLOBAL("nnvm.runtime.create")
TVM_REGISTER_GLOBAL("nnvm.runtime.createx")
.set_body([](TVMArgs args, TVMRetValue *rv) {
*rv = RuntimeCreate(args[0], args[1], args[2], args[3]);
});

TVM_REGISTER_GLOBAL("nnvm.runtime.remote_create")
TVM_REGISTER_GLOBAL("nnvm.runtime.remote_createx")
.set_body([](TVMArgs args, TVMRetValue *rv) {
void* mhandle = args[1];
*rv = RuntimeCreate(args[0],
Expand Down
24 changes: 1 addition & 23 deletions nnvm/src/runtime/graph_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,11 @@
#include <nnvm/pass.h>
#include <vector>
#include <string>
#include "./graph_runtime.h"

namespace nnvm {
namespace runtime {

/*! \brief Magic number for NDArray file */
constexpr uint64_t kTVMNDArrayMagic = 0xDD5E40F096B4A13F;
/*! \brief Magic number for NDArray list file */
constexpr uint64_t kTVMNDArrayListMagic = 0xF7E58D4F05049CB7;

/*! \brief DLPack compatible data types */
using DLTypeVector = std::vector<DLDataType>;

/*! \brief operator attributes about tvm op */
struct TVMOpParam : public dmlc::Parameter<TVMOpParam> {
std::string func_name;
uint32_t num_inputs;
uint32_t num_outputs;
bool flatten_data;

DMLC_DECLARE_PARAMETER(TVMOpParam) {
DMLC_DECLARE_FIELD(func_name);
DMLC_DECLARE_FIELD(num_inputs).set_default(1);
DMLC_DECLARE_FIELD(num_outputs).set_default(1);
DMLC_DECLARE_FIELD(flatten_data).set_default(false);
}
};

/*!
* \brief TVM Graph Executor.
* This is a minimum graph executor, embedded in TVM runtime
Expand Down
Loading

0 comments on commit d781a57

Please sign in to comment.