Skip to content

Commit

Permalink
remove mlir-aie submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Aug 7, 2024
1 parent 9fafe39 commit 9aa42ab
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 333 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build_tools/ci/build_test_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
Expand Down
2 changes: 1 addition & 1 deletion compiler/plugins/target/AMD-AIE/aie/AIE.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def AIE_Dialect : Dialect {
let useDefaultAttributePrinterParser = 1;
}

#endif // AIE_BASE
#endif // AIE_BASE
2 changes: 1 addition & 1 deletion compiler/plugins/target/AMD-AIE/aie/AIEAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def BDPadLayoutArrayAttr : ArrayOfAttr<
/*eltName*/BDPadLayoutAttr.cppClassName
>;

#endif // AIE_ATTRS
#endif // AIE_ATTRS
257 changes: 242 additions & 15 deletions compiler/plugins/target/AMD-AIE/aie/AIEDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ using namespace xilinx::AIE;
#include "aie/AIEDialect.cpp.inc"

namespace xilinx::AIE {
std::optional<mlir::iree_compiler::AMDAIE::AMDAIEDevice> symbolizeAIEDevice(
uint32_t d) {
return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d);
}

std::optional<mlir::iree_compiler::AMDAIE::AMDAIEDevice> symbolizeAIEDevice(
llvm::StringRef d) {
return mlir::iree_compiler::AMDAIE::symbolizeAMDAIEDevice(d);
}

namespace detail {
struct AIEObjectFifoTypeStorage : TypeStorage {
Expand All @@ -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;
}

Expand Down Expand Up @@ -78,7 +86,6 @@ static OptionalParseResult aieTypeParser(DialectAsmParser &parser,
parser.parseGreater())
return failure();

// Check that the type is a MemRef type.
if (!llvm::isa<MemRefType>(elementType)) {
parser.emitError(typeLoc,
"element type for an objectFifo must be "
Expand All @@ -92,28 +99,19 @@ 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<MemRefType>(elementType)) {
parser.emitError(typeLoc,
"element type for a subview must be "
"a MemRefType, got: ")
<< elementType;
return failure();
}

// Parse: `>`
if (parser.parseGreater()) return failure();

return result = AIEObjectFifoSubviewType::get(elementType), success();
}

return {};
}

Expand All @@ -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();
Expand All @@ -141,7 +138,6 @@ void AIEDialect::printType(Type type, DialectAsmPrinter &printer) const {
printer << "objectfifo<";
printer << objectFifoType.getElementType();
printer << '>';

} else if (llvm::isa<AIEObjectFifoSubviewType>(type)) {
auto subviewType = llvm::cast<AIEObjectFifoSubviewType>(type);
printer << "objectfifosubview<";
Expand All @@ -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;

Expand Down Expand Up @@ -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<BDDimLayoutAttr> emptyDims = {};
if (parser.parseOperand(operand)) return mlir::failure();
if (succeeded(parser.parseOptionalKeyword("toStream"))) {
if (parser.parseCustomAttributeWithFallback<BDDimLayoutArrayAttr>(
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<mlir::OpAsmParser::UnresolvedOperand> &tiles,
BDDimLayoutArrayArrayAttr &dimensions) {
std::vector<BDDimLayoutArrayAttr> 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<BDDimLayoutArrayAttr>(
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<TileOp>(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<int32_t> 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<MemOp>(*user)) return memOp;
return nullptr;
}

CoreOp getCoreOp(TileOp &op) {
auto users = op.getResult().getUsers();
for (auto user : users)
if (auto coreOp = llvm::dyn_cast<CoreOp>(*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<mlir::Operation *,
llvm::SmallVector<BufferOp, 4>> &buffers) {
for (BufferOp buffer : device.getOps<BufferOp>()) {
mlir::Operation *tileOp = buffer.getTile().getDefiningOp();
buffers[tileOp].push_back(buffer);
}
}

void collectTiles(xilinx::AIE::DeviceOp &device,
llvm::DenseMap<mlir::iree_compiler::AMDAIE::TileLoc,
mlir::Operation *> &tiles) {
for (auto tile : device.getOps<xilinx::AIE::TileOp>()) {
int getCol = tile.getCol();
int getRow = tile.getRow();
tiles[{getCol, getRow}] = tile;
}
}

int64_t getAllocationSize(BufferOp &op) {
auto type = llvm::cast<mlir::MemRefType>(op.getType());
return type.getNumElements() * type.getElementTypeBitWidth() / 8;
}

mlir::iree_compiler::AMDAIE::AMDAIEDeviceModel getDeviceModel(
mlir::Operation *op) {
if (auto t = llvm::dyn_cast<xilinx::AIE::DeviceOp>(op)) {
return mlir::iree_compiler::AMDAIE::getDeviceModel(
static_cast<mlir::iree_compiler::AMDAIE::AMDAIEDevice>(t.getDevice()));
}
if (auto t = op->getParentOfType<DeviceOp>()) {
return mlir::iree_compiler::AMDAIE::getDeviceModel(
static_cast<mlir::iree_compiler::AMDAIE::AMDAIEDevice>(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<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void ShimMuxOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void MemOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void CoreOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void MemTileDMAOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void BufferOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void LockOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
return xilinx::AIE::getAsmResultNames(this, setNameFn);
}

void TileOp::getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> 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
Loading

0 comments on commit 9aa42ab

Please sign in to comment.