Skip to content

Commit f5d34a8

Browse files
Merge branch 'main' into nm_xclbin_merge
2 parents aaec27e + 5241ec9 commit f5d34a8

File tree

13 files changed

+1249
-512
lines changed

13 files changed

+1249
-512
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
run: |
104104
python3 -m venv .venv
105105
source .venv/bin/activate
106-
pip install https://github.com/Xilinx/mlir-aie/releases/download/latest-wheels/mlir_aie-0.0.1.2024060222+6f70bfe-py3-none-manylinux_2_35_x86_64.whl
106+
pip install https://github.com/Xilinx/mlir-aie/releases/download/latest-wheels/mlir_aie-0.0.1.2024061222+3ac9566-py3-none-manylinux_2_35_x86_64.whl
107107
108108
pip install -r tests/matmul/requirements.txt
109109

build_tools/ci/run_matmul_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ run_matmul_test \
638638
--lhs_rhs_type "bf16" \
639639
--acc_type "f32" \
640640
--m "64" --n "64" --k "128" \
641-
--expect_compile_failure "1"
641+
--num_repeat_runs "0"
642642

643643
run_matmul_test \
644644
--name_prefix "packPeelLarge" \

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEAttrs.td

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ def LogicalObjectFifoPort: I32EnumAttr<"LogicalObjectFifoPort",
4141
let cppNamespace = "mlir::iree_compiler::AMDAIE";
4242
}
4343

44+
def MemoryAccess: I32EnumAttr<"MemoryAccess",
45+
"The memory access type",
46+
[
47+
I32EnumAttrCase<"None", 0>,
48+
I32EnumAttrCase<"Read", 1>,
49+
I32EnumAttrCase<"Write", 2>,
50+
I32EnumAttrCase<"Any", 3>,
51+
]
52+
> {
53+
let cppNamespace = "mlir::iree_compiler::AMDAIE";
54+
}
55+
4456
def AMDAIE_MemSpace_Global : I32EnumAttrCase<"Global", 0>;
4557
def AMDAIE_MemSpace_Shared : I32EnumAttrCase<"Shared", 1>;
4658
def AMDAIE_MemSpace_Local : I32EnumAttrCase<"Local", 2>;

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp

+62-13
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ LogicalObjectFifoFromMemrefOp CircularDmaCpyNdOp::getTargetObjectFifo() {
328328
return dyn_cast<LogicalObjectFifoFromMemrefOp>(getTarget().getDefiningOp());
329329
};
330330

331+
//===----------------------------------------------------------------------===//
332+
// AMDAIE_LogicalObjectFifoAccessOp
333+
//===----------------------------------------------------------------------===//
334+
335+
void LogicalObjectFifoAccessOp::build(OpBuilder &b,
336+
mlir::OperationState &result, Value input,
337+
MemoryAccess accessType) {
338+
auto type = llvm::cast<LogicalObjectFifoType>(input.getType());
339+
build(b, result, type.getElementType(), input, accessType);
340+
}
341+
342+
LogicalObjectFifoFromMemrefOp
343+
LogicalObjectFifoAccessOp::getLogicalObjectFifo() {
344+
return dyn_cast<LogicalObjectFifoFromMemrefOp>(getInput().getDefiningOp());
345+
};
346+
331347
//===----------------------------------------------------------------------===//
332348
// AMDAIE_LogicalObjectFifoAcquire
333349
//===----------------------------------------------------------------------===//
@@ -341,6 +357,26 @@ void LogicalObjectFifoAcquire::build(OpBuilder &b, mlir::OperationState &result,
341357
// AMDAIE_LogicalObjectFifoFromMemrefOp
342358
//===----------------------------------------------------------------------===//
343359

360+
/// Build with an array of static tile locations.
361+
void LogicalObjectFifoFromMemrefOp::build(
362+
OpBuilder &b, mlir::OperationState &result, Value memref,
363+
ArrayRef<std::pair<int64_t, int64_t>> tileLocations) {
364+
SmallVector<Value> tiles;
365+
tiles.reserve(tileLocations.size());
366+
for (auto [column, row] : tileLocations) {
367+
auto colIndex = b.create<arith::ConstantIndexOp>(b.getUnknownLoc(), column);
368+
auto rowIndex = b.create<arith::ConstantIndexOp>(b.getUnknownLoc(), row);
369+
auto tileOp =
370+
b.create<AMDAIE::TileOp>(b.getUnknownLoc(), colIndex, rowIndex);
371+
tiles.push_back(tileOp.getResult());
372+
}
373+
// For deterministic order.
374+
llvm::sort(tiles.begin(), tiles.end(),
375+
TileOp::tileValueColumnAndRowComparator);
376+
auto type = LogicalObjectFifoType::get(cast<MemRefType>(memref.getType()));
377+
build(b, result, type, memref, tiles);
378+
}
379+
344380
LogicalResult LogicalObjectFifoFromMemrefOp::canonicalize(
345381
LogicalObjectFifoFromMemrefOp logicalObjectFifo,
346382
PatternRewriter &rewriter) {
@@ -349,23 +385,19 @@ LogicalResult LogicalObjectFifoFromMemrefOp::canonicalize(
349385
return success();
350386
}
351387

352-
auto comparator = [](Value a, Value b) -> bool {
353-
TileOp tileA = dyn_cast<TileOp>(a.getDefiningOp());
354-
TileOp tileB = dyn_cast<TileOp>(b.getDefiningOp());
355-
int64_t colA = getConstantIntValue(tileA.getCol()).value();
356-
int64_t rowA = getConstantIntValue(tileA.getRow()).value();
357-
int64_t colB = getConstantIntValue(tileB.getCol()).value();
358-
int64_t rowB = getConstantIntValue(tileB.getRow()).value();
359-
if (colA == colB) return rowA < rowB;
360-
return colA < colB;
361-
};
362388
SmallVector<Value> tiles = logicalObjectFifo.getTiles();
363-
if (llvm::is_sorted(tiles, comparator)) {
389+
if (llvm::is_sorted(tiles, TileOp::tileValueColumnAndRowComparator)) {
390+
// Still erase duplicates.
391+
tiles.erase(std::unique(tiles.begin(), tiles.end()), tiles.end());
364392
return success();
365393
}
366394

367-
// If tiles are not sorted, sort them and replace the logical objectfifo
368-
llvm::sort(tiles.begin(), tiles.end(), comparator);
395+
// If tiles are not sorted, sort them, erase duplicates and replace the
396+
// logical objectfifo.
397+
llvm::sort(tiles.begin(), tiles.end(),
398+
TileOp::tileValueColumnAndRowComparator);
399+
tiles.erase(std::unique(tiles.begin(), tiles.end()), tiles.end());
400+
369401
rewriter.replaceOpWithNewOp<AMDAIE::LogicalObjectFifoFromMemrefOp>(
370402
logicalObjectFifo,
371403
llvm::cast<LogicalObjectFifoType>(
@@ -532,6 +564,23 @@ bool TileOp::hasStaticLocation() {
532564
return getConstantIntValue(getCol()) && getConstantIntValue(getRow());
533565
}
534566

567+
bool TileOp::tileColumnComparator(AMDAIE::TileOp &a, AMDAIE::TileOp &b) {
568+
int64_t colA = getConstantIntValue(a.getCol()).value();
569+
int64_t colB = getConstantIntValue(b.getCol()).value();
570+
return colA < colB;
571+
}
572+
573+
bool TileOp::tileValueColumnAndRowComparator(Value a, Value b) {
574+
TileOp tileA = dyn_cast<AMDAIE::TileOp>(a.getDefiningOp());
575+
TileOp tileB = dyn_cast<AMDAIE::TileOp>(b.getDefiningOp());
576+
int64_t colA = getConstantIntValue(tileA.getCol()).value();
577+
int64_t rowA = getConstantIntValue(tileA.getRow()).value();
578+
int64_t colB = getConstantIntValue(tileB.getCol()).value();
579+
int64_t rowB = getConstantIntValue(tileB.getRow()).value();
580+
if (colA == colB) return rowA < rowB;
581+
return colA < colB;
582+
};
583+
535584
//===----------------------------------------------------------------------===//
536585
// AMDAIE_WorkgroupOp
537586
//===----------------------------------------------------------------------===//

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td

+58-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def AMDAIE_TileOp: AMDAIE_Op<"tile", [
110110

111111
let extraClassDeclaration = [{
112112
bool hasStaticLocation();
113+
// Comparator for `amdaie.tile` based on column index.
114+
static bool tileColumnComparator(AMDAIE::TileOp &a, AMDAIE::TileOp &b);
115+
// Comparator for `amdaie.tile` values based on column index first and then
116+
// row index.
117+
static bool tileValueColumnAndRowComparator(Value a, Value b);
113118
}];
114119
}
115120

@@ -319,6 +324,53 @@ def AMDAIE_NpuDmaWaitOp: AMDAIE_Op<"npu.dma_wait", []> {
319324
// IREE AMDAIE LogicalObjectFifo Ops
320325
//===----------------------------------------------------------------------===//
321326

327+
def AMDAIE_LogicalObjectFifoAccessOp : AMDAIE_Op<"logicalobjectfifo.access"> {
328+
let summary = "Operation to access the encapsulated memref from a logical"
329+
"objectFifo.";
330+
let description = [{
331+
Returns the encapsulated memref from a logical objectFifo. This is meant to
332+
be used within `amdaie.core` operations to access and operate on the memref.
333+
Has a memory `access_type` argument that indicates the type of access being
334+
done. This can be used to generate a correct (semaphore) synchronization
335+
scheme to access the logical objectFifo's content.
336+
337+
Example:
338+
```mlir
339+
%tile = amdaie.tile(%c1, %c3)
340+
%alloc = memref.alloc() : memref<8x16xi32, 2>
341+
%0 = amdaie.logicalobjectfifo.from_memref %alloc, {%tile} : memref<8x16xi32, 2>
342+
-> !amdaie.logicalobjectfifo<memref<8x16xi32, 2>>
343+
%core = amdaie.core(%tile) {
344+
%1 = amdaie.logicalobjectfifo.access(%0, Read) :
345+
!amdaie.logicalobjectfifo<memref<8x16xi32, 2>> -> memref<8x16xi32, 2>
346+
```
347+
}];
348+
349+
let arguments = (
350+
ins AnyAMDAIELogicalObjectFifoType:$input,
351+
MemoryAccess:$access_type
352+
);
353+
354+
let results = (outs AnyMemRef:$output);
355+
356+
let assemblyFormat = [{
357+
`(` $input `,` $access_type `)` attr-dict `:` type($input) `->` type($output)
358+
}];
359+
360+
let builders = [
361+
// Build a LogicalObjectFifoAccessOp with a logicalObjectFifo value and access
362+
// type.
363+
OpBuilder<(ins "mlir::Value":$input, "MemoryAccess":$access_type)>
364+
];
365+
366+
let extraClassDeclaration = [{
367+
LogicalObjectFifoFromMemrefOp getLogicalObjectFifo();
368+
}];
369+
370+
// let hasVerifier = 1;
371+
let cppNamespace = "mlir::iree_compiler::AMDAIE";
372+
}
373+
322374
def AMDAIE_LogicalObjectFifoAcquire:
323375
AMDAIE_Op<"logicalobjectfifo.acquire", []> {
324376
let summary = "Semaphore operation to acquire objects from a logical"
@@ -430,7 +482,12 @@ def AMDAIE_LogicalObjectFifoFromMemrefOp
430482

431483
// Build a LogicalObjectFifoFromMemrefOp with just a memref value.
432484
let builders = [
433-
OpBuilder<(ins "mlir::Value":$memref)>
485+
OpBuilder<(ins "mlir::Value":$memref)>,
486+
// Build `LogicalObjectFifoFromMemrefOp` with an array of static tile
487+
// locations.
488+
OpBuilder<
489+
(ins "mlir::Value":$memref,
490+
"::llvm::ArrayRef<std::pair<int64_t, int64_t>>":$tileLocations)>
434491
];
435492

436493
let extraClassDeclaration = [{

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ func.func @dma_cpy_nd_mixed(%arg0: !amdaie.logicalobjectfifo<memref<1x1x8x16xi32
116116

117117
// -----
118118

119+
// CHECK-LABEL: func.func @logicalobjectfifo_access
120+
// CHECK: amdaie.logicalobjectfifo.access
121+
func.func @logicalobjectfifo_access(%arg0: !amdaie.logicalobjectfifo<memref<1x1x8x16xi32, 2>>) {
122+
%0 = amdaie.logicalobjectfifo.access(%arg0, Write) : !amdaie.logicalobjectfifo<memref<1x1x8x16xi32, 2>> -> memref<1x1x8x16xi32, 2 : i32>
123+
return
124+
}
125+
126+
// -----
127+
119128
// CHECK-LABEL: func.func @logicalobjectfifo_acquire
120129
// CHECK: %[[DMA:.+]] = amdaie.dma_cpy_nd
121130
// CHECK: amdaie.logicalobjectfifo.acquire

0 commit comments

Comments
 (0)