-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][flow] Move cast, reshape and bitcast after transfer op
We got incoming IR of the form ```mlir %cast = tensor.cast %0 : tensor<2xf32> to tensor<?xf32> %2 = flow.tensor.transfer %cast : tensor<?xf32>{%c2} to #hal.device.affinity<@__device_0> %cast_2 = tensor.cast %2 : tensor<?xf32> to tensor<2xf32> ``` We would like to allow for the 2 casts to get folded. We would also like to reduce the dynamism of the transfer op. To operate on a tensor with fewer dynamic dimensions.
- Loading branch information
Showing
5 changed files
with
194 additions
and
0 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#ifndef IREE_COMPILER_UTILS_SHAPE_H_ | ||
#define IREE_COMPILER_UTILS_SHAPE_H_ | ||
|
||
#include "llvm/ADT/STLExtras.h" | ||
#include "mlir/IR/BuiltinTypeInterfaces.h" | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
// Unranked shapes are always considered to have more dynamic dimensions than | ||
// ranked. | ||
inline bool shapeHasLessOrEqualDynamicDimensions(ShapedType t1, ShapedType t2) { | ||
if (!t2.hasRank()) { | ||
return true; | ||
} | ||
if (!t1.hasRank()) { | ||
return false; | ||
} | ||
|
||
return llvm::count_if(t1.getShape(), &ShapedType::isDynamic) <= | ||
llvm::count_if(t2.getShape(), &ShapedType::isDynamic); | ||
} | ||
|
||
} // namespace mlir::iree_compiler | ||
|
||
#endif // IREE_COMPILER_UTILS_SHAPE_H_ |