Commit a76851d7 by Tianqi Chen Committed by GitHub

[BUFFER] Smarter slice to detect compactness (#587)

* [BUFFER] Smarter slice to detect compactness

* move simplify of begins early
parent 5f79521b
......@@ -20,6 +20,13 @@ Array<Expr> GetStrides(Array<Expr> shape) {
return Array<Expr>(vec.rbegin(), vec.rend());
}
Array<Expr> SimplifyArray(Array<Expr> array) {
for (size_t i = 0; i < array.size(); ++i) {
array.Set(i, ir::Simplify(array[i]));
}
return array;
}
Buffer decl_buffer(Array<Expr> shape,
Type dtype,
std::string name) {
......@@ -302,6 +309,7 @@ Buffer Buffer::MakeStrideView() const {
Buffer Buffer::MakeSlice(Array<Expr> begins, Array<Expr> extents) const {
const BufferNode* n = operator->();
begins = SimplifyArray(begins);
Expr elem_offset = ir::Simplify(ElemOffset(n, begins));
Array<Expr> strides = n->strides;
if (strides.size() == 0) {
......
......@@ -321,7 +321,8 @@ class StorageFlattener : public IRMutator {
Buffer slice = be.buffer.MakeSlice(begins, extents);
if (buffer->strides.size() == 0) {
CHECK_EQ(slice->strides.size(), 0U)
<< "Trying to bind compact buffer to strided one";
<< "Trying to bind compact buffer to strided one strides="
<< slice->strides;
} else {
slice = slice.MakeStrideView();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment