@@ -2058,39 +2058,52 @@ def Vector_GatherOp :
2058
2058
Results<(outs AnyVectorOfNonZeroRank:$result)> {
2059
2059
2060
2060
let summary = [{
2061
- gathers elements from memory or ranked tensor into a vector as defined by an
2062
- index vector and a mask vector
2061
+ Gathers elements from memory or ranked tensor into a vector as defined by an
2062
+ index vector and a mask vector.
2063
2063
}];
2064
2064
2065
2065
let description = [{
2066
2066
The gather operation returns an n-D vector whose elements are either loaded
2067
- from memory or ranked tensor, or taken from a pass-through vector, depending
2067
+ from a k-D memref or tensor, or taken from an n-D pass-through vector, depending
2068
2068
on the values of an n-D mask vector.
2069
- If a mask bit is set, the corresponding result element is defined by the base
2070
- with indices and the n-D index vector (each index is a 1-D offset on the base).
2071
- Otherwise, the corresponding element is taken from the n-D pass-through vector.
2072
- Informally the semantics are:
2069
+
2070
+ If a mask bit is set, the corresponding result element is taken from `base`
2071
+ at an index defined by k indices and n-D `index_vec`. Otherwise, the element
2072
+ is taken from the pass-through vector. As an example, suppose that `base` is
2073
+ 3-D and the result is 2-D:
2074
+
2075
+ ```mlir
2076
+ func.func @gather_3D_to_2D(
2077
+ %base: memref<?x10x?xf32>, %i0: index, %i1: index, %i2: index,
2078
+ %index_vec: vector<2x3xi32>, %mask: vector<2x3xi1>,
2079
+ %fall_thru: vector<2x3xf32>) -> vector<2x3xf32> {
2080
+ %result = vector.gather %base[%i0, %i1, %i2]
2081
+ [%index_vec], %mask, %fall_thru : [...]
2082
+ return %result : vector<2x3xf32>
2083
+ }
2073
2084
```
2074
- result[0] := if mask[0] then base[index[0]] else pass_thru[0]
2075
- result[1] := if mask[1] then base[index[1]] else pass_thru[1]
2076
- etc.
2085
+
2086
+ The indexing semantics are then,
2087
+
2088
+ ```
2089
+ result[i,j] := if mask[i,j] then base[i0, i1, i2 + index_vec[i,j]]
2090
+ else pass_thru[i,j]
2077
2091
```
2092
+ The index into `base` only varies in the innermost ((k-1)-th) dimension.
2078
2093
2079
2094
If a mask bit is set and the corresponding index is out-of-bounds for the
2080
2095
given base, the behavior is undefined. If a mask bit is not set, the value
2081
2096
comes from the pass-through vector regardless of the index, and the index is
2082
2097
allowed to be out-of-bounds.
2083
2098
2084
- The gather operation can be used directly where applicable, or can be used
2085
- during progressively lowering to bring other memory operations closer to
2086
- hardware ISA support for a gather.
2087
-
2088
2099
Examples:
2089
2100
2090
2101
```mlir
2102
+ // 1-D memref gathered to 2-D vector.
2091
2103
%0 = vector.gather %base[%c0][%v], %mask, %pass_thru
2092
2104
: memref<?xf32>, vector<2x16xi32>, vector<2x16xi1>, vector<2x16xf32> into vector<2x16xf32>
2093
2105
2106
+ // 2-D memref gathered to 1-D vector.
2094
2107
%1 = vector.gather %base[%i, %j][%v], %mask, %pass_thru
2095
2108
: memref<16x16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
2096
2109
```
0 commit comments