Skip to content

[OneDNN Graph Dialect] Use Broadcast Trait and organize data types #81

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 3 commits into from
May 22, 2024

Conversation

BRUCE11111
Copy link

Some small changes:

  1. Use broadcast trait to replace some functions.
  2. Add some data types.

auto ret =
inferBroadcastShape<ValueShapeRange>(operands, outShape, getShapeIdx);
llvm::SmallVector<int64_t> input1, input2;
getShapeIdx(operands, 0).getDims(input1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use something like getShape to get the ArrayRef of shape for performance?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks~ Optimized the code~

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, maybe dyn_cast<ShapedType>() should be better, in case we need to support other shaped types in the future.

// final shape
auto retShape = ShapedTypeComponents(outShape, lhsShape.getElementType());
inferredReturnShapes.push_back(retShape);
// check for bias broadcasting
if (adaptor.getBias()) {
ShapeAdaptor biasShape(adaptor.getBias().getType());
ShapeAdaptor matShape(retShape);
llvm::SmallVector<int64_t> matmulShape;
matShape.getDims(matmulShape);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use something like getShape to get the ArrayRef of shape for performance?

@ZhennanQin ZhennanQin changed the title [Dialect] Use Broadcast Trait and add some data types [OneDNN Graph Dialect] Use Broadcast Trait and add some data types May 16, 2024
@LongshengDu LongshengDu changed the title [OneDNN Graph Dialect] Use Broadcast Trait and add some data types [OneDNN Graph Dialect] Use Broadcast Trait and organize data types May 16, 2024
@BRUCE11111 BRUCE11111 requested a review from kurapov-peter May 17, 2024 08:18
Comment on lines +21 to +32
// Floating-point types.
//===----------------------------------------------------------------------===//
def OneDNNGraph_Float : AnyTypeOf<[F32,
F16,
BF16]>;

//===----------------------------------------------------------------------===//
// Integer types.
//===----------------------------------------------------------------------===//

def OneDNNGraph_Int : AnyTypeOf<[SI<8>,
UI<8>]>;
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 the rationale for having separate types? Also, why do we only have fp16 and int8?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

For ops like matmul, only f32/bf16/f16 are supported: https://oneapi-src.github.io/oneDNN/dev_guide_op_matmul.html#supported-data-types

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.

Summary: having separate types just follows the spec and helps us automatically check typing. The change associated with potential op semantic change (e.g., quantize int->int) is estimated as minor.

@kurapov-peter
Copy link
Contributor

This will still need to change when fp8eX types are added.

@LongshengDu LongshengDu merged commit 6437c35 into main May 22, 2024
2 checks passed
@LongshengDu LongshengDu deleted the xiaohui/onednn_dialect_refactor branch May 22, 2024 12:10
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