You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The functions mapInLayoutToOutRoot and isCompliantWith have been moved from alias_analysis.cpp to allocation_utils.cpp, but there are no corresponding updates or additions in the tests to validate these changes.
The functions mapInLayoutToOutRoot and isCompliantWith are being moved from alias_analysis.cpp to allocation_utils.cpp, but they are being added back into allocation_utils.cpp without removing them from alias_analysis.cpp. This could lead to code duplication and maintenance issues.
namespace {
boolcontiguityIsCompliant(
const std::optional<bool>& actual,
const std::optional<bool>& required) {
if (actual == true && required == false) {
returntrue;
}
return actual == required;
}
} // namespaceboolisCompliantWith(const Layout& layout, const Layout& required) {
if (layout.allocation_domain != required.allocation_domain) {
// This can be relaxed by allowing broadcast dimensions to be ordered// differently.returnfalse;
}
for (constauto i : arange(layout.size())) {
if (!contiguityIsCompliant(layout.contiguity[i], required.contiguity[i])) {
returnfalse;
}
}
returntrue;
}
std::optional<Layout> mapInLayoutToOutRoot(
const std::optional<Layout>& in_layout,
TensorView* in,
TensorView* out) {
if (!in_layout.has_value()) {
return std::nullopt;
}
if (!ir_utils::computePermutation(
in->getLogicalDomain(), in_layout->allocation_domain)
.has_value()) {
// Give up when `in`'s allocation domain is not an logical permutation. As// an extension, we could map in_alloc to in_logical and apply the inverse// mapping to out_root.return std::nullopt;
}
std::unordered_map<IterDomain*, IterDomain*> in_logical_to_out_root =
PairwiseLogicalDomainMap(in, out).mapProducerToConsumer();
Layout out_layout;
for (auto&& [in_alloc_id, contiguity] :
zip(in_layout->allocation_domain, in_layout->contiguity)) {
IterDomain* out_root_id = getOrDefault(in_logical_to_out_root, in_alloc_id);
if (out_root_id == nullptr) {
// This can happen when in_alloc_id is of type reduction or squeezed out.continue;
}
out_layout.allocation_domain.push_back(out_root_id);
out_layout.contiguity.push_back(contiguity);
}
return out_layout;
}
The newly added functions isCompliantWith and mapInLayoutToOutRoot in allocation_utils.h lack detailed documentation. It is important to provide clear documentation for new functions to ensure they are used correctly.
// Returns whether `layout` is compliant with `required`. This is// uni-directional. For example, `contiguity=[t,t]` is compliant with// `contiguity=[f,f]` but not vice versa.boolisCompliantWith(constLayout&layout, constLayout&required);
// A helper function used to compute the perferred output layout. It computes// the mapping from `in_logical` to `out_root` and applies that mapping to// `preferred_in_layout`. For many ops, this function returns a good initial// preferred output layout for aliasing because it tries to preserve the input// layout. An op (e.g. ViewOp and SliceOp) that transforms root to logical// using expressions will have to modify this initial layout so its allocation// domain will be a function of its logical domain.//// Returns `nullopt` if computation fails, so the caller can handle things// conservatively.std::optional<Layout>mapInLayoutToOutRoot(
This file contains hidden or 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.
For #4554