Skip to content

[Dialect] Add basic oneDNN Graph dialect #43

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

Merged
merged 8 commits into from
May 14, 2024

Conversation

LongshengDu
Copy link
Contributor

@LongshengDu LongshengDu commented May 8, 2024

Add basic oneDNN Graph dialect, ops, types. More oneDNN Graph ops and lowering will be added in following PRs.
Also renamed OnednnGraphDialect to OneDNNGraphDialect as the original definition.

Tracking: #13

@LongshengDu LongshengDu changed the title dialect: add basic oneDNN Graph dialect dialect: add basic oneDNN Graph dialect and lowering May 8, 2024
let results = (outs OneDNNGraph_LogicalTensor:$result);

let assemblyFormat =
"operands attr-dict `:` functional-type(operands, results)";
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need custom assembly format?

Copy link
Contributor Author

@LongshengDu LongshengDu May 9, 2024

Choose a reason for hiding this comment

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

For consistency and visibility, we want to make assembly format explicit.

Copy link
Contributor

@kurapov-peter kurapov-peter left a comment

Choose a reason for hiding this comment

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

This adds lowering and some other stuff like shape propagation. Could you please split it into separate PRs? Simple lowering can go together with the dialect definition.
Let's also keep it clean. Could you please remove all the commented out code?

Comment on lines 33 to 34
def OneDNNGraph_LogicalTensor : TensorOf<[OneDNNGraph_DataType]>;
def OneDNNGraph_FloatLogicalTensor : TensorOf<[OneDNNGraph_FloatDataType]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have two different types? We are not even using the second one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Second one was used to test quantization ops, remove it for now. Later @BRUCE11111 will introduce a new PR to add a better way to organize types.

namespace mlir {
namespace onednn_graph {

// https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this reference for and how it is related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is before we switched to ResultsBroadcastableShape, kept it so @BRUCE11111 can migrate his PR to here. inferBroadcastShape will be deleted.


// https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md
template <typename ShapeRange>
static LogicalResult inferBroadcastShape(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need it for the dialect definition or can add later?

Copy link
Contributor Author

@LongshengDu LongshengDu May 9, 2024

Choose a reason for hiding this comment

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

inferBroadcastShape is necessary for onednn graph op verification, since InferTensorType trait is used. Will be replaced by ResultsBroadcastableShape trait next, while properly crediting the author.

PatternRewriter &rewriter) const final {
auto loc = op->getLoc();
auto resultTy = dyn_cast<TensorType>(op->getResultTypes().front());
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//

Comment on lines 182 to 183
// using ExpOpLowering = UnaryElemwiseLowering< //
// onednn_graph::ExpOp, CreateLoweredUnaryOp<math::ExpOp>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// using ExpOpLowering = UnaryElemwiseLowering< //
// onednn_graph::ExpOp, CreateLoweredUnaryOp<math::ExpOp>>;

Comment on lines 15 to 18
// CHECK: tensor.empty()
// CHECK: linalg.generic
// CHECK: arith.addf
%0 = onednn_graph.add %arg0, %arg1 : (tensor<128x256xf32>, tensor<128x256xf32>) -> tensor<128x256xf32>
Copy link
Contributor

Choose a reason for hiding this comment

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

These can lower to named ops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a separate branch updating the lowering code and to suit our need after previous design discussions, this one only migrates current code in old repo. Since we are about to add lowering in a separate PR, I will squash them together in the lowering PR.

@LongshengDu LongshengDu changed the title dialect: add basic oneDNN Graph dialect and lowering dialect: add basic oneDNN Graph dialect May 9, 2024
Longsheng Du added 2 commits May 13, 2024 11:12
@LongshengDu LongshengDu force-pushed the longsheng/add_onednn_graph branch from 4e629e5 to cd43162 Compare May 13, 2024 03:16
@LongshengDu
Copy link
Contributor Author

@kurapov-peter @Devjiu Please review again.

@LongshengDu LongshengDu changed the title dialect: add basic oneDNN Graph dialect [Dialect] add basic oneDNN Graph dialect May 13, 2024
@LongshengDu LongshengDu changed the title [Dialect] add basic oneDNN Graph dialect [Dialect] Add basic oneDNN Graph dialect May 13, 2024
Copy link
Contributor

@kurapov-peter kurapov-peter left a comment

Choose a reason for hiding this comment

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

This looks almost ready. I didn't look at the shape inference too closely as it's a subject for change.

Comment on lines +33 to +34
let assemblyFormat =
"operands attr-dict `:` functional-type(operands, results)";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think making assembly format explicit would be better.

Comment on lines 20 to 22
def OneDNNGraph_DataType : AnyTypeOf<[
F16,
BF16,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, my eye is twitching otherwise :)

Suggested change
def OneDNNGraph_DataType : AnyTypeOf<[
F16,
BF16,
def OneDNNGraph_DataType : AnyTypeOf<[
F16,
BF16,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 15 to 17
#include "mlir/Dialect/Tosa/IR/TosaOps.h"
#include "mlir/Dialect/Tosa/Utils/QuantUtils.h"
#include "mlir/Dialect/Tosa/Utils/ShapeUtils.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, was used to test some functionality.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be missing checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@LongshengDu LongshengDu requested a review from kurapov-peter May 14, 2024 07:14
@kurapov-peter kurapov-peter merged commit a713c16 into main May 14, 2024
2 checks passed
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.

4 participants