Repository navigation
Improve memref vectorization to not use larger type if not needed - #3915
Conversation
| (kMaxVectorizationSizeInBits % memrefType.getElementTypeBitWidth() == | ||
| 0) && | ||
| !ShapedType::isDynamic(memrefType.getShape().back()) && | ||
| getUsesIfAllTransferOp(v, uses)) { |
There was a problem hiding this comment.
Where is this function from?
There was a problem hiding this comment.
Same file, line 35. Note that this part of the code is just moved.
| Type elemType = type.getElementType(); | ||
| // If the vector we need to generate is bigger than the the max vector size | ||
| // allowed for loads use a larger element type. | ||
| if (numElements > kMaxVectorNumElements) { |
There was a problem hiding this comment.
I am actually not sure what is happening here. Based on the number of elements, the type is changing. That is counter-intuitive to me.
There was a problem hiding this comment.
Yes, the idea is that before we were trying to convert everything to memref<..vec<4xi32>>, this change is keeping the original type if the vectorization size we want is smaller. For instance if we are loading vec<4xf16>, the memref would get converted to memref<..vec<4xf16>> but if we are trying load vec<8xf16> this will create a memref<...vec<4xf32>> and cast the result of the load to vec<4xf16>. This can useful because sometimes we a type smaller than 4bytes and we still want to load it as a larger type and cast it to get better memory access patterns.
I can add more comments if you think that is what is missing or we can chat more about the logic.
There was a problem hiding this comment.
Why cant we convert to memref<...<vec<8xf16>>?
It might be easier to this in the analysis itself. Figure out the memref type to use for the allocation, and adjust the loads appropriately?
Let me know if you want to chat offline?
There was a problem hiding this comment.
Why cant we convert to
memref<...<vec<8xf16>>?It might be easier to this in the analysis itself. Figure out the memref type to use for the allocation, and adjust the loads appropriately?
Let me know if you want to chat offline?
I added a comment to explain the logic. Hopefully that makes it more clear.
| Type elemType = type.getElementType(); | ||
| // If the vector we need to generate is bigger than the the max vector size | ||
| // allowed for loads use a larger element type. | ||
| if (numElements > kMaxVectorNumElements) { |
There was a problem hiding this comment.
Why cant we convert to memref<...<vec<8xf16>>?
It might be easier to this in the analysis itself. Figure out the memref type to use for the allocation, and adjust the loads appropriately?
Let me know if you want to chat offline?
MaheshRavishankar
left a comment
There was a problem hiding this comment.
Thanks for the clarification. Looks good.
This allows better code generation for f16 cases as it can allow skipping costly back and forth casting.