Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/relax/analysis/layout_transformation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* \brief Analyze the PrimFunc and suggest layout transformation on it's blocks and buffers based on
* the user provided layout transformations on it's outputs.
*/
#include <tvm/arith/analyzer.h>
#include <tvm/arith/iter_affine_map.h>
#include <tvm/relax/analysis.h>
#include <tvm/tir/analysis.h>
Expand Down Expand Up @@ -172,8 +173,8 @@ static bool AreIdenticalTransforms(const IndexMap& t0, const IndexMap& t1) {
// Create a new shape expression.
Array<PrimExpr> t1_initial_indices =
t1->initial_indices.Map([](tir::Var i) -> PrimExpr { return i; });
auto t0_output = t0->MapIndices(t1_initial_indices);
arith::Analyzer analyzer;
auto t0_output = t0->MapIndices(t1_initial_indices, &analyzer);
for (size_t i = 0; i < t0_output.size(); ++i) {
if (!analyzer.CanProveEqual(t0_output[i], t1->final_indices[i])) return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/relax/op/tensor/manipulate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ StructInfo InferStructInfoLayoutTransform(const Call& call, const BlockBuilder&
return TensorStructInfo(data_sinfo->dtype, /*ndim=*/index_map->final_indices.size());
}

Array<PrimExpr> output_shape = index_map->MapShape(shape_sinfo->values.value());
arith::Analyzer analyzer;
Array<PrimExpr> output_shape = index_map->MapShape(shape_sinfo->values.value(), &analyzer);
return TensorStructInfo(ShapeExpr(output_shape), data_sinfo->dtype);
}

Expand Down
12 changes: 8 additions & 4 deletions src/relax/transform/alter_op_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* identify PrimFuncs to be replaced. Marks the new PrimFuncs with kFrozenLayout attribute set to
* true.
*/
#include <tvm/arith/analyzer.h>
#include <tvm/ir/attrs.h>
#include <tvm/node/serialization.h>
#include <tvm/relax/analysis.h>
Expand Down Expand Up @@ -60,9 +61,9 @@ static IndexMap DeepCopyIndexMap(const IndexMap& index_map) {
bool IsTransformBijective(const Expr& expr, const IndexMap& transform) {
Array<PrimExpr> input_shape = GetShapeFromTensor(expr);
Array<Range> initial_ranges = ConstructRangeFromShape(input_shape);
auto [inverse, padding_predicate] = transform.NonSurjectiveInverse(initial_ranges);
(void)inverse; // to avoid unused variable warning;
arith::Analyzer analyzer;
auto [inverse, padding_predicate] = transform.NonSurjectiveInverse(initial_ranges, &analyzer);
(void)inverse; // to avoid unused variable warning;
if (!analyzer.CanProve(!padding_predicate)) return false;
return true;
}
Expand Down Expand Up @@ -169,7 +170,9 @@ class AlterOpImplMutator : public ExprMutator {
const TensorStructInfo& old_tensor_sinfo) {
Array<PrimExpr> old_shape = GetShapeFromTensorStructInfo(old_tensor_sinfo);
Array<Range> initial_ranges = ConstructRangeFromShape(old_shape);
auto [inverse_index_map, padding_predicate] = index_map.NonSurjectiveInverse(initial_ranges);
arith::Analyzer analyzer;
auto [inverse_index_map, padding_predicate] =
index_map.NonSurjectiveInverse(initial_ranges, &analyzer);
ICHECK(tir::is_zero(padding_predicate))
<< "Only bijective transformations on input/output buffers are supported, but found "
"padding predicate "
Expand Down Expand Up @@ -245,7 +248,8 @@ class AlterOpImplMutator : public ExprMutator {
/*! \brief Returns the TensorStructInfo after applying the \p transform on its shape */
StructInfo UpdateStructInfo(const TensorStructInfo& tensor_sinfo, const IndexMap& transform) {
auto shape = GetShapeFromTensorStructInfo(tensor_sinfo);
auto new_shape = transform->MapShape(shape);
arith::Analyzer analyzer;
auto new_shape = transform->MapShape(shape, &analyzer);
return TensorStructInfo(ShapeExpr(new_shape), tensor_sinfo->dtype);
}

Expand Down