-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][vector][spirv] Lower vector.transfer_read and vector.transfer_write to SPIR-V #69708
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,6 +509,99 @@ struct VectorShuffleOpConvert final | |
} | ||
}; | ||
|
||
struct VectorTransferReadOpConverter final | ||
: public OpConversionPattern<vector::TransferReadOp> { | ||
using OpConversionPattern::OpConversionPattern; | ||
|
||
LogicalResult | ||
matchAndRewrite(vector::TransferReadOp transferReadOp, OpAdaptor adaptor, | ||
ConversionPatternRewriter &rewriter) const override { | ||
if (transferReadOp.getMask()) | ||
return rewriter.notifyMatchFailure(transferReadOp, | ||
"unsupported transfer_read with mask"); | ||
|
||
if (transferReadOp.hasOutOfBoundsDim()) | ||
return rewriter.notifyMatchFailure( | ||
transferReadOp, | ||
"unsupported transfer_read with out-of-bound dimensions"); | ||
|
||
auto sourceType = transferReadOp.getSource().getType(); | ||
auto memrefType = dyn_cast<MemRefType>(sourceType); | ||
if (!memrefType) | ||
return rewriter.notifyMatchFailure(transferReadOp, "not a memref source"); | ||
|
||
auto attr = | ||
dyn_cast_or_null<spirv::StorageClassAttr>(memrefType.getMemorySpace()); | ||
if (!attr) | ||
return failure(); | ||
|
||
const auto &typeConverter = *getTypeConverter<SPIRVTypeConverter>(); | ||
auto loc = transferReadOp.getLoc(); | ||
Value accessChain = | ||
spirv::getElementPtr(typeConverter, memrefType, adaptor.getSource(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only works when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I revoked the fix. I am still thinking why we need identity map here. Can you give more information about it? |
||
adaptor.getIndices(), loc, rewriter); | ||
if (!accessChain) | ||
return failure(); | ||
|
||
spirv::StorageClass storageClass = attr.getValue(); | ||
auto vectorType = transferReadOp.getVectorType(); | ||
auto vectorPtrType = spirv::PointerType::get(vectorType, storageClass); | ||
Value castedAccessChain = | ||
rewriter.create<spirv::BitcastOp>(loc, vectorPtrType, accessChain); | ||
rewriter.replaceOpWithNewOp<spirv::LoadOp>(transferReadOp, vectorType, | ||
castedAccessChain); | ||
|
||
return success(); | ||
} | ||
}; | ||
|
||
struct VectorTransferWriteOpConverter final | ||
Hsiangkai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: public OpConversionPattern<vector::TransferWriteOp> { | ||
using OpConversionPattern::OpConversionPattern; | ||
|
||
LogicalResult | ||
matchAndRewrite(vector::TransferWriteOp transferWriteOp, OpAdaptor adaptor, | ||
ConversionPatternRewriter &rewriter) const override { | ||
if (transferWriteOp.getMask()) | ||
return rewriter.notifyMatchFailure( | ||
transferWriteOp, "unsupported transfer_write with mask"); | ||
|
||
if (transferWriteOp.hasOutOfBoundsDim()) | ||
return rewriter.notifyMatchFailure( | ||
transferWriteOp, | ||
"unsupported transfer_write with out-of-bound dimensions"); | ||
|
||
auto sourceType = transferWriteOp.getSource().getType(); | ||
auto memrefType = dyn_cast<MemRefType>(sourceType); | ||
if (!memrefType) | ||
return rewriter.notifyMatchFailure(transferWriteOp, | ||
"not a memref source"); | ||
|
||
auto attr = | ||
dyn_cast_or_null<spirv::StorageClassAttr>(memrefType.getMemorySpace()); | ||
if (!attr) | ||
return failure(); | ||
|
||
const auto &typeConverter = *getTypeConverter<SPIRVTypeConverter>(); | ||
auto loc = transferWriteOp.getLoc(); | ||
Value accessChain = | ||
spirv::getElementPtr(typeConverter, memrefType, adaptor.getSource(), | ||
adaptor.getIndices(), loc, rewriter); | ||
if (!accessChain) | ||
return failure(); | ||
|
||
spirv::StorageClass storageClass = attr.getValue(); | ||
auto vectorType = transferWriteOp.getVectorType(); | ||
auto vectorPtrType = spirv::PointerType::get(vectorType, storageClass); | ||
Value castedAccessChain = | ||
rewriter.create<spirv::BitcastOp>(loc, vectorPtrType, accessChain); | ||
rewriter.replaceOpWithNewOp<spirv::StoreOp>( | ||
transferWriteOp, castedAccessChain, adaptor.getVector()); | ||
|
||
return success(); | ||
} | ||
}; | ||
|
||
struct VectorReductionToDotProd final : OpRewritePattern<vector::ReductionOp> { | ||
using OpRewritePattern::OpRewritePattern; | ||
|
||
|
@@ -622,7 +715,9 @@ void mlir::populateVectorToSPIRVPatterns(SPIRVTypeConverter &typeConverter, | |
VectorInsertOpConvert, VectorReductionPattern<GL_MAX_MIN_OPS>, | ||
VectorReductionPattern<CL_MAX_MIN_OPS>, VectorShapeCast, | ||
VectorInsertStridedSliceOpConvert, VectorShuffleOpConvert, | ||
VectorSplatPattern>(typeConverter, patterns.getContext()); | ||
VectorSplatPattern, VectorTransferReadOpConverter, | ||
VectorTransferWriteOpConverter>(typeConverter, | ||
patterns.getContext()); | ||
} | ||
|
||
void mlir::populateVectorReductionToSPIRVDotProductPatterns( | ||
|
Uh oh!
There was an error while loading. Please reload this page.