Skip to content

[MLIR][Linalg] Remove matmul_transpose variants #147961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,138 @@ std::pair<int64_t, int64_t> getFmrFromWinogradConv2DFmr(WinogradConv2DFmr fmr);
#define GET_OP_CLASSES
#include "mlir/Dialect/Linalg/IR/LinalgRelayoutOps.h.inc"

namespace mlir::linalg {

/// Specialization of `linalg.matmul` op that has a transpose map on A
class MatmulTransposeAOp : public MatmulOp {
/// Create an affine map for a transpose-A matmul. Used only in the builders.
static SmallVector<AffineMap> getAffineMaps(OpBuilder &builder);

public:
using MatmulOp::MatmulOp;
static ::mlir::TypeID resolveTypeID() { return TypeID::get<MatmulOp>(); }

/// Build a transpose A matmul.
static void build(OpBuilder &builder, OperationState &result,
ValueRange inputs, ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type and a cast type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs, Attribute cast,
ArrayRef<NamedAttribute> attributes = {});

/// Checks if the affine map is the expected one for this operation
static bool isExpectedAffineMaps(Attribute attr);

static bool classof(Operation *op);
};

/// Specialization of `linalg.matmul` op that has a transpose map on B
class MatmulTransposeBOp : public MatmulOp {
/// Create an affine map for a transpose-B matmul. Used only in the builders.
static SmallVector<AffineMap> getAffineMaps(OpBuilder &builder);

public:
using MatmulOp::MatmulOp;
static ::mlir::TypeID resolveTypeID() { return TypeID::get<MatmulOp>(); }

/// Build a transpose B matmul.
static void build(OpBuilder &builder, OperationState &result,
ValueRange inputs, ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose B matmul with a specific result type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose B matmul with a specific result type and a cast type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs, Attribute cast,
ArrayRef<NamedAttribute> attributes = {});

/// Checks if the affine map is the expected one for this operation
static bool isExpectedAffineMaps(Attribute attr);

static bool classof(Operation *op);
};

/// Specialization of `linalg.batch_matmul` op that has a transpose map on A
class BatchMatmulTransposeAOp : public BatchMatmulOp {
/// Create an affine map for a transpose-A batch_matmul. Used only in the
/// builders.
static SmallVector<AffineMap> getAffineMaps(OpBuilder &builder);

public:
using BatchMatmulOp::BatchMatmulOp;
static ::mlir::TypeID resolveTypeID() { return TypeID::get<BatchMatmulOp>(); }

/// Build a transpose A matmul.
static void build(OpBuilder &builder, OperationState &result,
ValueRange inputs, ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type and a cast type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs, Attribute cast,
ArrayRef<NamedAttribute> attributes = {});

/// Checks if the affine map is the expected one for this operation
static bool isExpectedAffineMaps(Attribute attr);

static bool classof(Operation *op);
};

/// Specialization of `linalg.batch_matmul` op that has a transpose map on B
class BatchMatmulTransposeBOp : public BatchMatmulOp {
/// Create an affine map for a transpose-B batch_matmul. Used only in the
/// builders.
static SmallVector<AffineMap> getAffineMaps(OpBuilder &builder);

public:
using BatchMatmulOp::BatchMatmulOp;
static ::mlir::TypeID resolveTypeID() { return TypeID::get<BatchMatmulOp>(); }

/// Build a transpose A matmul.
static void build(OpBuilder &builder, OperationState &result,
ValueRange inputs, ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs,
ArrayRef<NamedAttribute> attributes = {});

/// Build a transpose A matmul with a specific result type and a cast type.
static void build(OpBuilder &builder, OperationState &result,
TypeRange resultTensorTypes, ValueRange inputs,
ValueRange outputs, Attribute cast,
ArrayRef<NamedAttribute> attributes = {});

/// Checks if the affine map is the expected one for this operation
static bool isExpectedAffineMaps(Attribute attr);

static bool classof(Operation *op);
};

} // namespace mlir::linalg

#endif // MLIR_DIALECT_LINALG_IR_LINALG_H
Loading
Loading