Skip to content

Commit 6b431e3

Browse files
committed
add IR snippet for 3-D to 2-D, remove comment about gradual lowering
1 parent 7b9cff1 commit 6b431e3

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,33 +2068,42 @@ def Vector_GatherOp :
20682068
on the values of an n-D mask vector.
20692069

20702070
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. The indexing semantics are then,
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+
}
2084+
```
2085+
2086+
The indexing semantics are then,
20742087

20752088
```
2076-
result[i,j] := if mask[i,j] then
2077-
base[indices[0], indices[1], indices[2] + index_vec[i,j]]
2078-
else
2079-
pass_thru[i,j]
2089+
result[i,j] := if mask[i,j] then base[i0, i1, i2 + index_vec[i,j]]
2090+
else pass_thru[i,j]
20802091
```
2081-
The index into `base` only varies in the dimension k-1.
2092+
The index into `base` only varies in the innermost dimension, k-1.
20822093

20832094
If a mask bit is set and the corresponding index is out-of-bounds for the
20842095
given base, the behavior is undefined. If a mask bit is not set, the value
20852096
comes from the pass-through vector regardless of the index, and the index is
20862097
allowed to be out-of-bounds.
20872098

2088-
The gather operation can be used directly where applicable, or can be used
2089-
during progressive lowering to bring other memory operations closer to hardware
2090-
ISA support for a gather.
2091-
20922099
Examples:
20932100

20942101
```mlir
2102+
// 1-D memref gathered to 2-D vector.
20952103
%0 = vector.gather %base[%c0][%v], %mask, %pass_thru
20962104
: memref<?xf32>, vector<2x16xi32>, vector<2x16xi1>, vector<2x16xf32> into vector<2x16xf32>
20972105

2106+
// 2-D memref gathered to 1-D vector.
20982107
%1 = vector.gather %base[%i, %j][%v], %mask, %pass_thru
20992108
: memref<16x16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
21002109
```

0 commit comments

Comments
 (0)