bound.h 3.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
/*!
 * \file tvm/arith/bound.h
 * \brief Bound deducers.
 */
#ifndef TVM_ARITH_BOUND_H_
#define TVM_ARITH_BOUND_H_

#include <tvm/node/container.h>
#include <tvm/ir/expr.h>
#include <tvm/arith/int_set.h>
29 30
#include <tvm/tir/expr.h>
#include <tvm/tir/stmt.h>
31 32 33 34 35

#include <unordered_map>

namespace tvm {
// forward delcare Tensor
36
namespace te {
37
class Tensor;
38
}
39 40
namespace arith {

41 42 43 44 45
using tir::Var;
using tir::VarNode;
using tir::Domain;
using tir::Stmt;

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
/*!
 * \brief Deduce the bound of the target variable in a expression,
 *  give the domain of each variables. Return undefined IntSet to
 *  represent failure.
 *
 * \note The returned set may be smaller than set that
 *       contains all possible values of v that satisfies the bound.
 *
 * \param v The target variable to be deduced.
 * \param cond The conditional expression.
 * \param hint_map The domain of variable, used to help deduce.
 * \param relax_map The domain of each variable, used to relax the domain,
 *        The deduce bound must implies e for all value in relax_map
 * \return An integer set that always satisfies the condition.
 */
IntSet DeduceBound(PrimExpr v, PrimExpr cond,
                   const Map<Var, IntSet>& hint_map,
                   const Map<Var, IntSet>& relax_map);
/*!
 * \brief Same as DeduceBound with  unordered_map signature.
 *
 * \param v The target variable to be deduced.
 * \param cond The conditional expression.
 * \param hint_map The domain of variable, used to help deduce.
 * \param relax_map The domain of each variable, used to relax the domain,
 *        The deduce bound mush implies e for all value in relax_map
 * \return An integer set that always satisfies the condition.
 */
IntSet DeduceBound(PrimExpr v, PrimExpr cond,
                   const std::unordered_map<const VarNode*, IntSet>& hint_map,
                   const std::unordered_map<const VarNode*, IntSet>& relax_map);

/*!
 * \brief Infer a regular domain that covers all the calls or provides within the given statement.
 * \param body The given statement.
81 82 83
 * \param buffer The buffer to check the access info.
 * \param consider_loads If loads are considered.
 * \param consider_stores If stores are considered.
84 85
 * \return The domain that covers all the calls or provides within the given statement.
 */
86 87 88 89
Domain DomainTouched(const Stmt& body,
                     const tir::Buffer& buffer,
                     bool consider_loads,
                     bool consider_stores);
90 91 92 93

}  // namespace arith
}  // namespace tvm
#endif  // TVM_ARITH_BOUND_H_