Skip to content

Add, use getPermutationAndOffset() to memref layouts #20713

@krzysz00

Description

@krzysz00

There're a bunch of cases where a memref layout is contiguous, in the sense of the contiguous layout I proposed, and we'd like to optimize based on that (ex. the memref linearizer could just use affine.linearize_index disjoint) but it's not currently possible to detect that case.

Therefore, give memref layouts the method

/// If this layout is such that it can be represented as (d0, d1, ..., dN) -> (d(p0}, d{p1}, ... d{pN} + O)` where 
/// `O` is a constant (possibly 0) or symbol, return that offset (using `-1` for dynamic ones) and the permutation
/// `pN`. and succeed. Otherwise, fail, leaving the state of the input values undefined.
LogicalResult getPermutationAndOffsets(ArrayRef<int64_t> shape, SmallVector<int64_t>& perm, int64_t& offset);

and an analogous method on memref types for convenience.

Then, pull the implementation for identifying permuted maps from the contiguous memrefs PR and use it as a default implementation / the implementation for affine map.

Then, in new PRs, use that identification scheme to simplify code like memref::ExpandShape's setup and stuff like getLinearSizesAndOffset()

Also, update the returns types of stuff like memref.subview to canonicalize the strided layout, and fix canonicalizeStridedLayout to return an identity map for strides=[] or [1] and offset = 0.

(Followup work will be to introduce the contiguous layout attribute and use it for all the cases that aren't the identity. This adds the new layout but doesn't have the breaking change of messing with AffineMap{})

llvm/llvm-project#131663 is said PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions