Skip to content

Commit

Permalink
[Relay] Invoke tvm::build from relay compile_engine and interpreter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hlu1 authored and zhiics committed Jan 17, 2020
1 parent b171cf1 commit 3279957
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/relay/backend/compile_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,13 @@ class CompileEngineImpl : public CompileEngineNode {
CCacheValue value = LowerInternal(key);
if (value->packed_func != nullptr) return value->packed_func;
// build the function.
tvm::runtime::Module m;
if (const auto* f = runtime::Registry::Get("relay.backend.build")) {
tvm::runtime::Module m = (*f)(value->cached_func->funcs, key->target);
value->packed_func = m.GetFunction(value->cached_func->func_name);
m = (*f)(value->cached_func->funcs, key->target);
} else {
LOG(FATAL) << "relay.backend.build is not registered";
m = build(value->cached_func->funcs, key->target, Target(nullptr), BuildConfig::Current());
}
value->packed_func = m.GetFunction(value->cached_func->func_name);
return value->packed_func;
}

Expand Down
7 changes: 4 additions & 3 deletions src/relay/backend/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,14 @@ class Interpreter :
<< "Shape function output sizes mismatch";

PackedFunc shape_func;
Module m;
TVMRetValue rv;
if (const auto* f = runtime::Registry::Get("relay.backend.build")) {
tvm::runtime::Module m = (*f)(cfunc->funcs, cfunc->target);
shape_func = m.GetFunction(cfunc->func_name);
m = (*f)(cfunc->funcs, cfunc->target);
} else {
LOG(FATAL) << "relay.backend.build is not registered";
m = build(cfunc->funcs, cfunc->target, Target(nullptr), BuildConfig::Current());
}
shape_func = m.GetFunction(cfunc->func_name);
shape_func.CallPacked(TVMArgs(values.data(), codes.data(), arity), &rv);

// Get output shapes
Expand Down

0 comments on commit 3279957

Please sign in to comment.