Skip to content

Replace cooperative matrix marker by an analysis class - #2362

Merged
ThomasRaoux merged 1 commit into
iree-org:mainfrom
ThomasRaoux:matrix_analysis
Jul 7, 2020
Merged

ThomasRaoux merged 1 commit into
iree-org:mainfrom
ThomasRaoux:matrix_analysis

Conversation

@ThomasRaoux

Copy link
Copy Markdown
Contributor

The new analysis will be responsible to decide if a chain of
operations should use cooperative matrix extension or not. This allows
removing markers which were not the correct way to handle this. The
analysis is very basic and will be improved in future commits.

@antiagainst antiagainst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool! This is a step towards improving the current ad-hoc implementation and make it more principled. So LGTM! I just have a few nits inlined. It's a bit annoying to see all the use cooperative matrix checks proliferating in each pattern; what we want is some way to turn off a bunch of patterns all together. I'm not sure there is a way at the moment though.


//===- CooperativeMatrixAnalysis.h - Analysis to help lowering of matmul---===//
//
// Analysis class to help decide whether a chain of instruction can use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/instruction/operations/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

//
// Analysis class to help decide whether a chain of instruction can use
// cooperative matrix extension.
// Since cooperative matrix is a separate type it needs to be used consistenly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: consistenly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Analysis class to help decide whether a chain of instruction can use
// cooperative matrix extension.
// Since cooperative matrix is a separate type it needs to be used consistenly
// across operations. This analysis if a chain of operations can be fully

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/analysis/analyzes/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Since cooperative matrix is a separate type it needs to be used consistenly
// across operations. This analysis if a chain of operations can be fully
// converted to cooperative matrix operations. It then provides a query lowering
// passes can use to know whehter an instruction should use cooperative matrix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: whehter

... whether the root operation is in the chain and thus can be converted to its corresponding cooperative matrix operation...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

explicit CooperativeMatrixAnalysis(mlir::Operation *);

// Return true if the operation should be lowered using cooperative matrix
// type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/type/operations/

We turn operations into other operations not types. ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I meant operations using cooperative matrix types since it can the same operations type using cooperative types instead of scalar types. Reworded the comment.

if (lhsType.getElementType().isInteger(8) &&
rhsType.getElementType().isInteger(8) &&
accType.getElementType().isInteger(32)) {
if (dim == std::make_tuple(8, 8, 32) ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Merge into one if statement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

dim == std::make_tuple(16, 16, 16) || dim == std::make_tuple(16, 8, 16))
supportedType = true;
}
if (!supportedType) return false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just return supportedType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (isa<vector::ContractionOp>(op) &&
isLegalVectorContract(cast<vector::ContractionOp>(op)))
return true;
// We only support minimal set of operations right now. We cna trivially

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: cna

isLegalVectorContract(cast<vector::ContractionOp>(op)))
return true;
// We only support minimal set of operations right now. We cna trivially
// extend to ALU instructions supporint Cooperative Matrix in SPIR-V spec.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: supporint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

op->walk([&](Operation* op) {
auto contract = dyn_cast<vector::ContractionOp>(op);
if (contract == nullptr) return;
auto hasNoVectorDest = [](Operation* op) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the name inverted here? I think this is hasVectorDest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad, I had it reversed in a first place and didn't update the name.

@ThomasRaoux

Copy link
Copy Markdown
Contributor Author

Thanks Lei. I agree it is annoying to see the cooperative matrix checks spreading to unrelated code. The main difficulty is that we need to delay the lowering of cooperative matrix instructions until SPIR-V conversion. Once we have support for those in the GPU dialect we could do the conversion to cooperative matrix first and then the rest of the code wouldn't have to know about it. The more we go the more I think we may want to add this to GPU dialect rather sooner than later to be able to clean up the code. I'll probably try to start a discussion about that in the next few weeks.

The new analysis will be responsible to decide if a chain of
operations should use cooperative matrix extension or not. This allows
removing markers which were not the correct way to handle this. The
analysis is very basic and will be improved in future commits.
@ThomasRaoux
ThomasRaoux merged commit bf31292 into iree-org:main Jul 7, 2020
@GMNGeoffrey GMNGeoffrey mentioned this pull request Jul 8, 2020
@ThomasRaoux
ThomasRaoux deleted the matrix_analysis branch February 16, 2021 23:45
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