docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
CustomSpecializeSoftmax.h
Go to the documentation of this file.
1#pragma once
2
3#include "mlir/Dialect/Linalg/IR/Linalg.h"
4#include "mlir/IR/PatternMatch.h"
5
6namespace mlir {
7namespace linalg {
8
12struct LinalgGenericToLinalgSoftmax : public OpRewritePattern<GenericOp> {
13 using OpRewritePattern<GenericOp>::OpRewritePattern;
14
15 bool checkIndexingMap(Attribute attr, long long dim = -1) const;
16 bool checkIndexingMapCollapsed(Attribute attr, long long dim) const;
17 bool checkIndexingMaps(ArrayAttr maps, const std::vector<bool>& reduced_mask, long long dim) const;
18
19 bool checkIteratorTypes(ArrayAttr types, size_t rank, long long dim = -1) const;
20
21 bool equalShapes(const ArrayRef<int64_t>& shape1, const ArrayRef<int64_t>& shape2) const;
22 long long determineDimension(const ArrayRef<int64_t>& full_shape, const ArrayRef<int64_t>& reduced_shape) const;
23
24 template<typename ElemOp>
25 bool isElementwiseRegion(Region& region) const {
26 if (region.getBlocks().size() != 1) {
27 return false;
28 }
29 auto& block = region.getBlocks().front();
30 return (
31 block.getOperations().size() == 2 && llvm::dyn_cast_or_null<ElemOp>(block.getOperations().front()) &&
32 llvm::dyn_cast_or_null<YieldOp>(block.getOperations().back())
33 );
34 }
35
36 bool isFillOp(FillOp fill_op, uint64_t constant) const;
37
38 LogicalResult matchAndRewrite(GenericOp generic_op, PatternRewriter& rewriter) const override;
39};
40
41} // namespace linalg
42} // namespace mlir
Definition CustomSpecializeBatchNorm.h:8
Definition CustomPasses.h:6
y[..., d, ...] = exp(x) / sum_d(exp(x_d))
Definition CustomSpecializeSoftmax.h:12
long long determineDimension(const ArrayRef< int64_t > &full_shape, const ArrayRef< int64_t > &reduced_shape) const
bool checkIteratorTypes(ArrayAttr types, size_t rank, long long dim=-1) const
bool equalShapes(const ArrayRef< int64_t > &shape1, const ArrayRef< int64_t > &shape2) const
bool isFillOp(FillOp fill_op, uint64_t constant) const
bool checkIndexingMap(Attribute attr, long long dim=-1) const
bool isElementwiseRegion(Region &region) const
Definition CustomSpecializeSoftmax.h:25
LogicalResult matchAndRewrite(GenericOp generic_op, PatternRewriter &rewriter) const override
bool checkIndexingMapCollapsed(Attribute attr, long long dim) const
bool checkIndexingMaps(ArrayAttr maps, const std::vector< bool > &reduced_mask, long long dim) const