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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ add_subdirectory(src)
set(GC_LIB_LINKED_LIBS
MLIRLinalgx
MLIRMicrokernel
MLIROnednnGraph
MLIROneDNNGraph
)
add_library(graph_compiler SHARED ${GC_LIB_SOURCES})
target_include_directories(graph_compiler PUBLIC ${GC_LIB_INCLUDES})
Expand Down
2 changes: 1 addition & 1 deletion include/gc/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_subdirectory(OnednnGraph)
add_subdirectory(OneDNNGraph)
add_subdirectory(Microkernel)
add_subdirectory(Linalgx)
3 changes: 3 additions & 0 deletions include/gc/Dialect/OneDNNGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_mlir_dialect(OneDNNGraphOps onednn_graph)
add_mlir_doc(OneDNNGraphOps OneDNNGraphOps gc/Dialect/OneDNNGraph/ -gen-op-doc)
add_mlir_doc(OneDNNGraphDialect OneDNNGraphDialect gc/Dialect/OneDNNGraph/ -gen-dialect-doc)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- OnednnGraphDialect.h - OneDNN input dialect --------------*- C++ -*-===//
//===- OneDNNGraphDialect.h - OneDNN input dialect --------------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -10,7 +10,10 @@
#define GC_DIALECTS_ONEDNNGRAPHDIALECT_H

#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"

#include "gc/Dialect/OnednnGraph/OnednnGraphOpsDialect.h.inc"
#define GET_OP_CLASSES
#include "gc/Dialect/OneDNNGraph/OneDNNGraphOpsDialect.h.inc"

#endif // GC_DIALECTS_ONEDNNGRAPHDIALECT_H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- OnednnGraphDialect.td - OneDNN input dialect --------*- tablegen -*-===//
//===- OneDNNGraphDialect.td - OneDNN input dialect --------*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -15,15 +15,13 @@ include "mlir/IR/OpBase.td"
// OneDNNGraph dialect definition.
//===----------------------------------------------------------------------===//

def OnednnGraphDialect : Dialect {
def OneDNNGraphDialect : Dialect {
let name = "onednn_graph";
let summary = "A dialect for oneDNN Graph.";
let description = [{
This dialect follows oneDNN Graph Specification.
}];
let cppNamespace = "::mlir::onednn_graph";

let useDefaultTypePrinterParser = 1;
}

#endif // ONEDNNGRAPH_DIALECT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- OnednnGraphOps.h - OneDNN input dialect ops --------------*- C++ -*-===//
//===- OneDNNGraphOps.h - OneDNN input dialect ops --------------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,9 +9,15 @@
#ifndef GC_DIALECTS_ONEDNNGRAPHOPS_H
#define GC_DIALECTS_ONEDNNGRAPHOPS_H

#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#define GET_OP_CLASSES
#include "gc/Dialect/OnednnGraph/OnednnGraphOps.h.inc"
#include "gc/Dialect/OneDNNGraph/OneDNNGraphOps.h.inc"

#endif // GC_DIALECTS_ONEDNNGRAPHOPS_H
82 changes: 82 additions & 0 deletions include/gc/Dialect/OneDNNGraph/OneDNNGraphOps.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//===- OneDNNGraphOps.td - OneDNN input dialect ops --------*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef ONEDNNGRAPH_OPS
#define ONEDNNGRAPH_OPS

include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/DestinationStyleOpInterface.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"
include "OneDNNGraphDialect.td"
include "OneDNNGraphTypes.td"

//===----------------------------------------------------------------------===//
// Base OneDNNGraph operation definition.
//===----------------------------------------------------------------------===//

class OneDNNGraph_Op<string mnemonic, list<Trait> traits = []> :
Op<OneDNNGraphDialect, mnemonic, traits>;

class OneDNNGraph_ElemwiseBinaryOp<string mnemonic, list<Trait> traits = []> :
OneDNNGraph_Op<mnemonic, traits # [SameOperandsAndResultElementType, InferTensorType]> {
let arguments = (ins OneDNNGraph_LogicalTensor:$input_0,
OneDNNGraph_LogicalTensor:$input_1);
let results = (outs OneDNNGraph_LogicalTensor:$result);

let assemblyFormat =
"operands attr-dict `:` functional-type(operands, results)";
Comment on lines +33 to +34
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.

}

class OneDNNGraph_ElemwiseUnaryOp<string mnemonic, list<Trait> traits = []> :
OneDNNGraph_Op<mnemonic, traits # [SameOperandsAndResultType]> {
let arguments = (ins OneDNNGraph_LogicalTensor:$operand);
let results = (outs OneDNNGraph_LogicalTensor:$result);

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

//===----------------------------------------------------------------------===//
// OneDNNGraph op definitions
//===----------------------------------------------------------------------===//

def OneDNNGraph_MatMulOp :
OneDNNGraph_Op<"matmul", [SameOperandsAndResultElementType, InferTensorTypeAdaptor]> {
let summary = "Generalized matrix multiplication";
let description = [{
`https://spec.oneapi.io/onednn-graph/latest/ops/matrix/MatMul_1.html`
}];

let arguments = (ins OneDNNGraph_LogicalTensor:$input_a,
OneDNNGraph_LogicalTensor:$input_b,
Optional<OneDNNGraph_LogicalTensor>:$bias,
DefaultValuedAttr<BoolAttr, "false">:$transpose_a,
DefaultValuedAttr<BoolAttr, "false">:$transpose_b);
let results = (outs OneDNNGraph_LogicalTensor:$result);

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

def OneDNNGraph_ReLUOp : OneDNNGraph_ElemwiseUnaryOp<"relu"> {
let summary = "element-wise relu";
let description = [{
`https://spec.oneapi.io/onednn-graph/latest/ops/activation/ReLU_1.html`
}];
}

def OneDNNGraph_AddOp : OneDNNGraph_ElemwiseBinaryOp<"add", [Commutative]> {
let summary = "element-wise addition with multi-directional broadcast";
let description = [{
`https://spec.oneapi.io/onednn-graph/latest/ops/arithmetic/Add_1.html`
}];
}

#endif // ONEDNNGRAPH_OPS
17 changes: 17 additions & 0 deletions include/gc/Dialect/OneDNNGraph/OneDNNGraphTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===- OneDNNGraphTypes.h - OneDNN input dialect types ----------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef ONEDNNGRAPH_ONEDNNGRAPHTYPES_H
#define ONEDNNGRAPH_ONEDNNGRAPHTYPES_H

#include "mlir/IR/BuiltinTypes.h"

#define GET_TYPEDEF_CLASSES
#include "gc/Dialect/OneDNNGraph/OneDNNGraphOpsTypes.h.inc"

#endif // ONEDNNGRAPH_ONEDNNGRAPHTYPES_H
30 changes: 30 additions & 0 deletions include/gc/Dialect/OneDNNGraph/OneDNNGraphTypes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- OneDNNGraphTypes.h - OneDNN input dialect types -----*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef ONEDNNGRAPH_TYPES
#define ONEDNNGRAPH_TYPES

include "mlir/IR/BuiltinTypes.td"
include "mlir/IR/AttrTypeBase.td"
include "OneDNNGraphDialect.td"

//===----------------------------------------------------------------------===//
// OneDNNGraph type definitions
//===----------------------------------------------------------------------===//

def OneDNNGraph_DataType : AnyTypeOf<[
F16,
BF16,
F32,
SI<32>,
SI<8>,
UI<8>]>;

def OneDNNGraph_LogicalTensor : TensorOf<[OneDNNGraph_DataType]>;

#endif // ONEDNNGRAPH_TYPES
3 changes: 0 additions & 3 deletions include/gc/Dialect/OnednnGraph/CMakeLists.txt

This file was deleted.

14 changes: 0 additions & 14 deletions include/gc/Dialect/OnednnGraph/OnednnGraphOps.td

This file was deleted.

2 changes: 1 addition & 1 deletion lib/gc/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_subdirectory(Linalgx)
add_subdirectory(Microkernel)
add_subdirectory(OnednnGraph)
add_subdirectory(OneDNNGraph)
13 changes: 13 additions & 0 deletions lib/gc/Dialect/OneDNNGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_mlir_dialect_library(MLIROneDNNGraph
OneDNNGraphDialect.cpp
OneDNNGraphOps.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/gc/Dialect/OneDNNGraph

DEPENDS
MLIROneDNNGraphOpsIncGen

LINK_LIBS PUBLIC
MLIRIR
)
27 changes: 27 additions & 0 deletions lib/gc/Dialect/OneDNNGraph/OneDNNGraphDialect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===- OneDNNGraphDialect.h - OneDNN input dialect --------------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "gc/Dialect/OneDNNGraph/OneDNNGraphDialect.h"
#include "gc/Dialect/OneDNNGraph/OneDNNGraphOps.h"
#include "gc/Dialect/OneDNNGraph/OneDNNGraphTypes.h"

using namespace mlir;
using namespace mlir::onednn_graph;

#include "gc/Dialect/OneDNNGraph/OneDNNGraphOpsDialect.cpp.inc"

//===----------------------------------------------------------------------===//
// OneDNNGraph dialect.
//===----------------------------------------------------------------------===//

void OneDNNGraphDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "gc/Dialect/OneDNNGraph/OneDNNGraphOps.cpp.inc"
>();
}
Loading