Skip to content

Commit

Permalink
Merge branch 'Xilinx:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jackl-xilinx authored Apr 9, 2024
2 parents 916cd2c + 0774644 commit 5198394
Show file tree
Hide file tree
Showing 141 changed files with 184 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ endif()
# Last because each of these has its own CMakeLists.txt which reloads/re-finds LLVM, thus resettings globals.
add_subdirectory(reference_designs)
add_subdirectory(test)
add_subdirectory(tutorials)
add_subdirectory(mlir_tutorials)
add_subdirectory(cmake/modules)

get_filename_component(COMPILER_DIRECTORY ${CMAKE_CXX_COMPILER} DIRECTORY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GenericOp;
} // namespace linalg
} // namespace mlir

#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"

#define GET_OP_CLASSES
#include "aie/Dialect/AIEVec/TransformOps/AIEVecTransformOps.h.inc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
include "mlir/Dialect/PDL/IR/PDLTypes.td"
include "mlir/Dialect/Transform/IR/TransformAttrs.td"
include "mlir/Dialect/Transform/IR/TransformDialect.td"
include "mlir/Dialect/Transform/IR/TransformInterfaces.td"
include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
include "mlir/Dialect/Transform/IR/TransformTypes.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpBase.td"
Expand Down
40 changes: 29 additions & 11 deletions lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,34 @@ struct AIEObjectFifoStatefulTransformPass
std::vector<std::vector<int>> &dependencies, Value base,
int64_t step, bool inLoop) {
std::vector<Operation *> duplicatedOperations; // operations in current
// Recursive function to replace operands, uses recursion to handle nested
// loop structures.
std::function<void(Operation *, unsigned &, unsigned)> replaceOpsNested =
[&](Operation *op, unsigned &opIndex,
unsigned numDuplications) -> void {
if (auto loopOp = dyn_cast<scf::ForOp>(op)) {
Block *body = loopOp.getBody();
auto withoutTerminator = --body->end();
// NOTE(jornt): This only handles the cases where the nested scf::for is
// located at the start of the body. This should be the most common
// case, but is not fully generic.
if (auto nestedLoop = dyn_cast<scf::ForOp>(body->begin())) {
opIndex++;
replaceOperands(builder, nestedLoop, opIndex, base, step, inLoop,
numDuplications, dependencies, duplicatedOperations);
replaceOpsNested(nestedLoop, opIndex, numDuplications);
} else {
for (auto loopBodyOp = body->begin(); loopBodyOp != withoutTerminator;
++loopBodyOp) {
opIndex++;
replaceOperands(builder, &*loopBodyOp, opIndex, base, step, inLoop,
numDuplications, dependencies,
duplicatedOperations);
}
}
}
};

// duplication iteration
for (int i = 0; i < numDuplications; i++) {
duplicatedOperations.clear();
Expand All @@ -858,17 +886,7 @@ struct AIEObjectFifoStatefulTransformPass
replaceOperands(builder, clone, opIndex, base, step, inLoop, i,
dependencies, duplicatedOperations);
builder.insert(clone);

if (auto nestedLoop = dyn_cast<scf::ForOp>(clone)) {
Block *body = nestedLoop.getBody();
auto withoutTerminator = --body->end();
for (auto loopOp = body->begin(); loopOp != withoutTerminator;
++loopOp) {
opIndex++;
replaceOperands(builder, &*loopOp, opIndex, base, step, inLoop, i,
dependencies, duplicatedOperations);
}
}
replaceOpsNested(clone, opIndex, i);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/AIEVec/TransformOps/AIEVecTransformOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
#include "mlir/Dialect/Transform/IR/TransformTypes.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
#include "mlir/Dialect/Transform/Utils/Utils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) {
mlir_aie_release_ddr_test_buffer_in_lock(_xaie, 1, 0);
mlir_aie_release_ddr_test_buffer_out_lock(_xaie, 1, 0);

if(mlir_aie_acquire_ddr_test_buffer_out_lock(_xaie, 0, 1000) == XAIE_OK)
if (mlir_aie_acquire_ddr_test_buffer_out_lock(_xaie, 0, 1000) == XAIE_OK)
printf("Acquired ddr output lock(0). Output shim dma done.\n");
else
printf("Timed out (1000) while trying to acquire ddr output lock (0).\n");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 22 additions & 19 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@

include(AddMLIRPython)

execute_process(
COMMAND_ERROR_IS_FATAL ANY
COMMAND ${Python3_EXECUTABLE} -m
pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT
)
if(NOT CMD_ERROR EQUAL "0")
message(FATAL_ERROR "pip install requirements.txt failed:" ${CMD_OUTPUT})
endif()
option(AIE_REINSTALL_PYTHON_ENV_PACKAGES "pip install python requirements" ON)
if (AIE_REINSTALL_PYTHON_ENV_PACKAGES)
execute_process(
COMMAND_ERROR_IS_FATAL ANY
COMMAND ${Python3_EXECUTABLE} -m
pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT
)
if(NOT CMD_ERROR EQUAL "0")
message(FATAL_ERROR "pip install requirements.txt failed:" ${CMD_OUTPUT})
endif()

execute_process(
COMMAND_ERROR_IS_FATAL ANY
COMMAND ${Python3_EXECUTABLE} -m
pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/aie-python-extras-req.txt --force-reinstall
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT
)
if(NOT CMD_ERROR EQUAL "0")
message(FATAL_ERROR "pip install aie-python-extras-req.txt failed:" ${CMD_OUTPUT})
execute_process(
COMMAND_ERROR_IS_FATAL ANY
COMMAND ${Python3_EXECUTABLE} -m
pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/aie-python-extras-req.txt --force-reinstall
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT
)
if(NOT CMD_ERROR EQUAL "0")
message(FATAL_ERROR "pip install aie-python-extras-req.txt failed:" ${CMD_OUTPUT})
endif()
endif()

# The AIE copy of the MLIR bindings is in the `aie.mlir` namespace.
Expand Down
126 changes: 126 additions & 0 deletions test/objectFifo-stateful-transform/nested_loop_test.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//===- nested_loop_test.mlir -----------------------------------------*- MLIR -*-===//
//
// Copyright (C) 2024, Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Date: April 3rd 2024
//
//===----------------------------------------------------------------------===//

// RUN: aie-opt --aie-objectFifo-stateful-transform %s | FileCheck %s

// CHECK-LABEL: aie.device(ipu)
// CHECK: scf.for
// CHECK: {
// CHECK: aie.use_lock
// CHECK: memref.reinterpret_cast
// CHECK: aie.use_lock
// CHECK: memref.reinterpret_cast
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: memref.load
// CHECK: memref.load
// CHECK: memref.load
// CHECK: arith.muli
// CHECK: arith.addi
// CHECK: memref.store
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: aie.use_lock
// CHECK: aie.use_lock
// CHECK: aie.use_lock
// CHECK: memref.reinterpret_cast
// CHECK: aie.use_lock
// CHECK: memref.reinterpret_cast
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: scf.for
// CHECK: {
// CHECK: memref.load
// CHECK: memref.load
// CHECK: memref.load
// CHECK: arith.muli
// CHECK: arith.addi
// CHECK: memref.store
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: }
// CHECK: aie.use_lock
// CHECK: aie.use_lock
// CHECK: }

aie.device(ipu) {
%tile_0_1 = aie.tile(0, 1)
%tile_1_2 = aie.tile(1, 2)
%tile_0_2 = aie.tile(0, 2)
aie.objectfifo @in2(%tile_0_1, {%tile_0_2, %tile_1_2}, 4 : i32) : !aie.objectfifo<memref<32x64xi32, 1>>
aie.objectfifo @in7(%tile_0_1, {%tile_1_2}, 4 : i32) : !aie.objectfifo<memref<64x32xi32, 1>>
aie.objectfifo @in8(%tile_1_2, {%tile_0_1}, 4 : i32) : !aie.objectfifo<memref<32x32xi32, 1>>
%core_1_2 = aie.core(%tile_1_2) {
%c8 = arith.constant 8 : index
%c1 = arith.constant 1 : index
%c4 = arith.constant 4 : index
%c0 = arith.constant 0 : index
%c64 = arith.constant 64 : index
%c960 = arith.constant 960 : index
%0 = aie.objectfifo.acquire @in8(Produce, 1) : !aie.objectfifosubview<memref<32x32xi32, 1>>
%1 = aie.objectfifo.subview.access %0[0] : !aie.objectfifosubview<memref<32x32xi32, 1>> -> memref<32x32xi32, 1>
%reinterpret_cast = memref.reinterpret_cast %1 to offset: [0], sizes: [4, 8, 4, 8], strides: [256, 32, 8, 1] : memref<32x32xi32, 1> to memref<4x8x4x8xi32, 1>
aie.objectfifo.release @in2(Consume, 1)
aie.objectfifo.release @in7(Consume, 1)
scf.for %arg0 = %c64 to %c960 step %c64 {
%10 = aie.objectfifo.acquire @in2(Consume, 1) : !aie.objectfifosubview<memref<32x64xi32, 1>>
%11 = aie.objectfifo.subview.access %10[0] : !aie.objectfifosubview<memref<32x64xi32, 1>> -> memref<32x64xi32, 1>
%reinterpret_cast_4 = memref.reinterpret_cast %11 to offset: [0], sizes: [8, 8, 4, 8], strides: [256, 32, 8, 1] : memref<32x64xi32, 1> to memref<8x8x4x8xi32, 1>
%12 = aie.objectfifo.acquire @in7(Consume, 1) : !aie.objectfifosubview<memref<64x32xi32, 1>>
%13 = aie.objectfifo.subview.access %12[0] : !aie.objectfifosubview<memref<64x32xi32, 1>> -> memref<64x32xi32, 1>
%reinterpret_cast_5 = memref.reinterpret_cast %13 to offset: [0], sizes: [4, 8, 8, 8], strides: [512, 64, 8, 1] : memref<64x32xi32, 1> to memref<4x8x8x8xi32, 1>
scf.for %arg1 = %c0 to %c8 step %c1 {
scf.for %arg2 = %c0 to %c4 step %c1 {
scf.for %arg3 = %c0 to %c8 step %c1 {
scf.for %arg4 = %c0 to %c4 step %c1 {
scf.for %arg5 = %c0 to %c8 step %c1 {
scf.for %arg6 = %c0 to %c8 step %c1 {
%14 = memref.load %reinterpret_cast_4[%arg3, %arg1, %arg4, %arg6] : memref<8x8x4x8xi32, 1>
%15 = memref.load %reinterpret_cast_5[%arg2, %arg3, %arg6, %arg5] : memref<4x8x8x8xi32, 1>
%16 = memref.load %reinterpret_cast[%arg2, %arg1, %arg4, %arg5] : memref<4x8x4x8xi32, 1>
%17 = arith.muli %14, %15 : i32
%18 = arith.addi %16, %17 : i32
memref.store %18, %reinterpret_cast[%arg2, %arg1, %arg4, %arg5] : memref<4x8x4x8xi32, 1>
}
}
}
}
}
}
aie.objectfifo.release @in2(Consume, 1)
aie.objectfifo.release @in7(Consume, 1)
}
aie.end
}
}
4 changes: 2 additions & 2 deletions utils/clone-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
##===----------------------------------------------------------------------===##

# The LLVM commit to use.
LLVM_PROJECT_COMMIT=60dda1fc6ef82c5d7fe54000e6c0a21e7bafdeb5
DATETIME=2024031100
LLVM_PROJECT_COMMIT=d022f6b8ff94bb13d12d39f23a3c3e7836e90756
DATETIME=2024040913
WHEEL_VERSION=19.0.0.$DATETIME+${LLVM_PROJECT_COMMIT:0:8}

############################################################################################
Expand Down

0 comments on commit 5198394

Please sign in to comment.