[Mlir-commits] [mlir] [mlir][vector] Update docs for scalable vectors (PR #101842)

Cullen Rhodes llvmlistbot at llvm.org
Mon Aug 5 01:31:07 PDT 2024


================
@@ -73,12 +73,30 @@ following top-down rewrites and conversions:
 
 ### LLVM level
 
-On CPU, the `n-D` `vector` type currently lowers to `!llvm<array<vector>>`. More
-concretely, `vector<4x8x128xf32>` lowers to `!llvm<[4 x [ 8 x [ 128 x float
-]]]>`. There are tradeoffs involved related to how one can access subvectors and
-how one uses `llvm.extractelement`, `llvm.insertelement` and
-`llvm.shufflevector`. A [deeper dive section](#DeeperDive) discusses the current
-lowering choices and tradeoffs.
+On CPU, the `n-D` `vector` type currently lowers to `!llvm<array<vector>>`.
+More concretely,
+* `vector<4x8x128xf32>` lowers to `!llvm<[4 x [ 8 x < 128
+x float >]]>` (fixed-width vector), and
+* `vector<4x8x[128]xf32>` lowers to `!llvm<[4 x [ 8 x < vscale x 128
+x float >]]>` (scalable vector).
+
+There are tradeoffs involved related to how one can access subvectors and how
+one uses `llvm.extractelement`, `llvm.insertelement` and `llvm.shufflevector`.
+The section on [LLVM Lowering Tradeoffs](#llvm-lowering-tradeoffs) offers a
+deeper dive into the current design choices and tradeoffs.
+
+Note, while LLVM supports vectors of scalable vectors, these are required to be
+fixed-width arrays of 1-D scalable vectors. This means, effectively, that
+scalable vectors with a non-trailing scalable dimension (e.g.
+`vector<4x[8]x128xf32`) are not convertible to LLVM.
+
+Finally, as a brief reminder, MLIR takes similiar view on scalable Vectors as
+LLVM does (c.f. (Vector Type)[https://llvm.org/docs/LangRef.html#vector-type]):
+> The size of a specific scalable vector type is thus constant within IR, even
+> if the exact size in bytes cannot be determined until run time.
+
+Specifically, the size of a scalable vector is not known at compile time, but
+known and fixed at run time
----------------
c-rhodes wrote:

few suggestions
```suggestion
Finally, MLIR takes the same view on scalable Vectors as
LLVM (c.f. (Vector Type)[https://llvm.org/docs/LangRef.html#vector-type]):
> For scalable vectors, the total number of elements is a constant multiple
> (called vscale) of the specified number of elements; vscale is a positive
> integer that is unknown at compile time and the same hardware-dependent
> constant for all scalable vectors at run time.  The size of a specific
> scalable vector type is thus constant within IR, even if the exact size in
> bytes cannot be determined until run time.
```

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


More information about the Mlir-commits mailing list