Repository navigation
Replace cooperative matrix marker by an analysis class - #2362
Conversation
antiagainst
left a comment
There was a problem hiding this comment.
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 |
| // | ||
| // 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 |
| // 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 |
| // 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 |
There was a problem hiding this comment.
typo: whehter
... whether the root operation is in the chain and thus can be converted to its corresponding cooperative matrix operation...
| explicit CooperativeMatrixAnalysis(mlir::Operation *); | ||
|
|
||
| // Return true if the operation should be lowered using cooperative matrix | ||
| // type. |
There was a problem hiding this comment.
s/type/operations/
We turn operations into other operations not types. ;)
There was a problem hiding this comment.
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) || |
There was a problem hiding this comment.
Merge into one if statement?
| dim == std::make_tuple(16, 16, 16) || dim == std::make_tuple(16, 8, 16)) | ||
| supportedType = true; | ||
| } | ||
| if (!supportedType) return false; |
| if (isa<vector::ContractionOp>(op) && | ||
| isLegalVectorContract(cast<vector::ContractionOp>(op))) | ||
| return true; | ||
| // We only support minimal set of operations right now. We cna trivially |
| 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. |
| op->walk([&](Operation* op) { | ||
| auto contract = dyn_cast<vector::ContractionOp>(op); | ||
| if (contract == nullptr) return; | ||
| auto hasNoVectorDest = [](Operation* op) { |
There was a problem hiding this comment.
Is the name inverted here? I think this is hasVectorDest?
There was a problem hiding this comment.
My bad, I had it reversed in a first place and didn't update the name.
7a99f13 to
f6e5863
Compare
|
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.
f6e5863 to
f641985
Compare
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.