Skip to content

Commit

Permalink
#598: Runtime support for dealloc op, slight refactor (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnie-TT authored Sep 5, 2024
1 parent 9c61739 commit 344d4ad
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 165 deletions.
7 changes: 6 additions & 1 deletion include/ttmlir/Target/TTNN/program.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ table Conv2dOp {
groups: uint32;
}

table DeallocOp {
in: tt.target.TensorRef;
}

union OpType {
OpenDeviceOp,
CloseDeviceOp,
Expand All @@ -135,7 +139,8 @@ union OpType {
TransposeOp,
Conv2dOp,
ConcatOp,
ReshapeOp
ReshapeOp,
DeallocOp
}

table Operation {
Expand Down
12 changes: 12 additions & 0 deletions lib/Target/TTNN/TTNNToFlatbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ createSoftmaxOp(FlatbufferObjectCache &cache, SoftmaxOp op) {
return ::tt::target::ttnn::CreateSoftmaxOp(*cache.fbb, in, out, dimension);
}

template <typename DeallocOp>
::flatbuffers::Offset<::tt::target::ttnn::DeallocOp>
createDeallocOp(FlatbufferObjectCache &cache, DeallocOp op) {
auto in =
cache.at<::tt::target::TensorRef>(getOperandThroughDPSOps(op.getInput()));
return ::tt::target::ttnn::CreateDeallocOp(*cache.fbb, in);
}

::flatbuffers::Offset<::tt::target::ttnn::Operation>
emitTTNNOperation(FlatbufferObjectCache &cache, Operation *op,
std::string const &debugString) {
Expand Down Expand Up @@ -357,6 +365,10 @@ emitTTNNOperation(FlatbufferObjectCache &cache, Operation *op,
return createOperation(cache, createReshapeOp(cache, reshapeOp),
debugString);
}
if (auto deallocOp = dyn_cast<DeallocOp>(op); deallocOp) {
return createOperation(cache, createDeallocOp(cache, deallocOp),
debugString);
}

llvm_unreachable("unhandled op in emitTTNNOperation");
}
Expand Down
Loading

0 comments on commit 344d4ad

Please sign in to comment.