Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4k
Improve IntervalSet's floormod#5367
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
dafa2c340b767571f89984a8e173d043488ca883d5a8cd3c9e31ec5dda901cfc948f0384951aa3d12c266b5fb18File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -231,20 +231,22 @@ void ComputeOpNode::PropBoundToInputs( | ||
| // undefined behaviour), so we can intersect the estimated set of the argument with the | ||
| // range expected by the tensor. However, intersection may result in overly complex | ||
| // expressions, so we perform a more relaxed form of intersection. | ||
| IntSet arg_intset = EvalSet(call->args[i], dom_map); | ||
| IntSet arg_intset = analyzer->int_set(call->args[i], ConvertDomMap(dom_map)); | ||
| const arith::IntervalSetNode* arg_interval = arg_intset.as<arith::IntervalSetNode>(); | ||
| if (arg_interval) { | ||
| PrimExpr shape_i_min_value = make_zero(t->shape[i].dtype()); | ||
| PrimExpr shape_i_max_value = t->shape[i] - 1; | ||
| PrimExpr min_value = arg_interval->min_value; | ||
| PrimExpr max_value = arg_interval->max_value; | ||
| // Prefer the shape bounds only when we can prove they are tighter. | ||
| if (arith::is_neg_inf(min_value) || | ||
| analyzer->CanProve(shape_i_min_value >= min_value)) { | ||
| // We must update bound's ends in pairs. Here is an counter example: shape_i is | ||
| // [0, 0] and arg_interval is [threadIdx.y, threadIdx.y], where threadIdx.y's range is | ||
| // [0, 7]. If we allowed updating one end, the bound would become [threadIdx.y, 0], | ||
| // awkward for further analysis. | ||
| if ((arith::is_pos_inf(max_value) && arith::is_neg_inf(min_value)) || | ||
| (analyzer->CanProve(shape_i_min_value >= min_value) && | ||
| analyzer->CanProve(shape_i_max_value <= max_value))) { | ||
yongfeng-nv marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| min_value = shape_i_min_value; | ||
| } | ||
| if (arith::is_pos_inf(max_value) || | ||
| analyzer->CanProve(shape_i_max_value <= max_value)) { | ||
| max_value = shape_i_max_value; | ||
| } | ||
| dom.data[i].push_back(IntSet::interval(min_value, max_value)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -138,7 +138,7 @@ void InferRootBound(const Stage& stage, | ||
| Array<IterVar> stage_attach = ctx.attach_path.at(stage->op); | ||
| // The parent set. | ||
| for (const Operation& op : consumers) { | ||
| std::unordered_map<const VarNode*, IntSet> relax_set; | ||
| Map<Var, IntSet> relax_set; | ||
| std::unordered_map<IterVar, IntSet> up_state; | ||
| bool found_attach = false; | ||
| CHECK(ctx.op2stage_.count(op.get())); | ||
| @@ -177,9 +177,9 @@ void InferRootBound(const Stage& stage, | ||
| << "InferBound requires every leaf iter var's min equals 0, " | ||
| << "call schedule.normalize to achieve this."; | ||
| if (NeedRelax(iv, found_attach, ctx.bind_map, scope)) { | ||
| relax_set[iv->var.get()] = IntSet::range(vrange); | ||
| relax_set.Set(iv->var, IntSet::range(vrange)); | ||
| if (ctx.bind_map.count(iv)) { | ||
| relax_set[ctx.bind_map.at(iv)->var.get()] = IntSet::range(vrange); | ||
| relax_set.Set(ctx.bind_map.at(iv)->var, IntSet::range(vrange)); | ||
| } | ||
| } | ||
| } | ||
| @@ -191,6 +191,9 @@ void InferRootBound(const Stage& stage, | ||
| // Relax if needed. | ||
| std::unordered_map<const VarNode*, IntSet> dom_map; | ||
| arith::Analyzer analyzer; | ||
| for (auto entry : *rmap) { | ||
| analyzer.Bind(entry.first->var, entry.second); | ||
| } | ||
| for (auto iv : op->root_iter_vars()) { | ||
| Range r; | ||
| if (up_state.count(iv)) { | ||
| @@ -199,11 +202,13 @@ void InferRootBound(const Stage& stage, | ||
| r = iv->dom; | ||
| } | ||
| if (relax_set.size() != 0) { | ||
| dom_map[iv->var.get()] = EvalSet(r, relax_set); | ||
| dom_map[iv->var.get()] = IntSet::interval( | ||
| analyzer.int_set(r->min, relax_set).min(), | ||
| analyzer.int_set(r->min + r->extent - 1, relax_set).max()); | ||
| } else { | ||
| dom_map[iv->var.get()] = IntSet::range(r); | ||
| } | ||
| analyzer.Bind(iv->var, r); | ||
| analyzer.Bind(iv->var, r, true); | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous Bind call binds root IterVars. We have to override them here. Is there a easy way to tell an IterVar root IterVar? If so, we can avoid such binding/overriding. | ||
| } | ||
| op->PropBoundToInputs(op, &analyzer, dom_map, &tmap); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.