forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[BugFix] Fix offset caching in lowering #38
Merged
MasterJH5574
merged 4 commits into
yzh119:sparse
from
MasterJH5574:bugfix/2021-12-22-fix-sparse-buffer-context-offsets
Dec 22, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,10 +322,6 @@ class SparseBufferCtx { | |
matches_.emplace_back(axis->name == sp_iter_var->axis->name); | ||
} | ||
} | ||
|
||
// update offset | ||
PrimExpr new_offset = AggregateOffset(offsets_.back(), axis, std::move(coordinate), ana_); | ||
offsets_.emplace_back(std::move(new_offset)); | ||
} | ||
|
||
/*! \brief get the axis given dimension index of current buffer. */ | ||
|
@@ -341,7 +337,7 @@ class SparseBufferCtx { | |
AggregateOffset(add(offsets_[dim], 1), axis, Integer(0), ana_)}; | ||
} | ||
|
||
private: | ||
public: | ||
String buf_name_; | ||
Array<Axis> axes_; | ||
std::vector<PrimExpr> offsets_; | ||
|
@@ -375,7 +371,12 @@ class SparseBufferCtx { | |
top()->Register(dim, std::move(coordinate), std::move(orig_idx)); | ||
} | ||
|
||
private: | ||
void AddOffset(int dim, PrimExpr offset) { | ||
ICHECK_EQ(dim + 1, static_cast<int>(top()->offsets_.size())); | ||
top()->offsets_.push_back(offset); | ||
} | ||
|
||
public: | ||
std::vector<Scope> stack_; | ||
arith::Analyzer* ana_; | ||
|
||
|
@@ -421,18 +422,22 @@ class IndexTransformer : public StmtExprMutator { | |
auto sf_axis = axis.as<SparseFixedAxisNode>(); | ||
PrimExpr l, r; | ||
std::tie(l, r) = sp_buf_ctx_.GetIndicesRange(dim); | ||
offset = lower_bound(sf_axis->indices->data, coordinate, l, r); | ||
offset = lower_bound(sf_axis->indices->data, coordinate, l, r) - l; | ||
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. Thanks for the fix! |
||
break; | ||
} | ||
case AxisKind::kSparseVariable: | ||
auto sv_axis = axis.as<SparseVariableAxisNode>(); | ||
PrimExpr l, r; | ||
std::tie(l, r) = sp_buf_ctx_.GetIndicesRange(dim); | ||
offset = lower_bound(sv_axis->indices->data, coordinate, l, r); | ||
offset = lower_bound(sv_axis->indices->data, coordinate, l, r) - l; | ||
break; | ||
} | ||
} | ||
|
||
// update offset | ||
PrimExpr new_offset = AggregateOffset(sp_buf_ctx_.top()->offsets_.back(), axis, | ||
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. Why don't we expose a function to manipulate the offset? |
||
offset, sp_buf_ctx_.ana_); | ||
sp_buf_ctx_.top()->offsets_.push_back(std::move(new_offset)); | ||
return offset; | ||
} | ||
|
||
|
@@ -562,7 +567,8 @@ class IndexTransformer : public StmtExprMutator { | |
Axis axis = sp_it_var->axis; | ||
auto parent = axis->GetParentAxis(); | ||
bool create_new_blk = false; | ||
bool is_fixed_axis = axis->kind() == AxisKind::kDenseFixed || axis->kind() == AxisKind::kSparseFixed; | ||
bool is_fixed_axis = | ||
axis->kind() == AxisKind::kDenseFixed || axis->kind() == AxisKind::kSparseFixed; | ||
if (!is_fixed_axis && parent.defined()) { | ||
const AxisNode* parent_node = parent.value().get(); | ||
if (in_block.find(parent_node) != in_block.end()) { | ||
|
@@ -572,7 +578,8 @@ class IndexTransformer : public StmtExprMutator { | |
/* parent node is in the previous blocks in the stack, no need to create new block. */ | ||
create_new_blk = false; | ||
} else { | ||
CHECK(false) << "The parent axis of " << axis->GetName() << " should appear before " << axis->GetName() << " when defining a sparse block."; | ||
CHECK(false) << "The parent axis of " << axis->GetName() << " should appear before " | ||
<< axis->GetName() << " when defining a sparse block."; | ||
} | ||
} | ||
if (create_new_blk) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make it public?