Skip to content

Commit 9f5a264

Browse files
authored
[tune] Introduce transform.tune.select and tune dialect boilerplate (#1053)
Can be used to generate syntax which represents a non-deterministic choice. E.g., as follows: ```python diff --git a/python/mlir/tpp/sched/main.py b/python/mlir/tpp/sched/main.py index be31fb2..4f1f6719 100644 --- a/python/mlir/tpp/sched/main.py +++ b/python/mlir/tpp/sched/main.py @@ -5,6 +5,7 @@ from argparse import ArgumentParser from mlir import ir, passmanager from mlir.dialects import transform from mlir.dialects import check, perf, xsmm # Registers our TPP-MLIR dialects. +from mlir.dialects.transform import tune from mlir.dialects.transform import interpreter as transform_interpreter from . import bundles @@ -92,6 +93,12 @@ def overall_schedule(**config: Dict[str, Any]) -> ir.Module: op_name="builtin.module", deduplicate=True, ) + i64 = ir.IntegerType.get_signless(64) + tune.select( + transform.AnyParamType.get(), + name="coin_flip", + options=[ir.IntegerAttr.get(i64, 0), ir.IntegerAttr.get(i64, 1)], + ) try: # Now pass the module handle through the bundles. ```
1 parent ecedfb0 commit 9f5a264

File tree

19 files changed

+295
-0
lines changed

19 files changed

+295
-0
lines changed

include/TPP/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(Check)
22
add_subdirectory(Perf)
3+
add_subdirectory(Tune)
34
add_subdirectory(Xsmm)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#add_mlir_dialect(TuneOps tune)
2+
add_mlir_doc(TuneDialect TuneDialect TPP/ -gen-dialect-doc)
3+
4+
set(LLVM_TARGET_DEFINITIONS TuneTransformOps.td)
5+
mlir_tablegen(TuneTransformOps.h.inc -gen-op-decls)
6+
mlir_tablegen(TuneTransformOps.cpp.inc -gen-op-defs)
7+
add_public_tablegen_target(TuneTransformOpsIncGen)
8+
9+
add_mlir_doc(TuneTransformOps TuneTransformOps ./ -gen-op-doc)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- TuneDialect.h - Tune 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 TPP_DIALECT_TUNE_TUNEDIALECT_H
10+
#define TPP_DIALECT_TUNE_TUNEDIALECT_H
11+
12+
#include "mlir/IR/Dialect.h"
13+
14+
namespace mlir {
15+
namespace tune {
16+
17+
class TuneDialect : public Dialect {
18+
public:
19+
explicit TuneDialect(MLIRContext *context);
20+
static StringRef getDialectNamespace() { return "tune"; }
21+
};
22+
23+
} // namespace tune
24+
} // namespace mlir
25+
26+
#endif // TPP_DIALECT_TUNE_TUNEDIALECT_H
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===- TuneDialect.td - Tune dialect ----------------------*- tablegen -*--===//
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 TPP_TUNE_DIALECT
10+
#define TPP_TUNE_DIALECT
11+
12+
include "mlir/IR/OpBase.td"
13+
14+
//===----------------------------------------------------------------------===//
15+
// Tune dialect definition.
16+
//===----------------------------------------------------------------------===//
17+
18+
def Tune_Dialect : Dialect {
19+
let name = "tune";
20+
let summary = "Tune dialect.";
21+
let description = [{
22+
TODO
23+
}];
24+
let cppNamespace = "::mlir::tune";
25+
let usePropertiesForAttributes = 1;
26+
}
27+
28+
//===----------------------------------------------------------------------===//
29+
// Base operation definition.
30+
//===----------------------------------------------------------------------===//
31+
32+
class Tune_Op<string mnemonic, list<Trait> traits = []> :
33+
Op<Tune_Dialect, mnemonic, traits>;
34+
35+
#endif // TPP_TUNE_DIALECT
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef TPP_DIALECT_TUNE_TUNETRANSFORMOPS_H
2+
#define TPP_DIALECT_TUNE_TUNETRANSFORMOPS_H
3+
4+
#include "mlir/Dialect/Transform/IR/TransformOps.h"
5+
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
6+
#include "mlir/IR/OpImplementation.h"
7+
8+
#define GET_OP_CLASSES
9+
#include "TPP/Dialect/Tune/TuneTransformOps.h.inc"
10+
11+
namespace mlir {
12+
namespace tune {
13+
void registerTransformDialectExtension(DialectRegistry &registry);
14+
} // namespace tune
15+
} // namespace mlir
16+
17+
#endif // MLIR_TUNE_TRANSFORM_OPS_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef TUNE_TRANSFORM_OPS
2+
#define TUNE_TRANSFORM_OPS
3+
4+
include "mlir/Dialect/Transform/IR/TransformDialect.td"
5+
include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
6+
include "mlir/Interfaces/SideEffectInterfaces.td"
7+
8+
9+
def TuneSelectOp : Op<Transform_Dialect, "tune.select", [
10+
DeclareOpInterfaceMethods<TransformOpInterface>,
11+
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>
12+
]> {
13+
let summary = "Non-deterministically select a value from a set of values";
14+
let description = [{
15+
TODO
16+
}];
17+
18+
let arguments = (ins SymbolRefAttr:$name,
19+
ArrayAttr:$options);
20+
let results = (outs TransformParamTypeInterface:$selected);
21+
let assemblyFormat =
22+
"$name `from` $options attr-dict `:` type(results)";
23+
}
24+
25+
#endif // TUNE_TRANSFORM_OPS

lib/TPP-CAPI/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_mlir_public_c_api_library(TPPCAPI
33
LINK_LIBS PUBLIC
44
TPPCheckDialect
55
TPPPerfDialect
6+
TPPTuneDialect
67
TPPXsmmDialect
78
TPPTransforms
89
TPPPipeline

lib/TPP/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(Check)
22
add_subdirectory(Perf)
3+
add_subdirectory(Tune)
34
add_subdirectory(Xsmm)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_subdirectory(TransformOps)
2+
3+
add_mlir_dialect_library(TPPTuneDialect
4+
# Ops and dialects
5+
TuneDialect.cpp
6+
7+
ADDITIONAL_HEADER_DIRS
8+
${PROJECT_SOURCE_DIR}/include/TPP
9+
10+
LINK_LIBS PUBLIC
11+
MLIRIR
12+
MLIRInferTypeOpInterface
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_mlir_dialect_library(TuneTransformOps
2+
TuneTransformOps.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${PROJECT_SOURCE_DIR}/include/TPP
6+
7+
DEPENDS
8+
TuneTransformOpsIncGen
9+
10+
LINK_LIBS PUBLIC
11+
MLIRIR
12+
MLIRTransformDialect
13+
)

0 commit comments

Comments
 (0)