Skip to content

Commit

Permalink
[Relay][VM] Allow to config allocator type and refactor vm code struc…
Browse files Browse the repository at this point in the history
…ture (apache#6105)

* [Relay][VM] Allow to config allocator type and refactor vm code structure

* fix doc

* fix

* update

* trigger ci

* trigger ci

* trigger ci

* trigger ci

* fix doc warning
  • Loading branch information
icemelon authored and Trevor Morris committed Aug 26, 2020
1 parent 6d68dd6 commit 47f47a5
Show file tree
Hide file tree
Showing 37 changed files with 1,723 additions and 1,525 deletions.
11 changes: 8 additions & 3 deletions docs/dev/virtual_machine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ VM.
Currently, three types of objects, ``NDArray``, ``ADT``, and ``Closure`` objects, are used
to represent tensor, tuple/list, and closure data, respectively. More details
for each of them can be found at `include/tvm/runtime/ndarray.h`_,
`include/tvm/runtime/vm.h`_, and `include/tvm/runtime/container.h`_, respectively.
`include/tvm/runtime/vm/vm.h`_, and `include/tvm/runtime/container.h`_, respectively.

.. _include/tvm/runtime/ndarray.h: https://github.com/apache/incubator-tvm/blob/master/include/tvm/runtime/ndarray.h

.. _include/tvm/runtime/vm.h: https://github.com/apache/incubator-tvm/blob/master/include/tvm/runtime/vm.h
.. _include/tvm/runtime/vm/vm.h: https://github.com/apache/incubator-tvm/blob/master/include/tvm/runtime/vm/vm.h

.. _include/tvm/runtime/container.h: https://github.com/apache/incubator-tvm/blob/master/include/tvm/runtime/container.h

Expand Down Expand Up @@ -321,7 +321,12 @@ VM Compiler

An important part of this infrastructure is a compiler from Relay's full IR into a sequence of bytecode.
The VM compiler transforms a ``tvm::relay::Module`` into a ``tvm::relay::vm::Executable``. The executable
contains a set of compiled functions, the compiled functions are contained in ``tvm::relay::vm::Function``. The functions contain metadata about the function as well as its compiled bytecode. The emitted executable object then can be loaded and run by a ``tvm::relay::vm::VirtualMachine`` object. For full definitions of the data structures, please see `include/tvm/runtime/vm.h`_.
contains a set of compiled functions, the compiled functions are contained in ``tvm::relay::vm::Function``.
The functions contain metadata about the function as well as its compiled bytecode. The emitted executable
object then can be loaded and run by a ``tvm::relay::vm::VirtualMachine`` object. For full definitions of the
data structures, please see `include/tvm/runtime/vm/executable.h`_ and `include/tvm/runtime/vm/vm.h`_.

.. _include/tvm/runtime/vm/executable.h: https://github.com/apache/incubator-tvm/blob/master/include/tvm/runtime/vm/executable.h

Optimizations
~~~~~~~~~~~~~
Expand Down
9 changes: 4 additions & 5 deletions include/tvm/relay/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <tvm/relay/expr.h>
#include <tvm/runtime/container.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/vm.h>
#include <tvm/target/target.h>

namespace tvm {
Expand Down Expand Up @@ -67,7 +66,7 @@ runtime::TypedPackedFunc<ObjectRef(Expr)> CreateInterpreter(IRModule mod, DLCont
Target target);

/*! \brief The container type of Closures used by the interpreter. */
class InterpreterClosureObj : public runtime::vm::ClosureObj {
class InterpreterClosureObj : public runtime::ClosureObj {
public:
/*! \brief The set of free variables in the closure.
*
Expand All @@ -89,13 +88,13 @@ class InterpreterClosureObj : public runtime::vm::ClosureObj {
}

static constexpr const char* _type_key = "interpreter.Closure";
TVM_DECLARE_FINAL_OBJECT_INFO(InterpreterClosureObj, runtime::vm::ClosureObj);
TVM_DECLARE_FINAL_OBJECT_INFO(InterpreterClosureObj, runtime::ClosureObj);
};

class InterpreterClosure : public runtime::vm::Closure {
class InterpreterClosure : public runtime::Closure {
public:
TVM_DLL InterpreterClosure(tvm::Map<Var, ObjectRef> env, Function func);
TVM_DEFINE_OBJECT_REF_METHODS(InterpreterClosure, runtime::vm::Closure, InterpreterClosureObj);
TVM_DEFINE_OBJECT_REF_METHODS(InterpreterClosure, runtime::Closure, InterpreterClosureObj);
};

/*! \brief The container type of RecClosure. */
Expand Down
17 changes: 17 additions & 0 deletions include/tvm/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,23 @@ struct PackedFuncValueConverter<Optional<T>> {
}
};

/*!
* \brief An object representing a closure. This object is used by both the
* Relay VM and interpreter.
*/
class ClosureObj : public Object {
public:
static constexpr const uint32_t _type_index = TypeIndex::kRuntimeClosure;
static constexpr const char* _type_key = "runtime.Closure";
TVM_DECLARE_BASE_OBJECT_INFO(ClosureObj, Object);
};

/*! \brief reference to closure. */
class Closure : public ObjectRef {
public:
TVM_DEFINE_OBJECT_REF_METHODS(Closure, ObjectRef, ClosureObj);
};

} // namespace runtime

// expose the functions to the root namespace.
Expand Down
Loading

0 comments on commit 47f47a5

Please sign in to comment.