@@ -74,12 +74,30 @@ following top-down rewrites and conversions:
74
74
### LLVM level
75
75
76
76
On CPU, the ` n-D ` ` vector ` type currently lowers to ` !llvm<array<vector>> ` .
77
- More concretely, ` vector<4x8x128xf32> ` lowers to `!llvm<[ 4 x [ 8 x [ 128 x
78
- float ]]] >`. There are tradeoffs involved related to how one can access
79
- subvectors and how one uses ` llvm.extractelement ` , ` llvm.insertelement ` and
80
- ` llvm.shufflevector ` . The section on [ LLVM Lowering
81
- Tradeoffs] ( #llvm-lowering-tradeoffs ) offers a deeper dive into the current
82
- design choices and tradeoffs.
77
+ More concretely,
78
+ * ` vector<4x8x128xf32> ` lowers to `!llvm<[ 4 x [ 8 x < 128
79
+ x float >]] >` (fixed-width vector), and
80
+ * ` vector<4x8x[128]xf32> ` lowers to `!llvm<[ 4 x [ 8 x < vscale x 128
81
+ x float >]] >` (scalable vector).
82
+
83
+ There are tradeoffs involved related to how one can access subvectors and how
84
+ one uses ` llvm.extractelement ` , ` llvm.insertelement ` and ` llvm.shufflevector ` .
85
+ The section on [ LLVM Lowering Tradeoffs] ( #llvm-lowering-tradeoffs ) offers a
86
+ deeper dive into the current design choices and tradeoffs.
87
+
88
+ Note, while LLVM supports arrarys of scalable vectors, these are required to be
89
+ fixed-width arrays of 1-D scalable vectors. This means scalable vectors with a
90
+ non-trailing scalable dimension (e.g. ` vector<4x[8]x128xf32 ` ) are not
91
+ convertible to LLVM.
92
+
93
+ Finally, MLIR takes the same view on scalable Vectors as LLVM (c.f. (Vector
94
+ Type)[ https://llvm.org/docs/LangRef.html#vector-type ] ):
95
+ > For scalable vectors, the total number of elements is a constant multiple
96
+ > (called vscale) of the specified number of elements; vscale is a positive
97
+ > integer that is unknown at compile time and the same hardware-dependent
98
+ > constant for all scalable vectors at run time. The size of a specific
99
+ > scalable vector type is thus constant within IR, even if the exact size in
100
+ > bytes cannot be determined until run time.
83
101
84
102
### Hardware Vector Ops
85
103
@@ -269,11 +287,6 @@ proposal for now, this assumes LLVM only has built-in support for 1-D vector.
269
287
The relationship with the LLVM Matrix proposal is discussed at the end of this
270
288
document.
271
289
272
- MLIR does not currently support dynamic vector sizes (i.e. SVE style) so the
273
- discussion is limited to static rank and static vector sizes (e.g.
274
- ` vector<4x8x16x32xf32> ` ). This section discusses operations on vectors in LLVM
275
- and MLIR.
276
-
277
290
LLVM instructions are prefixed by the ` llvm. ` dialect prefix (e.g.
278
291
` llvm.insertvalue ` ). Such ops operate exclusively on 1-D vectors and aggregates
279
292
following the [ LLVM LangRef] ( https://llvm.org/docs/LangRef.html ) . MLIR
@@ -287,10 +300,11 @@ Consider a vector of rank n with static sizes `{s_0, ... s_{n-1}}` (i.e. an MLIR
287
300
` vector<s_0x...s_{n-1}xf32> ` ). Lowering such an ` n-D ` MLIR vector type to an
288
301
LLVM descriptor can be done by either:
289
302
290
- 1 . Flattening to a ` 1-D ` vector: ` !llvm<"(s_0*...*s_{n-1})xfloat"> ` in the MLIR
303
+ 1 . Nested aggregate type of ` 1-D ` vector:
304
+ ` !llvm."[s_0x[s_1x[...<s_{n-1}xf32>]]]"> ` in the MLIR LLVM dialect (current
305
+ lowering in MLIR).
306
+ 2 . Flattening to a ` 1-D ` vector: ` !llvm<"(s_0*...*s_{n-1})xfloat"> ` in the MLIR
291
307
LLVM dialect.
292
- 2 . Nested aggregate type of ` 1-D ` vector:
293
- ` !llvm."[s_0x[s_1x[...<s_{n-1}xf32>]]]"> ` in the MLIR LLVM dialect.
294
308
3 . A mix of both.
295
309
296
310
There are multiple tradeoffs involved in choosing one or the other that we
@@ -303,9 +317,11 @@ vector<4x8x16x32xf32> to vector<4x4096xf32>` operation, that flattens the most
303
317
304
318
The first constraint was already mentioned: LLVM only supports ` 1-D ` ` vector `
305
319
types natively. Additional constraints are related to the difference in LLVM
306
- between vector and aggregate types: `“Aggregate Types are a subset of derived
307
- types that can contain multiple member types. Arrays and structs are aggregate
308
- types. Vectors are not considered to be aggregate types.”.`
320
+ between vector and
321
+ [ aggregate types] ( https://llvm.org/docs/LangRef.html#aggregate-types ) :
322
+ > Aggregate Types are a subset of derived types that can contain multiple
323
+ > member types. Arrays and structs are aggregate types. Vectors are not
324
+ > considered to be aggregate types.
309
325
310
326
This distinction is also reflected in some of the operations. For ` 1-D ` vectors,
311
327
the operations ` llvm.extractelement ` , ` llvm.insertelement ` , and
@@ -314,12 +330,15 @@ vectors with `n>1`, and thus aggregate types at LLVM level, the more restrictive
314
330
operations ` llvm.extractvalue ` and ` llvm.insertvalue ` apply, which only accept
315
331
static indices. There is no direct shuffling support for aggregate types.
316
332
317
- The next sentence illustrates a recurrent tradeoff, also found in MLIR, between
333
+ The next sentence (cf. LangRef [ structure
334
+ type] ( https://llvm.org/docs/LangRef.html#structure-type ) ) illustrates a
335
+ recurrent tradeoff, also found in MLIR, between
318
336
“value types” (subject to SSA use-def chains) and “memory types” (subject to
319
- aliasing and side-effects): `“Structures in memory are accessed using ‘load’ and
320
- ‘store’ by getting a pointer to a field with the llvm.getelementptr instruction.
321
- Structures in registers are accessed using the llvm.extractvalue and
322
- llvm.insertvalue instructions.”`
337
+ aliasing and side-effects):
338
+ > Structures in memory are accessed using ‘load’ and ‘store’ by getting a
339
+ > pointer to a field with the llvm.getelementptr instruction. Structures in
340
+ > registers are accessed using the llvm.extractvalue and llvm.insertvalue
341
+ > instructions.
323
342
324
343
When transposing this to MLIR, ` llvm.getelementptr ` works on pointers to ` n-D `
325
344
vectors in memory. For ` n-D ` , vectors values that live in registers we can use
0 commit comments