[Mlir-commits] [mlir] [mlir][spirv] Add definition for VectorTimesMatrixOp (PR #124571)

Igor Wodiany llvmlistbot at llvm.org
Mon Jan 27 08:31:11 PST 2025


================
@@ -198,4 +197,50 @@ def SPIRV_TransposeOp : SPIRV_Op<"Transpose", [Pure]> {
 
 // -----
 
+def SPIRV_VectorTimesMatrixOp : SPIRV_Op<"VectorTimesMatrix", [Pure]> {
+  let summary = "Linear-algebraic Vector X Matrix.";
+
+  let description = [{
+    Result Type must be a vector of floating-point type.
+
+    Vector must be a vector with the same Component Type as the Component
+    Type in Result Type. Its number of components must equal the number of
+    components in each column in Matrix.
+
+    Matrix must be a matrix with the same Component Type as the Component
+    Type in Result Type. Its number of columns must equal the number of
+    components in Result Type.
+
+    <!-- End of AutoGen section -->
+
+    #### Example:
+
+    ```mlir
+    %result = spirv.VectorTimesMatrix %vector, %matrix : vector<4xf32>, !spirv.matrix<4 x vector<4xf32>> -> vector<4xf32>
+    ```
+  }];
+
+  let availability = [
+    MinVersion<SPIRV_V_1_0>,
+    MaxVersion<SPIRV_V_1_6>,
+    Extension<[]>,
+    Capability<[SPIRV_C_Matrix]>
+  ];
+
+  let arguments = (ins
+    SPIRV_AnyVector:$vector,
----------------
IgWod-IMG wrote:

That's a good question. According to the spec:

> Result Type must be a vector of [floating-point type](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Floating).

And:

> Vector must be a vector with the same Component Type as the Component Type in Result Type.

So, the spec only explicitly defines the type of the result, and the type of the vector is defined in terms of the type of the result. My implementation literally follows the spec. I enforce the result to be float, and then the vector to have the same type as the result. However, this means that the vector will be float as well, so that could be directly enforced in ODS with `SPIRV_VectorOf<SPIRV_Float>`. Same goes for matrix.

Anyway, I'm happy to restrict all arguments to be floats, as I don't have any strong feelings about it. So up to you! I probably overthought it :)

https://github.com/llvm/llvm-project/pull/124571


More information about the Mlir-commits mailing list