Skip to content

[DT] Collapse matmul_narrow_M/N field into round_dims_to attribute. - #18599

Merged
hanhanW merged 5 commits into
iree-org:mainfrom
hanhanW:encoding-narrow-cleanup
Sep 26, 2024
Merged

hanhanW merged 5 commits into
iree-org:mainfrom
hanhanW:encoding-narrow-cleanup

Conversation

@hanhanW

@hanhanW hanhanW commented Sep 25, 2024 •

Copy link
Copy Markdown
Contributor

The revision refines how we handle matmul_narrow_M/N in encodings. The matmul_narrow_M/N attributes are retired in the patch. The information is carried in round_dims_to attribute which is rounded to the next power of two. E.g., if the value of matmul_narrow_M is 3, it will be 4 in the round_dims_to attribute.

The kNarrowThreshold constant is introduced to Encoding namespace. A dimension is considered as "narrow" only if the size of the dimension is less than kNarrowThreshold.

The revision implements getMatmulNarrowM and getMatmulNarrowN helpers based on the definition of round_dims_to and the kNarrowThreshold variable. Users can call the helpers to get the narrow size of M/N. Again, you'll get the value that is rounded to the next power of two if they are considered "narrow". E.g., getMatmulNarrowM() returns 4 if M equals to 3.

The revision also fixes a bug in chooseMatmulTile on CPU side. The hostDefinedUpperBound is not updated in the narrow-N cases.

Fixes #17729
Fixes #15466

@hanhanW

hanhanW commented Sep 25, 2024

Copy link
Copy Markdown
Contributor Author

oh, there are issues in vmvx + uk. Because the old path assumes that the sizes will always be aligned with 16. Let me take a look how to fix it properly.

namespace mlir::iree_compiler::IREE::Encoding {

/// Threadshold that determines if a dimension is considered "narrow" or not.
constexpr int64_t kNarrowThreshold = 32;

@bjacob bjacob Sep 26, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call that constant kDefaultRoundDimsTo. EDIT - sorry, I realize now that the default value of round_dims_to is defined elsewhere. What I mean here is that these two constants should be united. We shouldn't hardcode the constant 32 in two different places, right?

The "narrow" concept is merely an optimization for narrow matmuls. It is one of the purposes of this constant, but since it is only an optimization purpose, it is not the most essential purpose. Instead, the primary purpose of this constant is ensuring sufficiently large allocations (the original role of round_dims_to). The naming should reflect that - so that a future developer tempted to reduce this constant's value understand that that might cause crashes, not just performance regressions.

In a follow-up PR, I would like this kDefaultRoundDimsTo to become per-target-backend, and in the case of multi-target-backend compilations, we should use the maximum value over the individual backends. WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, let's land your PR as-is and I will do a follow-up with what I have in mind.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjacob
bjacob self-requested a review September 26, 2024 15:14
@hanhanW
hanhanW merged commit b13d38b into iree-org:main Sep 26, 2024
@hanhanW
hanhanW deleted the encoding-narrow-cleanup branch September 26, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants