From 60fa26e7af75a5c7b3259d04cc1c1e05b91b83b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Thu, 15 Aug 2024 12:46:28 +0200 Subject: [PATCH] [quidditch_snitch] Rename `cluster_index` to `compute_core_index` (#108) The op as it is currently used and specified returns the index of compute cores (in our current simulations 0 to exclusive 8) and has unspecified behavior on the DMA core. This will be used in a later PR to properly lower it when doing DMA code specialization. --- .../Conversion/ConvertSnitchToLLVM.cpp | 21 ++++++++++--------- .../Dialect/Snitch/IR/QuidditchSnitchOps.td | 11 ++++++++-- .../Snitch/Transforms/LowerForallOp.cpp | 2 +- .../Quidditch/Target/RemoveTrivialLoops.cpp | 4 ++-- ...ter_index.mlir => compute_core_index.mlir} | 2 +- .../Snitch/Transforms/lower-forall.mlir | 2 +- .../tests/Target/remove-trivial-loops.mlir | 2 +- 7 files changed, 26 insertions(+), 18 deletions(-) rename codegen/tests/Conversion/ConvertSnitchToLLVM/{cluster_index.mlir => compute_core_index.mlir} (81%) diff --git a/codegen/compiler/src/Quidditch/Conversion/ConvertSnitchToLLVM.cpp b/codegen/compiler/src/Quidditch/Conversion/ConvertSnitchToLLVM.cpp index 9028e06..10ac9ed 100644 --- a/codegen/compiler/src/Quidditch/Conversion/ConvertSnitchToLLVM.cpp +++ b/codegen/compiler/src/Quidditch/Conversion/ConvertSnitchToLLVM.cpp @@ -482,18 +482,19 @@ struct CallMicrokernelOpLowering : ConvertOpToLLVMPattern { } }; -struct ClusterIndexOpLowering : ConvertOpToLLVMPattern { +struct ComputeCoreIndexOpLowering : ConvertOpToLLVMPattern { - LLVM::LLVMFuncOp clusterIndexFunc; + LLVM::LLVMFuncOp computeCoreIndexFunc; - ClusterIndexOpLowering(LLVM::LLVMFuncOp clusterIndexFunc, - const LLVMTypeConverter &converter) - : ConvertOpToLLVMPattern(converter), clusterIndexFunc(clusterIndexFunc) {} + ComputeCoreIndexOpLowering(LLVM::LLVMFuncOp computeCoreIndexFunc, + const LLVMTypeConverter &converter) + : ConvertOpToLLVMPattern(converter), + computeCoreIndexFunc(computeCoreIndexFunc) {} LogicalResult - matchAndRewrite(ClusterIndexOp op, OpAdaptor adaptor, + matchAndRewrite(ComputeCoreIndexOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOpWithNewOp(op, clusterIndexFunc, + rewriter.replaceOpWithNewOp(op, computeCoreIndexFunc, ValueRange()); return success(); } @@ -525,17 +526,17 @@ void quidditch::populateSnitchToLLVMConversionPatterns( i32, ArrayRef{ptrType, ptrType, sizeT, sizeT, sizeT, sizeT})); dmaStart2D->setAttr("hal.import.bitcode", builder.getUnitAttr()); - auto clusterCoreIndex = builder.create( + auto computeCoreIndex = builder.create( builder.getUnknownLoc(), "snrt_cluster_core_idx", LLVM::LLVMFunctionType::get(i32, ArrayRef{})); - clusterCoreIndex->setAttr("hal.import.bitcode", builder.getUnitAttr()); + computeCoreIndex->setAttr("hal.import.bitcode", builder.getUnitAttr()); patterns.insert(typeConverter); patterns.insert(dmaStart1D, typeConverter); patterns.insert(dmaStart2D, typeConverter); - patterns.insert(clusterCoreIndex, typeConverter); + patterns.insert(computeCoreIndex, typeConverter); patterns.insert(SymbolTable(moduleOp), typeConverter); } diff --git a/codegen/compiler/src/Quidditch/Dialect/Snitch/IR/QuidditchSnitchOps.td b/codegen/compiler/src/Quidditch/Dialect/Snitch/IR/QuidditchSnitchOps.td index dfe49b3..0537f23 100644 --- a/codegen/compiler/src/Quidditch/Dialect/Snitch/IR/QuidditchSnitchOps.td +++ b/codegen/compiler/src/Quidditch/Dialect/Snitch/IR/QuidditchSnitchOps.td @@ -235,8 +235,15 @@ def QuidditchSnitch_BarrierOp : QuidditchSnitch_Op<"barrier"> { }]; } -def QuidditchSnitch_ClusterIndexOp - : QuidditchSnitch_Op<"cluster_index", [Pure]> { +def QuidditchSnitch_ComputeCoreIndexOp + : QuidditchSnitch_Op<"compute_core_index", [Pure]> { + + let description = [{ + Returns the index of the compute core within a given cluster. + This is guaranteed to return a number between 0 and exclusive + `compute_cores` where `compute_cores` is an `IntegerAttr` in + the surrounding `ExecutableTargetAttr`. + }]; let results = (outs Index:$result); diff --git a/codegen/compiler/src/Quidditch/Dialect/Snitch/Transforms/LowerForallOp.cpp b/codegen/compiler/src/Quidditch/Dialect/Snitch/Transforms/LowerForallOp.cpp index 52143c9..90f1399 100644 --- a/codegen/compiler/src/Quidditch/Dialect/Snitch/Transforms/LowerForallOp.cpp +++ b/codegen/compiler/src/Quidditch/Dialect/Snitch/Transforms/LowerForallOp.cpp @@ -44,7 +44,7 @@ void LowerForallOp::runOnOperation() { forallOp.getTerminator().erase(); OpBuilder builder(forallOp); - Value id = builder.create(forallOp.getLoc()); + Value id = builder.create(forallOp.getLoc()); Value lb = forallOp.getLowerBound(builder).front(); Value ub = forallOp.getUpperBound(builder).front(); diff --git a/codegen/compiler/src/Quidditch/Target/RemoveTrivialLoops.cpp b/codegen/compiler/src/Quidditch/Target/RemoveTrivialLoops.cpp index f06c9f0..a238bff 100644 --- a/codegen/compiler/src/Quidditch/Target/RemoveTrivialLoops.cpp +++ b/codegen/compiler/src/Quidditch/Target/RemoveTrivialLoops.cpp @@ -30,8 +30,8 @@ static std::optional> getWorkgroupRange(Value processorValue, std::optional numComputeCores, ArrayRef workgroupCount) { - if (auto idOp = - processorValue.getDefiningOp()) { + if (auto idOp = processorValue + .getDefiningOp()) { if (!numComputeCores) return std::nullopt; diff --git a/codegen/tests/Conversion/ConvertSnitchToLLVM/cluster_index.mlir b/codegen/tests/Conversion/ConvertSnitchToLLVM/compute_core_index.mlir similarity index 81% rename from codegen/tests/Conversion/ConvertSnitchToLLVM/cluster_index.mlir rename to codegen/tests/Conversion/ConvertSnitchToLLVM/compute_core_index.mlir index 45d6341..ec84b21 100644 --- a/codegen/tests/Conversion/ConvertSnitchToLLVM/cluster_index.mlir +++ b/codegen/tests/Conversion/ConvertSnitchToLLVM/compute_core_index.mlir @@ -3,6 +3,6 @@ // CHECK-LABEL: @test func.func private @test() -> index { // CHECK: call @snrt_cluster_core_idx() - %0 = quidditch_snitch.cluster_index + %0 = quidditch_snitch.compute_core_index return %0 : index } diff --git a/codegen/tests/Dialect/Snitch/Transforms/lower-forall.mlir b/codegen/tests/Dialect/Snitch/Transforms/lower-forall.mlir index 2291c6a..a2c20c9 100644 --- a/codegen/tests/Dialect/Snitch/Transforms/lower-forall.mlir +++ b/codegen/tests/Dialect/Snitch/Transforms/lower-forall.mlir @@ -13,7 +13,7 @@ hal.executable @test { // CHECK-SAME: %[[UB:[[:alnum:]]+]] // CHECK-SAME: %[[STEP:[[:alnum:]]+]] func.func @test(%lb : index, %ub : index, %step : index) { - // CHECK: %[[ID:.*]] = quidditch_snitch.cluster_index + // CHECK: %[[ID:.*]] = quidditch_snitch.compute_core_index // CHECK: %[[NLB:.*]] = affine.apply #[[$MAP1]](%[[LB]], %[[ID]], %[[STEP]]) // CHECK: %[[NSTEP:.*]] = affine.apply #[[$MAP2]](%[[STEP]]) // CHECK: scf.for %[[IV:.*]] = %[[NLB]] to %[[UB]] step %[[NSTEP]] diff --git a/codegen/tests/Target/remove-trivial-loops.mlir b/codegen/tests/Target/remove-trivial-loops.mlir index 594ae12..1d541a6 100644 --- a/codegen/tests/Target/remove-trivial-loops.mlir +++ b/codegen/tests/Target/remove-trivial-loops.mlir @@ -7,7 +7,7 @@ hal.executable @test { builtin.module { // CHECK-LABEL: func @test func.func @test() { - %0 = quidditch_snitch.cluster_index + %0 = quidditch_snitch.compute_core_index %1 = arith.constant 8 : index // CHECK-NOT: scf.for scf.for %arg3 = %0 to %1 step %1 {