Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change fvisitor to mutator to match tvm name convention/type signature #3

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
8c72766
Add stripped down version of expr.h and type.h
jroesch Aug 19, 2018
ac1455d
Add InternTable data structure
jroesch Aug 19, 2018
4a285f8
Add placeholder defn of Operator
jroesch Aug 20, 2018
694e95b
Add initial port of environment.h
jroesch Aug 20, 2018
bd45443
Add expr_functor.h
jroesch Aug 20, 2018
bbb7b7e
Add initial version of type_functor.h
jroesch Aug 20, 2018
697ba97
Make type_functor.h a private header
jroesch Aug 20, 2018
a4c7df1
Add ir.h
jroesch Aug 20, 2018
f1b9e92
Add back Relay's logging.h
jroesch Aug 20, 2018
de80240
Add type checker header
jroesch Aug 20, 2018
ebc1bf2
Add alpha_eq
jroesch Aug 21, 2018
2d83e48
Add incomplete_type.h
jroesch Aug 21, 2018
ad068cd
Add type call
jroesch Aug 21, 2018
1ddfe12
Add test for let with IR builder
jroesch Aug 21, 2018
3ecbc2b
Add initial version of unifier and old tests
jroesch Aug 21, 2018
73d4570
Update type_functor.h for incomplete type.
jroesch Aug 21, 2018
7dc6a24
Add Python side of unifier
jroesch Aug 21, 2018
5ce60e6
Add to incomplete_type and add impl in typechecker.cc
jroesch Aug 21, 2018
ee218d0
Add type_visitor.h
jroesch Aug 21, 2018
c1e2047
Add expr_visitor.h
jroesch Aug 21, 2018
36d92c2
Start reparing unifier and tests
jroesch Aug 21, 2018
221d157
Fix test_unifier.py, now runs but all tests fail
jroesch Aug 21, 2018
ff49fdb
Remove tests for ommitted features and fix
jroesch Aug 22, 2018
44b3216
Start refactoring type checker
jroesch Aug 22, 2018
17a4ab3
Get a failing test for the type checker
jroesch Aug 22, 2018
66a80bd
Iterate on first test case
jroesch Aug 22, 2018
b5e655a
First simple test passes
jroesch Aug 22, 2018
9cdfb9a
Iterate towards second test
jroesch Aug 22, 2018
1cfc271
Remove placeholder op.h
jroesch Aug 22, 2018
491880e
[OP] Current op system
tqchen Aug 22, 2018
0e6cdcc
WIP
jroesch Aug 23, 2018
8520a30
WIP
jroesch Aug 23, 2018
cedf572
Change over to new Node construction
jroesch Aug 24, 2018
c32bbe7
Basic tests working
jroesch Aug 24, 2018
5d0242f
Remove unifier from Python interface
jroesch Aug 24, 2018
5b3573b
[OP] Structral refactor
tqchen Aug 24, 2018
aebf124
Add type_subst back
jroesch Aug 24, 2018
4bf8779
Clean up code while refactoring inference
jroesch Aug 24, 2018
05051d3
Restore old TVM backend code
jroesch Aug 24, 2018
d9d3642
Type checker is working for one op case
jroesch Aug 24, 2018
cd5c105
op step 2
tqchen Aug 24, 2018
22aa1ca
WIP
jroesch Aug 24, 2018
88dde8b
Address comments from Friday
jroesch Aug 27, 2018
4d6f6e3
Repair tests
jroesch Aug 27, 2018
0aedf89
Work on type relation
jroesch Aug 27, 2018
744dc95
Fix find and replace bug
jroesch Aug 28, 2018
d70e870
Add normalization for type relations
jroesch Aug 28, 2018
fd430ea
Iterating on Broadcast
jroesch Aug 28, 2018
3e0cb42
Address CR feedback
jroesch Aug 28, 2018
c0c8d57
Address more CR feedback
jroesch Aug 28, 2018
7610941
Add SourceMap and clean up environment.h
jroesch Aug 28, 2018
0531b73
Reogranize a bit
jroesch Aug 28, 2018
aacf30b
Kill dead code in env.py
jroesch Aug 28, 2018
6cad866
Fix commit mistake
jroesch Aug 28, 2018
61f3534
Move type_infer into pass.py
jroesch Aug 28, 2018
37753b6
Reorganize passes a bit
jroesch Aug 28, 2018
5cd2bbe
More cleaning
jroesch Aug 28, 2018
828a62b
Remove dead code
jroesch Aug 29, 2018
c6bbb86
Clean up code in Unifier
jroesch Aug 29, 2018
408b51a
Clean up environment.h
jroesch Aug 29, 2018
eb61a11
Fix up Python imports
jroesch Aug 29, 2018
4dd336d
Add first pass add broadcast inference
jroesch Aug 31, 2018
f734521
Add ability to build and check a global
jroesch Aug 31, 2018
df5b4c6
Address first round of CR comments
jroesch Sep 1, 2018
b05842c
Add skeleton for kind checker
jroesch Sep 1, 2018
907c7df
Tweak docs in pass.h
jroesch Sep 1, 2018
e06c71f
Refactor kind_check.{h, cc}
jroesch Sep 1, 2018
f813d51
Improve type checking, can check control-flow-y program.
jroesch Sep 3, 2018
2a2dc3f
Rename TVM compiler to to_tvm.py
jroesch Sep 3, 2018
6b877cd
Begin work on lowering Relay to TVM
jroesch Sep 4, 2018
888914a
WIP debugging
jroesch Sep 5, 2018
be285d6
Add another test case and do a little clean up
jroesch Sep 6, 2018
d47f637
Port docs from previous Relay version
jroesch Sep 6, 2018
71dcd1e
Update docs
jroesch Sep 7, 2018
b75c223
Add skeleton for converting from NNVM models
jroesch Sep 7, 2018
92a8323
Address more code review feedback
jroesch Sep 7, 2018
998e10a
Fix cpplint
jroesch Sep 7, 2018
3a98c3d
Fix pylint
jroesch Sep 7, 2018
6ef6965
Fix doc error
jroesch Sep 7, 2018
a07c956
Fix doc error again
jroesch Sep 7, 2018
f6e51c6
Fix signed/unsigned compare
jroesch Sep 7, 2018
1e10ba2
Kill a few more warnings
jroesch Sep 7, 2018
ed1a84f
Remove another size_t
jroesch Sep 7, 2018
fe9c408
Fix warning
jroesch Sep 7, 2018
8a85b4f
Rewriting language reference to newest version of Relay.
jroesch Sep 9, 2018
d626dfd
Revert "Port docs from previous Relay version"
jroesch Sep 13, 2018
cde0854
change fvisitor to mutator to match tvm name convention/type signature
MarisaKirisame Sep 14, 2018
b77082f
do the same for typefvisitor
MarisaKirisame Sep 14, 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
1 change: 0 additions & 1 deletion include/tvm/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,5 @@ struct NodeFactoryReg {
*/
#define TVM_ADD_FILELINE "\n\nDefined in " __FILE__ ":L" TVM_STRINGIZE(__LINE__)


} // namespace tvm
#endif // TVM_BASE_H_
172 changes: 172 additions & 0 deletions include/tvm/relay/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*!
* 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>

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 contrainer 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 source name in the Span
*/
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);
};

RELAY_DEFINE_NODE_REF(SourceName, SourceNameNode, NodeRef);

/*!
* \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 debug information, 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());
}

/*!
* \brief Get PackedFunction from global registry and
* report error if it does not exist
* \param name The name of the function.
* \return The created PackedFunc.
*/
inline const PackedFunc& GetPackedFunc(const std::string& name) {
const PackedFunc* pf = tvm::runtime::Registry::Get(name);
CHECK(pf != nullptr) << "Cannot find function " << name << " in registry";
return *pf;
}

} // namespace relay
} // namespace tvm

#endif // TVM_RELAY_BASE_H_
108 changes: 108 additions & 0 deletions include/tvm/relay/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*!
* 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/source_map.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 will 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 {
private:
/*! \brief A map from string names to global variables ensures global
* uniqueness. */
tvm::Map<std::string, GlobalVar> global_map_;
/*! \brief A map from file names to source fragments. */
SourceMap source_map_;
/*! \brief A list of the errors reported during the current run. */
std::vector<SpannedError> errors_;

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

EnvironmentNode() {}

void VisitAttrs(tvm::AttrVisitor* v) final {}

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

void Add(const GlobalVar& var, const Function& func, bool update = false);
void Update(const GlobalVar& var, const Function& func);
void Remove(const GlobalVar& var);

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

/*! \brief Lookup a global function by its variable. */
Function Lookup(const GlobalVar& id);

/*! \brief Lookup a global function by its string name */
Function Lookup(const std::string& s);

// TODO(@jroesch, @tqchen): what are the semantics here
void Merge(const Environment& env);

/*! \brief Add a source fragment to the environment. */
SourceName AddSource(std::string file_name, std::string source);

using Transformer = runtime::TypedPackedFunc<
runtime::TypedPackedFunc<Function(const GlobalVar&, const Function&)>(const Environment&)>;

/*! \brief Apply a function over every function in the global environment. */
void Transform(Transformer tranformer);

void AddDiagnostic(SpannedError);
void DisplayErrors();

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

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_
42 changes: 42 additions & 0 deletions include/tvm/relay/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*!
* 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) {}
};

struct SpannedError {
std::string msg;
Span sp;
SpannedError(std::string msg, Span sp) : msg(msg), sp(sp) {}
};

// FIX, we should change spanned errors to have a method which allow them to
// report on 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