From 672e5b3e40f45467cab3f7c1bbca6536ee9336f7 Mon Sep 17 00:00:00 2001 From: James Newling Date: Fri, 10 Jan 2025 15:13:50 -0800 Subject: [PATCH] squash commits --- .../AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp | 52 +++++++++ .../AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td | 5 +- .../iree-amd-aie/IR/test/roundtrip.mlir | 102 ++++++++++++++++++ 3 files changed, 157 insertions(+), 2 deletions(-) diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp index 09f890879..bb10d0e39 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp @@ -625,6 +625,58 @@ LogicalObjectFifoFromBuffersOp::replaceWithNewTiles( // AMDAIE_LogicalObjectFifoFromMemrefOp //===----------------------------------------------------------------------===// +void LogicalObjectFifoFromMemrefOp::getAsmResultNames( + function_ref setNameFn) { + // 'lof' for 'logical object fifo' + constexpr const char *const name = "lof"; + + auto tiles = getTiles(); + + if (tiles.empty()) { + setNameFn(getResult(), name); + return; + } + + // Denotes one or more tiles with multiple possible row/column values. + constexpr int64_t multiple{-2}; + constexpr int64_t unset{-1}; + int64_t col{unset}; + int64_t row{unset}; + + for (Value index : tiles) { + TileOp tile = dyn_cast(index.getDefiningOp()); + if (!tile) { + col = multiple; + row = multiple; + } else { + std::optional maybeCol = getConstantIntValue(tile.getCol()); + if (!maybeCol) col = multiple; + if (col >= 0 && maybeCol.value() != col) col = multiple; + if (col == unset) col = maybeCol.value(); + + std::optional maybeRow = getConstantIntValue(tile.getRow()); + if (!maybeRow) row = multiple; + if (row >= 0 && maybeRow.value() != row) row = multiple; + if (row == unset) row = maybeRow.value(); + } + } + + std::ostringstream namestream; + namestream << name << '_'; + + if (col >= 0) { + namestream << col; + } else { + namestream << 'c'; + } + if (row >= 0) { + namestream << '_' << row; + } else { + namestream << '_' << 'r'; + } + setNameFn(getResult(), namestream.str()); +} + /// Build with an array of static tile locations. void LogicalObjectFifoFromMemrefOp::build( OpBuilder &b, mlir::OperationState &result, Value memref, diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td index 535b5e0a2..efca31ebc 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td @@ -1279,8 +1279,9 @@ def AMDAIE_LogicalObjectFifoFromBuffersOp } def AMDAIE_LogicalObjectFifoFromMemrefOp - : AMDAIE_Op<"logicalobjectfifo.from_memref", - [DeclareOpInterfaceMethods, + : AMDAIE_Op<"logicalobjectfifo.from_memref", [ + DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods, Pure]> { let summary = "Create a logical objectFifo from a memref"; let description = [{ diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir index 174dd890b..d22b0700b 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir @@ -523,3 +523,105 @@ func.func @tile_a_b(%i : index) { } return } + +// ----- + +// CHECK-LABEL: func.func @from_memref_known_tiles +func.func @from_memref_known_tiles(%arg0 : memref<8xi32>, %t0 : index) { + %c2 = arith.constant 2: index + %c3 = arith.constant 3 : index + amdaie.workgroup { + %tile_2_3 = amdaie.tile(%c2, %c3) + %tile_3_3 = amdaie.tile(%c3, %c3) + %tile_3_2 = amdaie.tile(%c3, %c2) + %tile_2_2 = amdaie.tile(%c2, %c2) + // logicalobjectfifo without any tiles: + // CHECK: %lof = + %fifo0 = amdaie.logicalobjectfifo.from_memref %arg0, {} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with one known tile: + // CHECK: %lof_2_3 = + %fifo3 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_3} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with two known tiles, in the same column. + // 'r' in the SSA value denotes multiple rows. + // CHECK: %lof_2_r = + %fifo4 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_3, %tile_2_2} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with two known tiles, in the same row. + // 'c' in the SSA value denotes multiple columns. + // CHECK: %lof_c_3 = + %fifo5 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_3, %tile_3_3} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with two known tiles, in different rows and columns: + // CHECK: %lof_c_r = + %fifo6 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_3, %tile_3_2} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with 4 tiles, spanning 2 rows and 2 columns: + // CHECK: %lof_c_r_0 = + %fifo7 = amdaie.logicalobjectfifo.from_memref %arg0, + {%tile_2_3, %tile_3_3, %tile_3_2, %tile_2_2} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + amdaie.controlcode { + amdaie.end + } + } + return +} + +// ----- + +// CHECK-LABEL: func.func @from_memref_unknown_row +func.func @from_memref_unknown_row(%arg0 : memref<8xi32>, %t0 : index) { + %c2 = arith.constant 2: index + amdaie.workgroup { + %tile_2_u = amdaie.tile(%c2, %t0) + // CHECK: %lof_2_r = + %fifo = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_u} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + amdaie.controlcode { + amdaie.end + } + } + return +} + +// ----- + +// CHECK-LABEL: func.func @from_memref_unknown_column +func.func @from_memref_unknown_column(%arg0 : memref<8xi32>, %t0 : index) { + %c3 = arith.constant 3 : index + amdaie.workgroup { + %tile_u_3 = amdaie.tile(%t0, %c3) + // CHECK: %lof_c_3 = + %fifo = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_u_3} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + amdaie.controlcode { + amdaie.end + } + } + return +} + +// ----- + +// CHECK-LABEL: func.func @from_memref_unknown_row_column +func.func @from_memref_unknown_row_column(%arg0 : memref<8xi32>, %t0 : index) { + amdaie.workgroup { + %c2 = arith.constant 2: index + %tile_2_2 = amdaie.tile(%c2, %c2) + %tile_u_u = amdaie.tile(%t0, %t0) + // logicalobjectfifo with a single tile with unknown row and column: + // CHECK: %lof_c_r = + %fifo1 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_u_u} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + // logicalobjectfifo with one unknown tile, and one known tile: + // CHECK: %lof_c_r_0 = + %fifo2 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_2_2, %tile_u_u} : + memref<8xi32> -> !amdaie.logicalobjectfifo> + amdaie.controlcode { + amdaie.end + } + } + return +}