Skip to content

Commit

Permalink
Handle ops with fixed layout (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
odjuricicTT authored Sep 6, 2024
1 parent dc3eb48 commit 1b21a8d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/Dialect/TTIR/Analysis/LegalGridAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ bool tensor_shape_compatible_with_shard(Operation *op, LayoutAttr layout) {
return (MTiles % gridR == 0) && (KTIles % gridC == 0);
}

bool cantChangeOutputLayout(Operation *op) {
// Only TTIR ops.
if (not llvm::isa<TTIROp>(op)) {
return true;
}
if (llvm::isa<ToLayoutOp>(op)) {
return true;
}
return false;
}

bool LegalGridAnalysis::applyOverrides() {
// Lookup grid size overrides based on location information for current
// operation.
Expand Down Expand Up @@ -74,23 +85,22 @@ void LegalGridAnalysis::analysisImplementation() {
// This implementation is a placeholder and is meant to just enable testing of
// other components.

// Process only TTIR ops.
if (not llvm::isa<TTIROp>(op)) {
return;
}
// Skip operations that don't have output tensors.
if (op->getNumResults() == 0) {
return;
}
if (llvm::isa<ToLayoutOp>(op)) {
return;
}

// Get output tensor type.
RankedTensorType tensorType =
mlir::cast<RankedTensorType>(op->getResult(0).getType());
LayoutAttr layout = mlir::cast<LayoutAttr>(tensorType.getEncoding());

// Return existing layout if it is not possible to change it.
if (cantChangeOutputLayout(op)) {
analysisResult.push_back(layout);
return;
}

// DRAM
// No grid is set since the tensor is not sharded.
// TODO(odjuricic): We need to set grid here since it will be used as the
Expand Down

0 comments on commit 1b21a8d

Please sign in to comment.