Skip to content

Commit

Permalink
[Relay][Runtime] Implementation of Relay VM (apache#2889)
Browse files Browse the repository at this point in the history
* Implement the virtual machine

Co-Authored-By: wweic <ipondering.weic@gmail.com>

* Fix rebase build issues

* Reorganize vm.py and fix allocator bug

* Remove compiler

* Remove tests

* Remove backend/vm/vm.cc too

* Fix docs

* Fix doc

* Fix doc

* Add vm docs

* Remove change to dead_code.cc

* Remove Relay logging

* Remove reduce

* Update include/tvm/runtime/vm.h

Co-Authored-By: jroesch <roeschinc@gmail.com>

* Reformat

* Update include/tvm/runtime/vm.h

Co-Authored-By: jroesch <roeschinc@gmail.com>

* Address feedback

* Update include/tvm/runtime/vm.h

Co-Authored-By: jroesch <roeschinc@gmail.com>

* Apply suggestions from code review

Co-Authored-By: jroesch <roeschinc@gmail.com>

* Fix a couple outstanding comments

* Last couple comments

* Update include/tvm/runtime/vm.h

Co-Authored-By: jroesch <roeschinc@gmail.com>

* Address code review feedback

* Fix final comment

* Address comments

* Error reporting and example

* add Const

* Explicitly delete copy assignment operator

* Fix rebase

* Pass 3rd arg to fusion
  • Loading branch information
jroesch authored and Wei Chen committed May 13, 2019
1 parent 1d16e83 commit b260969
Show file tree
Hide file tree
Showing 41 changed files with 1,627 additions and 170 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" O
tvm_option(USE_STACKVM_RUNTIME "Include stackvm into the runtime" OFF)
tvm_option(USE_GRAPH_RUNTIME "Build with tiny graph runtime" ON)
tvm_option(USE_GRAPH_RUNTIME_DEBUG "Build with tiny graph runtime debug mode" OFF)
tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
tvm_option(USE_SGX "Build with SGX" OFF)
tvm_option(USE_RTTI "Build with RTTI" ON)
tvm_option(USE_MSVC_MT "Build with MT" OFF)
Expand Down Expand Up @@ -141,7 +142,10 @@ file(GLOB TOPI_SRCS
)
file(GLOB_RECURSE HALIDEIR_SRCS 3rdparty/HalideIR/src/*.cpp)
list(APPEND COMPILER_SRCS ${HALIDEIR_SRCS})
file(GLOB RUNTIME_SRCS src/runtime/*.cc)
file(GLOB RUNTIME_SRCS
src/runtime/*.cc
src/runtime/vm/*.cc
)

# Package runtime rules
if(NOT USE_RTTI)
Expand Down Expand Up @@ -201,6 +205,13 @@ add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
add_library(tvm_topi SHARED ${TOPI_SRCS})
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS})

if(USE_RELAY_DEBUG)
message(STATUS "Building Relay in debug mode...")
set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG")
set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "NDEBUG")
endif(USE_RELAY_DEBUG)

if(NOT USE_SGX STREQUAL "OFF")
add_dependencies(tvm sgx_edl)
add_dependencies(tvm_runtime sgx_edl tvm_t)
Expand Down
4 changes: 4 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ set(USE_ANTLR OFF)

# Build TSIM for VTA
set(USE_VTA_TSIM OFF)

# Whether use Relay debug mode
set(USE_RELAY_DEBUG OFF)

51 changes: 0 additions & 51 deletions include/tvm/relay/logging.h

This file was deleted.

19 changes: 18 additions & 1 deletion include/tvm/relay/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ TVM_DLL bool AlphaEqual(const Expr& e1, const Expr& e2);
*/
TVM_DLL bool AlphaEqual(const Type& t1, const Type& t2);

/*! \brief Add abstraction over a function
*
* For example: `square` is transformed to
* `fun x -> square x`.
*
* See https://en.wikipedia.org/wiki/Lambda_calculus#%CE%B7-conversion
* for more details.
*
* \param e The original function.
* \param mod The module used for referencing global functions, can be
* None.
*
* \return the new function with abstraction
*/
TVM_DLL Expr EtaExpand(const Expr& e, const Module& mod);

/*! \brief Check that each Var is only bound once.
*
* For example, the expression `let x = 1 in let x = 2 in 3` bound x twice.
Expand Down Expand Up @@ -467,9 +483,10 @@ TVM_DLL Expr FoldConstant(const Expr& expr);
* \brief Fuse operations into expr into seperate functions.
* \param expr The expression.
* \param fuse_opt_level Optimization level.
* \param mod the module.
* \return The optimized expression.
*/
TVM_DLL Expr FuseOps(const Expr& expr, int fuse_opt_level);
TVM_DLL Expr FuseOps(const Expr& expr, int fuse_opt_level, const Module& mod);

/*!
* \brief Apply rewrite rules to rewrite the expr in post DFS order.
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef enum {
kStr = 11U,
kBytes = 12U,
kNDArrayContainer = 13U,
kObject = 14U,
// Extension codes for other frameworks to integrate TVM PackedFunc.
// To make sure each framework's id do not conflict, use first and
// last sections to mark ranges.
Expand All @@ -113,7 +114,6 @@ typedef enum {
// The following section of code is used for non-reserved types.
kExtReserveEnd = 64U,
kExtEnd = 128U,
kObject = 14U,
} TVMTypeCode;

/*!
Expand Down
6 changes: 4 additions & 2 deletions include/tvm/runtime/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,11 @@ class NDArray::Container {
DLContext ctx) {
dl_tensor.data = data;
shape_ = std::move(shape);
dl_tensor.shape = dmlc::BeginPtr(shape);
dl_tensor.ndim = static_cast<int>(shape.size());
dl_tensor.ndim = static_cast<int>(shape_.size());
dl_tensor.shape = dmlc::BeginPtr(shape_);
dl_tensor.dtype = dtype;
dl_tensor.strides = nullptr;
dl_tensor.byte_offset = 0;
dl_tensor.ctx = ctx;
}

Expand Down
Loading

0 comments on commit b260969

Please sign in to comment.