From 9aa42ab8dcec71fcf22c6fcc5296124f8b3742c4 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 7 Aug 2024 01:09:03 -0500 Subject: [PATCH] remove mlir-aie submodule --- .github/workflows/ci.yml | 1 + .gitmodules | 4 - build_tools/ci/build_test_cpp.sh | 1 + compiler/plugins/target/AMD-AIE/aie/AIE.td | 2 +- .../plugins/target/AMD-AIE/aie/AIEAttrs.td | 2 +- .../plugins/target/AMD-AIE/aie/AIEDialect.cpp | 257 +++++++++++++++- .../plugins/target/AMD-AIE/aie/AIEDialect.h | 276 ++---------------- .../plugins/target/AMD-AIE/aie/AIEEnums.h | 2 +- compiler/plugins/target/AMD-AIE/aie/AIEOps.td | 35 +-- .../plugins/target/AMD-AIE/aie/AIETypes.td | 2 +- compiler/plugins/target/AMD-AIE/aie/AIEX.td | 30 +- .../target/AMD-AIE/aie/AMDAIEXToStandard.cpp | 1 - .../iree-amd-aie/Target/AMDAIETargetBCF.cpp | 7 +- .../Target/AMDAIETargetLdScript.cpp | 6 +- experimental/delegate/README.md | 2 - iree_compiler_plugin.cmake | 1 - iree_runtime_plugin.cmake | 1 - .../aie_runtime/test/CMakeLists.txt | 6 - .../aie_runtime/test/cdo/CMakeLists.txt | 5 - third_party/mlir-aie | 1 - 20 files changed, 309 insertions(+), 333 deletions(-) delete mode 160000 third_party/mlir-aie diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 546bb6b3a..26d5625c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,7 @@ jobs: with: path: ${{ env.CACHE_DIR }} key: linux-build-test-cpp-asserts-manylinux-v2-${{ github.sha }} + test_linux: runs-on: amd7940hs needs: build_test_linux diff --git a/.gitmodules b/.gitmodules index 3d0b202f2..a4b6a7412 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,10 +6,6 @@ path = third_party/mlir-air url = https://github.com/nod-ai/mlir-air.git shallow = true -[submodule "third_party/mlir-aie"] - path = third_party/mlir-aie - url = https://github.com/nod-ai/mlir-aie.git - shallow = true [submodule "third_party/aie-rt"] path = third_party/aie-rt url = https://github.com/Xilinx/aie-rt.git diff --git a/build_tools/ci/build_test_cpp.sh b/build_tools/ci/build_test_cpp.sh index 753bcd3cf..d462da28d 100644 --- a/build_tools/ci/build_test_cpp.sh +++ b/build_tools/ci/build_test_cpp.sh @@ -7,6 +7,7 @@ repo_root="$(cd $this_dir/../.. && pwd)" iree_dir="$(cd $repo_root/../iree && pwd)" build_dir="$repo_root/iree-build" install_dir="$repo_root/iree-install" +rm -rf "$build_dir" "$install_dir" mkdir -p "$build_dir" build_dir="$(cd $build_dir && pwd)" cache_dir="${cache_dir:-}" diff --git a/compiler/plugins/target/AMD-AIE/aie/AIE.td b/compiler/plugins/target/AMD-AIE/aie/AIE.td index 9b674418f..94f3c686f 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIE.td +++ b/compiler/plugins/target/AMD-AIE/aie/AIE.td @@ -16,4 +16,4 @@ def AIE_Dialect : Dialect { let useDefaultAttributePrinterParser = 1; } -#endif // AIE_BASE \ No newline at end of file +#endif // AIE_BASE diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEAttrs.td b/compiler/plugins/target/AMD-AIE/aie/AIEAttrs.td index ebcfcad18..9d309dbdf 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEAttrs.td +++ b/compiler/plugins/target/AMD-AIE/aie/AIEAttrs.td @@ -82,4 +82,4 @@ def BDPadLayoutArrayAttr : ArrayOfAttr< /*eltName*/BDPadLayoutAttr.cppClassName >; -#endif // AIE_ATTRS \ No newline at end of file +#endif // AIE_ATTRS diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEDialect.cpp b/compiler/plugins/target/AMD-AIE/aie/AIEDialect.cpp index 1d5cea379..89beea625 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEDialect.cpp +++ b/compiler/plugins/target/AMD-AIE/aie/AIEDialect.cpp @@ -19,6 +19,15 @@ using namespace xilinx::AIE; #include "aie/AIEDialect.cpp.inc" namespace xilinx::AIE { +std::optional symbolizeAIEDevice( + uint32_t d) { + return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d); +} + +std::optional symbolizeAIEDevice( + llvm::StringRef d) { + return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d); +} namespace detail { struct AIEObjectFifoTypeStorage : TypeStorage { @@ -41,7 +50,6 @@ AIEObjectFifoType AIEObjectFifoType::get(MemRefType elementType) { } mlir::MemRefType AIEObjectFifoType::getElementType() { - // 'getImpl' returns a pointer to the internal storage instance. return getImpl()->elementType; } @@ -78,7 +86,6 @@ static OptionalParseResult aieTypeParser(DialectAsmParser &parser, parser.parseGreater()) return failure(); - // Check that the type is a MemRef type. if (!llvm::isa(elementType)) { parser.emitError(typeLoc, "element type for an objectFifo must be " @@ -92,14 +99,9 @@ static OptionalParseResult aieTypeParser(DialectAsmParser &parser, if (name == "objectfifosubview") { if (parser.parseLess()) return failure(); - - // Parse the element type of the struct. MemRefType elementType; - // Parse the current element type. SMLoc typeLoc = parser.getCurrentLocation(); if (parser.parseType(elementType)) return failure(); - - // Check that the type is a MemRefType. if (!llvm::isa(elementType)) { parser.emitError(typeLoc, "element type for a subview must be " @@ -107,13 +109,9 @@ static OptionalParseResult aieTypeParser(DialectAsmParser &parser, << elementType; return failure(); } - - // Parse: `>` if (parser.parseGreater()) return failure(); - return result = AIEObjectFifoSubviewType::get(elementType), success(); } - return {}; } @@ -122,7 +120,6 @@ static ParseResult parse(Type &result, StringRef name, if (OptionalParseResult parseResult = aieTypeParser(parser, name, result); parseResult.has_value()) return parseResult.value(); - parser.emitError(parser.getNameLoc(), "unknown AIE dialect type: \"") << name << "\""; return failure(); @@ -141,7 +138,6 @@ void AIEDialect::printType(Type type, DialectAsmPrinter &printer) const { printer << "objectfifo<"; printer << objectFifoType.getElementType(); printer << '>'; - } else if (llvm::isa(type)) { auto subviewType = llvm::cast(type); printer << "objectfifosubview<"; @@ -150,8 +146,8 @@ void AIEDialect::printType(Type type, DialectAsmPrinter &printer) const { } } -// without this, canonicalize/cse/etc will lift eg constants out of core ops -// causing eg lower-to-aie to fail to converge +/// without this, canonicalize/cse/etc will lift eg constants out of core ops +/// causing eg lower-to-aie to fail to converge struct AIEDialectFoldInterface : DialectFoldInterface { using DialectFoldInterface::DialectFoldInterface; @@ -186,3 +182,234 @@ void AIEDialect::initialize() { // Include implementations for custom attributes #define GET_ATTRDEF_CLASSES #include "aie/AIEAttrs.cpp.inc" + +namespace xilinx::AIE { + +mlir::ParseResult parseObjectFifoProducerTile( + mlir::OpAsmParser &parser, mlir::OpAsmParser::UnresolvedOperand &operand, + BDDimLayoutArrayAttr &dimensions) { + std::vector emptyDims = {}; + if (parser.parseOperand(operand)) return mlir::failure(); + if (succeeded(parser.parseOptionalKeyword("toStream"))) { + if (parser.parseCustomAttributeWithFallback( + dimensions)) { + return mlir::failure(); + } + } else { + dimensions = BDDimLayoutArrayAttr::get(parser.getContext(), + llvm::ArrayRef(emptyDims)); + } + return mlir::success(); +} + +void printObjectFifoProducerTile(mlir::OpAsmPrinter &printer, + mlir::Operation *op, mlir::Value operand, + BDDimLayoutArrayAttr dimensions) { + printer << operand; + if (!dimensions.empty()) { + printer << " toStream "; + printer.printStrippedAttrOrType(dimensions); + } +} + +mlir::ParseResult parseObjectFifoConsumerTiles( + mlir::OpAsmParser &parser, + llvm::SmallVectorImpl &tiles, + BDDimLayoutArrayArrayAttr &dimensions) { + std::vector tileDims = {}; + auto parseOneOperand = [&]() -> llvm::ParseResult { + if (parser.parseOperand(tiles.emplace_back(), true)) { + return mlir::failure(); + } + BDDimLayoutArrayAttr dimAttr = + BDDimLayoutArrayAttr::get(parser.getContext(), {}); + if (succeeded(parser.parseOptionalKeyword("fromStream"))) { + if (parser.parseCustomAttributeWithFallback( + dimAttr)) { + return mlir::failure(); + } + } + tileDims.emplace_back(dimAttr); + return mlir::success(); + }; + + if (parser.parseCommaSeparatedList(mlir::AsmParser::Delimiter::None, + parseOneOperand, " in operand list")) + return mlir::failure(); + + dimensions = BDDimLayoutArrayArrayAttr::get(parser.getContext(), tileDims); + return mlir::success(); +} + +void printObjectFifoConsumerTiles(mlir::OpAsmPrinter &printer, + mlir::Operation *op, mlir::OperandRange tiles, + BDDimLayoutArrayArrayAttr dimsPerTileAttr) { + size_t tileIdx = 0; + for (auto tile : tiles) { + printer << tile; + if (dimsPerTileAttr && tileIdx < dimsPerTileAttr.size() && + dimsPerTileAttr[tileIdx] && !dimsPerTileAttr[tileIdx].empty()) { + printer << " fromStream "; + printer.printStrippedAttrOrType(dimsPerTileAttr[tileIdx]); + } + if (tileIdx < tiles.size() - 1) { + printer << ", "; + } + tileIdx++; + } +} + +TileOp getTileOp(mlir::Operation &op) { + mlir::Value t = *op.getOperands().begin(); + return llvm::cast(t.getDefiningOp()); +} + +TileOp CoreOp::getTileOp() { return ::xilinx::AIE::getTileOp(*getOperation()); } + +TileOp BufferOp::getTileOp() { + return ::xilinx::AIE::getTileOp(*getOperation()); +} + +TileOp ShimDMAOp::getTileOp() { + return ::xilinx::AIE::getTileOp(*getOperation()); +} + +int32_t getBufferElementTypeWidthInBytes(DMABDOp &op) { + return op.getBuffer().getType().getElementTypeBitWidth() / 8; +} + +int32_t getLenInBytes(DMABDOp &op) { + if (std::optional len = op.getLen(); len.has_value()) + return len.value() * getBufferElementTypeWidthInBytes(op); + else + return op.getBuffer().getType().getNumElements() * + getBufferElementTypeWidthInBytes(op); +} + +int32_t getOffsetInBytes(DMABDOp &op) { + return op.getOffset() * getBufferElementTypeWidthInBytes(op); +} + +MemOp getMemOp(TileOp &op) { + auto users = op.getResult().getUsers(); + for (auto user : users) + if (auto memOp = llvm::dyn_cast(*user)) return memOp; + return nullptr; +} + +CoreOp getCoreOp(TileOp &op) { + auto users = op.getResult().getUsers(); + for (auto user : users) + if (auto coreOp = llvm::dyn_cast(*user)) return coreOp; + return nullptr; +} + +MemOp TileOp::getMemOp() { return ::xilinx::AIE::getMemOp(*this); } + +CoreOp TileOp::getCoreOp() { return ::xilinx::AIE::getCoreOp(*this); } + +void collectBuffers(DeviceOp &device, + llvm::DenseMap> &buffers) { + for (BufferOp buffer : device.getOps()) { + mlir::Operation *tileOp = buffer.getTile().getDefiningOp(); + buffers[tileOp].push_back(buffer); + } +} + +void collectTiles(xilinx::AIE::DeviceOp &device, + llvm::DenseMap &tiles) { + for (auto tile : device.getOps()) { + int getCol = tile.getCol(); + int getRow = tile.getRow(); + tiles[{getCol, getRow}] = tile; + } +} + +int64_t getAllocationSize(BufferOp &op) { + auto type = llvm::cast(op.getType()); + return type.getNumElements() * type.getElementTypeBitWidth() / 8; +} + +mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel getDeviceModel( + mlir::Operation *op) { + if (auto t = llvm::dyn_cast(op)) { + return mlir::iree_compiler::AMDAIE::getDeviceModel( + static_cast(t.getDevice())); + } + if (auto t = op->getParentOfType()) { + return mlir::iree_compiler::AMDAIE::getDeviceModel( + static_cast(t.getDevice())); + } + llvm::report_fatal_error("couldn't find device model for op"); +} + +size_t TileOp::getNumDestConnections( + mlir::iree_compiler::AMDAIE::StrmSwPortType s) { + auto deviceModel = getDeviceModel(this->getOperation()); + return deviceModel.getNumDestSwitchBoxConnections(this->getCol(), + this->getRow(), s); +} + +size_t TileOp::getNumSourceConnections( + mlir::iree_compiler::AMDAIE::StrmSwPortType s) { + auto deviceModel = getDeviceModel(this->getOperation()); + return deviceModel.getNumSourceSwitchBoxConnections(this->getCol(), + this->getRow(), s); +} + +bool TileOp::isMemTile() { + auto deviceModel = getDeviceModel(this->getOperation()); + return deviceModel.isMemTile(this->getCol(), this->getRow()); +} + +void SwitchboxOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void ShimMuxOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void MemOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void CoreOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void MemTileDMAOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void BufferOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void LockOp::getAsmResultNames( + llvm::function_ref setNameFn) { + return xilinx::AIE::getAsmResultNames(this, setNameFn); +} + +void TileOp::getAsmResultNames( + llvm::function_ref setNameFn) { + std::string nameWithoutDialect = + getOperationName().str().substr(getOperationName().find('.') + 1); + setNameFn(getResult(), nameWithoutDialect + "_" + std::to_string(getCol()) + + "_" + std::to_string(getRow())); +} + +mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel DeviceOp::getTargetModel() { + return getDeviceModel(this->getOperation()); +} + +uint32_t getAddressGenGranularity() { return 32; }; +} // namespace xilinx::AIE diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEDialect.h b/compiler/plugins/target/AMD-AIE/aie/AIEDialect.h index ec1caf38a..77588e7b9 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEDialect.h +++ b/compiler/plugins/target/AMD-AIE/aie/AIEDialect.h @@ -75,15 +75,10 @@ using AIEArch = mlir::iree_compiler::AMDAIE::AIEArch; using AIEDevice = mlir::iree_compiler::AMDAIE::AMDAIEDevice; using AIEDeviceAttr = mlir::iree_compiler::AMDAIE::AMDAIEDeviceAttr; -inline std::optional -symbolizeAIEDevice(uint32_t d) { - return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d); -} - -inline std::optional -symbolizeAIEDevice(llvm::StringRef d) { - return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d); -} +std::optional symbolizeAIEDevice( + uint32_t d); +std::optional symbolizeAIEDevice( + llvm::StringRef d); } // namespace xilinx::AIE #include "aie/AIEDialect.h.inc" @@ -96,200 +91,41 @@ symbolizeAIEDevice(llvm::StringRef d) { #include "aie/AIEOps.h.inc" namespace xilinx::AIE { - -inline mlir::ParseResult parseObjectFifoProducerTile( +mlir::ParseResult parseObjectFifoProducerTile( mlir::OpAsmParser &parser, mlir::OpAsmParser::UnresolvedOperand &operand, - BDDimLayoutArrayAttr &dimensions) { - std::vector emptyDims = {}; - if (parser.parseOperand(operand)) return mlir::failure(); - if (succeeded(parser.parseOptionalKeyword("toStream"))) { - if (parser.parseCustomAttributeWithFallback( - dimensions)) { - return mlir::failure(); - } - } else { - dimensions = BDDimLayoutArrayAttr::get(parser.getContext(), - llvm::ArrayRef(emptyDims)); - } - return mlir::success(); -} + BDDimLayoutArrayAttr &dimensions); -inline void printObjectFifoProducerTile(mlir::OpAsmPrinter &printer, - mlir::Operation *op, - mlir::Value operand, - BDDimLayoutArrayAttr dimensions) { - printer << operand; - if (!dimensions.empty()) { - printer << " toStream "; - printer.printStrippedAttrOrType(dimensions); - } -} +void printObjectFifoProducerTile(mlir::OpAsmPrinter &printer, + mlir::Operation *op, mlir::Value operand, + BDDimLayoutArrayAttr dimensions); -inline mlir::ParseResult parseObjectFifoConsumerTiles( +mlir::ParseResult parseObjectFifoConsumerTiles( mlir::OpAsmParser &parser, llvm::SmallVectorImpl &tiles, - BDDimLayoutArrayArrayAttr &dimensions) { - // parseCommaSeparatedList doesn't handle the missing case for "none", - // so we handle it custom here. - std::vector tileDims = {}; - - auto parseOneOperand = [&]() -> llvm::ParseResult { - if (parser.parseOperand(tiles.emplace_back(), true)) { - return mlir::failure(); - } - // By default, create empty dimensions array for each consumer; this way, - // we can be certain to have as many entries in the dimensions array as - // there are customer - BDDimLayoutArrayAttr dimAttr = - BDDimLayoutArrayAttr::get(parser.getContext(), {}); - - if (succeeded(parser.parseOptionalKeyword("fromStream"))) { - // If specified, parse actual data layout transform dimensions - if (parser.parseCustomAttributeWithFallback( - dimAttr)) { - return mlir::failure(); - } - } - tileDims.emplace_back(dimAttr); - return mlir::success(); - }; - - if (parser.parseCommaSeparatedList(mlir::AsmParser::Delimiter::None, - parseOneOperand, " in operand list")) - return mlir::failure(); - - dimensions = BDDimLayoutArrayArrayAttr::get(parser.getContext(), tileDims); - return mlir::success(); -} - -inline void printObjectFifoConsumerTiles( - mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange tiles, - BDDimLayoutArrayArrayAttr dimsPerTileAttr) { - size_t tileIdx = 0; - for (auto tile : tiles) { - printer << tile; - if (dimsPerTileAttr && tileIdx < dimsPerTileAttr.size() && - dimsPerTileAttr[tileIdx] && !dimsPerTileAttr[tileIdx].empty()) { - printer << " fromStream "; - printer.printStrippedAttrOrType(dimsPerTileAttr[tileIdx]); - } - if (tileIdx < tiles.size() - 1) { - printer << ", "; - } - tileIdx++; - } -} - -inline TileOp getTileOp(mlir::Operation &op) { - mlir::Value t = *op.getOperands().begin(); - return llvm::cast(t.getDefiningOp()); -} - -inline TileOp CoreOp::getTileOp() { - return ::xilinx::AIE::getTileOp(*getOperation()); -} - -inline TileOp BufferOp::getTileOp() { - return ::xilinx::AIE::getTileOp(*getOperation()); -} - -inline TileOp ShimDMAOp::getTileOp() { - return ::xilinx::AIE::getTileOp(*getOperation()); -} - -inline int32_t getBufferElementTypeWidthInBytes(DMABDOp &op) { - return op.getBuffer().getType().getElementTypeBitWidth() / 8; -} - -inline int32_t getLenInBytes(DMABDOp &op) { - if (std::optional len = op.getLen(); len.has_value()) - return len.value() * getBufferElementTypeWidthInBytes(op); - else - return op.getBuffer().getType().getNumElements() * - getBufferElementTypeWidthInBytes(op); -} - -inline int32_t getOffsetInBytes(DMABDOp &op) { - return op.getOffset() * getBufferElementTypeWidthInBytes(op); -} - -inline MemOp getMemOp(TileOp &op) { - auto users = op.getResult().getUsers(); - for (auto user : users) - if (auto memOp = llvm::dyn_cast(*user)) return memOp; - return nullptr; -} - -inline CoreOp getCoreOp(TileOp &op) { - auto users = op.getResult().getUsers(); - for (auto user : users) - if (auto coreOp = llvm::dyn_cast(*user)) return coreOp; - return nullptr; -} - -inline MemOp TileOp::getMemOp() { return ::xilinx::AIE::getMemOp(*this); } - -inline CoreOp TileOp::getCoreOp() { return ::xilinx::AIE::getCoreOp(*this); } - -inline void collectBuffers( + BDDimLayoutArrayArrayAttr &dimensions); + +void printObjectFifoConsumerTiles(mlir::OpAsmPrinter &printer, + mlir::Operation *op, mlir::OperandRange tiles, + BDDimLayoutArrayArrayAttr dimsPerTileAttr); + +TileOp getTileOp(mlir::Operation &op); +int32_t getBufferElementTypeWidthInBytes(DMABDOp &op); +int32_t getLenInBytes(DMABDOp &op); +int32_t getOffsetInBytes(DMABDOp &op); +MemOp getMemOp(TileOp &op); +CoreOp getCoreOp(TileOp &op); +void collectBuffers( DeviceOp &device, - llvm::DenseMap> - &buffers) { - for (BufferOp buffer : device.getOps()) { - mlir::Operation *tileOp = buffer.getTile().getDefiningOp(); - buffers[tileOp].push_back(buffer); - } -} - -inline void collectTiles(xilinx::AIE::DeviceOp &device, - llvm::DenseMap &tiles) { - for (auto tile : device.getOps()) { - int getCol = tile.getCol(); - int getRow = tile.getRow(); - tiles[{getCol, getRow}] = tile; - } -} - -inline int64_t getAllocationSize(BufferOp &op) { - auto type = llvm::cast(op.getType()); - return type.getNumElements() * type.getElementTypeBitWidth() / 8; -} - -inline mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel getDeviceModel( - mlir::Operation *op) { - if (auto t = llvm::dyn_cast(op)) { - return mlir::iree_compiler::AMDAIE::getDeviceModel( - static_cast(t.getDevice())); - } - if (auto t = op->getParentOfType()) { - return mlir::iree_compiler::AMDAIE::getDeviceModel( - static_cast(t.getDevice())); - } - llvm::report_fatal_error("couldn't find device model for op"); -} - -inline size_t TileOp::getNumDestConnections( - mlir::iree_compiler::AMDAIE::StrmSwPortType s) { - auto deviceModel = getDeviceModel(this->getOperation()); - return deviceModel.getNumDestSwitchBoxConnections(this->getCol(), - this->getRow(), s); -} - -inline size_t TileOp::getNumSourceConnections( - mlir::iree_compiler::AMDAIE::StrmSwPortType s) { - auto deviceModel = getDeviceModel(this->getOperation()); - return deviceModel.getNumSourceSwitchBoxConnections(this->getCol(), - this->getRow(), s); -} - -inline bool TileOp::isMemTile() { - auto deviceModel = getDeviceModel(this->getOperation()); - return deviceModel.isMemTile(this->getCol(), this->getRow()); -} + llvm::DenseMap> &buffers); +void collectTiles(xilinx::AIE::DeviceOp &device, + llvm::DenseMap &tiles); +int64_t getAllocationSize(BufferOp &op); +mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel getDeviceModel( + mlir::Operation *op); template -inline void getAsmResultNames( +void getAsmResultNames( T op, llvm::function_ref setNameFn) { std::string nameWithoutDialect = op->getOperationName().str().substr(op->getOperationName().find('.') + 1); @@ -299,55 +135,7 @@ inline void getAsmResultNames( std::to_string(t.getRow())); } -inline void SwitchboxOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void ShimMuxOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void MemOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void CoreOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void MemTileDMAOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void BufferOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void LockOp::getAsmResultNames( - llvm::function_ref setNameFn) { - return xilinx::AIE::getAsmResultNames(this, setNameFn); -} - -inline void TileOp::getAsmResultNames( - llvm::function_ref setNameFn) { - std::string nameWithoutDialect = - getOperationName().str().substr(getOperationName().find('.') + 1); - setNameFn(getResult(), nameWithoutDialect + "_" + std::to_string(getCol()) + - "_" + std::to_string(getRow())); -} - -inline mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel -DeviceOp::getTargetModel() { - return getDeviceModel(this->getOperation()); -} - -inline uint32_t getAddressGenGranularity() { return 32; }; +uint32_t getAddressGenGranularity(); struct DMAChannel { DMAChannelDir direction; diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEEnums.h b/compiler/plugins/target/AMD-AIE/aie/AIEEnums.h index 7e6dbe508..b1628d732 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEEnums.h +++ b/compiler/plugins/target/AMD-AIE/aie/AIEEnums.h @@ -12,4 +12,4 @@ #include "aie/AIEEnums.h.inc" -#endif \ No newline at end of file +#endif diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEOps.td b/compiler/plugins/target/AMD-AIE/aie/AIEOps.td index 3862babc3..edbb52407 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEOps.td +++ b/compiler/plugins/target/AMD-AIE/aie/AIEOps.td @@ -22,7 +22,6 @@ include "mlir/IR/OpAsmInterface.td" class AIE_Op traits = []> : Op; - def AIE_DeviceOp: AIE_Op<"device", [ HasParent<"mlir::ModuleOp">, SymbolTable, SingleBlock, NoTerminator, IsolatedFromAbove @@ -146,7 +145,7 @@ def AIE_CoreOp: AIE_Op<"core", [ }]; } -def AIE_ConnectOp: AIE_Op<"connect", [ParentOneOf<["SwitchboxOp", "ShimMuxOp"]> ]> { +def AIE_ConnectOp: AIE_Op<"connect"> { let arguments = ( ins StrmSwPortTypeAttr:$source_bundle, ConfinedAttr]>:$source_channel, @@ -159,7 +158,7 @@ def AIE_ConnectOp: AIE_Op<"connect", [ParentOneOf<["SwitchboxOp", "ShimMuxOp"]> }]; } -def AIE_FlowOp: AIE_Op<"flow", []> { +def AIE_FlowOp: AIE_Op<"flow"> { let arguments = ( ins Index:$source, StrmSwPortTypeAttr:$source_bundle, @@ -222,7 +221,7 @@ def AIE_PacketRulesOp: AIE_Op<"packet_rules", [SingleBlockImplicitTerminator<"En let assemblyFormat = [{ `(` $source_bundle `:` $source_channel `)` regions attr-dict }]; } -def AIE_PacketRuleOp: AIE_Op<"rule", [HasParent<"PacketRulesOp">]> { +def AIE_PacketRuleOp: AIE_Op<"rule"> { let arguments = ( ins I8Attr:$mask, I8Attr:$value, @@ -250,7 +249,7 @@ def AIE_PacketFlowOp: AIE_Op<"packet_flow", [SingleBlockImplicitTerminator<"EndO }]; } -def AIE_PacketSourceOp: AIE_Op<"packet_source", [HasParent<"PacketFlowOp">]> { +def AIE_PacketSourceOp: AIE_Op<"packet_source"> { let arguments = ( ins Index:$tile, StrmSwPortTypeAttr:$bundle, @@ -267,7 +266,7 @@ def AIE_PacketSourceOp: AIE_Op<"packet_source", [HasParent<"PacketFlowOp">]> { }]; } -def AIE_PacketDestOp: AIE_Op<"packet_dest", [HasParent<"PacketFlowOp">]> { +def AIE_PacketDestOp: AIE_Op<"packet_dest"> { let arguments = ( ins Index:$tile, StrmSwPortTypeAttr:$bundle, @@ -284,7 +283,7 @@ def AIE_PacketDestOp: AIE_Op<"packet_dest", [HasParent<"PacketFlowOp">]> { }]; } -def AIE_DMABDPACKETOp: AIE_Op<"dma_bd_packet", []> { +def AIE_DMABDPACKETOp: AIE_Op<"dma_bd_packet"> { let summary = "Enable packet headers for a dma block descriptor"; let arguments = ( ins I32Attr:$packet_type, @@ -298,13 +297,12 @@ def AIE_DMABDPACKETOp: AIE_Op<"dma_bd_packet", []> { def AIE_DMABDOp: AIE_Op<"dma_bd", [ DeclareOpInterfaceMethods, - ParentOneOf<["MemOp", "MemTileDMAOp"]>, ]> { let summary = "Declare a dma buffer descriptor op"; let arguments = ( ins AnyMemRef:$buffer, // in multiples of element width (not bytes) - DefaultValuedOptionalAttr:$offset, + DefaultValuedOptionalAttr:$offset, // in multiples of element width (not bytes) OptionalAttr:$len, OptionalAttr:$dimensions, @@ -349,7 +347,6 @@ def AIE_DMABDOp: AIE_Op<"dma_bd", [ } def AIE_DMAStartOp: AIE_Op<"dma_start", [ - ParentOneOf<["MemOp", "MemTileDMAOp", "mlir::func::FuncOp"]>, Terminator, DeclareOpInterfaceMethods ]>, Results<(outs I1:$valid)> { @@ -399,9 +396,7 @@ def AIE_MemTileDMAOp: AIE_Op<"memtile_dma", [ }]; } -def AIE_NextBDOp: AIE_Op<"next_bd", [ - Terminator, ParentOneOf<["MemOp", "MemTileDMAOp", "mlir::func::FuncOp"]> - ]> { +def AIE_NextBDOp: AIE_Op<"next_bd", [Terminator]> { let summary = "The next buffer descriptor"; let successors = (successor AnySuccessor:$dest); @@ -446,7 +441,7 @@ def AIE_LockOp: AIE_Op<"lock", [ }]; } -def AIE_UseLockOp: AIE_Op<"use_lock", []> { +def AIE_UseLockOp: AIE_Op<"use_lock"> { let summary = "acquire/release lock op"; let arguments = ( ins Index:$lock, @@ -492,7 +487,7 @@ def AIE_BufferOp: AIE_Op<"buffer", [ }]; } -def AIE_ShimDMAAllocationOp : AIE_Op<"shim_dma_allocation", [HasParent<"DeviceOp">]> { +def AIE_ShimDMAAllocationOp : AIE_Op<"shim_dma_allocation"> { let summary = "Runtime allocation information for a single shim DMA"; let arguments = ( ins FlatSymbolRefAttr:$sym_name, @@ -510,7 +505,7 @@ def AIE_ShimDMAAllocationOp : AIE_Op<"shim_dma_allocation", [HasParent<"DeviceOp }]; } -def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [HasParent<"DeviceOp">, Symbol]> { +def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [Symbol]> { let summary = "Create a circular buffer or channel between two tiles"; let arguments = ( ins SymbolNameAttr:$sym_name, @@ -560,7 +555,7 @@ def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [HasParent<"DeviceOp">, Symbol] }]; } -def AIE_ObjectFifoLinkOp: AIE_Op<"objectfifo.link", [HasParent<"DeviceOp">]> { +def AIE_ObjectFifoLinkOp: AIE_Op<"objectfifo.link"> { let summary = "Links two objectFifos through an intermediary tile's DMA"; let arguments = ( ins SymbolRefArrayAttr:$fifoIns, @@ -574,7 +569,7 @@ def AIE_ObjectFifoLinkOp: AIE_Op<"objectfifo.link", [HasParent<"DeviceOp">]> { }]; } -def AIE_ObjectFifoAcquireOp: AIE_Op<"objectfifo.acquire", []> { +def AIE_ObjectFifoAcquireOp: AIE_Op<"objectfifo.acquire"> { let summary = "Acquire operation to lock and return objects of an ObjectFifo"; let arguments = ( ins ObjectFifoPort:$port, @@ -590,7 +585,7 @@ def AIE_ObjectFifoAcquireOp: AIE_Op<"objectfifo.acquire", []> { } -def AIE_ObjectFifoReleaseOp: AIE_Op<"objectfifo.release", []> { +def AIE_ObjectFifoReleaseOp: AIE_Op<"objectfifo.release"> { let summary = "Release operation for object locks in an ObjectFifo"; let arguments = ( ins ObjectFifoPort:$port, @@ -604,7 +599,7 @@ def AIE_ObjectFifoReleaseOp: AIE_Op<"objectfifo.release", []> { } -def AIE_ObjectFifoSubviewAccessOp : AIE_Op<"objectfifo.subview.access", []> { +def AIE_ObjectFifoSubviewAccessOp : AIE_Op<"objectfifo.subview.access"> { let summary = "ObjectFifoSubview type accessor method"; let arguments = ( ins AIE_ObjectFifoSubviewType:$subview, diff --git a/compiler/plugins/target/AMD-AIE/aie/AIETypes.td b/compiler/plugins/target/AMD-AIE/aie/AIETypes.td index 33e68dde1..41a81d510 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIETypes.td +++ b/compiler/plugins/target/AMD-AIE/aie/AIETypes.td @@ -20,4 +20,4 @@ def AIE_ObjectFifoSubviewType : DialectType($_self)">, "AIE ObjectFifoSubview type">; -#endif // AIE_TYPES \ No newline at end of file +#endif // AIE_TYPES diff --git a/compiler/plugins/target/AMD-AIE/aie/AIEX.td b/compiler/plugins/target/AMD-AIE/aie/AIEX.td index 61d916424..69fd6bc59 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AIEX.td +++ b/compiler/plugins/target/AMD-AIE/aie/AIEX.td @@ -26,8 +26,7 @@ def AIEX_Dialect : Dialect { class AIEX_Op traits = []> : Op; - -def AIE_RuntimeSequenceOp : AIEX_Op<"runtime_sequence", [NoTerminator, HasParent<"AIE::DeviceOp">]> { +def AIE_RuntimeSequenceOp : AIEX_Op<"runtime_sequence", [NoTerminator]> { let summary = "Program the configuration co-processor of the AI Engine array"; let arguments = ( ins OptionalAttr:$sym_name @@ -82,7 +81,7 @@ def AIE_NpuDmaMemcpyNdOp: AIEX_Op<"npu.dma_memcpy_nd", [ }]; } -def AIE_NpuDmaWaitOp: AIEX_Op<"npu.dma_wait", []> { +def AIE_NpuDmaWaitOp: AIEX_Op<"npu.dma_wait"> { let summary = "Blocking operation to wait for a DMA to complete execution."; let arguments = ( ins FlatSymbolRefAttr:$symbol @@ -92,18 +91,7 @@ def AIE_NpuDmaWaitOp: AIEX_Op<"npu.dma_wait", []> { }]; } -def AIE_NpuWriteRTPOp: AIEX_Op<"npu.rtp_write", []> { - let summary = "rtp write operator"; - let arguments = ( - ins FlatSymbolRefAttr:$buffer, - UI32Attr:$index, - I32Attr:$value - ); - let results = (outs ); - let assemblyFormat = [{ `(` $buffer `,` $index `,` $value `)` attr-dict }]; -} - -def AIE_NpuPushQueueOp: AIEX_Op<"npu.push_queue", []> { +def AIE_NpuPushQueueOp: AIEX_Op<"npu.push_queue"> { let summary = "bd queue push operator"; let arguments = ( ins I32Attr:$column, @@ -120,7 +108,7 @@ def AIE_NpuPushQueueOp: AIEX_Op<"npu.push_queue", []> { }]; } -def AIE_NpuWrite32Op: AIEX_Op<"npu.write32", []> { +def AIE_NpuWrite32Op: AIEX_Op<"npu.write32"> { let summary = "write32 operator"; let arguments = ( ins UI32Attr:$address, @@ -135,7 +123,7 @@ def AIE_NpuWrite32Op: AIEX_Op<"npu.write32", []> { }]; } -def AIE_NpuBlockWriteOp: AIEX_Op<"npu.blockwrite", []> { +def AIE_NpuBlockWriteOp: AIEX_Op<"npu.blockwrite"> { let summary = "blockwrite operator"; let arguments = ( ins UI32Attr:$address, @@ -151,7 +139,7 @@ def AIE_NpuBlockWriteOp: AIEX_Op<"npu.blockwrite", []> { } // OP_SYNC -def AIE_NpuSyncOp: AIEX_Op<"npu.sync", []> { +def AIE_NpuSyncOp: AIEX_Op<"npu.sync"> { let summary = "sync operator"; let arguments = ( ins I32Attr:$column, @@ -167,7 +155,7 @@ def AIE_NpuSyncOp: AIEX_Op<"npu.sync", []> { }]; } -def AIE_NpuAddressPatchOp: AIEX_Op<"npu.address_patch", []> { +def AIE_NpuAddressPatchOp: AIEX_Op<"npu.address_patch"> { let summary = "address patch operator"; let arguments = ( ins UI32Attr:$addr, @@ -181,7 +169,7 @@ def AIE_NpuAddressPatchOp: AIEX_Op<"npu.address_patch", []> { } // NPU Bd Write operation -def AIE_NpuWriteBdOp: AIEX_Op<"npu.writebd", []> { +def AIE_NpuWriteBdOp: AIEX_Op<"npu.writebd"> { let summary = "dma operator"; let arguments = ( ins I32Attr:$column, @@ -214,4 +202,4 @@ def AIE_NpuWriteBdOp: AIEX_Op<"npu.writebd", []> { let assemblyFormat = [{ attr-dict }]; } -#endif // AIEX_OPS \ No newline at end of file +#endif // AIEX_OPS diff --git a/compiler/plugins/target/AMD-AIE/aie/AMDAIEXToStandard.cpp b/compiler/plugins/target/AMD-AIE/aie/AMDAIEXToStandard.cpp index f9416d7bc..4e0de9c09 100644 --- a/compiler/plugins/target/AMD-AIE/aie/AMDAIEXToStandard.cpp +++ b/compiler/plugins/target/AMD-AIE/aie/AMDAIEXToStandard.cpp @@ -67,7 +67,6 @@ struct AMDAIEXToStandardPass : mlir::OperationPass { removepatterns.add>(m.getContext(), m); removepatterns.add>(m.getContext(), m); removepatterns.add>(m.getContext(), m); - removepatterns.add>(m.getContext(), m); removepatterns.add>(m.getContext(), m); removepatterns.add>(m.getContext(), m); removepatterns.add>(m.getContext(), m); diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetBCF.cpp b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetBCF.cpp index 735502b15..48fc13527 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetBCF.cpp +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetBCF.cpp @@ -6,7 +6,6 @@ #include "AMDAIETargets.h" #include "aie/AIEDialect.h" -#include "aie/Passes.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Module.h" @@ -16,8 +15,6 @@ using namespace xilinx::AIE; std::string utohexstr(uint32_t u) { return "0x" + llvm::utohexstr(u); } -namespace {} // namespace - namespace mlir::iree_compiler::AMDAIE { LogicalResult AIETranslateToBCF(ModuleOp module, raw_ostream &output, @@ -115,8 +112,8 @@ LogicalResult AIETranslateToBCF(ModuleOp module, raw_ostream &output, "the core can't see\n"; // chess's libc expects a _main not a main (despite what me_basic.c looks // like...) - output << "_resolve _main core_" << tile.getCol() << "_" << tile.getRow() - << "\n"; + output << "_resolve _main core_" << std::to_string(tile.getCol()) << "_" + << std::to_string(tile.getRow()) << "\n"; } return success(); diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetLdScript.cpp b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetLdScript.cpp index d770e81df..a106f1e53 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetLdScript.cpp +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AMDAIETargetLdScript.cpp @@ -101,7 +101,7 @@ SECTIONS } > data )THESCRIPT"; auto doBuffer = [&](std::optional tile, int offset, - std::string dir) { + const std::string& dir) { if (tile) { if (tiles.count({tile->col, tile->row})) for (auto buf : buffers[tiles[{tile->col, tile->row}]]) @@ -139,8 +139,8 @@ SECTIONS output << " .bss.DMb.4 : { *(.bss.DMb.4) } > data\n"; output << "}\n"; if (auto coreOp = getCoreOp(tile)) { - output << "PROVIDE(main = core_" << tile.getCol() << "_" - << tile.getRow() << ");\n"; + output << "PROVIDE(main = core_" << std::to_string(tile.getCol()) << "_" + << std::to_string(tile.getRow()) << ");\n"; } } return success(); diff --git a/experimental/delegate/README.md b/experimental/delegate/README.md index 002ac7e88..6b15bb37f 100644 --- a/experimental/delegate/README.md +++ b/experimental/delegate/README.md @@ -211,12 +211,10 @@ cd export IREE_ROOT=$PWD cd iree-amd-aie/experimental/delegate export IREE_INSTALL_DIR=$IREE_ROOT/iree-build/ -export MLIR_AIE_INSTALL_DIR=$IREE_ROOT/iree-amd-aie/third_party/mlir-aie/install export PEANO_INSTALL_DIR=$IREE_ROOT/install export VITIS_INSTALL_PATH=/proj/xbuilds/2023.2_released/installs/lin64/Vitis/2023.2 ../../build_tools/ci/run_matmul_test.sh results_dir_tmp $IREE_INSTALL_DIR \ - $MLIR_AIE_INSTALL_DIR $PEANO_INSTALL_DIR /opt/xilinx/xrt \ $VITIS_INSTALL_PATH 0 ``` diff --git a/iree_compiler_plugin.cmake b/iree_compiler_plugin.cmake index 1061b273b..7ec4465b4 100644 --- a/iree_compiler_plugin.cmake +++ b/iree_compiler_plugin.cmake @@ -10,7 +10,6 @@ include_directories(${Boost_INCLUDE_DIRS}) set(IREE_AMD_AIE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}") set(IREE_AMD_AIE_RUNTIME_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/runtime/src) set(IREE_MLIR_AIR_SOURCE_DIR "${IREE_AMD_AIE_SOURCE_DIR}/third_party/mlir-air/mlir") -set(IREE_MLIR_AIE_SOURCE_DIR "${IREE_AMD_AIE_SOURCE_DIR}/third_party/mlir-aie") add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/compiler/plugins/target/AMD-AIE target/AMD-AIE) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests/samples AMD-AIE/tests/samples) diff --git a/iree_runtime_plugin.cmake b/iree_runtime_plugin.cmake index 080c78bbe..b76099120 100644 --- a/iree_runtime_plugin.cmake +++ b/iree_runtime_plugin.cmake @@ -8,7 +8,6 @@ include(FetchContent) set(IREE_AMD_AIE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}") set(IREE_MLIR_AIR_SOURCE_DIR "${IREE_AMD_AIE_SOURCE_DIR}/third_party/mlir-air/mlir") -set(IREE_MLIR_AIE_SOURCE_DIR "${IREE_AMD_AIE_SOURCE_DIR}/third_party/mlir-aie") set(IREE_AMD_AIE_ENABLE_XRT_DRIVER OFF) if("xrt" IN_LIST IREE_EXTERNAL_HAL_DRIVERS) diff --git a/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt b/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt index 227bda174..6ec772dd6 100644 --- a/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt +++ b/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt @@ -105,10 +105,4 @@ iree_lit_test( "hostonly" ) - -#target_include_directories( -# iree-amd-aie_aie_runtime_test_DeviceModelTestCppTest -# PRIVATE "${IREE_MLIR_AIE_SOURCE_DIR}/include" -#) - add_subdirectory(cdo) diff --git a/runtime/src/iree-amd-aie/aie_runtime/test/cdo/CMakeLists.txt b/runtime/src/iree-amd-aie/aie_runtime/test/cdo/CMakeLists.txt index b20e0518c..664c78da6 100644 --- a/runtime/src/iree-amd-aie/aie_runtime/test/cdo/CMakeLists.txt +++ b/runtime/src/iree-amd-aie/aie_runtime/test/cdo/CMakeLists.txt @@ -14,11 +14,6 @@ iree_cc_binary( iree_target_amd-aie_Target_AIETargets ) -target_include_directories( - iree-amd-aie_aie_runtime_test_cdo_aie_cdo_gen_test - PRIVATE "${IREE_MLIR_AIE_SOURCE_DIR}/include" -) - file(GLOB _mlir_files *.mlir) iree_lit_test_suite( diff --git a/third_party/mlir-aie b/third_party/mlir-aie deleted file mode 160000 index 527370a0d..000000000 --- a/third_party/mlir-aie +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 527370a0d3982a20a8559944fbcaa532356b2819