Skip to content

Use linalg-on-tensors for pre-partitioning linalg fusion #1354

Closed

Description

@benvanik

The current IREE flow dialect partitioning is done based solely on limited op matching (xla_hlo.dot and xla_hlo.conv) and generic invocation count calculation. This is sub-optimal for many reasons:

  • does not fuse many trivial indexing op/broadcasts, leading in additional intermediate tensors and dispatches
  • does not enable layout-aware linalg optimizations as layout is isolated and fixed
  • the hardcoded xla_hlo op checking ties our input logic to the source dialect preventing other non-XLA HLO-based inputs

If instead we convert HLO ops to linalg ops and then run linalg optimizations a large majority of those corner cases that matter in performance-sensitive scenarios are eliminated. We need to use linalg-on-tensors (vs. buffers) as we are operating within the value-semantic tensor domain and need to continue in that form for further scheduling work.

This is a meta issue to track progress on augmenting the current system to allow it to operate on linalg-on-tensors:

  • Try enabling some HLO->linalg lowerings prior to partitioning and see what breaks
  • Ensure the linalg library approach scales to VMLA ops so that we can always rely on linalg in the compiler flow don't care about VMLA
  • Remove the existing hardcoded dot/conv logic once those are lowered earlier on
  • Enable or plan out interesting linalg-on-tensor level optimizations

Activity

  1. added
    compiler/dialects
    codegen
    on Apr 2, 2020
  2. benvanik commented on Nov 22, 2020

    @benvanik
    CollaboratorAuthor

    Remember April? hah

  3. MaheshRavishankar commented on Nov 23, 2020

    @MaheshRavishankar
    Collaborator

    To really enable the use of Linalg on tensors, would be preferable to hook up linalg on tensors to Vector dialect. Ideally would want to prove out linalg on tensors on CPU side as much as possible, and then make sure we can match whatever perf we are getting currently. In the mean time much of the CPU/GPU pipelines must get unified. That should make the switch to use linalg on tensors on GPU fairly easy.

    Also

    Remove the existing hardcoded dot/conv logic once those are lowered earlier on

    There is no reason to remove it. The conversion from mhlo.conv to linalg.conv are correct. They lower to linalg.conv on buffers. They just need to lower to linalg.conv on tensors.

  4. benvanik commented on Nov 23, 2020

    @benvanik
    CollaboratorAuthor

    The specific task here is removing the if (mhlo::ConvOp) return dont_fuse; logic from IdentifyDispatchRegions that we won't need when linalg is used for partitioning instead of the current hacky IREE logic. I'm hoping we can get to that point sooner rather than later regardless of how the linalg.conv ends up in codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

codegencompiler/dialects

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions