Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
cc7706e
Add stripped down version of expr.h and type.h
jroesch Aug 19, 2018
8b79ae0
Add InternTable data structure
jroesch Aug 19, 2018
e2b6a2f
Add placeholder defn of Operator
jroesch Aug 20, 2018
4d0a60d
Add initial port of environment.h
jroesch Aug 20, 2018
dd392be
Add expr_functor.h
jroesch Aug 20, 2018
336fe2b
Add initial version of type_functor.h
jroesch Aug 20, 2018
e31e945
Make type_functor.h a private header
jroesch Aug 20, 2018
425d5f2
Add ir.h
jroesch Aug 20, 2018
a429689
Add back Relay's logging.h
jroesch Aug 20, 2018
9033747
Add type checker header
jroesch Aug 20, 2018
bb1e501
Add alpha_eq
jroesch Aug 21, 2018
4a84f25
Add incomplete_type.h
jroesch Aug 21, 2018
2a2131c
Add type call
jroesch Aug 21, 2018
9e7b18a
Add test for let with IR builder
jroesch Aug 21, 2018
133b1dc
Add initial version of unifier and old tests
jroesch Aug 21, 2018
bc9754f
Update type_functor.h for incomplete type.
jroesch Aug 21, 2018
d9d1131
Add Python side of unifier
jroesch Aug 21, 2018
860d7e6
Add to incomplete_type and add impl in typechecker.cc
jroesch Aug 21, 2018
32bb3c2
Add type_visitor.h
jroesch Aug 21, 2018
e044e89
Add expr_visitor.h
jroesch Aug 21, 2018
0795d41
Start reparing unifier and tests
jroesch Aug 21, 2018
b6803b5
Fix test_unifier.py, now runs but all tests fail
jroesch Aug 21, 2018
fee67de
Remove tests for ommitted features and fix
jroesch Aug 22, 2018
4cdf3f9
Start refactoring type checker
jroesch Aug 22, 2018
a1027bf
Get a failing test for the type checker
jroesch Aug 22, 2018
fe6b31a
Iterate on first test case
jroesch Aug 22, 2018
02f6b1e
First simple test passes
jroesch Aug 22, 2018
7d2624a
Iterate towards second test
jroesch Aug 22, 2018
1ca8c4a
Remove placeholder op.h
jroesch Aug 22, 2018
2c6b521
[OP] Current op system
tqchen Aug 22, 2018
e197681
WIP
jroesch Aug 23, 2018
b2fa023
WIP
jroesch Aug 23, 2018
bf5e16d
Change over to new Node construction
jroesch Aug 24, 2018
b73e3c5
Basic tests working
jroesch Aug 24, 2018
e9f8bd5
Remove unifier from Python interface
jroesch Aug 24, 2018
920768f
[OP] Structral refactor
tqchen Aug 24, 2018
4cec4f1
Add type_subst back
jroesch Aug 24, 2018
b1ba347
Clean up code while refactoring inference
jroesch Aug 24, 2018
3a4ff26
Restore old TVM backend code
jroesch Aug 24, 2018
b91ffb5
Type checker is working for one op case
jroesch Aug 24, 2018
26755ec
op step 2
tqchen Aug 24, 2018
f8540ec
WIP
jroesch Aug 24, 2018
0325fa6
Address comments from Friday
jroesch Aug 27, 2018
7ad860f
Repair tests
jroesch Aug 27, 2018
5353663
Work on type relation
jroesch Aug 27, 2018
ac254c3
Fix find and replace bug
jroesch Aug 28, 2018
b79f63a
Add normalization for type relations
jroesch Aug 28, 2018
23e64bc
Iterating on Broadcast
jroesch Aug 28, 2018
918d081
Address CR feedback
jroesch Aug 28, 2018
5f9529f
Address more CR feedback
jroesch Aug 28, 2018
66f01ad
Add SourceMap and clean up environment.h
jroesch Aug 28, 2018
e0b9ed7
Reogranize a bit
jroesch Aug 28, 2018
b29e17a
Kill dead code in env.py
jroesch Aug 28, 2018
0449680
Fix commit mistake
jroesch Aug 28, 2018
f151ea9
Move type_infer into pass.py
jroesch Aug 28, 2018
78a8d64
Reorganize passes a bit
jroesch Aug 28, 2018
1dbf636
More cleaning
jroesch Aug 28, 2018
3445b9f
Remove dead code
jroesch Aug 29, 2018
d716e6c
Clean up code in Unifier
jroesch Aug 29, 2018
33ef935
Clean up environment.h
jroesch Aug 29, 2018
3c3d719
Fix up Python imports
jroesch Aug 29, 2018
c075bd3
Add first pass add broadcast inference
jroesch Aug 31, 2018
c080d7b
Add ability to build and check a global
jroesch Aug 31, 2018
124381f
Address first round of CR comments
jroesch Sep 1, 2018
8db9d57
Add skeleton for kind checker
jroesch Sep 1, 2018
cd32bb9
Tweak docs in pass.h
jroesch Sep 1, 2018
4feda67
Refactor kind_check.{h, cc}
jroesch Sep 1, 2018
4e747c2
Improve type checking, can check control-flow-y program.
jroesch Sep 3, 2018
f25865e
Rename TVM compiler to to_tvm.py
jroesch Sep 3, 2018
8941d41
Begin work on lowering Relay to TVM
jroesch Sep 4, 2018
fb21edb
WIP debugging
jroesch Sep 5, 2018
9fcd45d
Add another test case and do a little clean up
jroesch Sep 6, 2018
6323e39
Port docs from previous Relay version
jroesch Sep 6, 2018
9fac901
Update docs
jroesch Sep 7, 2018
d6ed957
Add skeleton for converting from NNVM models
jroesch Sep 7, 2018
f4a3358
Address more code review feedback
jroesch Sep 7, 2018
142d4e3
Fix cpplint
jroesch Sep 7, 2018
e0c6143
Fix pylint
jroesch Sep 7, 2018
356a810
Fix doc error
jroesch Sep 7, 2018
12dcc2c
Fix doc error again
jroesch Sep 7, 2018
2c4f54c
Fix signed/unsigned compare
jroesch Sep 7, 2018
91757a7
Kill a few more warnings
jroesch Sep 7, 2018
2d72cb5
Remove another size_t
jroesch Sep 7, 2018
0f48f49
Fix warning
jroesch Sep 7, 2018
98efaf9
Rewriting language reference to newest version of Relay.
jroesch Sep 9, 2018
ef2a229
Revert "Port docs from previous Relay version"
jroesch Sep 13, 2018
059727a
Rewrite type inferencer to use new relations
jroesch Sep 14, 2018
cd02ec7
Convert printing to logging
jroesch Sep 14, 2018
561e710
Remove Normalizer
jroesch Sep 14, 2018
b327d05
Address a bunch of CR feedback
jroesch Sep 14, 2018
032c040
Rename LocalVar to Var
jroesch Sep 14, 2018
1c0007b
Fix cpplint
jroesch Sep 14, 2018
c72d3a6
More clean up to type inference
jroesch Sep 14, 2018
4495bda
Remove error reporting and RTS code.
jroesch Sep 15, 2018
3f5e2c8
Add documentation for env.py
jroesch Sep 16, 2018
c908b7a
Clean up and docs
jroesch Sep 16, 2018
c03be26
Add docs to unifier.h
jroesch Sep 16, 2018
bc94272
resolve.h docs and clean up whitespace
jroesch Sep 16, 2018
255cf15
Clean up interface a little more
jroesch Sep 16, 2018
1e19248
Fix a few issues from clean up
jroesch Sep 16, 2018
1b625a6
Another few tweaks
jroesch Sep 16, 2018
6d386c8
Add SourceName::Get and serialization
jroesch Sep 16, 2018
303e512
Add serialization for op.cc
jroesch Sep 16, 2018
ac0bb19
Fix lint
jroesch Sep 16, 2018
0fae0de
mend
jroesch Sep 16, 2018
2c81356
Restore alpha_eq.cc and refactor type_relations to use EnvFunc.
jroesch Sep 17, 2018
5c0a84c
Rename ExprFVisitor to ExprMutator
jroesch Sep 17, 2018
bee3325
Remove compiler bits
jroesch Sep 17, 2018
0352410
Address CR feedback
jroesch Sep 17, 2018
19e4419
Refactor expr_visitor.h
jroesch Sep 17, 2018
dc73305
WIP trying to rearrange type_relation
jroesch Sep 17, 2018
63cdbd2
Fix crash
jroesch Sep 18, 2018
4e4ee00
Address more CR feedback
jroesch Sep 18, 2018
d100018
Restore AlphaEqual for Expr
jroesch Sep 18, 2018
bd45407
Fix linting
jroesch Sep 18, 2018
91c7b45
Fix doc issue
jroesch Sep 18, 2018
fb74e2c
Address majority of in-person feedback.
jroesch Sep 18, 2018
defa8e4
Remove alpha_eq tests
jroesch Sep 18, 2018
167d235
Style fix in expr.cc
jroesch Sep 18, 2018
a6b6038
Fix & style
jroesch Sep 19, 2018
41098c4
Fix more style issues
jroesch Sep 19, 2018
bee4234
Remove whitespace
jroesch Sep 19, 2018
7e86f56
Address final comments modulo type_infer.cc
jroesch Sep 19, 2018
8339eaf
Address CR and work on 2.7 support
jroesch Sep 19, 2018
a7b67ad
Move annotations to expr.pyi
jroesch Sep 19, 2018
a1734d7
Fix bug introduced by refactor
jroesch Sep 19, 2018
4976808
Python2 and Python3 tests pass locally
jroesch Sep 19, 2018
f074edd
Refactor type relation solver.
jroesch Sep 19, 2018
d7835fa
Fix PyLint
jroesch Sep 19, 2018
9281077
Fix PyLint
jroesch Sep 19, 2018
b1c8ecd
Repair tests
jroesch Sep 19, 2018
b5c5626
Add initial version of concat
jroesch Sep 19, 2018
388b275
Fix issue in type_relations.cc
jroesch Sep 19, 2018
81c9d6d
Fix PyLint ... again
jroesch Sep 19, 2018
4e0c7b8
Fix issue with test case
jroesch Sep 19, 2018
052d619
Fix & style
jroesch Sep 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ file(GLOB COMPILER_SRCS
src/schedule/*.cc
)

file(GLOB_RECURSE RELAY_SRCS
src/relay/*.cc
)
list(APPEND COMPILER_SRCS ${RELAY_SRCS})


if(NOT MSVC)
file(GLOB COMPILER_VERILOG_SRCS src/codegen/verilog/*.cc)
list(APPEND COMPILER_SRCS ${COMPILER_VERILOG_SRCS})
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# General information about the project.
project = u'tvm'
author = u'%s developers' % project
copyright = u'2017, %s' % author
copyright = u'2018, %s' % author
github_doc_root = 'https://github.com/tqchen/tvm/tree/master/docs/'

# add markdown parser
Expand Down
203 changes: 203 additions & 0 deletions include/tvm/relay/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*!
* Copyright (c) 2018 by Contributors
* \file tvm/relay/base.h
* \brief Base classes for the Relay IR.
*/
#ifndef TVM_RELAY_BASE_H_
#define TVM_RELAY_BASE_H_

#include <tvm/api_registry.h>
#include <tvm/ir.h>
#include <tvm/node.h>
#include <string>
#include <vector>

namespace tvm {
/*!
* \brief Relay: a high level functional IR for TVM.
*
* This namespace contains the abstract syntax tree, and other
* essential data structures for the Relay IR.
*
* You can find more about Relay by reading the language reference.
*/
namespace relay {
/*!
* \brief we always used NodeRef for referencing nodes.
*
* By default, NodeRef is a std::shared_ptr of node
*/
using NodeRef = tvm::NodeRef;

/*!
* \brief Content data type.
*/
using DataType = ::tvm::Type;

/*!
* \brief Symbolic expression for tensor shape.
*/
using ShapeExpr = ::tvm::Expr;

/*!
* \brief Hash function for nodes.
* e.g. std::unordered_map<Expr, Value, NodeHash, NodeEqual>
*/
using NodeHash = ::tvm::NodeHash;
/*!
* \brief Equality check function for nodes.
*/
using NodeEqual = ::tvm::NodeEqual;

/*!
* \brief Macro to make it easy to define node ref type given node
* \param TypeName The name of the reference type.
* \param NodeName The internal container name.
* \param NodeRefBase The base type.
*/
#define RELAY_DEFINE_NODE_REF(TypeName, NodeName, NodeRefBase) \
class TypeName : public NodeRefBase { \
public: \
TypeName() {} \
explicit TypeName(std::shared_ptr<::tvm::Node> n) : NodeRefBase(n) {} \
const NodeName* operator->() const { \
return static_cast<const NodeName*>(node_.get()); \
} \
operator bool() { return this->defined(); } \
using ContainerType = NodeName; \
};

/*!
* \brief The source name in the Span
* \sa SourceNameNode, Span
*/
class SourceName;
/*!
* \brief The name of a source fragment.
*/
class SourceNameNode : public Node {
public:
/*! \brief The source name. */
std::string name;
// override attr visitor
void VisitAttrs(AttrVisitor* v) final { v->Visit("name", &name); }

TVM_DLL static SourceName make(std::string name);

static constexpr const char* _type_key = "relay.SourceName";
TVM_DECLARE_NODE_TYPE_INFO(SourceNameNode, Node);
};

/*!
* \brief The source name of a file span.
* \sa SourceNameNode, Span
*/
class SourceName : public NodeRef {
public:
/*! \brief default constructor */
SourceName() {}

/*! \brief constructor from node pointer */
explicit SourceName(std::shared_ptr<Node> n) : NodeRef(n) {}
/*!
* \brief access the internal node container
* \return the pointer to the internal node container
*/
inline const SourceNameNode* operator->() const;

/*!
* \brief Get an SourceName for a given operator name.
* Will raise an error if the source name has not been registered.
* \param name Name of the operator.
* \return Reference to a SourceName valid throughout program lifetime.
*/
TVM_DLL static const SourceName& Get(const std::string& name);

/*! \brief specify container node */
using ContainerType = SourceNameNode;
};

/*!
* \brief Span information for debugging purposes
*/
class Span;
/*!
* \brief Stores locations in frontend source that generated a node.
*/
class SpanNode : public Node {
public:
/*! \brief The source name */
SourceName source;
/*! \brief Line number */
int lineno;
/*! \brief column offset */
int col_offset;
// override attr visitor
void VisitAttrs(AttrVisitor* v) final {
v->Visit("source", &source);
v->Visit("lineno", &lineno);
v->Visit("col_offset", &col_offset);
}

TVM_DLL static Span make(SourceName source, int lineno, int col_offset);

static constexpr const char* _type_key = "relay.Span";
TVM_DECLARE_NODE_TYPE_INFO(SpanNode, Node);
};

RELAY_DEFINE_NODE_REF(Span, SpanNode, NodeRef);

/*!
* \brief This is the base node container of all relay structures.
*/
class RelayNode : public Node {
public:
/*! \brief The location of the program in a SourceFragment can be null,
* check with span.defined() */
mutable Span span;

static constexpr const char* _type_key = "relay.Node";
TVM_DECLARE_BASE_NODE_INFO(RelayNode, Node);
};

/*!
* \brief Get a reference type from a Node ptr type
*
* It is always important to get a reference type
* if we want to return a value as reference or keep
* the node alive beyond the scope of the function.
*
* \param ptr The node pointer
* \tparam RefType The reference type
* \tparam NodeType The node type
* \return The corresponding RefType
*/
template <typename RefType, typename NodeType>
RefType GetRef(const NodeType* ptr) {
static_assert(std::is_same<typename RefType::ContainerType, NodeType>::value,
"Can only cast to the ref of same container type");
return RefType(const_cast<NodeType*>(ptr)->shared_from_this());
}

// TODO(@tqchen, @jroesch): can we move these semantics to HalideIR
template <typename T>
inline const T* As(const NodeRef& node) {
const Node* ptr = static_cast<const Node*>(node.get());
if (ptr && (ptr->is_type<T>() || ptr->derived_from<T>())) {
return static_cast<const T*>(ptr);
}
return nullptr;
}

template <typename SubRef, typename BaseRef>
SubRef Downcast(BaseRef ref) {
CHECK(ref->template is_type<typename SubRef::ContainerType>())
<< "Downcast from " << ref->type_key() << " to "
<< SubRef::ContainerType::_type_key << " failed.";
return SubRef(ref.node_);
}

} // namespace relay
} // namespace tvm

#endif // TVM_RELAY_BASE_H_
121 changes: 121 additions & 0 deletions include/tvm/relay/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*!
* Copyright (c) 2018 by Contributors
* \file tvm/relay/environment.h
* \brief The global environment: contains information needed to
* compile & optimize Relay programs.
*/
#ifndef TVM_RELAY_ENVIRONMENT_H_
#define TVM_RELAY_ENVIRONMENT_H_

#include <tvm/relay/error.h>
#include <tvm/relay/expr.h>
#include <tvm/relay/op.h>
#include <tvm/relay/type.h>
#include <string>
#include <vector>

namespace tvm {
namespace relay {

struct Environment;

/*! \brief The global environment of Relay programs.
*
* The global environment contains the global
* information needed to compile a Relay program.
*
* It contains all global functions, and configuration
* options.
*
* Many operations require access to the global
* Environment. We pass the Environment by value
* in a functional style as an explicit argument,
* but we mutate the Environment while optimizing
* Relay programs.
*
* The functional style allows users to construct custom
* environments easily, for example each thread can store
* an Environment while auto-tuning.
* */

class EnvironmentNode : public RelayNode {
public:
/*! \brief A map from ids to all global functions. */
tvm::Map<GlobalVar, Function> functions;

EnvironmentNode() {}

void VisitAttrs(tvm::AttrVisitor* v) final {
v->Visit("functions", &functions);
v->Visit("global_map_", &global_map_);
}

TVM_DLL static Environment make(tvm::Map<GlobalVar, Function> global_funcs);

/*! \brief Add a function to the global environment.
* \param var The name of the global function.
* \param func The function.
* \param update Controls whether you can replace a definition in the
* environment.
*/
void Add(const GlobalVar& var, const Function& func, bool update = false);

/*! \brief Update a function in the global environment.
* \param var The name of the global function to update.
* \param func The new function.
*/
void Update(const GlobalVar& var, const Function& func);

/*! \brief Remove a function from the global environment.
* \param var The name of the global function to update.
*/
void Remove(const GlobalVar& var);

/*! \brief Lookup a global function by its variable.
* \param str The unique string specifying the global variable.
* \returns The global variable.
*/
GlobalVar GetGlobalVar(const std::string& str);

/*! \brief Lookup a global function by its variable.
* \param var The global var to lookup.
* \returns The function named by the variable argument.
*/
Function Lookup(const GlobalVar& var);

/*! \brief Lookup a global function by its string name
* \param name The name of the function.
* \returns The function named by the argument.
*/
Function Lookup(const std::string& name);

/*! \brief Combine with another Environment.
* \param other The other environment.
*/
void Merge(const Environment& other);

static constexpr const char* _type_key = "relay.Environment";
TVM_DECLARE_NODE_TYPE_INFO(EnvironmentNode, Node);

private:
/*! \brief A map from string names to global variables that
* ensures global uniqueness.
*/
tvm::Map<std::string, GlobalVar> global_map_;
};

struct Environment : public NodeRef {
Environment() {}
explicit Environment(std::shared_ptr<tvm::Node> p) : NodeRef(p) {}

inline EnvironmentNode* operator->() const {
return static_cast<EnvironmentNode*>(node_.get());
}

using ContainerType = EnvironmentNode;
};

} // namespace relay
} // namespace tvm

#endif // TVM_RELAY_ENVIRONMENT_H_
36 changes: 36 additions & 0 deletions include/tvm/relay/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* Copyright (c) 2018 by Contributors
* \file error.h
* \brief The set of errors raised by Relay.
*/
#ifndef TVM_RELAY_ERROR_H_
#define TVM_RELAY_ERROR_H_

#include <string>
#include "./base.h"

namespace tvm {
namespace relay {

struct Error : dmlc::Error {
explicit Error(const std::string &msg) : dmlc::Error(msg) {}
};

struct InternalError : Error {
explicit InternalError(const std::string &msg) : Error(msg) {}
};

// TODO(@jroesch): we should change spanned errors to report
// errors against the Environment, inverting control to error definition.
struct FatalTypeError : dmlc::Error {
explicit FatalTypeError(const std::string &s) : dmlc::Error(s) {}
};

struct TypecheckerError : public dmlc::Error {
explicit TypecheckerError(const std::string &msg) : Error(msg) {}
};

} // namespace relay
} // namespace tvm

#endif // TVM_RELAY_ERROR_H_
Loading