Skip to content
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

[LLVMGPU] Add a verifier for tile sizes. #19906

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ verifyLoweringConfiguration(FunctionOpInterface funcOp,
IREE::Codegen::TranslationInfoAttr translationInfo,
ArrayRef<int64_t> workgroupSize, F verificationFn) {
auto walkResult = funcOp.walk([&](Operation *op) -> WalkResult {
auto loweringConfig =
auto codegenLoweringConfig =
getLoweringConfig<IREE::Codegen::LoweringConfigAttr>(op);
if (!loweringConfig)
auto gpuLoweringConfig =
getLoweringConfig<IREE::GPU::LoweringConfigAttr>(op);
if (!codegenLoweringConfig && !gpuLoweringConfig)
return WalkResult::advance();
return verificationFn(op, loweringConfig, translationInfo, workgroupSize);
return verificationFn(op, codegenLoweringConfig, translationInfo,
gpuLoweringConfig, workgroupSize);
});
return failure(walkResult.wasInterrupted());
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ void buildLLVMGPUCodegenPassPipeline(OpPassManager &variantPassManagery,
/// Lowering calling vectorization patterns.
LogicalResult
verifyGPUMatmulPipeline(Operation *op,
IREE::Codegen::LoweringConfigAttr loweringConfig,
IREE::Codegen::LoweringConfigAttr codegenloweringConfig,
IREE::Codegen::TranslationInfoAttr translationInfo,
IREE::GPU::LoweringConfigAttr gpuloweringConfig,
ArrayRef<int64_t> workgroupSize);

//----------------------------------------------------------------------------//
Expand Down
53 changes: 49 additions & 4 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/Verifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,65 @@ getInstructionShape(Operation *op, CodeGenPipeline pipeline,
/// and Tensor Core pipelines.
LogicalResult
verifyGPUMatmulPipeline(Operation *op,
IREE::Codegen::LoweringConfigAttr loweringConfig,
IREE::Codegen::LoweringConfigAttr codegenloweringConfig,
IREE::Codegen::TranslationInfoAttr translationInfo,
IREE::GPU::LoweringConfigAttr gpuLoweringConfig,
ArrayRef<int64_t> workgroupSize) {
// This verifier only applies to matmul.
CodeGenPipeline pipeline = translationInfo.getDispatchLoweringPassPipeline();

if (pipeline != CodeGenPipeline::LLVMGPUMatmulTensorCore &&
pipeline != CodeGenPipeline::LLVMGPUMatmulTensorCoreMmaSync) {
pipeline != CodeGenPipeline::LLVMGPUMatmulTensorCoreMmaSync &&
pipeline != CodeGenPipeline::LLVMGPUVectorDistribute) {
return success();
}

// Only verify batched and unbatched matmul.
if (!isa<linalg::MatmulOp, linalg::BatchMatmulOp>(op)) {
return success();
}

uint32_t reduction = static_cast<uint32_t>(IREE::GPU::TilingLevel::Reduction);
uint numLoops = llvm::cast<linalg::MatmulOp>(op).getNumLoops();
size_t size = 0;
if (gpuLoweringConfig.hasTilingLevel(reduction)) {
SmallVector<int64_t> reductionTileSizes =
gpuLoweringConfig.getStaticTilingLevelSizes(reduction, op);

if (!reductionTileSizes.empty()) {
size = reductionTileSizes.size();
}

if (size > numLoops) {
// return op->emitOpError(
// "expected number of reduction tile size is equal or "
// "less than number of loops");
}
for (size_t i = 0; i < size; ++i) {
if (reductionTileSizes[i] > 0 &&
llvm::cast<linalg::MatmulOp>(op).getIteratorTypesArray()[i] !=
utils::IteratorType::reduction) {
return op->emitOpError(
"expected to non-zero reduction tile has reduction iterator");
}
}
}
// SmallVector<int64_t> workgroupTileSizes =
// gpuLoweringConfig.getWorkgroupTileSizes();
// size = workgroupTileSizes.size();

// for (size_t i = 0; i < size; ++i) {
// if (workgroupTileSizes[i] > 0 &&
// llvm::cast<linalg::MatmulOp>(op).getIteratorTypesArray()[i] !=
// utils::IteratorType::parallel) {
// return op->emitOpError(
// "expected to non-zero workgroup tile has parallel iterator");
// }
// }

if (pipeline == CodeGenPipeline::LLVMGPUVectorDistribute) {
return success();
}

// Early exit if the workgroup size is not set.
if (workgroupSize.empty()) {
return op->emitOpError("expected workgroup size for GPU pipelines");
Expand Down Expand Up @@ -123,7 +168,7 @@ verifyGPUMatmulPipeline(Operation *op,

// Tile shapes in number of elements.
SmallVector<int64_t> tileShape =
loweringConfig.getTileSizeVals(kWorkgroupTileLevel);
codegenloweringConfig.getTileSizeVals(kWorkgroupTileLevel);
SmallVector<int64_t> threadBlockShape{tileShape};

if (auto batchMatmulOp = dyn_cast<linalg::BatchMatmulOp>(op)) {
Expand Down
Loading