Skip to content

Commit 5669660

Browse files
chencha3joker-eph
andauthored
[MLIR] XeGPU dialect for Intel GPU - core definitions and base classes (#78483)
This PR follows our previous [RFC ](https://discourse.llvm.org/t/rfc-add-xegpu-dialect-for-intel-gpus/75723) to add XeGPU dialect definition for Intel GPUs. It contains dialect, type, attributes and operators definitions, as well as testcases for semantic checks. The lowering and optimization passes will be issued with separated passes. --------- Co-authored-by: Mehdi Amini <[email protected]>
1 parent 5d33f71 commit 5669660

15 files changed

+250
-1
lines changed

mlir/include/mlir/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ add_subdirectory(UB)
4040
add_subdirectory(Utils)
4141
add_subdirectory(Vector)
4242
add_subdirectory(X86Vector)
43+
add_subdirectory(XeGPU)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_mlir_dialect(XeGPU xegpu)
2+
add_mlir_doc(XeGPU XeGPU Dialects/ -gen-dialect-doc -dialect=xegpu)
3+
4+
set(LLVM_TARGET_DEFINITIONS XeGPU.td)
5+
mlir_tablegen(XeGPUAttrs.h.inc -gen-attrdef-decls)
6+
mlir_tablegen(XeGPUAttrs.cpp.inc -gen-attrdef-defs)
7+
add_public_tablegen_target(MLIRXeGPUAttrsIncGen)
8+
add_dependencies(mlir-headers MLIRXeGPUAttrsIncGen)
9+
10+
set(LLVM_TARGET_DEFINITIONS XeGPU.td)
11+
mlir_tablegen(XeGPUEnums.h.inc -gen-enum-decls)
12+
mlir_tablegen(XeGPUEnums.cpp.inc -gen-enum-defs)
13+
add_public_tablegen_target(MLIRXeGPUEnumsIncGen)
14+
add_dependencies(mlir-headers MLIRXeGPUEnumsIncGen)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- XeGPU.h - MLIR dialect for XeGPU -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPU_H
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPU_H
11+
12+
#include <mlir/IR/Dialect.h>
13+
14+
namespace mlir {
15+
namespace xegpu {
16+
// placeholder
17+
} // namespace xegpu
18+
} // namespace mlir
19+
20+
#include <mlir/Dialect/XeGPU/IR/XeGPUDialect.h.inc>
21+
#include <mlir/Dialect/XeGPU/IR/XeGPUEnums.h.inc>
22+
#define GET_ATTRDEF_CLASSES
23+
#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.h.inc>
24+
#define GET_TYPEDEF_CLASSES
25+
#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.h.inc>
26+
#define GET_OP_CLASSES
27+
#include <mlir/Dialect/XeGPU/IR/XeGPU.h.inc>
28+
29+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPU_H
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===- XeGPU.td - XeGPU dialect definition ------------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPU_TD
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPU_TD
11+
12+
include "mlir/Dialect/XeGPU/IR/XeGPUOps.td"
13+
14+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPU_TD
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===- XeGPUAttrs.td - XeGPU dialect attributes definition --*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPUATTRS_TD
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPUATTRS_TD
11+
12+
include "mlir/Dialect/XeGPU/IR/XeGPUDialect.td"
13+
14+
class XeGPUAttr<string name, string attrMnemonic, list<Trait> traits = [],
15+
string baseCppClass = "::mlir::Attribute">
16+
: AttrDef<XeGPU_Dialect, name, traits, baseCppClass> {
17+
let mnemonic = attrMnemonic;
18+
}
19+
20+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPUATTRS_TD
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- XeGPUDialect.td - XeGPU dialect definition -----------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPUDIALECT_TD
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPUDIALECT_TD
11+
12+
include "mlir/IR/OpBase.td"
13+
14+
def XeGPU_Dialect : Dialect {
15+
let name = "xegpu";
16+
let cppNamespace = "::mlir::xegpu";
17+
let summary = "The XeGPU dialect that models Intel GPU's ISA";
18+
let description = [{
19+
The XeGPU dialect models Intel Xe ISA semantics but works at vector and
20+
TensorDesc data type. It provides 1:1 mappings to match Xe instructions
21+
like DPAS and 2D block load. The matrix size being processed at this level
22+
exactly matches the hardware instructions or the intrinsic supported by
23+
the lower-level GPU compiler.
24+
}];
25+
26+
// let useDefaultTypePrinterParser = true;
27+
// let useDefaultAttributePrinterParser = true;
28+
}
29+
30+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPUDIALECT_TD
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- XeGPUOps.td - XeGPU dialect operations definition ----*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPUOPS_TD
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPUOPS_TD
11+
12+
include "mlir/Dialect/XeGPU/IR/XeGPUAttrs.td"
13+
include "mlir/Dialect/XeGPU/IR/XeGPUDialect.td"
14+
include "mlir/Dialect/XeGPU/IR/XeGPUTypes.td"
15+
16+
17+
// Base class for dialect operations. This operation inherits from the base
18+
// `Op` class in OpBase.td, and provides:
19+
// * The parent dialect of the operation.
20+
// * The mnemonic for the operation, or the name without the dialect prefix.
21+
// * A list of traits for the operation.
22+
class XeGPU_Op<string mnemonic, list<Trait> traits = []>:
23+
Op<XeGPU_Dialect, mnemonic, traits>;
24+
25+
26+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPUOPS_TD
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- XeGPUTypes.td - XeGPU dialect types definition -------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_DIALECT_XEGPU_IR_XEGPUTYPES_TD
10+
#define MLIR_DIALECT_XEGPU_IR_XEGPUTYPES_TD
11+
12+
include "mlir/IR/BuiltinTypes.td"
13+
include "mlir/Dialect/XeGPU/IR/XeGPUAttrs.td"
14+
include "mlir/Dialect/XeGPU/IR/XeGPUDialect.td"
15+
16+
def XeGPU_IntType: AnyTypeOf<[I1, I8, I16, I32, I64, SI1, SI8, SI16, SI32, SI64, UI1, UI8, UI16, UI32, UI64]>;
17+
def XeGPU_FloatType: AnyTypeOf<[F16, F32, F64, BF16, TF32]>;
18+
def XeGPU_ScalarType: AnyTypeOf<[XeGPU_IntType, XeGPU_FloatType]>;
19+
def XeGPU_BaseAddrType: AnyTypeOf<[MemRefRankOf<[XeGPU_ScalarType], [1, 2]>, UI64, UI32, I64, I32]>;
20+
def XeGPU_DpasOpType: VectorOfRankAndType<[2, 3], [XeGPU_ScalarType]>;
21+
def XeGPU_OffsetType: VectorOfRankAndType<[1], [Index]>;
22+
def XeGPU_MaskType: AnyTypeOf<[VectorOfRankAndType<[1,2], [I1]>, I1]>;
23+
def XeGPU_ValueType: AnyTypeOf<[VectorOfRankAndType<[1,2,3,4], [XeGPU_ScalarType]>, XeGPU_ScalarType]>;
24+
def XeGPU_Vector2DType: VectorOfRankAndType<[2], [XeGPU_ScalarType]>;
25+
26+
// common base class for types in XeGPU dialect
27+
class XeGPUTypeDef<string name, string typeMnemonic, list<Trait> traits = [],
28+
string baseCppClass = "::mlir::Type">
29+
: TypeDef<XeGPU_Dialect, name, traits, baseCppClass> {
30+
let mnemonic = typeMnemonic;
31+
}
32+
33+
#endif // MLIR_DIALECT_XEGPU_IR_XEGPUTYPES_TD

mlir/include/mlir/InitAllDialects.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
#include "mlir/Dialect/Vector/Transforms/BufferizableOpInterfaceImpl.h"
9090
#include "mlir/Dialect/Vector/Transforms/SubsetOpInterfaceImpl.h"
9191
#include "mlir/Dialect/X86Vector/X86VectorDialect.h"
92+
#include "mlir/Dialect/XeGPU/IR/XeGPU.h"
9293
#include "mlir/IR/Dialect.h"
9394
#include "mlir/Interfaces/CastInterfaces.h"
9495
#include "mlir/Target/LLVM/NVVM/Target.h"
@@ -141,7 +142,8 @@ inline void registerAllDialects(DialectRegistry &registry) {
141142
transform::TransformDialect,
142143
ub::UBDialect,
143144
vector::VectorDialect,
144-
x86vector::X86VectorDialect>();
145+
x86vector::X86VectorDialect,
146+
xegpu::XeGPUDialect>();
145147
// clang-format on
146148

147149
// Register all external models.

mlir/lib/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ add_subdirectory(UB)
4040
add_subdirectory(Utils)
4141
add_subdirectory(Vector)
4242
add_subdirectory(X86Vector)
43+
add_subdirectory(XeGPU)
4344

4445
set(LLVM_OPTIONAL_SOURCES
4546
Traits.cpp

mlir/lib/Dialect/XeGPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_mlir_dialect_library(MLIRXeGPUDialect
2+
XeGPUDialect.cpp
3+
XeGPUOps.cpp
4+
5+
ADDITIONAL_HEADER_DIRS
6+
${PROJECT_SOURCE_DIR}/include/mlir/Dialect/XeGPU
7+
8+
DEPENDS
9+
MLIRXeGPUIncGen
10+
MLIRXeGPUAttrsIncGen
11+
MLIRXeGPUEnumsIncGen
12+
13+
LINK_LIBS PUBLIC
14+
MLIRIR
15+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===- XeGPUDialect.cpp - MLIR XeGPU dialect implementation -----*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <mlir/Dialect/XeGPU/IR/XeGPU.h>
10+
11+
namespace mlir {
12+
namespace xegpu {
13+
14+
void XeGPUDialect::initialize() {
15+
addTypes<
16+
#define GET_TYPEDEF_LIST
17+
#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.cpp.inc>
18+
>();
19+
addOperations<
20+
#define GET_OP_LIST
21+
#include <mlir/Dialect/XeGPU/IR/XeGPU.cpp.inc>
22+
>();
23+
addAttributes<
24+
#define GET_ATTRDEF_LIST
25+
#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.cpp.inc>
26+
>();
27+
}
28+
29+
// this file is for position occupation,
30+
// we will add functions in following PRs.
31+
32+
} // namespace xegpu
33+
} // namespace mlir
34+
35+
#include <mlir/Dialect/XeGPU/IR/XeGPUDialect.cpp.inc>
36+
#define GET_ATTRDEF_CLASSES
37+
#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.cpp.inc>
38+
#define GET_TYPEDEF_CLASSES
39+
#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.cpp.inc>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- XeGPUOps.cpp - MLIR XeGPU ops implementation -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <mlir/Dialect/XeGPU/IR/XeGPU.h>
10+
11+
#define DEBUG_TYPE "xegpu"
12+
13+
namespace mlir {
14+
namespace xegpu {
15+
// this file is for position occupation,
16+
// we will add functions in following PRs.
17+
18+
} // namespace xegpu
19+
} // namespace mlir
20+
21+
#include <mlir/Dialect/XeGPU/IR/XeGPUEnums.cpp.inc>
22+
#define GET_OP_CLASSES
23+
#include <mlir/Dialect/XeGPU/IR/XeGPU.cpp.inc>

0 commit comments

Comments
 (0)