Skip to content

Commit

Permalink
[REFACTOR] Establish tir (#4740)
Browse files Browse the repository at this point in the history
TIR is the new namespace for low-level IR
for tensor-level optimizations and loop transformations.

This PR establishes the namespace and files.

- lowered_func.h,buffer.h,data_layout.h -> tir/buffer.h,tir/data_layout.h,tir/lowered_func.h
- ir.h -> tir/expr.h, tir/stmt.h
- ir_functor_ext.h -> tir/expr_functor.h, tir/stmt_functor.h
  • Loading branch information
tqchen committed Jan 19, 2020
1 parent 7e39201 commit cf59b20
Show file tree
Hide file tree
Showing 267 changed files with 4,515 additions and 4,324 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ file(GLOB_RECURSE COMPILER_SRCS
src/top/*.cc
src/api/*.cc
src/autotvm/*.cc
src/lang/*.cc
src/pass/*.cc
src/tir/*.cc
)

file(GLOB CODEGEN_SRCS
src/codegen/*.cc
src/codegen/*.cc
)

list(APPEND COMPILER_SRCS ${CODEGEN_SRCS})
Expand Down
3 changes: 2 additions & 1 deletion apps/extension/src/tvm_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
#include <tvm/runtime/registry.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/device_api.h>
#include <tvm/expr_operator.h>
#include <tvm/tir/op.h>

using namespace tvm;
using namespace tvm::tir;
using namespace tvm::runtime;

namespace tvm_ext {
Expand Down
4 changes: 2 additions & 2 deletions apps/lldb/tvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __lldb_init_module(debugger, _):
"tvm::IterVarAttr",
"tvm::IterVarRelation",
"tvm::Layout",
"tvm::LoweredFunc",
"tir::LoweredFunc",
"tvm::Map",
"tvm::Map",
"tvm::MemoryInfo",
Expand All @@ -60,7 +60,7 @@ def __lldb_init_module(debugger, _):
"tvm::TensorIntrin",
"tvm::TensorIntrinCall",
"tvm::TypedEnvFunc",
"tvm::Var",
"tvm::tir::Var",
"tvm::ir::CommReducer",
"tvm::ir::FunctionRef",
"tvm::relay::BaseTensorType",
Expand Down
2 changes: 2 additions & 0 deletions include/tvm/arith/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace arith {
// Forward declare Analyzer
class Analyzer;

using tir::Var;

/*!
* \brief Constant integer up and lower bound(inclusive).
* Useful for value bound analysis.
Expand Down
8 changes: 7 additions & 1 deletion include/tvm/arith/bound.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <tvm/node/container.h>
#include <tvm/ir/expr.h>
#include <tvm/arith/int_set.h>
#include <tvm/expr.h>
#include <tvm/tir/expr.h>
#include <tvm/tir/stmt.h>

#include <unordered_map>

Expand All @@ -37,6 +38,11 @@ class Tensor;
}
namespace arith {

using tir::Var;
using tir::VarNode;
using tir::Domain;
using tir::Stmt;

/*!
* \brief Deduce the bound of the target variable in a expression,
* give the domain of each variables. Return undefined IntSet to
Expand Down
8 changes: 6 additions & 2 deletions include/tvm/arith/int_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
#define TVM_ARITH_INT_SET_H_

#include <tvm/ir/expr.h>
#include <tvm/expr.h>
#include <tvm/tir/expr.h>
#include <unordered_map>

namespace tvm {
namespace arith {

using tir::Var;
using tir::VarNode;
using tir::IterVar;

//-----------------------------------------------
// Integer set data structure.
//
Expand Down Expand Up @@ -165,7 +169,7 @@ IntSet EvalSet(PrimExpr e,
* \return An integer set that can cover all the possible values of e.
*/
IntSet EvalSet(PrimExpr e,
const std::unordered_map<const VarNode*, IntSet>& dom_map);
const std::unordered_map<const tir::VarNode*, IntSet>& dom_map);

/*!
* \brief Find an symbolic integer set that contains is union over
Expand Down
6 changes: 3 additions & 3 deletions include/tvm/arith/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <tvm/node/container.h>
#include <tvm/ir/expr.h>
#include <tvm/expr.h>
#include <tvm/tir/expr.h>

namespace tvm {
namespace arith {
Expand All @@ -39,7 +39,7 @@ namespace arith {
* \return [coeff[i]] if it is possible, empty array if it is not.
*/
Array<PrimExpr> DetectLinearEquation(const PrimExpr& e,
const Array<Var>& vars);
const Array<tir::Var>& vars);

/*!
* \brief Detect if expression corresponds to clip bound of the vars
Expand All @@ -50,7 +50,7 @@ Array<PrimExpr> DetectLinearEquation(const PrimExpr& e,
* return empty if the e does not match the pattern.
*/
Array<PrimExpr> DetectClipBound(const PrimExpr& e,
const Array<Var>& vars);
const Array<tir::Var>& vars);

} // namespace arith
} // namespace tvm
Expand Down
32 changes: 16 additions & 16 deletions include/tvm/build_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@
#ifndef TVM_BUILD_MODULE_H_
#define TVM_BUILD_MODULE_H_

#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>
#include <tvm/support/with.h>
#include <tvm/top/schedule_pass.h>
#include <tvm/tir/lowered_func.h>

#include <string>
#include <vector>
#include <utility>
#include <unordered_map>
#include <unordered_set>

#include "runtime/packed_func.h"

#include "lowered_func.h"

namespace tvm {

/*!
Expand Down Expand Up @@ -174,11 +172,12 @@ class BuildConfig : public ::tvm::ObjectRef {
* \param config The build configuration.
* \return The lowered function.
*/
TVM_DLL Array<LoweredFunc> lower(top::Schedule sch,
const Array<top::Tensor>& args,
const std::string& name,
const std::unordered_map<top::Tensor, Buffer>& binds,
const BuildConfig& config);
TVM_DLL Array<tir::LoweredFunc> lower(
top::Schedule sch,
const Array<top::Tensor>& args,
const std::string& name,
const std::unordered_map<top::Tensor, tir::Buffer>& binds,
const BuildConfig& config);
/*!
* \brief Split host/device function and running necessary pass before build
* \param funcs The functions to be built.
Expand All @@ -188,10 +187,11 @@ TVM_DLL Array<LoweredFunc> lower(top::Schedule sch,
* \return The Array<Array<LoweredFunc>> with 2 elements. First is host function Array,
second is device function array
*/
TVM_DLL Array<Array<LoweredFunc> > split_dev_host_funcs(const Array<LoweredFunc>& funcs,
const Target& target,
const Target& target_host,
const BuildConfig& config);
TVM_DLL Array<Array<tir::LoweredFunc> > split_dev_host_funcs(
const Array<tir::LoweredFunc>& funcs,
const Target& target,
const Target& target_host,
const BuildConfig& config);

/*!
* \brief Build a device and host module for a specific target from an array of lowered functions.
Expand All @@ -201,7 +201,7 @@ TVM_DLL Array<Array<LoweredFunc> > split_dev_host_funcs(const Array<LoweredFunc>
* \param config The build configuration.
* \return The built module.
*/
TVM_DLL runtime::Module build(const Array<LoweredFunc>& funcs,
TVM_DLL runtime::Module build(const Array<tir::LoweredFunc>& funcs,
const Target& target,
const Target& target_host,
const BuildConfig& config);
Expand All @@ -216,7 +216,7 @@ TVM_DLL runtime::Module build(const Array<LoweredFunc>& funcs,
* \param config The build configuration.
* \return The built module that contains code for different processors.
*/
TVM_DLL runtime::Module build(const Map<Target, Array<LoweredFunc>>& input,
TVM_DLL runtime::Module build(const Map<Target, Array<tir::LoweredFunc>>& input,
const Target& target_host,
const BuildConfig& config);

Expand All @@ -231,7 +231,7 @@ TVM_DLL runtime::Module build(const Map<Target, Array<LoweredFunc>>& input,
* \param config The build configuration.
* \return The built module that contains code for different processors.
*/
TVM_DLL runtime::Module build(const Map<std::string, Array<LoweredFunc>>& input,
TVM_DLL runtime::Module build(const Map<std::string, Array<tir::LoweredFunc>>& input,
const Target& target_host,
const BuildConfig& config);

Expand Down
9 changes: 5 additions & 4 deletions include/tvm/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
#ifndef TVM_CODEGEN_H_
#define TVM_CODEGEN_H_

#include <tvm/runtime/packed_func.h>
#include <tvm/tir/expr.h>
#include <tvm/tir/lowered_func.h>
#include <string>
#include "expr.h"
#include "lowered_func.h"
#include "runtime/packed_func.h"


namespace tvm {
/*! \brief namespace for lowlevel IR pass and codegen */
Expand All @@ -45,7 +46,7 @@ using runtime::TVMRetValue;
*
* \note Calls global API function "_codegen_build_" + target
*/
runtime::Module Build(const Array<LoweredFunc>& funcs,
runtime::Module Build(const Array<tir::LoweredFunc>& funcs,
const std::string& target);
/*!
* \brief Pack imported device library to a C file.
Expand Down
Loading

0 comments on commit cf59b20

Please sign in to comment.