• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===-- SPIRVMatrixOps.td - MLIR SPIR-V Matrix Ops ---------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains matrix operations for the SPIR-V dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef SPIRV_MATRIX_OPS
14#define SPIRV_MATRIX_OPS
15include "mlir/Interfaces/SideEffectInterfaces.td"
16
17// -----
18
19def SPV_MatrixTimesMatrixOp : SPV_Op<"MatrixTimesMatrix", [NoSideEffect]> {
20  let summary = "Linear-algebraic multiply of LeftMatrix X RightMatrix.";
21
22  let description = [{
23    Result Type must be an OpTypeMatrix whose Column Type is a vector of
24    floating-point type.
25
26    LeftMatrix must be a matrix whose Column Type is the same as the Column
27    Type in Result Type.
28
29    RightMatrix must be a matrix with the same Component Type as the
30    Component Type in Result Type. Its number of columns must equal the
31    number of columns in Result Type. Its columns must have the same number
32    of components as the number of columns in LeftMatrix.
33
34    <!-- End of AutoGen section -->
35
36    ```
37    matrix-times-matrix-op ::= ssa-id `=` `spv.MatrixTimesMatrix` ssa-use,
38    ssa-use `:` matrix-type `,` matrix-type `->` matrix-type
39    ```mlir
40
41    #### Example:
42
43    ```
44    %0 = spv.MatrixTimesMatrix %matrix_1, %matrix_2 :
45        !spv.matrix<4 x vector<3xf32>>, !spv.matrix<3 x vector<4xf32>> ->
46        !spv.matrix<4 x vector<4xf32>>
47    ```
48  }];
49
50  let availability = [
51    MinVersion<SPV_V_1_0>,
52    MaxVersion<SPV_V_1_5>,
53    Extension<[]>,
54    Capability<[SPV_C_Matrix]>
55  ];
56
57  let arguments = (ins
58    SPV_AnyMatrix:$leftmatrix,
59    SPV_AnyMatrix:$rightmatrix
60  );
61
62  let results = (outs
63    SPV_AnyMatrix:$result
64  );
65  let assemblyFormat = [{
66    operands attr-dict `:` type($leftmatrix) `,` type($rightmatrix) `->` type($result)
67  }];
68  let verifier = [{ return verifyMatrixTimesMatrix(*this); }];
69}
70
71// -----
72
73def SPV_MatrixTimesScalarOp : SPV_Op<"MatrixTimesScalar", [NoSideEffect]> {
74  let summary = "Scale a floating-point matrix.";
75
76  let description = [{
77    Result Type must be an OpTypeMatrix whose Column Type is a vector of
78    floating-point type.
79
80     The type of Matrix must be the same as Result Type. Each component in
81    each column in Matrix is multiplied by Scalar.
82
83    Scalar must have the same type as the Component Type in Result Type.
84
85    <!-- End of AutoGen section -->
86
87    ```
88    matrix-times-scalar-op ::= ssa-id `=` `spv.MatrixTimesScalar` ssa-use,
89    ssa-use `:` matrix-type `,` float-type `->` matrix-type
90
91    ```
92
93    #### Example:
94
95    ```mlir
96
97    %0 = spv.MatrixTimesScalar %matrix, %scalar :
98    !spv.matrix<3 x vector<3xf32>>, f32 -> !spv.matrix<3 x vector<3xf32>>
99
100    ```
101  }];
102
103  let availability = [
104    MinVersion<SPV_V_1_0>,
105    MaxVersion<SPV_V_1_5>,
106    Extension<[]>,
107    Capability<[SPV_C_Matrix]>
108  ];
109
110  let arguments = (ins
111    SPV_AnyMatrix:$matrix,
112    SPV_Float:$scalar
113  );
114
115  let results = (outs
116    SPV_AnyMatrix:$result
117  );
118
119  // TODO: we need just one matrix type given that the input and result are the
120  // same and the scalar's type can be deduced from it.
121  let assemblyFormat = [{
122    operands attr-dict `:` type($matrix) `,` type($scalar) `->` type($result)
123  }];
124
125  let availability = [
126    MinVersion<SPV_V_1_0>,
127    MaxVersion<SPV_V_1_5>,
128    Extension<[]>,
129    Capability<[SPV_C_Matrix]>
130  ];
131
132  let verifier = [{ return verifyMatrixTimesScalar(*this); }];
133}
134
135// -----
136
137def SPV_TransposeOp : SPV_Op<"Transpose", [NoSideEffect]> {
138  let summary = "Transpose a matrix.";
139
140  let description = [{
141    Result Type must be an OpTypeMatrix.
142
143    Matrix must be an object of type OpTypeMatrix. The number of columns and
144    the column size of Matrix must be the reverse of those in Result Type.
145    The types of the scalar components in Matrix and Result Type must be the
146    same.
147
148    Matrix must have of type of OpTypeMatrix.
149
150    <!-- End of AutoGen section -->
151
152    ```
153    transpose-op ::= ssa-id `=` `spv.Transpose` ssa-use `:` matrix-type `->`
154    matrix-type
155
156    ```mlir
157
158    #### Example:
159
160    ```
161    %0 = spv.Transpose %matrix: !spv.matrix<2 x vector<3xf32>> ->
162    !spv.matrix<3 x vector<2xf32>>
163
164    ```
165  }];
166
167  let availability = [
168    MinVersion<SPV_V_1_0>,
169    MaxVersion<SPV_V_1_5>,
170    Extension<[]>,
171    Capability<[SPV_C_Matrix]>
172  ];
173
174  let arguments = (ins
175    SPV_AnyMatrix:$matrix
176  );
177
178  let results = (outs
179    SPV_AnyMatrix:$result
180  );
181
182  let assemblyFormat = [{
183    operands attr-dict `:` type($matrix) `->` type($result)
184  }];
185
186  let verifier = [{ return verifyTranspose(*this); }];
187}
188
189// -----
190
191#endif // SPIRV_MATRIX_OPS
192