3#include "mlir/Dialect/Linalg/IR/Linalg.h"
4#include "mlir/Dialect/Tensor/IR/Tensor.h"
5#include "mlir/IR/PatternMatch.h"
14 using OpRewritePattern<GenericOp>::OpRewritePattern;
22 template<
typename ElemOp>
24 if (region.getBlocks().size() != 1) {
27 auto& block = region.getBlocks().front();
29 block.getOperations().size() == 2 && llvm::dyn_cast_or_null<ElemOp>(block.getOperations().front()) &&
30 llvm::dyn_cast_or_null<YieldOp>(block.getOperations().back())
34 template<
typename ElemOp>
37 generic_op.getInputs().size() == 2 && generic_op.getOutputs().size() == 1 &&
38 this->checkIndexingMaps(generic_op.getIndexingMaps()) &&
39 this->checkIteratorTypes(generic_op.getIteratorTypes()) &&
40 this->isElementwiseRegion<ElemOp>(generic_op.getRegion())
44 bool isTypeNCHW(Type type, Type element_type, int64_t n, int64_t c, int64_t h, int64_t w)
const;
45 bool isTypeC11(Type type, Type element_type, int64_t c)
const;
46 bool isTypeC(Type type, Type element_type, int64_t c)
const;
50 LogicalResult
matchAndRewrite(GenericOp generic_op, PatternRewriter& rewriter)
const override;
Definition CustomSpecializeBatchNorm.h:8
Definition CustomPasses.h:6
y = (x - E[x]) / sqrt(Var[x] + eps) * gamma + beta
Definition CustomSpecializeBatchNorm.h:13
bool is4dIdentityMap(Attribute attr) const
bool isTypeC11(Type type, Type element_type, int64_t c) const
bool checkIndexingMaps(ArrayAttr array_attr) const
bool checkExpandShape(tensor::ExpandShapeOp expand_shape_op, int64_t c) const
LogicalResult matchAndRewrite(GenericOp generic_op, PatternRewriter &rewriter) const override
bool checkGenericOp(GenericOp generic_op) const
Definition CustomSpecializeBatchNorm.h:35
bool isTypeC(Type type, Type element_type, int64_t c) const
bool checkIteratorTypes(ArrayAttr array_attr) const
bool isElementwiseRegion(Region ®ion) const
Definition CustomSpecializeBatchNorm.h:23
bool isTypeNCHW(Type type, Type element_type, int64_t n, int64_t c, int64_t h, int64_t w) const
bool is3dIdentityMap(Attribute attr) const