2020-05-05 03:41:43 +08:00
|
|
|
set(LLVM_LINK_COMPONENTS
|
|
|
|
Core
|
|
|
|
Support
|
|
|
|
)
|
2021-02-21 14:46:27 +08:00
|
|
|
|
|
|
|
set(LLVM_OPTIONAL_SOURCES
|
|
|
|
mlir-linalg-ods-gen.cpp
|
|
|
|
mlir-linalg-ods-yaml-gen.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
# Original mlir-linalg-ods-gen (to be replaced).
|
2020-10-05 06:17:34 +08:00
|
|
|
add_llvm_tool(mlir-linalg-ods-gen
|
[mlir][Linalg] Create a tool to generate named Linalg ops from a Tensor Comprehensions-like specification.
Summary:
This revision adds a tool that generates the ODS and C++ implementation for "named" Linalg ops according to the [RFC discussion](https://llvm.discourse.group/t/rfc-declarative-named-ops-in-the-linalg-dialect/745).
While the mechanisms and language aspects are by no means set in stone, this revision allows connecting the pieces end-to-end from a mathematical-like specification.
Some implementation details and short-term decisions taken for the purpose of bootstrapping and that are not set in stone include:
1. using a "[Tensor Comprehension](https://arxiv.org/abs/1802.04730)-inspired" syntax
2. implicit and eager discovery of dims and symbols when parsing
3. using EDSC ops to specify the computation (e.g. std_addf, std_mul_f, ...)
A followup revision will connect this tool to tablegen mechanisms and allow the emission of named Linalg ops that automatically lower to various loop forms and run end to end.
For the following "Tensor Comprehension-inspired" string:
```
def batch_matmul(A: f32(Batch, M, K), B: f32(K, N)) -> (C: f32(Batch, M, N)) {
C(b, m, n) = std_addf<k>(std_mulf(A(b, m, k), B(k, n)));
}
```
With -gen-ods-decl=1, this emits (modulo formatting):
```
def batch_matmulOp : LinalgNamedStructured_Op<"batch_matmul", [
NInputs<2>,
NOutputs<1>,
NamedStructuredOpTraits]> {
let arguments = (ins Variadic<LinalgOperand>:$views);
let results = (outs Variadic<AnyRankedTensor>:$output_tensors);
let extraClassDeclaration = [{
llvm::Optional<SmallVector<StringRef, 8>> referenceIterators();
llvm::Optional<SmallVector<AffineMap, 8>> referenceIndexingMaps();
void regionBuilder(ArrayRef<BlockArgument> args);
}];
let hasFolder = 1;
}
```
With -gen-ods-impl, this emits (modulo formatting):
```
llvm::Optional<SmallVector<StringRef, 8>> batch_matmul::referenceIterators() {
return SmallVector<StringRef, 8>{ getParallelIteratorTypeName(),
getParallelIteratorTypeName(),
getParallelIteratorTypeName(),
getReductionIteratorTypeName() };
}
llvm::Optional<SmallVector<AffineMap, 8>> batch_matmul::referenceIndexingMaps()
{
MLIRContext *context = getContext();
AffineExpr d0, d1, d2, d3;
bindDims(context, d0, d1, d2, d3);
return SmallVector<AffineMap, 8>{
AffineMap::get(4, 0, {d0, d1, d3}),
AffineMap::get(4, 0, {d3, d2}),
AffineMap::get(4, 0, {d0, d1, d2}) };
}
void batch_matmul::regionBuilder(ArrayRef<BlockArgument> args) {
using namespace edsc;
using namespace intrinsics;
ValueHandle _0(args[0]), _1(args[1]), _2(args[2]);
ValueHandle _4 = std_mulf(_0, _1);
ValueHandle _5 = std_addf(_2, _4);
(linalg_yield(ValueRange{ _5 }));
}
```
Differential Revision: https://reviews.llvm.org/D77067
2020-04-11 01:54:08 +08:00
|
|
|
mlir-linalg-ods-gen.cpp
|
|
|
|
)
|
|
|
|
llvm_update_compile_flags(mlir-linalg-ods-gen)
|
|
|
|
target_link_libraries(mlir-linalg-ods-gen PRIVATE
|
|
|
|
MLIRSupport
|
2020-09-03 07:57:47 +08:00
|
|
|
MLIRIR
|
[mlir][Linalg] Create a tool to generate named Linalg ops from a Tensor Comprehensions-like specification.
Summary:
This revision adds a tool that generates the ODS and C++ implementation for "named" Linalg ops according to the [RFC discussion](https://llvm.discourse.group/t/rfc-declarative-named-ops-in-the-linalg-dialect/745).
While the mechanisms and language aspects are by no means set in stone, this revision allows connecting the pieces end-to-end from a mathematical-like specification.
Some implementation details and short-term decisions taken for the purpose of bootstrapping and that are not set in stone include:
1. using a "[Tensor Comprehension](https://arxiv.org/abs/1802.04730)-inspired" syntax
2. implicit and eager discovery of dims and symbols when parsing
3. using EDSC ops to specify the computation (e.g. std_addf, std_mul_f, ...)
A followup revision will connect this tool to tablegen mechanisms and allow the emission of named Linalg ops that automatically lower to various loop forms and run end to end.
For the following "Tensor Comprehension-inspired" string:
```
def batch_matmul(A: f32(Batch, M, K), B: f32(K, N)) -> (C: f32(Batch, M, N)) {
C(b, m, n) = std_addf<k>(std_mulf(A(b, m, k), B(k, n)));
}
```
With -gen-ods-decl=1, this emits (modulo formatting):
```
def batch_matmulOp : LinalgNamedStructured_Op<"batch_matmul", [
NInputs<2>,
NOutputs<1>,
NamedStructuredOpTraits]> {
let arguments = (ins Variadic<LinalgOperand>:$views);
let results = (outs Variadic<AnyRankedTensor>:$output_tensors);
let extraClassDeclaration = [{
llvm::Optional<SmallVector<StringRef, 8>> referenceIterators();
llvm::Optional<SmallVector<AffineMap, 8>> referenceIndexingMaps();
void regionBuilder(ArrayRef<BlockArgument> args);
}];
let hasFolder = 1;
}
```
With -gen-ods-impl, this emits (modulo formatting):
```
llvm::Optional<SmallVector<StringRef, 8>> batch_matmul::referenceIterators() {
return SmallVector<StringRef, 8>{ getParallelIteratorTypeName(),
getParallelIteratorTypeName(),
getParallelIteratorTypeName(),
getReductionIteratorTypeName() };
}
llvm::Optional<SmallVector<AffineMap, 8>> batch_matmul::referenceIndexingMaps()
{
MLIRContext *context = getContext();
AffineExpr d0, d1, d2, d3;
bindDims(context, d0, d1, d2, d3);
return SmallVector<AffineMap, 8>{
AffineMap::get(4, 0, {d0, d1, d3}),
AffineMap::get(4, 0, {d3, d2}),
AffineMap::get(4, 0, {d0, d1, d2}) };
}
void batch_matmul::regionBuilder(ArrayRef<BlockArgument> args) {
using namespace edsc;
using namespace intrinsics;
ValueHandle _0(args[0]), _1(args[1]), _2(args[2]);
ValueHandle _4 = std_mulf(_0, _1);
ValueHandle _5 = std_addf(_2, _4);
(linalg_yield(ValueRange{ _5 }));
}
```
Differential Revision: https://reviews.llvm.org/D77067
2020-04-11 01:54:08 +08:00
|
|
|
)
|
2021-01-18 18:54:06 +08:00
|
|
|
|
2021-02-14 01:15:47 +08:00
|
|
|
set(MLIR_LINALG_ODS_GEN mlir-linalg-ods-gen CACHE
|
|
|
|
STRING "Native mlir-linalg-ods-gen executable. Saves building one when cross-compiling.")
|
|
|
|
|
|
|
|
set(MLIR_LINALG_ODS_GEN_EXE ${MLIR_LINALG_ODS_GEN} PARENT_SCOPE)
|
2021-01-18 18:54:06 +08:00
|
|
|
set(MLIR_LINALG_ODS_GEN_TARGET mlir-linalg-ods-gen PARENT_SCOPE)
|
|
|
|
|
|
|
|
if(LLVM_USE_HOST_TOOLS)
|
2021-03-05 01:24:25 +08:00
|
|
|
if (${MLIR_LINALG_ODS_GEN} STREQUAL "mlir-linalg-ods-gen")
|
2021-02-14 01:15:47 +08:00
|
|
|
build_native_tool(mlir-linalg-ods-gen MLIR_LINALG_ODS_GEN_EXE DEPENDS mlir-linalg-ods-gen)
|
|
|
|
set(MLIR_LINALG_ODS_GEN_EXE ${MLIR_LINALG_ODS_GEN_EXE} PARENT_SCOPE)
|
2021-01-18 18:54:06 +08:00
|
|
|
|
2021-02-14 01:15:47 +08:00
|
|
|
add_custom_target(mlir-linalg-ods-gen-host DEPENDS ${MLIR_LINALG_ODS_GEN_EXE})
|
|
|
|
set(MLIR_LINALG_ODS_GEN_TARGET mlir-linalg-ods-gen-host DEPENDS PARENT_SCOPE)
|
2021-01-18 18:54:06 +08:00
|
|
|
|
2021-02-14 01:15:47 +08:00
|
|
|
if(NOT LLVM_BUILD_UTILS)
|
|
|
|
set_target_properties(mlir-linalg-ods-gen PROPERTIES EXCLUDE_FROM_ALL ON)
|
|
|
|
endif()
|
2021-01-18 18:54:06 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
2021-02-21 14:46:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
# New mlir-linalg-ods-yaml-gen.
|
|
|
|
add_llvm_tool(mlir-linalg-ods-yaml-gen
|
|
|
|
mlir-linalg-ods-yaml-gen.cpp
|
|
|
|
)
|
|
|
|
llvm_update_compile_flags(mlir-linalg-ods-yaml-gen)
|
|
|
|
target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE
|
|
|
|
MLIRIR
|
|
|
|
MLIRSupport
|
|
|
|
MLIRParser
|
|
|
|
)
|
|
|
|
|
|
|
|
set(MLIR_LINALG_ODS_YAML_GEN mlir-linalg-ods-yaml-gen CACHE
|
|
|
|
STRING "Native mlir-linalg-ods-yaml-gen executable. Saves building one when cross-compiling.")
|
|
|
|
|
|
|
|
set(MLIR_LINALG_ODS_YAML_GEN_EXE ${MLIR_LINALG_ODS_YAML_GEN} PARENT_SCOPE)
|
|
|
|
set(MLIR_LINALG_ODS_YAML_GEN_TARGET mlir-linalg-ods-yaml-gen PARENT_SCOPE)
|
|
|
|
|
|
|
|
if(LLVM_USE_HOST_TOOLS)
|
2021-03-05 01:24:25 +08:00
|
|
|
if (${MLIR_LINALG_ODS_YAML_GEN} STREQUAL "mlir-linalg-ods-yaml-gen")
|
|
|
|
build_native_tool(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN_EXE DEPENDS mlir-linalg-ods-yaml-gen)
|
|
|
|
set(MLIR_LINALG_ODS_YAML_GEN_EXE ${MLIR_LINALG_ODS_YAML_GEN_EXE} PARENT_SCOPE)
|
2021-02-21 14:46:27 +08:00
|
|
|
|
2021-03-05 01:24:25 +08:00
|
|
|
add_custom_target(mlir-linalg-ods-yaml-gen-host DEPENDS ${MLIR_LINALG_ODS_YAML_GEN_EXE})
|
|
|
|
set(MLIR_LINALG_ODS_YAML_GEN_TARGET mlir-linalg-ods-yaml-gen-host DEPENDS PARENT_SCOPE)
|
2021-02-21 14:46:27 +08:00
|
|
|
|
2021-03-05 01:24:25 +08:00
|
|
|
if(NOT LLVM_BUILD_UTILS)
|
|
|
|
set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES EXCLUDE_FROM_ALL ON)
|
|
|
|
endif()
|
2021-02-21 14:46:27 +08:00
|
|
|
endif()
|
|
|
|
endif()
|