Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i1] Remove command line option to enable packed storage #19528

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lialan
Copy link
Contributor

@lialan lialan commented Dec 19, 2024

  • only use #iree_encoding.packed_storage to designate if an i1 tensor is of packed memory layout.
  • remove iree-experimental-packed-i1-storage command line option.
  • teach type converters to allow casting into packed tensor types

@lialan
Copy link
Contributor Author

lialan commented Dec 31, 2024

This is a successor, improving PR to #19354

@lialan lialan marked this pull request as ready for review December 31, 2024 09:30
@hanhanW
Copy link
Contributor

hanhanW commented Jan 7, 2025

The diff is off. There are some changes from #19354. E.g., the below is not part of this PR, right?

image

Can you rebase and fix it?

Base automatically changed from lialan/i1_attr to main January 10, 2025 02:02
@lialan lialan force-pushed the lialan/bitcast branch 4 times, most recently from a6f4a4c to 6468ea1 Compare January 10, 2025 04:56
@lialan
Copy link
Contributor Author

lialan commented Jan 10, 2025

Note that changes that are not in this PR: #19618

Copy link
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

First round of the review comments, thanks for pushing on this!

#packed = #iree_encoding.packed_storage
func.func @i1_type_slice() {
%input = util.unfoldable_constant dense<[0, 255, 0]> : tensor<3xi8>
%flat_input_all = flow.tensor.bitcast %input : tensor<3xi8> -> tensor<24xi1, #packed>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with how flow.tensor.bitcast works. Is the encoding dropped in the TensorExportBufferViewOpPattern pattern? How does it become a tensor_export_buffer_view op? I think we need some input from Ben about the change and the test.

Copy link
Contributor Author

@lialan lialan Jan 14, 2025

Choose a reason for hiding this comment

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

The encoding dropped while it is calculating streamOp's allocated sizes.

flow.tensor.bitcast is just an omni-potent caster here to cast a tensor to another tensor with #packed_storage attribute.

@lialan lialan force-pushed the lialan/bitcast branch 3 times, most recently from c1711b1 to fa8e6d6 Compare January 14, 2025 05:49
@lialan lialan requested a review from hanhanW January 14, 2025 09:38
Copy link
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

@@ -1512,7 +1517,7 @@ LogicalResult TensorCloneOp::verify() {
// information.
auto sourceEncoding = llvm::cast<RankedTensorType>(op.getSourceEncoding());
auto resultEncoding = llvm::cast<RankedTensorType>(op.getResultEncoding());
if (sourceEncoding.getEncoding() != resultEncoding.getEncoding()) {
if (getEncodingAttr(sourceEncoding) != getEncodingAttr(resultEncoding)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required by flow.tensor.bitcast lowering? I.e., the op is lowered to flow.tensor.clone and you need to bypass the check?

I'm not convinced that the change is correct. Because the getEncodingAttr checks if the tensor type has IREE::Encoding::EncodingAttr attribute. There could be other encodings and it is a bug if we introduce new encodings. E.g., tensor<3x4xi32, #whatever_other_encoding_with_padding_semantic> can not be cloned to tensor<3x4xi32>. I think we need to have a stronger restriction. Perhaps just relax the check for packed_storage encoding?

EncodingAttr getEncodingAttr(RankedTensorType type) {
return dyn_cast_or_null<EncodingAttr>(type.getEncoding());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a little tricky. And yes this is required by flow.tensor.bitcast, and we would sometimes cast from a tensor without attribute to another tensor with packed attribute. In such case, we shouldn't check if both the source and result matches packed attribute.

I have slightly updated it to exclude packed attribute comparison. Suggestions are welcome.

compiler/src/iree/compiler/Utils/ElementPackingUtils.cpp Outdated Show resolved Hide resolved
@lialan lialan force-pushed the lialan/bitcast branch 3 times, most recently from 09316fa to 6f232c9 Compare January 15, 2025 13:06
Copy link
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

Reminder: the test is not added yet. #19528 (review)

Comment on lines 1516 to 1518
if (sourceEncoding.getEncoding() != resultEncoding.getEncoding() &&
!IREE::Encoding::hasPackedStorageAttr(sourceEncoding) &&
!IREE::Encoding::hasPackedStorageAttr(resultEncoding)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks better to me. I think we need some input from @benvanik

The previous comment is not tracked in the review mode. Here was the previous comment: #19528 (comment)

TLDR is that we use flow.tensor.bitcast to prepare packed data for e2e testing. The op becomes TensorClone op during the lowering. So we want to relax the verification here.

%flat_input_all = flow.tensor.bitcast %input : tensor<3xi8> -> tensor<24xi1, #packed>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benvanik Do you have opinions on this?

@lialan lialan force-pushed the lialan/bitcast branch 2 times, most recently from f4b5379 to 4a626d6 Compare January 16, 2025 05:26
@lialan
Copy link
Contributor Author

lialan commented Jan 16, 2025

@hanhanW I've added a test to test type propagation.

Copy link
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

Just a few final nits. LGTM except the TensorCloneOp::verify part. Please coordinate with @benvanik about it.

* only use `#iree_encoding.packed_storage` to designate if an `i1` tensor is of packed memory layout.
* remove `iree-experimental-packed-i1-storage` command line option.
* teach type converters to allow casting into packed tensor types

Signed-off-by: Alan Li <[email protected]>
@lialan lialan force-pushed the lialan/bitcast branch 2 times, most recently from dbcaa0a to 0e60383 Compare February 5, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants