Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2d243d

Browse files
authored
[LLVMGPU] Add a verifier for tile sizes. (iree-org#19906)
Add a verifier for tile sizes. --------- Signed-off-by: erman-gurses <[email protected]>
1 parent ad86fa6 commit d2d243d

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

compiler/src/iree/compiler/Codegen/LLVMGPU/LLVMGPUSelectLoweringStrategy.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@ class LLVMGPUSelectLoweringStrategyPass final
3939

4040
/// Verify that valid configuration is set for all ops within the compiled
4141
/// module.
42-
template <typename F>
42+
template <typename ConfigTy>
4343
static LogicalResult
4444
verifyLoweringConfiguration(FunctionOpInterface funcOp,
4545
IREE::Codegen::TranslationInfoAttr translationInfo,
46-
ArrayRef<int64_t> workgroupSize, F verificationFn) {
46+
ArrayRef<int64_t> workgroupSize) {
4747
auto walkResult = funcOp.walk([&](Operation *op) -> WalkResult {
48-
auto loweringConfig =
49-
getLoweringConfig<IREE::Codegen::LoweringConfigAttr>(op);
48+
auto loweringConfig = getLoweringConfig<ConfigTy>(op);
5049
if (!loweringConfig)
5150
return WalkResult::advance();
52-
return verificationFn(op, loweringConfig, translationInfo, workgroupSize);
51+
52+
// Calls the correct overloaded function based on ConfigTy.
53+
if constexpr (std::is_same_v<ConfigTy, IREE::GPU::LoweringConfigAttr>) {
54+
return verifyGPUMatmulPipeline(op, loweringConfig, translationInfo);
55+
} else {
56+
return verifyGPUMatmulPipeline(op, loweringConfig, translationInfo,
57+
workgroupSize);
58+
}
5359
});
60+
5461
return failure(walkResult.wasInterrupted());
5562
}
5663

@@ -63,8 +70,18 @@ verifyEntryPoint(FunctionOpInterface funcOp,
6370
"failed to get workgroup size needed for verification");
6471
}
6572

66-
return verifyLoweringConfiguration(
67-
funcOp, translationInfo, workgroupSize.value(), verifyGPUMatmulPipeline);
73+
// Verify GPU-specific configuration
74+
if (failed(verifyLoweringConfiguration<IREE::GPU::LoweringConfigAttr>(
75+
funcOp, translationInfo, workgroupSize.value()))) {
76+
return failure();
77+
}
78+
79+
// Verify Codegen-specific configuration
80+
if (failed(verifyLoweringConfiguration<IREE::Codegen::LoweringConfigAttr>(
81+
funcOp, translationInfo, workgroupSize.value()))) {
82+
return failure();
83+
}
84+
6885
return success();
6986
}
7087

compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ void buildLLVMGPUCodegenConfigurationPassPipeline(
9090
/// the module within the IREE::HAL::ExecutableOp.
9191
void buildLLVMGPUCodegenPassPipeline(OpPassManager &variantPassManagery,
9292
bool useROCM);
93+
LogicalResult
94+
verifyGPUMatmulPipeline(Operation *op,
95+
IREE::GPU::LoweringConfigAttr loweringConfig,
96+
IREE::Codegen::TranslationInfoAttr translationInfo);
9397

9498
/// Lowering calling vectorization patterns.
9599
LogicalResult

compiler/src/iree/compiler/Codegen/LLVMGPU/Verifiers.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ verifyGPUMatmulPipeline(Operation *op,
7575
IREE::Codegen::LoweringConfigAttr loweringConfig,
7676
IREE::Codegen::TranslationInfoAttr translationInfo,
7777
ArrayRef<int64_t> workgroupSize) {
78-
// This verifier only applies to matmul.
7978
CodeGenPipeline pipeline = translationInfo.getDispatchLoweringPassPipeline();
79+
8080
if (pipeline != CodeGenPipeline::LLVMGPUMatmulTensorCore &&
8181
pipeline != CodeGenPipeline::LLVMGPUMatmulTensorCoreMmaSync) {
8282
return success();
8383
}
84+
8485
// Only verify batched and unbatched matmul.
8586
if (!isa<linalg::MatmulOp, linalg::BatchMatmulOp>(op)) {
8687
return success();
@@ -234,4 +235,58 @@ verifyGPUMatmulPipeline(Operation *op,
234235
return success();
235236
}
236237

238+
/// Verifies pipelines that use iree_gpu.lowering_config attributes.
239+
LogicalResult
240+
verifyGPUMatmulPipeline(Operation *op,
241+
IREE::GPU::LoweringConfigAttr loweringConfig,
242+
IREE::Codegen::TranslationInfoAttr translationInfo) {
243+
244+
CodeGenPipeline pipeline = translationInfo.getDispatchLoweringPassPipeline();
245+
// TODO: add verification for other pipelines
246+
if (pipeline != CodeGenPipeline::LLVMGPUVectorDistribute) {
247+
return success();
248+
}
249+
250+
// Only verify batched and unbatched matmul.
251+
if (!isa<linalg::MatmulOp, linalg::BatchMatmulOp>(op)) {
252+
return success();
253+
}
254+
255+
unsigned reduction = static_cast<uint32_t>(IREE::GPU::TilingLevel::Reduction);
256+
uint numLoops = llvm::cast<linalg::LinalgOp>(op).getNumLoops();
257+
size_t size = 0;
258+
259+
SmallVector<int64_t> reductionTileSizes =
260+
loweringConfig.getStaticTilingLevelSizes(reduction, op);
261+
262+
size = reductionTileSizes.size();
263+
264+
if (size > numLoops) {
265+
return op->emitOpError("expected number of reduction tile size is equal "
266+
"or less than number of loops");
267+
}
268+
for (size_t i = 0; i < size; ++i) {
269+
if (reductionTileSizes[i] > 0 &&
270+
llvm::cast<linalg::LinalgOp>(op).getIteratorTypesArray()[i] !=
271+
utils::IteratorType::reduction) {
272+
return op->emitOpError(
273+
"expected to non-zero reduction tile has reduction iterator");
274+
}
275+
}
276+
277+
SmallVector<int64_t> workgroupTileSizes =
278+
loweringConfig.getWorkgroupTileSizes();
279+
size = workgroupTileSizes.size();
280+
for (size_t i = 0; i < size; ++i) {
281+
if (workgroupTileSizes[i] > 0 &&
282+
llvm::cast<linalg::LinalgOp>(op).getIteratorTypesArray()[i] !=
283+
utils::IteratorType::parallel) {
284+
return op->emitOpError(
285+
"expected to non-zero workgroup tile has parallel iterator");
286+
}
287+
}
288+
289+
return success();
290+
}
291+
237292
} // namespace mlir::iree_compiler

0 commit comments

Comments
 (0)