op_util.h 2.71 KB
Newer Older
1 2
/*!
 *  Copyright (c) 2017 by Contributors
3 4
 * \file op_util.h
 * \brief Common utility used in operator construction.
5
 */
6 7
#ifndef TVM_OP_OP_UTIL_H_
#define TVM_OP_OP_UTIL_H_
8 9 10 11 12 13 14

#include <tvm/expr.h>
#include <tvm/schedule.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "../pass/ir_util.h"
15
#include "../pass/arg_binder.h"
16
#include "../schedule/message_passing.h"
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

namespace tvm {
namespace op {

using ir::MergeNest;

/*!
 * \brief Build loop nest for stage.
 *
 * \param stage The stage to create a loop nest.
 * \param dom_map The range of each iter var.
 * \param begin_iter_pos The beginning position of leaf_iter_vars to generate loop.
 * \param new_loop_var Whether create new loop variable.
 * \param skip_iter Whether skip certain iteration.
 * \param p_value_map The result value of each IterVar.
32
 * \param debug_keep_trivial_loop Whether keep trivial loops with extent of 1
33 34 35 36 37 38 39
 */
std::vector<std::vector<Stmt> >
MakeLoopNest(const Stage& stage,
             const std::unordered_map<IterVar, Range>& dom_map,
             size_t begin_iter_pos,
             bool new_loop_var,
             const std::unordered_set<IterVar>& skip_iter,
40
             std::unordered_map<IterVar, Expr>* p_value_map,
41
             bool debug_keep_trivial_loop);
42

43 44 45 46 47 48 49
/*!
 * \brief Create a nest of if checking the predicates.
 *
 * \param predicates The predicates to be checked.
 * \return List of If nest that checks the predicates.
 */
std::vector<Stmt> MakeIfNest(const std::vector<Expr>& predicates);
50 51

/*!
52
 * \brief Replace the tensor reference (especially in Call's) in stmt by the replace map.
53 54 55 56 57 58
 * \param stmt The statement to be processed.
 * \param replace The replacement rule.
 */
Stmt ReplaceTensor(Stmt stmt,
                   const std::unordered_map<Tensor, Tensor>& replace);
/*!
59
 * \brief Replace the tensor reference (especially in Call's) in stmt by the replace map.
60 61 62 63 64 65
 * \param expr The expression to be processed.
 * \param replace The replacement rule.
 */
Expr ReplaceTensor(Expr expr,
                   const std::unordered_map<Tensor, Tensor>& replace);

66 67 68 69 70 71 72 73 74
/*!
 * \brief Substitute the variables of stmt by value map.
 * \param stmt the statment
 * \param value_map The value map.
 * \return Substituted result.
 */
Stmt Substitute(Stmt stmt,
                const std::unordered_map<IterVar, Expr>& value_map);

75 76 77 78 79 80 81 82 83 84 85 86
/*!
 * \brief Converts Halide ForType to its corresponding IterVarType
 * \param for_type The ForType to be converted
 */
IterVarType ForTypeToIterVarType(ir::ForType for_type);

/*!
 * \brief Converts IterVarType to its corresponding Halide ForType
 * \param iter_type The IterVarType to be converted
 */
ir::ForType IterVarTypeToForType(IterVarType iter_type);

87 88
}  // namespace op
}  // namespace tvm
89
#endif  // TVM_OP_OP_UTIL_H_