Skip to content

Commit 5de3506

Browse files
author
Menooker
authored
add cpuruntime dialect (#70)
1 parent 4330dd7 commit 5de3506

22 files changed

+447
-2
lines changed

include/gc/Dialect/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(CPURuntime)
12
add_subdirectory(OneDNNGraph)
23
add_subdirectory(Microkernel)
34
add_subdirectory(Linalgx)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(IR)
2+
add_subdirectory(Transforms)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_mlir_dialect(CPURuntimeOps cpuruntime)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===- CPURuntimeDialect.h - CPU Runtime dialect ----------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPURUNTIME_CPURUNTIMEDIALECT_H
10+
#define CPURUNTIME_CPURUNTIMEDIALECT_H
11+
12+
#include "mlir/Bytecode/BytecodeOpInterface.h"
13+
#include "mlir/IR/Dialect.h"
14+
#include "mlir/Interfaces/DestinationStyleOpInterface.h"
15+
16+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOpsDialect.h.inc"
17+
18+
#endif // CPURUNTIME_CPURUNTIMEDIALECT_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- CPURuntimeDialect.td - CPU Runtime Dialect ---------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPUPARALLEL_DIALECT
10+
#define CPUPARALLEL_DIALECT
11+
12+
include "mlir/IR/OpBase.td"
13+
14+
//===----------------------------------------------------------------------===//
15+
// CPURuntime dialect definition.
16+
//===----------------------------------------------------------------------===//
17+
18+
def CPURuntime_Dialect : Dialect {
19+
let name = "cpuruntime";
20+
let summary = "A dialect for CPU parallel primitives.";
21+
let description = [{
22+
This dialect contains primitives for CPU runtime.
23+
}];
24+
let cppNamespace = "::mlir::cpuruntime";
25+
}
26+
27+
//===----------------------------------------------------------------------===//
28+
// Base cpuruntime operation definition.
29+
//===----------------------------------------------------------------------===//
30+
31+
class CPURuntime_Op<string mnemonic, list<Trait> traits = []> :
32+
Op<CPURuntime_Dialect, mnemonic, traits>;
33+
34+
#endif // CPUPARALLEL_DIALECT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- CPURuntimeOps.h - CPU Runtime Ops ====--------------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPURUNTIME_CPURUNTIMEOPS_H
10+
#define CPURUNTIME_CPURUNTIMEOPS_H
11+
12+
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
13+
#include "mlir/Dialect/MemRef/IR/MemRef.h"
14+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
15+
#include "mlir/Dialect/SCF/IR/SCF.h"
16+
#include "mlir/IR/BuiltinTypes.h"
17+
#include "mlir/IR/Dialect.h"
18+
#include "mlir/IR/OpDefinition.h"
19+
#include "mlir/Interfaces/ControlFlowInterfaces.h"
20+
#include "mlir/Interfaces/InferTypeOpInterface.h"
21+
#include "mlir/Interfaces/SideEffectInterfaces.h"
22+
23+
#define GET_OP_CLASSES
24+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h.inc"
25+
26+
#endif // CPURUNTIME_CPURUNTIMEOPS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- CPURuntimeOps.td - CPU Runtime Ops -----------------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPURUNTIME_OPS
10+
#define CPURUNTIME_OPS
11+
12+
include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.td"
13+
include "mlir/Interfaces/SideEffectInterfaces.td"
14+
15+
16+
def CPURuntime_PrintfOp : CPURuntime_Op<"printf", [MemoryEffects<[MemWrite]>]>,
17+
Arguments<(ins StrAttr:$format,
18+
Variadic<AnyTypeOf<[AnyInteger, Index, AnyFloat]>>:$args)> {
19+
let summary = "C-style printf";
20+
let description = [{
21+
`cpuruntime.printf` takes a literal format string `format` and an arbitrary number of
22+
scalar arguments that should be printed.
23+
24+
The format string is a C-style printf string, subject to any restrictions
25+
imposed by the target platform.
26+
}];
27+
let assemblyFormat = [{
28+
$format attr-dict ($args^ `:` type($args))?
29+
}];
30+
}
31+
32+
33+
#endif // CPURUNTIME_OPS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(LLVM_TARGET_DEFINITIONS CPURuntimePasses.td)
2+
mlir_tablegen(CPURuntimePasses.h.inc --gen-pass-decls -name CPURuntime)
3+
mlir_tablegen(CPURuntimePasses.capi.h.inc -gen-pass-capi-header --prefix CPURuntime)
4+
mlir_tablegen(CPURuntimePasses.capi.cpp.inc -gen-pass-capi-impl --prefix CPURuntime)
5+
add_public_tablegen_target(MLIRCPURuntimePassesIncGen)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- CPURuntimePasses.h - CPU Runtime Passes ------------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPURUNTIME_CPURUNTIMEPASSES_H
10+
#define CPURUNTIME_CPURUNTIMEPASSES_H
11+
12+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h"
13+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h"
14+
#include "mlir/Pass/Pass.h"
15+
#include <memory>
16+
17+
namespace mlir {
18+
namespace cpuruntime {
19+
void registerConvertCPURuntimeToLLVMInterface(DialectRegistry &registry);
20+
21+
#define GEN_PASS_DECL
22+
#include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h.inc"
23+
24+
#define GEN_PASS_REGISTRATION
25+
#include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h.inc"
26+
} // namespace cpuruntime
27+
} // namespace mlir
28+
29+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- CPURuntimePasses.td - CPU Runtime Passes -----------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 CPURUNTIME_PASS
10+
#define CPURUNTIME_PASS
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def CPURuntimeToLLVM: Pass<"convert-cpuruntime-to-llvm"> {
15+
let summary = "Convert cpuruntime to LLVM dialect";
16+
let description = [{
17+
This pass converts supported cpuruntime ops to LLVM dialect instructions.
18+
}];
19+
let dependentDialects = ["LLVM::LLVMDialect"];
20+
}
21+
22+
#endif // CPURUNTIME_PASS

lib/gc/Dialect/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(CPURuntime)
12
add_subdirectory(Linalgx)
23
add_subdirectory(Microkernel)
34
add_subdirectory(OneDNNGraph)
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(IR)
2+
add_subdirectory(Transforms)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_mlir_dialect_library(MLIRCPURuntimeDialect
2+
CPURuntimeDialect.cpp
3+
CPURuntimeOps.cpp
4+
5+
ADDITIONAL_HEADER_DIRS
6+
${PROJECT_SOURCE_DIR}/include/
7+
8+
DEPENDS
9+
MLIRCPURuntimeOpsIncGen
10+
MLIRCPURuntimePassesIncGen
11+
12+
LINK_LIBS PUBLIC
13+
MLIRFuncDialect
14+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- CPURuntimeDialect.cpp - CPU Runtime Dialect --------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h"
10+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h"
11+
12+
using namespace mlir;
13+
using namespace mlir::cpuruntime;
14+
15+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOpsDialect.cpp.inc"
16+
17+
//===----------------------------------------------------------------------===//
18+
// CPURuntime dialect.
19+
//===----------------------------------------------------------------------===//
20+
21+
void CPURuntimeDialect::initialize() {
22+
addOperations<
23+
#define GET_OP_LIST
24+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.cpp.inc"
25+
>();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===- CPURuntimeOps.cpp - CPU Runtime Ops ----------------------*- C++ -*-===//
2+
//
3+
// This file is licensed 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 "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h"
10+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h"
11+
12+
#define GET_OP_CLASSES
13+
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.cpp.inc"
14+
15+
#include <llvm/Support/Debug.h>
16+
17+
namespace mlir {
18+
namespace cpuruntime {} // namespace cpuruntime
19+
} // namespace mlir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_mlir_dialect_library(MLIRCPURuntimeTransforms
2+
CPURuntimeToLLVM.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${PROJECT_SOURCE_DIR}/include/
6+
7+
DEPENDS
8+
MLIRCPURuntimePassesIncGen
9+
10+
LINK_LIBS PUBLIC
11+
MLIRFuncDialect
12+
MLIRCPURuntimeDialect
13+
)
14+
15+
set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS MLIRCPURuntimeTransforms)

0 commit comments

Comments
 (0)