-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR][NVGPU] Improve and Cleanup verifier of TMA OPs #70923
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,34 +335,83 @@ LogicalResult LdMatrixOp::verify() { | |
// NVGPU_TmaAsyncLoadOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
LogicalResult TmaAsyncLoadOp::verify() { | ||
// Destination memref | ||
auto dstMemref = llvm::cast<MemRefType>(getDst().getType()); | ||
std::optional<InFlightDiagnostic> verifyTmaDescriptorWithMemref( | ||
Operation *op, nvgpu::TensorMapDescriptorType descType, | ||
std::optional<MemRefType> memrefType = std::nullopt) { | ||
MemRefType descMemref = descType.getTensor(); | ||
// Limitation | ||
if (descType.getInterleave() != TensorMapInterleaveKind::INTERLEAVE_NONE) | ||
return op->emitError() << "Interleave options are not supported yet."; | ||
|
||
// Address space check for shared memory check | ||
if (!NVGPUDialect::hasSharedMemoryAddressSpace(descMemref)) { | ||
return op->emitError() << "the tensor map descriptor has incorrect address " | ||
"space, it must be shared memory address space."; | ||
} | ||
// Support only static shape for the time being | ||
if (!descMemref.hasStaticShape()) | ||
return op->emitError() << "the tensor map descriptor must be static shaped"; | ||
|
||
// No verification if memref type is not provided | ||
if (!memrefType.has_value()) | ||
return std::nullopt; | ||
|
||
MemRefType dstMemref = memrefType.value(); | ||
|
||
// Check element type | ||
if (descMemref.getElementType() != dstMemref.getElementType()) { | ||
return op->emitError() << "the element type of tensor map descriptor and " | ||
"memref must be same"; | ||
} | ||
|
||
if (!NVGPUDialect::hasSharedMemoryAddressSpace(dstMemref)) { | ||
return emitError() | ||
<< "The operation stores data to shared memory, but " | ||
"the destination memref does not have a memory space of " | ||
<< NVGPUDialect::kSharedMemoryAddressSpace; | ||
return op->emitError() << "the destination memref has incorrect address " | ||
"space, it must be shared memory address space."; | ||
} | ||
if (getCoordinates().size() > 5) { | ||
return emitError() << "Maximum 5 coordinates are supported."; | ||
if (!dstMemref.hasStaticShape()) | ||
return op->emitError() << "the destination memref must be static shaped"; | ||
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 would move this check close to its |
||
|
||
if (dstMemref.getRank() != descMemref.getRank()) { | ||
return op->emitError() << "the shape of tensor map descriptor and " | ||
"memref must have same rank"; | ||
} | ||
if (getCoordinates().size() != size_t(dstMemref.getRank())) { | ||
return emitError() << "Destination memref rank is " | ||
<< size_t(dstMemref.getRank()) << " but there are " | ||
<< getCoordinates().size() | ||
<< " coordinates. They must match."; | ||
if (!descMemref.getShape().equals(dstMemref.getShape())) { | ||
return op->emitError() << "memref and tensor map shapes mismatch " | ||
<< descMemref << " != " << dstMemref; | ||
} | ||
|
||
return std::nullopt; | ||
} | ||
|
||
LogicalResult TmaAsyncLoadOp::verify() { | ||
std::optional<InFlightDiagnostic> error = verifyTmaDescriptorWithMemref( | ||
*this, getTensorMapDescriptor().getType(), getDst().getType()); | ||
if (error.has_value()) | ||
return error.value(); | ||
|
||
if (getCoordinates().size() > kMaxTMATensorDimension) { | ||
return emitError() << "Maximum " << kMaxTMATensorDimension | ||
<< " coordinates are supported."; | ||
} | ||
grypp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (getCoordinates().size() != | ||
getTensorMapDescriptor().getType().getTensor().getRank()) { | ||
return emitError() << "number of coordinates do not match with the rank of " | ||
"tensor descriptor map."; | ||
} | ||
|
||
return success(); | ||
} | ||
|
||
LogicalResult TmaCreateDescriptorOp::verify() { | ||
if (getBoxDimensions().size() > 5) { | ||
return emitError() << "Maximum 5 dimensional box is supported."; | ||
if (getBoxDimensions().size() > kMaxTMATensorDimension) { | ||
return emitError() << "Maximum " << kMaxTMATensorDimension | ||
<< " coordinates are supported."; | ||
} | ||
nvgpu::TensorMapDescriptorType desc = getTensorMap().getType(); | ||
if (desc.getInterleave() != TensorMapInterleaveKind::INTERLEAVE_NONE) | ||
return emitError() << "Interleave options are not supported yet."; | ||
|
||
std::optional<InFlightDiagnostic> error = | ||
verifyTmaDescriptorWithMemref(*this, getTensorMap().getType()); | ||
if (error.has_value()) | ||
return error.value(); | ||
|
||
return success(); | ||
} | ||
|
@@ -372,17 +421,10 @@ LogicalResult TmaCreateDescriptorOp::verify() { | |
//===----------------------------------------------------------------------===// | ||
|
||
LogicalResult WarpgroupGenerateDescriptorOp::verify() { | ||
MemRefType memrefType = getTensor().getType(); | ||
MemRefType tensorMapType = getTensorMap().getType().getTensor(); | ||
|
||
if (memrefType != tensorMapType) | ||
return emitError() << "memref and tensor map type mismatch"; | ||
|
||
if (!memrefType.hasStaticShape() || !tensorMapType.hasStaticShape()) | ||
return emitError() << "supports only static shapes"; | ||
|
||
if (memrefType.getRank() != 2) | ||
return emitError() << "supports only 2d memref is supported for now"; | ||
std::optional<InFlightDiagnostic> error = | ||
verifyTmaDescriptorWithMemref(*this, getTensorMap().getType()); | ||
if (error.has_value()) | ||
return error.value(); | ||
|
||
if (getTensorMap().getType().getSwizzle() != | ||
TensorMapSwizzleKind::SWIZZLE_128B) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.