- Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][amdgpu] lowerings for ScaledExtPacked816 #168123
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
base: main
Are you sure you want to change the base?
Conversation
krzysz00 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a few nits
| if (is_fp8 && firstScaleLane == 1 && firstScaleByte == 2 && is_block_16) { | ||
| return 0b1101; | ||
| } | ||
| if (is_fp8 && firstScaleLane == 1 && firstScaleByte == 3 && !is_block_16) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to make this a bit less of an exhaustive enumeration of the cases?
| ScaledExtPacked816Op op, ScaledExtPacked816OpAdaptor adaptor, | ||
| ConversionPatternRewriter &rewriter) const { | ||
| | ||
| int firstScaleLane = op.getFirstScaleLane(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is int the right type here? Probably int64_t for index and int32_t otherwise.
| } else if (isa<Float6E3M2FNType>(srcElemType) && destElemType.isF16()) { | ||
| rewriter.replaceOpWithNewOp<ROCDL::CvtPkScalePk16F16Bf6Op>( | ||
| op, op.getResult().getType(), castedSource, castedScale, scaleSel); | ||
| } else if (isa<Float6E2M3FNType>(srcElemType) && destElemType.isBF16()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could pull a page out of the MFMA book and have a general create that is relying on an OperationName, so that we don't have to repeat the ::create part N different times.
| // When lowering amdgpu.scaled_ext_packed816 to | ||
| // rocdl.cvt.scale.pk*.f*.f* operations, the | ||
| // attributes blockSize, sourceType, firstScaleLane and firstScaleByte | ||
| // are merged into a single attribute scaleSel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: reflow this comment
| | ||
| llvm_unreachable("invalid combination of firstScaleLane, firstScaleByte, " | ||
| "blockSize and type."); | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No return after unreachable
| ConversionPatternRewriter &rewriter) const { | ||
| | ||
| int firstScaleLane = op.getFirstScaleLane(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ConversionPatternRewriter &rewriter) const { | |
| int firstScaleLane = op.getFirstScaleLane(); | |
| ConversionPatternRewriter &rewriter) const { | |
| int firstScaleLane = op.getFirstScaleLane(); |
nit: superfluous empty line
| Type packedType; | ||
| if (isa<Float4E2M1FNType>(srcElemType)) { | ||
| packedType = i32; | ||
| packedType = getTypeConverter()->convertType(packedType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the most general case, type conversion can fail -- are we checking this anywhere?
| Value castedSource = | ||
| LLVM::BitcastOp::create(rewriter, loc, packedType, source); | ||
| | ||
| if (isa<Float4E2M1FNType>(srcElemType) && destElemType.isF16()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can define type aliases for these, e.g.: using fp4 = Float4E2M1FNType to make the code more concise.
| return failure(); | ||
| } | ||
| | ||
| return success(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this reachable?
Depends on #167369