Skip to content

add cpuruntime dialect #70

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 9 commits into from
May 16, 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
1 change: 1 addition & 0 deletions include/gc/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(CPURuntime)
add_subdirectory(OneDNNGraph)
add_subdirectory(Microkernel)
add_subdirectory(Linalgx)
2 changes: 2 additions & 0 deletions include/gc/Dialect/CPURuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
1 change: 1 addition & 0 deletions include/gc/Dialect/CPURuntime/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_mlir_dialect(CPURuntimeOps cpuruntime)
18 changes: 18 additions & 0 deletions include/gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===- CPURuntimeDialect.h - CPU Runtime 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
//
//===----------------------------------------------------------------------===//

#ifndef CPURUNTIME_CPURUNTIMEDIALECT_H
#define CPURUNTIME_CPURUNTIMEDIALECT_H

#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/IR/Dialect.h"
#include "mlir/Interfaces/DestinationStyleOpInterface.h"

#include "gc/Dialect/CPURuntime/IR/CPURuntimeOpsDialect.h.inc"

#endif // CPURUNTIME_CPURUNTIMEDIALECT_H
34 changes: 34 additions & 0 deletions include/gc/Dialect/CPURuntime/IR/CPURuntimeDialect.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===- CPURuntimeDialect.td - CPU Runtime 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
//
//===----------------------------------------------------------------------===//

#ifndef CPUPARALLEL_DIALECT
#define CPUPARALLEL_DIALECT

include "mlir/IR/OpBase.td"

//===----------------------------------------------------------------------===//
// CPURuntime dialect definition.
//===----------------------------------------------------------------------===//

def CPURuntime_Dialect : Dialect {
let name = "cpuruntime";
let summary = "A dialect for CPU parallel primitives.";
let description = [{
This dialect contains primitives for CPU runtime.
}];
let cppNamespace = "::mlir::cpuruntime";
}

//===----------------------------------------------------------------------===//
// Base cpuruntime operation definition.
//===----------------------------------------------------------------------===//

class CPURuntime_Op<string mnemonic, list<Trait> traits = []> :
Op<CPURuntime_Dialect, mnemonic, traits>;

#endif // CPUPARALLEL_DIALECT
26 changes: 26 additions & 0 deletions include/gc/Dialect/CPURuntime/IR/CPURuntimeOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- CPURuntimeOps.h - CPU Runtime Ops ====--------------------*- 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 CPURUNTIME_CPURUNTIMEOPS_H
#define CPURUNTIME_CPURUNTIMEOPS_H

#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#define GET_OP_CLASSES
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h.inc"

#endif // CPURUNTIME_CPURUNTIMEOPS_H
33 changes: 33 additions & 0 deletions include/gc/Dialect/CPURuntime/IR/CPURuntimeOps.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- CPURuntimeOps.td - CPU Runtime Ops -----------------------*- 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 CPURUNTIME_OPS
#define CPURUNTIME_OPS

include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.td"
include "mlir/Interfaces/SideEffectInterfaces.td"


def CPURuntime_PrintfOp : CPURuntime_Op<"printf", [MemoryEffects<[MemWrite]>]>,
Arguments<(ins StrAttr:$format,
Variadic<AnyTypeOf<[AnyInteger, Index, AnyFloat]>>:$args)> {
let summary = "C-style printf";
let description = [{
`cpuruntime.printf` takes a literal format string `format` and an arbitrary number of
scalar arguments that should be printed.

The format string is a C-style printf string, subject to any restrictions
imposed by the target platform.
}];
let assemblyFormat = [{
$format attr-dict ($args^ `:` type($args))?
}];
}


#endif // CPURUNTIME_OPS
5 changes: 5 additions & 0 deletions include/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(LLVM_TARGET_DEFINITIONS CPURuntimePasses.td)
mlir_tablegen(CPURuntimePasses.h.inc --gen-pass-decls -name CPURuntime)
mlir_tablegen(CPURuntimePasses.capi.h.inc -gen-pass-capi-header --prefix CPURuntime)
mlir_tablegen(CPURuntimePasses.capi.cpp.inc -gen-pass-capi-impl --prefix CPURuntime)
add_public_tablegen_target(MLIRCPURuntimePassesIncGen)
29 changes: 29 additions & 0 deletions include/gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===- CPURuntimePasses.h - CPU Runtime Passes ------------------*- 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 CPURUNTIME_CPURUNTIMEPASSES_H
#define CPURUNTIME_CPURUNTIMEPASSES_H

#include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h"
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h"
#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {
namespace cpuruntime {
void registerConvertCPURuntimeToLLVMInterface(DialectRegistry &registry);

#define GEN_PASS_DECL
#include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h.inc"

#define GEN_PASS_REGISTRATION
#include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h.inc"
} // namespace cpuruntime
} // namespace mlir

#endif
22 changes: 22 additions & 0 deletions include/gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- CPURuntimePasses.td - CPU Runtime Passes -----------------*- 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 CPURUNTIME_PASS
#define CPURUNTIME_PASS

include "mlir/Pass/PassBase.td"

def CPURuntimeToLLVM: Pass<"convert-cpuruntime-to-llvm"> {
let summary = "Convert cpuruntime to LLVM dialect";
let description = [{
This pass converts supported cpuruntime ops to LLVM dialect instructions.
}];
let dependentDialects = ["LLVM::LLVMDialect"];
}

#endif // CPURUNTIME_PASS
1 change: 1 addition & 0 deletions lib/gc/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(CPURuntime)
add_subdirectory(Linalgx)
add_subdirectory(Microkernel)
add_subdirectory(OneDNNGraph)
2 changes: 2 additions & 0 deletions lib/gc/Dialect/CPURuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
14 changes: 14 additions & 0 deletions lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_mlir_dialect_library(MLIRCPURuntimeDialect
CPURuntimeDialect.cpp
CPURuntimeOps.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/

DEPENDS
MLIRCPURuntimeOpsIncGen
MLIRCPURuntimePassesIncGen

LINK_LIBS PUBLIC
MLIRFuncDialect
)
26 changes: 26 additions & 0 deletions lib/gc/Dialect/CPURuntime/IR/CPURuntimeDialect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- CPURuntimeDialect.cpp - CPU Runtime 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/CPURuntime/IR/CPURuntimeDialect.h"
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.h"

using namespace mlir;
using namespace mlir::cpuruntime;

#include "gc/Dialect/CPURuntime/IR/CPURuntimeOpsDialect.cpp.inc"

//===----------------------------------------------------------------------===//
// CPURuntime dialect.
//===----------------------------------------------------------------------===//

void CPURuntimeDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.cpp.inc"
>();
}
19 changes: 19 additions & 0 deletions lib/gc/Dialect/CPURuntime/IR/CPURuntimeOps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===- CPURuntimeOps.cpp - CPU Runtime Ops ----------------------*- 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/CPURuntime/IR/CPURuntimeOps.h"
#include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h"

#define GET_OP_CLASSES
#include "gc/Dialect/CPURuntime/IR/CPURuntimeOps.cpp.inc"

#include <llvm/Support/Debug.h>

namespace mlir {
namespace cpuruntime {} // namespace cpuruntime
} // namespace mlir
15 changes: 15 additions & 0 deletions lib/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_mlir_dialect_library(MLIRCPURuntimeTransforms
CPURuntimeToLLVM.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/

DEPENDS
MLIRCPURuntimePassesIncGen

LINK_LIBS PUBLIC
MLIRFuncDialect
MLIRCPURuntimeDialect
)

set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS MLIRCPURuntimeTransforms)
Loading