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

[BufferizeToAllocation] Handle pack operands dependent on other op types #972

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

jtuyls
Copy link
Collaborator

@jtuyls jtuyls commented Dec 9, 2024

Refactor getOperandsFromDefOp to search for and return pack ops up to a certain depth away from the linalg op's inputs and rename to getPackOperands. This enables more complex cases with intermediate extract_slice operations, see the new test cases being added.

@newling
Copy link
Contributor

newling commented Dec 9, 2024

Looks good, minor suggestions in jtuyls#15

One question -- why is the default depth 2, shouldn't it be 1 because the the bufferization in the current pipeline is always on the closest pack op to the matmul? Or maybe there should just be no default.

@jtuyls
Copy link
Collaborator Author

jtuyls commented Dec 9, 2024

Looks good, minor suggestions in jtuyls#15

One question -- why is the default depth 2, shouldn't it be 1 because the the bufferization in the current pipeline is always on the closest pack op to the matmul? Or maybe there should just be no default.

Yeah, maybe it's better to set default to 1 instead.

@jtuyls jtuyls force-pushed the bufferize-to-allocation-fix branch from 15aa726 to 3844fc4 Compare December 9, 2024 17:28
clEnumValN(mlir::iree_compiler::AMDAIE::BufferizeOperand::DefOp, "def-op",
"Create new allocations for operands from the def ops of a linalg op.")
)}]>
clEnumValN(mlir::iree_compiler::AMDAIE::BufferizeOperand::Pack, "pack",
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel pack may not be a good name for this situation. Maybe we should rename these options to something like "LinalgInput"/"LinalgOutput"/"PackInput"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, renamed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I see you didn't change the other options. Do you think it's more clear if we change option "Input" to "LinalgInput" and "Output" to "LinalgOutput", etc? This is not critical, so can be addressed in the future if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think that makes sense, but I wanted to avoid convoluting this PR with those changes.

@@ -1,7 +1,7 @@
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-bufferize-to-allocation{memory-space=2 bufferize-operand=input-output}))' --split-input-file %s | FileCheck %s --check-prefix=INPUT-OUTPUT
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-bufferize-to-allocation{memory-space=2 bufferize-operand=input}))' --split-input-file %s | FileCheck %s --check-prefix=INPUT
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-bufferize-to-allocation{memory-space=2 bufferize-operand=output}))' --split-input-file %s | FileCheck %s --check-prefix=OUTPUT
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-bufferize-to-allocation{memory-space=1 bufferize-operand=def-op}))' --split-input-file %s | FileCheck %s --check-prefix=DEF-OP
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-bufferize-to-allocation{memory-space=1 bufferize-operand=pack pack-depth=2}))' --split-input-file --verify-diagnostics %s | FileCheck %s --check-prefix=PACK
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to add --verify-diagnostics?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, initially, I put all test cases in this file, but some fail for some of the runs commands.

Comment on lines +86 to +90
if (!currentOp) {
return linalgOp.emitOpError()
<< "operand #" << input.index() << " only has pack ops to depth "
<< currentLevel << ", but request is for a depth " << depthLevel
<< " pack op.";
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if it is easy to add a test for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yzhang93
Copy link
Contributor

yzhang93 commented Dec 9, 2024

Looks good, minor suggestions in jtuyls#15
One question -- why is the default depth 2, shouldn't it be 1 because the the bufferization in the current pipeline is always on the closest pack op to the matmul? Or maybe there should just be no default.

Yeah, maybe it's better to set default to 1 instead.

I think we may keep default as 2, as currently PackDepth is only used within getPackOperands function and the existing tests are only with pack-depth=2. And option bufferize-operand=pack pack-depth=1 seems to be a specific case for option bufferize-operand=input. Note the linalg input operand could be other operations than pack ops.

@jtuyls
Copy link
Collaborator Author

jtuyls commented Dec 9, 2024

I think we may keep default as 2, as currently PackDepth is only used within getPackOperands function and the existing tests are only with pack-depth=2. And option bufferize-operand=pack pack-depth=1 seems to be a specific case for option bufferize-operand=input. Note the linalg input operand could be other operations than pack ops.

That's why I initially had it as 2, but I think the default is not necessarily the one we're using, but the one that makes sense from a tranformation's perspective, for which I think 1 is a better default as in principal there are more cases with one level of packs than two.

@jtuyls jtuyls force-pushed the bufferize-to-allocation-fix branch from 3844fc4 to 6f66792 Compare December 9, 2024 20:53
clEnumValN(mlir::iree_compiler::AMDAIE::BufferizeOperand::DefOp, "def-op",
"Create new allocations for operands from the def ops of a linalg op.")
)}]>
clEnumValN(mlir::iree_compiler::AMDAIE::BufferizeOperand::PackInput, "pack",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change this to pack-input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@jtuyls jtuyls force-pushed the bufferize-to-allocation-fix branch from b7cb01d to bcfcb4b Compare December 9, 2024 21:25
@jtuyls jtuyls merged commit f5ab91e into nod-ai:main Dec 9, 2024
7 checks passed
@jtuyls jtuyls deleted the bufferize-to-allocation-fix branch December 10, 2024 07:44
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.

3 participants