Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTNN->EmitC new op conversion infrastructure #2331

Merged
merged 19 commits into from
Mar 3, 2025
Merged

Conversation

azecevicTT
Copy link
Contributor

@azecevicTT azecevicTT commented Feb 28, 2025

Ticket

#2311

Problem description

Existing way of TTNN->EmitC conversion exhibits a few limitations:

  1. requires too much consideration on the OP to OP basis (requires user to explicitly make differentiation between operands and attributes)
  2. didn't take into consideration many-to-many relationship of MLIR and C++ types (i.e. {ArrayAttr, DenseI32ArrayAttr} <-> {ttnn::SmallVector<int32_t>, std::vector<uint32_t>})

What's changed

Introduction of the new EmitCTTNNEmitter class that should address these limitations in the following way:

  1. Most conversions should follow this pattern
ttnn_to_emitc::EmitCTTNNEmitter<TTNNOp> emitter(srcOp, adaptor, rewrite);

llvm::SmallVector<mlir::Attribute> args {
  emitter.emit(srcOp.getArg0()),
  emitter.emit(srcOp.getArg1()),
  ...,
  emitter.emit(srcOp.getArgN())
};

emitter.replaceOp(*this, args);

return success();
  1. For many-to-many relationship between MLIR and C++ types we 'hint' emit member function with the target C++ type
emitter.emit<ttnn::SmallVector<int32_t>>(srcOp.getSomeDenseArrayAttr())

Of course, this is still a utility and it's not baked directly into MLIR's conversion pattern rewriter, so we can still do it the old way for the ops whose structure deviates too much from the general op structure.

Checklist

  • New/Existing tests provide coverage for changes
  • At this point EmitCTTNNEmitter and related class should still be considered WIP, next goal is to transfer all of the existing ops to this type of conversion and leverage existing tests to iron out some missing details

@azecevicTT azecevicTT self-assigned this Feb 28, 2025
@azecevicTT azecevicTT linked an issue Feb 28, 2025 that may be closed by this pull request
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

Copy link
Contributor

@sdjordjevicTT sdjordjevicTT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! Thanks!

Copy link
Contributor

@svuckovicTT svuckovicTT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azecevicTT
Copy link
Contributor Author

@svuckovicTT For the docs I planned to do it in the separate PR, just to test it a little bit further to verify that this won't require some major change.

Copy link
Contributor

@svuckovicTT svuckovicTT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs in next iteration.

@azecevicTT azecevicTT enabled auto-merge (squash) March 3, 2025 14:28
@azecevicTT azecevicTT merged commit fd32356 into main Mar 3, 2025
33 checks passed
@azecevicTT azecevicTT deleted the azecevic/emitc-emitter branch March 3, 2025 14:36
azecevicTT added a commit that referenced this pull request Mar 6, 2025
### Ticket
#2343

### Problem description
Part of the effort to onboard all TTNN ops to conversion infrastructure
introduced in #2331

### What's changed
Transitioned ops with existing conversion to conversion with the new
converter. Few changes in the Emitter class, mainly in the way how
operands are treated, to accommodate more complex cases like `Variadic`
of tensors that maps to `std::vector<ttnn::Tensor>`.
vwellsTT pushed a commit that referenced this pull request Mar 6, 2025
### Ticket
#2343

### Problem description
Part of the effort to onboard all TTNN ops to conversion infrastructure
introduced in #2331

### What's changed
Transitioned ops with existing conversion to conversion with the new
converter. Few changes in the Emitter class, mainly in the way how
operands are treated, to accommodate more complex cases like `Variadic`
of tensors that maps to `std::vector<ttnn::Tensor>`.
odjuricicTT pushed a commit that referenced this pull request Mar 8, 2025
### Ticket
#2311

### Problem description
Existing way of TTNN->EmitC conversion exhibits a few limitations:
1. requires too much consideration on the OP to OP basis (requires user
to explicitly make differentiation between operands and attributes)
2. didn't take into consideration many-to-many relationship of MLIR and
C++ types (i.e. {`ArrayAttr`, `DenseI32ArrayAttr`} <->
{`ttnn::SmallVector<int32_t>`, `std::vector<uint32_t>`})

### What's changed
Introduction of the new `EmitCTTNNEmitter` class that should address
these limitations in the following way:
1. Most conversions should follow this pattern
```cpp
ttnn_to_emitc::EmitCTTNNEmitter<TTNNOp> emitter(srcOp, adaptor, rewrite);

llvm::SmallVector<mlir::Attribute> args {
  emitter.emit(srcOp.getArg0()),
  emitter.emit(srcOp.getArg1()),
  ...,
  emitter.emit(srcOp.getArgN())
};

emitter.replaceOp(*this, args);

return success();
```
2. For many-to-many relationship between MLIR and C++ types we 'hint'
emit member function with the target C++ type
```cpp
emitter.emit<ttnn::SmallVector<int32_t>>(srcOp.getSomeDenseArrayAttr())
```
Of course, this is still a utility and it's not baked directly into
MLIR's conversion pattern rewriter, so we can still do it the old way
for the ops whose structure deviates too much from the general op
structure.

### Checklist
- [x] New/Existing tests provide coverage for changes
- At this point `EmitCTTNNEmitter` and related class should still be
considered WIP, next goal is to transfer all of the existing ops to this
type of conversion and leverage existing tests to iron out some missing
details
odjuricicTT pushed a commit that referenced this pull request Mar 8, 2025
### Ticket
#2343

### Problem description
Part of the effort to onboard all TTNN ops to conversion infrastructure
introduced in #2331

### What's changed
Transitioned ops with existing conversion to conversion with the new
converter. Few changes in the Emitter class, mainly in the way how
operands are treated, to accommodate more complex cases like `Variadic`
of tensors that maps to `std::vector<ttnn::Tensor>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TTNN->EmitC new converter
3 participants