Factor out commonly reusable names across structured ops dialects
This CL starts extracting commonalities between dialects that use the structured ops abstractions. Also fixes an OSS build issue where StringRef were incorrectly used with constexpr. PiperOrigin-RevId: 284591114 Change-Id: I990c0584cff4e8d107e4947f135083c749df2d77
This commit is contained in:
parent
8fad4f1946
commit
8ccf72521d
17
third_party/mlir/BUILD
vendored
17
third_party/mlir/BUILD
vendored
@ -12,7 +12,6 @@ package_group(
|
||||
packages = ["//..."],
|
||||
)
|
||||
|
||||
# Before adding a project here, please read go/mlir-sla
|
||||
# In particular the OWNERS file of the dependent project should be updated.
|
||||
# TODO(b/140669524): Use proper MLIR tests instead of end-to-end tests for
|
||||
# tf_runtime and tf_runtime_google.
|
||||
@ -342,6 +341,21 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "DialectUtils",
|
||||
srcs = [
|
||||
],
|
||||
hdrs = [
|
||||
"include/mlir/Dialect/Utils/StructuredOpsUtils.h",
|
||||
],
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":IR",
|
||||
":Support",
|
||||
"@llvm//:support",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "AffineOps",
|
||||
srcs = [
|
||||
@ -484,6 +498,7 @@ cc_library(
|
||||
],
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":DialectUtils",
|
||||
":EDSC",
|
||||
":IR",
|
||||
":StandardOps",
|
||||
|
||||
56
third_party/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
vendored
Normal file
56
third_party/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
//===- StructuredOpsUtils.h - Utilities used by structured ops --*- C++ -*-===//
|
||||
//
|
||||
// Copyright 2019 The MLIR Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// =============================================================================
|
||||
//
|
||||
// This header file define utilities that operate on standard types and are
|
||||
// useful across multiple dialects that use structured ops abstractions. These
|
||||
// abstractions consist of define custom operations that encode and transport
|
||||
// information about their semantics (e.g. type of iterators like parallel,
|
||||
// reduction, etc..) as attributes.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef MLIR_DIALECT_UTILS_STRUCTUREDOPSUTILS_H
|
||||
#define MLIR_DIALECT_UTILS_STRUCTUREDOPSUTILS_H
|
||||
|
||||
#include "mlir/Support/LLVM.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace mlir {
|
||||
/// Attribute name for the AffineArrayAttr which encodes the relationship
|
||||
/// between a structured op iterators' and its operands.
|
||||
static constexpr StringLiteral getIndexingMapsAttrName() {
|
||||
return "indexing_maps";
|
||||
}
|
||||
|
||||
/// Attribute name for the StrArrayAttr which encodes the type of a structured
|
||||
/// op's iterators.
|
||||
static constexpr StringLiteral getIteratorTypesAttrName() {
|
||||
return "iterator_types";
|
||||
}
|
||||
|
||||
/// Use to encode that a particular iterator type has parallel semantics.
|
||||
inline static constexpr StringLiteral getParallelIteratorTypeName() {
|
||||
return "parallel";
|
||||
}
|
||||
|
||||
/// Use to encode that a particular iterator type has reduction semantics.
|
||||
inline static constexpr StringLiteral getReductionIteratorTypeName() {
|
||||
return "reduction";
|
||||
}
|
||||
} // end namespace mlir
|
||||
|
||||
#endif // MLIR_UTILS_STRUCTUREDOPSUTILS_H
|
||||
@ -131,12 +131,6 @@ def Vector_ContractionOp :
|
||||
"Builder *builder, OperationState &result, Value *lhs, Value *rhs, "
|
||||
"Value *acc, ArrayAttr indexingMaps, ArrayAttr iteratorTypes">];
|
||||
let extraClassDeclaration = [{
|
||||
static constexpr StringLiteral getIndexingMapsAttrName() {
|
||||
return "indexing_maps";
|
||||
}
|
||||
static constexpr StringLiteral getIteratorTypesAttrName() {
|
||||
return "iterator_types";
|
||||
}
|
||||
VectorType getLhsType() {
|
||||
return lhs()->getType().cast<VectorType>();
|
||||
}
|
||||
@ -159,12 +153,6 @@ def Vector_ContractionOp :
|
||||
}
|
||||
ArrayRef<StringRef> getTraitAttrNames();
|
||||
SmallVector<AffineMap, 4> getIndexingMaps();
|
||||
static StringRef getReductionIteratorTypeName() {
|
||||
return "reduction";
|
||||
}
|
||||
static StringRef getParallelIteratorTypeName() {
|
||||
return "parallel";
|
||||
}
|
||||
static unsigned getAccOperandIndex() { return 2; }
|
||||
|
||||
// Returns the bounds of each dimension in the iteration space spanned
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "mlir/Dialect/VectorOps/VectorOps.h"
|
||||
#include "mlir/Dialect/StandardOps/Ops.h"
|
||||
#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
|
||||
#include "mlir/IR/AffineExpr.h"
|
||||
#include "mlir/IR/AffineMap.h"
|
||||
#include "mlir/IR/Builders.h"
|
||||
@ -246,9 +247,10 @@ static LogicalResult verify(ContractionOp op) {
|
||||
}
|
||||
|
||||
ArrayRef<StringRef> ContractionOp::getTraitAttrNames() {
|
||||
static constexpr StringRef names[2] = {getIndexingMapsAttrName(),
|
||||
getIteratorTypesAttrName()};
|
||||
return ArrayRef<StringRef>(names);
|
||||
static constexpr StringLiteral names[2] = {getIndexingMapsAttrName(),
|
||||
getIteratorTypesAttrName()};
|
||||
ArrayRef<StringLiteral> res{names};
|
||||
return ArrayRef<StringRef>{res.begin(), res.end()};
|
||||
}
|
||||
|
||||
static int64_t getResultIndex(AffineMap map, AffineExpr targetExpr) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user