@@ -193,9 +193,10 @@ static void buildMatmulOp(OpBuilder &b, OperationState &state,
193
193
ArrayRef<AffineMap> indexingMaps) {
194
194
// Initialize indexingMaps attribute, for MatmulOp.
195
195
SmallVector<Attribute, 3 > indexingMapsAttrVal;
196
- indexingMapsAttrVal = llvm::map_to_vector (
197
- MatmulOp::getDefaultIndexingMaps (b.getContext ()),
198
- [](AffineMap map) -> Attribute { return AffineMapAttr::get (map); });
196
+ indexingMapsAttrVal =
197
+ llvm::map_to_vector (indexingMaps, [](AffineMap map) -> Attribute {
198
+ return AffineMapAttr::get (map);
199
+ });
199
200
state.addAttribute (" indexing_maps" , b.getArrayAttr (indexingMapsAttrVal));
200
201
return buildStructuredOp (b, state, resultTensorTypes, inputs, outputs,
201
202
attributes, regionBuilder);
@@ -3881,6 +3882,172 @@ Speculation::Speculatability MatmulOp::getSpeculatability() {
3881
3882
return getGenericSpeculatabilityImpl (cast<LinalgOp>(getOperation ()));
3882
3883
}
3883
3884
3885
+ SmallVector<AffineMap> MatmulTransposeAOp::getAffineMaps (OpBuilder &builder) {
3886
+ AffineExpr d0, d1, d2;
3887
+ auto context = builder.getContext ();
3888
+ bindDims (context, d0, d1, d2);
3889
+ AffineMap mapLHS = AffineMap::get (3 , 0 , {d2, d0}, context);
3890
+ AffineMap mapRHS = AffineMap::get (3 , 0 , {d2, d1}, context);
3891
+ AffineMap mapOut = AffineMap::get (3 , 0 , {d0, d1}, context);
3892
+ SmallVector<AffineMap> affineMaps{mapLHS, mapRHS, mapOut};
3893
+ return affineMaps;
3894
+ }
3895
+
3896
+ void linalg::MatmulTransposeAOp::build (OpBuilder &builder,
3897
+ OperationState &result,
3898
+ ValueRange inputs, ValueRange outputs,
3899
+ ArrayRef<NamedAttribute> attributes) {
3900
+ buildMatmulOp (builder, result, std::nullopt, inputs, outputs, attributes,
3901
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3902
+ }
3903
+
3904
+ void linalg::MatmulTransposeAOp::build (OpBuilder &builder,
3905
+ OperationState &result,
3906
+ TypeRange resultTensorTypes,
3907
+ ValueRange inputs, ValueRange outputs,
3908
+ ArrayRef<NamedAttribute> attributes) {
3909
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
3910
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3911
+ }
3912
+
3913
+ void linalg::MatmulTransposeAOp::build (OpBuilder &builder,
3914
+ OperationState &result,
3915
+ TypeRange resultTensorTypes,
3916
+ ValueRange inputs, ValueRange outputs,
3917
+ Attribute cast,
3918
+ ArrayRef<NamedAttribute> attributes) {
3919
+ result.addAttribute (" cast" , cast);
3920
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
3921
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3922
+ }
3923
+
3924
+ bool MatmulTransposeAOp::classof (Operation *op) {
3925
+ return dyn_cast_or_null<linalg::MatmulOp>(op);
3926
+ }
3927
+
3928
+ SmallVector<AffineMap> MatmulTransposeBOp::getAffineMaps (OpBuilder &builder) {
3929
+ AffineExpr d0, d1, d2;
3930
+ auto context = builder.getContext ();
3931
+ bindDims (context, d0, d1, d2);
3932
+ AffineMap mapLHS = AffineMap::get (3 , 0 , {d0, d2}, context);
3933
+ AffineMap mapRHS = AffineMap::get (3 , 0 , {d1, d2}, context);
3934
+ AffineMap mapOut = AffineMap::get (3 , 0 , {d0, d1}, context);
3935
+ SmallVector<AffineMap> affineMaps{mapLHS, mapRHS, mapOut};
3936
+ return affineMaps;
3937
+ }
3938
+
3939
+ void linalg::MatmulTransposeBOp::build (OpBuilder &builder,
3940
+ OperationState &result,
3941
+ ValueRange inputs, ValueRange outputs,
3942
+ ArrayRef<NamedAttribute> attributes) {
3943
+ buildMatmulOp (builder, result, std::nullopt, inputs, outputs, attributes,
3944
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3945
+ }
3946
+
3947
+ void linalg::MatmulTransposeBOp::build (OpBuilder &builder,
3948
+ OperationState &result,
3949
+ TypeRange resultTensorTypes,
3950
+ ValueRange inputs, ValueRange outputs,
3951
+ ArrayRef<NamedAttribute> attributes) {
3952
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
3953
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3954
+ }
3955
+
3956
+ void linalg::MatmulTransposeBOp::build (OpBuilder &builder,
3957
+ OperationState &result,
3958
+ TypeRange resultTensorTypes,
3959
+ ValueRange inputs, ValueRange outputs,
3960
+ Attribute cast,
3961
+ ArrayRef<NamedAttribute> attributes) {
3962
+ result.addAttribute (" cast" , cast);
3963
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
3964
+ MatmulOp::getRegionBuilder (), getAffineMaps (builder));
3965
+ }
3966
+
3967
+ bool MatmulTransposeBOp::classof (Operation *op) {
3968
+ return dyn_cast_or_null<linalg::MatmulOp>(op);
3969
+ }
3970
+
3971
+ SmallVector<AffineMap>
3972
+ BatchMatmulTransposeAOp::getAffineMaps (OpBuilder &builder) {
3973
+ AffineExpr d0, d1, d2, d3;
3974
+ auto context = builder.getContext ();
3975
+ bindDims (context, d0, d1, d2, d3);
3976
+ AffineMap mapLHS = AffineMap::get (4 , 0 , {d0, d3, d1}, context);
3977
+ AffineMap mapRHS = AffineMap::get (4 , 0 , {d0, d3, d2}, context);
3978
+ AffineMap mapOut = AffineMap::get (4 , 0 , {d0, d1, d2}, context);
3979
+ SmallVector<AffineMap> affineMaps{mapLHS, mapRHS, mapOut};
3980
+ return affineMaps;
3981
+ }
3982
+
3983
+ void linalg::BatchMatmulTransposeAOp::build (
3984
+ OpBuilder &builder, OperationState &result, ValueRange inputs,
3985
+ ValueRange outputs, ArrayRef<NamedAttribute> attributes) {
3986
+ buildMatmulOp (builder, result, std::nullopt, inputs, outputs, attributes,
3987
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
3988
+ }
3989
+
3990
+ void linalg::BatchMatmulTransposeAOp::build (
3991
+ OpBuilder &builder, OperationState &result, TypeRange resultTensorTypes,
3992
+ ValueRange inputs, ValueRange outputs,
3993
+ ArrayRef<NamedAttribute> attributes) {
3994
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
3995
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
3996
+ }
3997
+
3998
+ void linalg::BatchMatmulTransposeAOp::build (
3999
+ OpBuilder &builder, OperationState &result, TypeRange resultTensorTypes,
4000
+ ValueRange inputs, ValueRange outputs, Attribute cast,
4001
+ ArrayRef<NamedAttribute> attributes) {
4002
+ result.addAttribute (" cast" , cast);
4003
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
4004
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
4005
+ }
4006
+
4007
+ bool BatchMatmulTransposeAOp::classof (Operation *op) {
4008
+ return dyn_cast_or_null<linalg::BatchMatmulOp>(op);
4009
+ }
4010
+
4011
+ SmallVector<AffineMap>
4012
+ BatchMatmulTransposeBOp::getAffineMaps (OpBuilder &builder) {
4013
+ AffineExpr d0, d1, d2, d3;
4014
+ auto context = builder.getContext ();
4015
+ bindDims (context, d0, d1, d2, d3);
4016
+ AffineMap mapLHS = AffineMap::get (4 , 0 , {d0, d1, d3}, context);
4017
+ AffineMap mapRHS = AffineMap::get (4 , 0 , {d0, d2, d3}, context);
4018
+ AffineMap mapOut = AffineMap::get (4 , 0 , {d0, d1, d2}, context);
4019
+ SmallVector<AffineMap> affineMaps{mapLHS, mapRHS, mapOut};
4020
+ return affineMaps;
4021
+ }
4022
+
4023
+ void linalg::BatchMatmulTransposeBOp::build (
4024
+ OpBuilder &builder, OperationState &result, ValueRange inputs,
4025
+ ValueRange outputs, ArrayRef<NamedAttribute> attributes) {
4026
+ buildMatmulOp (builder, result, std::nullopt, inputs, outputs, attributes,
4027
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
4028
+ }
4029
+
4030
+ void linalg::BatchMatmulTransposeBOp::build (
4031
+ OpBuilder &builder, OperationState &result, TypeRange resultTensorTypes,
4032
+ ValueRange inputs, ValueRange outputs,
4033
+ ArrayRef<NamedAttribute> attributes) {
4034
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
4035
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
4036
+ }
4037
+
4038
+ void linalg::BatchMatmulTransposeBOp::build (
4039
+ OpBuilder &builder, OperationState &result, TypeRange resultTensorTypes,
4040
+ ValueRange inputs, ValueRange outputs, Attribute cast,
4041
+ ArrayRef<NamedAttribute> attributes) {
4042
+ result.addAttribute (" cast" , cast);
4043
+ buildMatmulOp (builder, result, resultTensorTypes, inputs, outputs, attributes,
4044
+ BatchMatmulOp::getRegionBuilder (), getAffineMaps (builder));
4045
+ }
4046
+
4047
+ bool BatchMatmulTransposeBOp::classof (Operation *op) {
4048
+ return dyn_cast_or_null<linalg::BatchMatmulOp>(op);
4049
+ }
4050
+
3884
4051
// ===----------------------------------------------------------------------===//
3885
4052
// ContractOp
3886
4053
// ===----------------------------------------------------------------------===//
0 commit comments