Skip to content

Commit

Permalink
[BugFix] Fix binary search & SpIterVar (apache#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJH5574 committed Nov 5, 2021
1 parent 42049a6 commit be3975a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions include/tvm/tir/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,30 @@ TVM_DLL PrimExpr round(PrimExpr x, Span span = Span());
*/
TVM_DLL PrimExpr nearbyint(PrimExpr x, Span span = Span());

/*!
* \brief Lower bound function for binary search
* \param arr The buffer variable of the array to be looked up in
* \param val The value to be looked up in the array
* \param l The left boundary of the look-up range (inclusive)
* \param r The right boundary of the look-up range (exclusive)
* \param span The location of this operation in the source
* \return The look-up result
*/
TVM_DLL PrimExpr lower_bound(tir::Var arr, PrimExpr val, PrimExpr l, PrimExpr r,
Span span = Span());

/*!
* \brief Upper bound function for binary search
* \param arr The buffer variable of the array to be looked up in
* \param val The value to be looked up in the array
* \param l The left boundary of the look-up range (inclusive)
* \param r The right boundary of the look-up range (exclusive)
* \param span The location of this operation in the source
* \return The look-up result
*/
TVM_DLL PrimExpr upper_bound(tir::Var arr, PrimExpr val, PrimExpr l, PrimExpr r,
Span span = Span());

/*!
* \brief Calculate trunc(x)
* \param x The input expression.
Expand Down
4 changes: 2 additions & 2 deletions src/tir/op/op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ PrimExpr nearbyint(PrimExpr x, Span span) {
TIR_REGISTER_PURE_UNARY_OP("tir.nearbyint");

// lower_bound
PrimExpr lower_bound(Var arr, PrimExpr val, PrimExpr l, PrimExpr r, Span span) {
PrimExpr lower_bound(tir::Var arr, PrimExpr val, PrimExpr l, PrimExpr r, Span span) {
return tir::Call({kDLInt, 32, 1}, builtin::tvm_lower_bound(), {arr, val, l, r}, span);
}

// upper_bound
PrimExpr upper_bound(Var arr, PrimExpr val, PrimExpr l, PrimExpr r, Span span) {
PrimExpr upper_bound(tir::Var arr, PrimExpr val, PrimExpr l, PrimExpr r, Span span) {
return tir::Call({kDLInt, 32, 1}, builtin::tvm_upper_bound(), {arr, val, l, r}, span);
}

Expand Down

0 comments on commit be3975a

Please sign in to comment.